Chris Lambacher wrote:

[snip] ...updating the UI from one thread.  It means
that you have to push some data over to the UI thread, but you do get
rid of all of your nasty threads_enter, threads_leave conditions.

In the case above I would define run something like:
    def run(self):
     while not self.is_canceled:
       calculate_step()
       data = collect_data_for_ui()
       gtk.gdk.threads_enter()
       gobject.idle_add(update_ui, data)
       gtk.gdk.threads_leave()

    def update_ui(data):
         #perform ui updating here
return False

Apparently you do not need the threads_enter/threads_leave pair around
the idle_add call.  I always put it in because it has never broken
anything and I don't want to mess with success.

You're right, you don't need to enter/leave calls around gobject.idle_add. But you *do* need them inside the update_ui method. I would use something like this:

  class Buzy(Threading):
      def run(self):
          while not self.is_canceled:
              calculate_step()
              data = collect_data_for_ui()
              gobject.idle_add(self._update_ui, data)

      def _update_ui(self, data):
          gtk.threads_enter()
          try:
              #perform ui updating here
              return False
          finally:
              gtk.threads_leave()

--
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to