|
View:
New views
8 Messages
—
Rating Filter:
Alert me
|
|
|
Modal window and gtk.main()?
I have a problem that I really need some help with. I need to open a new window from my applications main window. This new window need to be modal, I need to be able to get a result from it based on user interaction with it, I need to be able to toggle it between fullscreen and non-fullscreen and I also need it to host a widget without any borders or padding in it.
gtk.Dialog makes it easy to create a window that implements most of the behaviour trough the “run” method. Problem is that I don’t need the separator and the button area. I can hide them but I still en up with a frame or padding between the content areas VBox and the windows borders. I also have to play with the “set_type_hint” method in order for it to accept the “fullscreen” and “unfullscreen” methods. I wanted to take a look at the source for gtk.Dialog to se if I could mimic the “run” method from a gtk.Window but I never found the actual source for gtk.Dialog.run(). I then read about gtk.main() and gtk.main_quit(). And if I understood the documentation, then I am supposed to be able to run gtm.main() in my main window and call it again from my other window, exit this second main loop with gtk.main_quit(). I tried it out and everything seems to work as intended except that I can’t close the main window when I get back from my second gtk.main(). I am running Ubuntu 9.04 and I also install idle hooks trough gobject.idle_add() in both the main window and my other window. I haven’t found one single example of how to open another window from the main window with an additional call to gtk.main() and exit from it using gtk.main_quit(). I would happily use the gtk.Dialog class if there was a simple dialog window without additional widgets that I might not use in my dialog (such as the action and content areas gtk.ButtonBox and gtk.VBox) or windows properties (such as extra decorations, frames, padding etc.) or behaviour (such as not being able to set fullscreen) out of my control (trough obvious class member functions or properties). I personally feel that it would make more sense with a gtk.Dialog class that is just an empty dialog without the content and action area etc. and then a sub-class implementing these additional bells and whistles, but that’s me. Back to my problem, should it be possible to make nested calls to gtk.main() and gtk.main_quit() without any additional calls to prevent side effects (like the main window stop responding to some events)? Note I have no threads of my own running in this application (I use the idle hooks instead of threads). Could gobject.idle_add() and my idle hooks affect the behaviour of nested calls to gtk.main() and gtk.main_quit()? Where can I find examples of how to properly use nested calls to gtk.main() and gtk.main_quit() in order to make a window act as a modal dialog without having to use gtk.Dialog (or how can I make my own tgk.Dialog.run method for a regular gtk.Window)? Is there a way to remove the frame or padding or decoration (or whatever it is) that gtkDialog puts around the content and action area? Where can I find examples of best practise to implement and handle more than one window (more than one gtk.Window, not the use of one gtk.Window and additional windows realized with the use of gtk.Dialog or its sub-classes) in a pygtk application (I can’t find any examples in the documentation, the tutorial or the FAQ, am I missing something obvious here?)? Thankful for any information that can take me further towards a solution to my problem… Regards / Robert _______________________________________________________________ |
|
|
Re: Modal window and gtk.main()?Il giorno gio, 22/10/2009 alle 11.51 -0700, Robert Palmqvist ha scritto:
> I have a problem that I really need some help with. I need to open a > new window from my applications main window. This new window need to > be modal, I need to be able to get a result from it based on user > interaction with it, I need to be able to toggle it between fullscreen > and non-fullscreen and I also need it to host a widget without any > borders or padding in it. > > gtk.Dialog makes it easy to create a window that implements most of > the behaviour trough the “run” method. Problem is that I > don’t need the separator and the button area. I can hide them but > I still en up with a frame or padding between the content areas VBox > and the windows borders. I also have to play with the > “set_type_hint” method in order for it to accept the > “fullscreen” and “unfullscreen” methods. > > I wanted to take a look at the source for gtk.Dialog to se if I could > mimic the “run” method from a gtk.Window but I never found > the actual source for gtk.Dialog.run(). > > I then read about gtk.main() and gtk.main_quit(). And if I understood > the documentation, then I am supposed to be able to run gtm.main() in > my main window and call it again from my other window, exit this > second main loop with gtk.main_quit(). I tried it out and everything > seems to work as intended except that I can’t close the main > window when I get back from my second gtk.main(). I am running Ubuntu > 9.04 and I also install idle hooks trough gobject.idle_add() in both > the main window and my other window. > > I haven’t found one single example of how to open another window > from the main window with an additional call to gtk.main() and exit > from it using gtk.main_quit(). I would happily use the gtk.Dialog > class if there was a simple dialog window without additional widgets > that I might not use in my dialog (such as the action and content > areas gtk.ButtonBox and gtk.VBox) or windows properties (such as extra > decorations, frames, padding etc.) or behaviour (such as not being > able to set fullscreen) out of my control (trough obvious class member > functions or properties). I personally feel that it would make more > sense with a gtk.Dialog class that is just an empty dialog without the > content and action area etc. and then a sub-class implementing these > additional bells and whistles, but that’ > > Back to my problem, should it be possible to make nested calls to > gtk.main() and gtk.main_quit() without any additional calls to prevent > side effects (like the main window stop responding to some events)? > Note I have no threads of my own running in this application (I use > the idle hooks instead of threads). > > Could gobject.idle_add() and my idle hooks affect the behaviour of > nested calls to gtk.main() and gtk.main_quit()? > > Where can I find examples of how to properly use nested calls to > gtk.main() and gtk.main_quit() in order to make a window act as a > modal dialog without having to use gtk.Dialog (or how can I make my > own tgk.Dialog.run method for a regular gtk.Window)? > > Is there a way to remove the frame or padding or decoration (or > whatever it is) that gtkDialog puts around the content and action > area? > > Where can I find examples of best practise to implement and handle > more than one window (more than one gtk.Window, not the use of one > gtk.Window and additional windows realized with the use of gtk.Dialog > or its sub-classes) in a pygtk application (I can’t find any > examples in the documentation, the tutorial or the FAQ, am I missing > something obvious here?)? > > Thankful for any information that can take me further towards a > solution to my problem… > > Regards / Robert > > > > _______________________________________________________________ > Nu kan du vinna riktigt mycket i Betssons Casino! > > _______________________________________________ > pygtk mailing list pygtk@... > http://www.daa.com.au/mailman/listinfo/pygtk > Read the PyGTK FAQ: http://faq.pygtk.org/ Ehm... sorry if my question is very stupid, but it is a risk I want to take: before playing with main loops, did you take a look at gtk.Window.set_modal ? Pietro _______________________________________________ pygtk mailing list pygtk@... http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/ |
|
|
Re: Modal window and gtk.main()?Robert Palmqvist schrieb:
> I wanted to take a look at the source for gtk.Dialog to se if I could > mimic the “run” method from a gtk.Window but I never found the actual > source for gtk.Dialog.run(). The source is here: http://git.gnome.org/cgit/gtk+/tree/gtk/gtkdialog.c#n993 > Where can I find examples of best practise to implement and handle more > than one window (more than one gtk.Window, not the use of one > gtk.Window and additional windows realized with the use of gtk.Dialog or > its sub-classes) in a pygtk application (I can’t find any examples in > the documentation, the tutorial or the FAQ, am I missing something > obvious here?)? Example: -----------------------8<----------------------- import gtk 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) 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 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) def run (self): self.w.show_all () gtk.main () def show_second_win (self, button, w): w.show () w = MainWin () w.run () ----------------------->8----------------------- HTH. _______________________________________________ pygtk mailing list pygtk@... http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/ |
|
|
Re: Modal window and gtk.main()?On 10/22/09, Pietro Battiston <toobaz@...> wrote:
> Ehm... sorry if my question is very stupid, but it is a risk I want to > take: before playing with main loops, did you take a look at > gtk.Window.set_modal ? > > Pietro > The question is not stupid at all. Yes I took a look at gtk.Window.set_modal and I played around with it but it didn't seem to be the root cause of my problem. _______________________________________________ pygtk mailing list pygtk@... http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/ |
|
|
Re: Modal window and gtk.main()?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). 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()... 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) 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) 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) 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<----------------------- On Thu, Oct 22, 2009 at 5:13 PM, Christian Becke <christianbecke@...> wrote: Robert Palmqvist schrieb: _______________________________________________ pygtk mailing list pygtk@... http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/ |
|
|
|
|
|
Re: Modal window and gtk.main()?I use the idle_add to do background work on idle time in both windows (one is loading files from a queue, files are added to that queue on and drag and drop. The other windows is preloading files if there is anything to preload in its queue and so on... It works really well.
I use nested calls to gtk.main() but the problem was my use of gtk.main_iteration. It was a rest from a previous solution and I don't really need it anymore. I just cut-and-pasted it from the FAQ when I needed a way to force update of some widgets. But it can be done in a better way if a utilize the idle hooks a bit differently. The root cause of my problem became quite obvious when I added my code to your simple example. I shared it becuase someone else might run into the same problem. I just had to remove gtk.main_iteration from my idle hooks to make nested calls to gtk.main work as intended. Thanks a lot for your help. On Fri, Oct 23, 2009 at 6:03 AM, Christian Becke <christianbecke@...> wrote: Robert Palmqvist schrieb: _______________________________________________ pygtk mailing list pygtk@... http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/ |
|
|
Re: Modal window and gtk.main()?> > Where can I find examples of how to properly use nested calls to > gtk.main() and gtk.main_quit() in order to make a window act as a > modal dialog without having to use gtk.Dialog (or how can I make my > own tgk.Dialog.run method for a regular gtk.Window)? gtk.Widget.grab_add ? John _______________________________________________ pygtk mailing list pygtk@... http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/ |
| Free embeddable forum powered by Nabble | Forum Help |