Naib
Naib

Reputation: 1029

Generating dialog from a separate thread

I have almost completed converting a pyGTK application to pyQT4. One of the last aspects I am struggling with is generating a dialog from a separate thread.

I have a main GUI and a background thread. On the offchance of thread-specific issues, the thread generates a dialog.

For pyGTK what I do is:

  def update_gui(function, *args, **kargs):
      '''DocString'''
      def idle_func():
          '''DocString'''
          Gdk.threads_enter()
          try:
            function(*args, **kargs)
          finally:
              Gdk.threads_leave()
      GObject.idle_add(idle_func)


  def gui_error(msg):
      '''Simple wrapper for a warning dialog'''
      md = Gtk.MessageDialog(parent=None, message_type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.CLOSE)
      md.set_markup(msg)
      md.run()
      md.destroy()

Called as: update_gui(gui_error,'help')

Is there an equivelent in pyQT4 or do I need to gut what I have to start passing signals?

Upvotes: 0

Views: 79

Answers (1)

zmo
zmo

Reputation: 24812

do I need to gut what I have to start passing signals?

yes you do.

You can always have your "other thread" be QObject based and have a QObject from QApplication's children based object as parent, and call the moveToThread() method but it's better to have the main thread handle GUI, and other threads send signals to the main thread to have it updated.

Take the opportunity of moving from GTK to QT, to actually redesign correctly your application, with real decoupling between the main components of your software.

Upvotes: 1

Related Questions