[pygtk] [PyGTK] Singleton Window
Steve McClure
smcclure at racemi.com
Mon Mar 16 22:19:56 WST 2009
On Mar 7, 2009, at 1:22 PM, alex goretoy wrote:
> I apologize for reposting this....I just never received an answer
> from the pythonlist(which makes sense, since It was intended for
> pygtk list )
>
> Please, how to make shmingleton show contents again when re-opening
> window(hide(), then show() or show_all()) without recreating it?
> does GC run on the destroyed object if I destroy() the window? If
> so , then that means I have to recreate it and my options are to
> hide() then show(), but how to get contents back?
>
> There seems to be not alot of content on this subject on the net.
I use a delete handler that calls hide then returns True. That way the
widget isn't destroyed and I can then just call show when the dialog
needed to be displayed again.
>
>
> I am trying to create a singleton window in pygtk and for the life
> of me can't seem to figure out a better way to go about doing this.
> The way I'm doing it now is to recreate the window and show it.
> Example code is below. I would much appreciate any assistance in
> this matter. I've googled to no avail. I'm hiding the child window
> because when I execute main_quit on the child it kills parent (which
> makes sense).
>
> My singleton hack works, but its cluncky, I am wondering if theres
> some other way(working shmingleton?).
>
> My question is this. How to create a singleton child window without
> hiding old childs(seeing as this creates many hidden childs after a
> while) or how to hide it and when showing it again also have it
> display all contents in the child window?
>
> Thank you.
>
> #!/usr/bin/env python
> import os, sys
>
> import pygtk
> pygtk.require('2.0')
> try:
> import gtk
> except:
> print >> sys.stderr, "You need to install the python gtk bindings"
> sys.exit(1)
>
>
>
> class Singleton_Test(object):
> def __init__(self):
> self.root_window = gtk.Window( type=gtk.WINDOW_TOPLEVEL )
> self.root_window.set_title("Singleton Test")
> self.root_window.connect("delete_event", lambda w,e:
> gtk.main_quit())
>
> self.vbox = gtk.VBox(False,0)
> self.root_window.add(self.vbox)
> self.vbox.show()
>
> self.singleton_button = gtk.Button("SINGLETON")
> self.singleton_button.connect("clicked",self.singleton_cb)
> self.vbox.pack_start(self.singleton_button,False,False,0)
>
> self.singleton_button.show()
>
> self.shmingleton_button = gtk.Button("SHMINGLETON")
> self.shmingleton_button.connect("clicked",self.shmingleton_cb)
> self.vbox.pack_start(self.shmingleton_button,False,False,0)
>
> self.shmingleton_button.show()
>
> self.create_singleton_child_window()
>
> self.root_window.show()
>
> singleton_window_count=0
> def singleton_cb(self,w):
> if self.singleton_window_count>0:
> self.create_singleton_child_window()
>
> self.singleton_child_window.show()
> print "singleton child window count is
> ",self.singleton_window_count
> self.singleton_window_count+=1
>
> def shmingleton_cb(self,w):
> self.singleton_child_window.show_all() #doesn't work as
> expected, neither does show
>
>
> def create_singleton_child_window(self):
> self.singleton_child_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
> self.singleton_child_window.set_title("SINGLETON child")
>
> #only hiding since gtk.main_quit kills parent, any better way?
> self.singleton_child_window.connect("destroy", lambda w:
> self.singleton_child_window.hide()) #or destroy()
> self.singleton_child_window.connect("delete_event", lambda w,e:
> self.singleton_child_window.hide()) #or destroy()
>
> self.vbox = gtk.VBox(False, 0)
> self.singleton_child_window.add(self.vbox)
> self.vbox.show()
> self.label = gtk.Label("SINGLETON")
> self.vbox.pack_start(self.label,False,False,0)
> self.label.show()
>
> def main(self):
> gtk.main()
>
> if __name__ == "__main__":
> singleton = Singleton_Test()
> singleton.main()
>
> -Alex Goretoy
> http://www.goretoy.com
>
>
>
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
--
Steve McClure
smcclure at racemi.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20090316/e02f35f5/attachment.htm
More information about the pygtk
mailing list