Robert Palmqvist schrieb:
> Thanks a lot for your simple example Christian. It works like a charm
> and it also made it easy to reproduce my issue. Take a look at the
> additions I made to your code. I added an idle hook to each of the
> windows and the code now behave like my application (show the second
> window and you can't use the button to close the first one anymore,
> you can kill it by closing it by the window manager but it will leave
> the interpreter hanging).
What exactly are you trying to achieve with the idle_add?
If I understood you correctly, you want to show a secondary window, and
inhibit interaction with the main window as long as the secondary window
is shown, right? If this is the case, there is no need for the idle_add.
If you want to allow interaction with the main window while the
secondary window is shown, just skip the call to window.set_modal.
> So what have I done wrong? Setting idle
> hooks in combination with nested gtk.main() or is it because i call
> gtk.events_pending() and gtk.main_iteration(False) in the idle hooks?
> I don't know if I am supposed to be able to call gtk.events_pending()
> or gtk.main_iteration(False) in an idle hook but it worked until I
> started to use a nested gtk.main()...
You are not using a nested gtk.main. You'd have to call gtk.main a
second time for that.
You are misusing gtk.main_iteration. It is intended for integrating a
gtk mainloop into another mainloop, or stepping through the gtk mainloop
while there is no gtk mainloop running. Just don't call
gtk.main_iteration while there is a gtk mainloop running.
>
> Example:
> -----------------------8<-----------------------
> import gtk, gobject
>
> class SecondWin:
>
> def __init__ (self, parent):
> self.parent = parent
> self.w = gtk.Window ()
>
> # Disable interaction with parent
> self.w.set_modal (True)
>
> # Tell WM this is a dialog
> self.w.set_type_hint (gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
>
> # Tell WM this window belongs to parent
> self.w.set_transient_for (parent)
> self.w.connect ("delete-event", self.hide)
>
> box = gtk.VButtonBox ()
> self.w.add (box)
>
> b = gtk.Button (stock=gtk.STOCK_CLOSE)
> b.connect ("clicked", self.hide)
> box.add (b)
> gobject.idle_add(self.on_idle)
>
>
> def show (self):
> self.w.show_all ()
> # Indicate visually that interaction with parent
> # is not possible while we are shown
> self.parent.set_sensitive (False)
>
> def on_idle(self):
> while gtk.events_pending():
> gtk.main_iteration(False)
> return True
>
> def hide (self, *args):
> # Indicate visually that interaction with parent
> # is possible again
> self.parent.set_sensitive (True)
> self.w.hide ()
> return True
>
>
> class MainWin:
>
> def __init__ (self):
> self.w = gtk.Window ()
> self.w.set_position (gtk.WIN_POS_CENTER)
> self.w.connect ("delete-event", gtk.main_quit)
>
> box = gtk.VButtonBox ()
> self.w.add (box)
>
> self.sw = SecondWin (self.w)
>
> b = gtk.Button ("show second win")
> b.connect ("clicked", self.show_second_win, self.sw)
> box.pack_start (b, False)
>
> b = gtk.Button (stock=gtk.STOCK_QUIT)
> b.connect ("clicked", gtk.main_quit)
> box.pack_start (b, False)
> gobject.idle_add(self.on_idle)
>
> def on_idle(self):
> while gtk.events_pending():
> gtk.main_iteration(False)
> return True
>
> def run (self):
> self.w.show_all ()
> gtk.main ()
>
>
> def show_second_win (self, button, w):
> w.show ()
>
> w = MainWin ()
> w.run ()
> -----------------------8<-----------------------
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/