On Mon, 2002-06-03 at 11:14, Christian Reis wrote: > On Fri, May 31, 2002 at 09:30:09AM -0400, Steve McClure wrote: > > On Fri, 2002-05-31 at 08:52, Collins wrote: > > > I'm using a clist as a display window for background tasks. While the > > > task is running, output is captured (compiles, for example) and > > > written to a temporary file and the output is also written to the > > > screen (when over 30 lines, row zero is removed before inserting new > > > data at the bottom. > > > > > > Unfortunately, the data only appears after all is said and done (the > > > command has run to completion). How can I make the data appear as it > > > is added to the clist? Once full, the clist should appear as a > > > continuously scrolling window with new data appearing at the bottom > > > and old data removed at the top. > > > > After you add the data to the CList try something like: > > > > while gtk.events_pending(): > > gtk.mainiteration(gtk.FALSE) > > Added faq item 3.7: > > http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq03.007.htp
The description sounds good. I have tried some solutions to deal with the last sentence in the entry: === Of course, if your callback has a single instruction that takes a long time to process, this isn't an option. There is no easy alternative to solve this problem, as far as I can see. === I have used a thread to run the long task. It works pretty well but you have to be very careful about the timing so that mainiteration and/or mainloop don't get called from two seperate threads. I attached a code snippet since I can't figure out how to get the Evolution email composer to not wrap. My code snippet is pretty much geared for my use, but you might find some of the concepts useful. For example, all the long running tasks can interact with a UserInterfaceCallBack class that allows some passing of status messages to the caller. > > Take care, > -- > Christian Reis, Senior Engineer, Async Open Source, Brazil. > http://async.com.br/~kiko/ | [+55 16] 272 3330 | NMFL > _______________________________________________ > pygtk mailing list [EMAIL PROTECTED] > http://www.daa.com.au/mailman/listinfo/pygtk > Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/ -- Steve McClure 430 10th St NW Racemi Suite N-210 http://www.racemi.com Atlanta, GA 30318 [EMAIL PROTECTED] voice/fax: 404-892-5850
busyDialog = myappWorkingDialog()
busyDialog.startProgressIndicator()
args = (<somemodule>, <method_name>, x, y, z)
waitForThreadedCommand(busyDialog, args)
busyDialog.stopProgressIndicator()
class myappWorkingDialog(GtkExtra._MessageBox):
#... (lots of stuff not shown)
def startProgressIndicator(self)
self.show()
self.progressTimerId = gtk.timeout_add(100, self.updateProgress)
def updateProgress(self, val = None)
if self.activity_mode:
val = bar.get_value() + 1
# all that has to happen is to make a change to
# the value and the bar does the rest.
if val > 100:
val = 0
bar.set_value(val)
else: # download mode
pct = <some value, in my case, from the long running
task itself>
bar.update(pct)
def stopProgressIndicator(self):
''' Call this when the work is completed, it stops the auto
update
and hides the dialog.
'''
if self.progressTimerId:
gtk.timeout_remove(self.progressTimerId)
self.progressTimerId = None
# sometimes this is associated to a thread so let's check and
wait
# until the thread goes away. That way the buggy gtk code
doesn't
# have two "mainloop" excutions.
try:
while (self.threadID):
pass
except AttributeError:
# the two thread mechanisms aren't totally compatible,
one
# doesn't keep the thread id around at all so don't
worry
# about it.
pass
# let's use a delay so that it doesn't get confused when the
busy
# task doesn't take very long.
gtk.timeout_add(1000, self._delayHideDialog, self)
class myappComponentBaseClass():
def waitForThreadedCommand(self, dialog, args):
threadKey = time.asctime()
args = (threadKey,) + args
thread.start_new_thread(self.threadedExecution, args)
# stuff to retrieve messages from task thread and display them in
# the working dialog
drainEventQueue() #this is just the code block listed in faq
item 3.7
# in case of an exception, the thread will save the type and data
# in a tuple in the dictionary.
retval = self.threads[threadKey]
if type(retval) == type(()):
# Even if the thing that is executed returns a tuple, this
should
# catch all exceptions.
if issubclass(retval[0], Exception):
del self.threads[threadKey]
raise retval[0], retval[1]
del self.threads[threadKey]
return retval
signature.asc
Description: This is a digitally signed message part
