Frage

I'm writing an application in GTK2 (technically pyGTK) and will be performing some long operations.

If I perform the long operation in the main thread (which isn't a good idea), the application will become unresponsive.

The desirable portion of this is the part that prevents the user from modifying the text-entry widgets, but the undesirable portion is that the window won't repaint itself.

Is there another way to do this?

War es hilfreich?

Lösung

If the GUI does not need user interaction during the expensive process then there's no reason it can't be in the main thread. You can still update the UI (repaint, handle moving/sizing the window, etc.) manually in your loop

  1. Disable the widget by setting it's "sensitive" property to False. widget.set_sensitive(False)
  2. During each iteration (or every n iteraions) of your processing loop, update the UI with: while gtk.events_pending(): gtk.main_iteration().

If you are going to use threads, the comment from ergosys with the link to the PyGTK F.A.Q. should help. You should also read Threads in the GTK+ Reference Documentation.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top