Need guidelines to show results of a process

V

Vizcayno

Hi:
I wrote a Python program which, during execution, shows me messages on
console indicating at every moment the time and steps being performed
so I can have a 'log online' and guess remaining time for termination,
I used many 'print' instructions to show those messages, i.e. print
"I am in step 4 at "+giveTime() .... print "I am in step 5 at
"+giveTime(), etc.
Now I need to execute the same program but from a GUI application. I
must show the same messages but on a "text field".
As you can guess, it implies the changing of my program or make a copy
and replace the print instructions by textField += "I am in step 4
at "+giveTime() then textField += "I am in step 5 at "+giveTime(),
etc.
I wanted to do the next:
if output == "GUI":
textField += "I am in step 4 at "+giveTime()
force_output()
else:
print "I am in step 4 at "+giveTime()
But it is not smart, elegant, clean ... isn't it?
Any ideas please?
Regards.
 
M

Mensanator

Hi:
I wrote a Python program which, during execution, shows me messages on
console indicating at every moment the time and steps being performed
so I can have a 'log online' and guess remaining time for termination,
I used many 'print' instructions to show those messages, i.e.  print
"I am in step 4 at "+giveTime() .... print "I am in step 5 at
"+giveTime(), etc.
Now I need to execute the same program but from a GUI application. I
must show the same messages but on a "text field".
As you can guess, it implies the changing of my program or make a copy
and replace the print instructions by   textField += "I am in step 4
at "+giveTime() then textField += "I am in step 5 at "+giveTime(),
etc.
I wanted to do the next:
if output == "GUI":
    textField += "I am in step 4 at "+giveTime()
    force_output()
else:
    print "I am in step 4 at "+giveTime()
But it is not smart, elegant, clean ... isn't it?

Oh, then you want one of those elegant progress meters.
You know, where the tenth box accounts for 90% of the elapsed time.

Elegant isn't necessarily smart.
Any ideas please?

It looks good to me, only I would use elapsed time instead of clock
time.
Something along the lines of "Step 4 completed in",t1-t0,"seconds."
 
M

MRAB

Vizcayno said:
Hi:
I wrote a Python program which, during execution, shows me messages on
console indicating at every moment the time and steps being performed
so I can have a 'log online' and guess remaining time for termination,
I used many 'print' instructions to show those messages, i.e. print
"I am in step 4 at "+giveTime() .... print "I am in step 5 at
"+giveTime(), etc.
Now I need to execute the same program but from a GUI application. I
must show the same messages but on a "text field".
As you can guess, it implies the changing of my program or make a copy
and replace the print instructions by textField += "I am in step 4
at "+giveTime() then textField += "I am in step 5 at "+giveTime(),
etc.
I wanted to do the next:
if output == "GUI":
textField += "I am in step 4 at "+giveTime()
force_output()
else:
print "I am in step 4 at "+giveTime()
But it is not smart, elegant, clean ... isn't it?
Any ideas please?
Regards.
At the very least you could put the reporting into a function:

def report(message):
if output == "GUI":
textField += message
force_output()
else:
print message

...
report("I am in step 4 at " + giveTime())
 
B

bieffe62

Hi:
I wrote a Python program which, during execution, shows me messages on
console indicating at every moment the time and steps being performed
so I can have a 'log online' and guess remaining time for termination,
I used many 'print' instructions to show those messages, i.e.  print
"I am in step 4 at "+giveTime() .... print "I am in step 5 at
"+giveTime(), etc.
Now I need to execute the same program but from a GUI application. I
must show the same messages but on a "text field".
As you can guess, it implies the changing of my program or make a copy
and replace the print instructions by   textField += "I am in step 4
at "+giveTime() then textField += "I am in step 5 at "+giveTime(),
etc.
I wanted to do the next:
if output == "GUI":
    textField += "I am in step 4 at "+giveTime()
    force_output()
else:
    print "I am in step 4 at "+giveTime()
But it is not smart, elegant, clean ... isn't it?
Any ideas please?
Regards.

If you have many sparse print and you don't want to change all by
hand,
you can try redirecting sys.stdout (and maybe sys.stderr) to something
that collects the output and make it available for display however you
like it. The only requirement is that your sys.output replacement
shall
have a 'write' method wich accept a string parameter.
I did it once I needed to quickly add a GUI (Tkinter) to a console-
based
program, and it worked well.

IIRC the wxPython toolkit does that by default, unless you tell it
differently,
and displays any output/error in a default dialog window.

Ciao
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top