I apologize for reposting this....I just never received an answer from the pythonlist(which makes sense, since It was intended for pygtk list )<br><br>Please, how to make shmingleton show contents again when re-opening window(hide(), then show() or show_all()) without recreating it?<br>
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?<br><br>There seems to be not alot of content on this subject on the net. <br clear="all">
<br><div class="gmail_quote"><div><div class="h5"><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>I am trying to create a singleton window in pygtk and for the life of me can&#39;t seem to figure out a better way to go about doing this. The way I&#39;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&#39;ve googled to no avail. I&#39;m hiding the child window because when I execute main_quit on the child it kills parent (which makes sense).<br>


<br>My singleton hack works, but its cluncky, I am wondering if theres some other way(working shmingleton?).<br><br>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? <br>


<br>Thank you.<br><br>#!/usr/bin/env python<br>import os, sys<br><br>import pygtk<br>pygtk.require(&#39;2.0&#39;)<br>try:<br>  import gtk<br>except:<br>  print &gt;&gt; sys.stderr, &quot;You need to install the python gtk bindings&quot;<br>


  sys.exit(1)<br><br><br><br>class Singleton_Test(object):<br>  def __init__(self):<br>    self.root_window = gtk.Window( type=gtk.WINDOW_TOPLEVEL )<br>    self.root_window.set_title(&quot;Singleton Test&quot;)<br>    self.root_window.connect(&quot;delete_event&quot;, lambda w,e: gtk.main_quit())<br>


<br>    self.vbox = gtk.VBox(False,0)<br>    self.root_window.add(self.vbox)<br>    self.vbox.show()<br><br>    self.singleton_button = gtk.Button(&quot;SINGLETON&quot;)<br>    self.singleton_button.connect(&quot;clicked&quot;,self.singleton_cb)<br>


    self.vbox.pack_start(self.singleton_button,False,False,0)<br><br>    self.singleton_button.show()<br><br>    self.shmingleton_button = gtk.Button(&quot;SHMINGLETON&quot;)<br>    self.shmingleton_button.connect(&quot;clicked&quot;,self.shmingleton_cb)<br>


    self.vbox.pack_start(self.shmingleton_button,False,False,0)<br><br>    self.shmingleton_button.show()<br><br>    self.create_singleton_child_window()<br><br>    self.root_window.show()<br><br>  singleton_window_count=0<br>


  def singleton_cb(self,w):<br>    if self.singleton_window_count&gt;0:<br>      self.create_singleton_child_window()<br><br>    self.singleton_child_window.show()<br>    print &quot;singleton child window count is &quot;,self.singleton_window_count<br>


    self.singleton_window_count+=1<br><br>  def shmingleton_cb(self,w):<br>    self.singleton_child_window.show_all() #doesn&#39;t work as expected, neither does show<br><br><br>  def create_singleton_child_window(self):<br>


    self.singleton_child_window = gtk.Window(gtk.WINDOW_TOPLEVEL)<br>    self.singleton_child_window.set_title(&quot;SINGLETON child&quot;)<br>    <br>    #only hiding since gtk.main_quit kills parent, any better way?<br>


    self.singleton_child_window.connect(&quot;destroy&quot;, lambda w: self.singleton_child_window.hide()) #or destroy()<br>    self.singleton_child_window.connect(&quot;delete_event&quot;, lambda w,e: self.singleton_child_window.hide()) #or destroy()<br>


<br>    self.vbox = gtk.VBox(False, 0)<br>    self.singleton_child_window.add(self.vbox)<br>    self.vbox.show()<br>    self.label = gtk.Label(&quot;SINGLETON&quot;)<br>    self.vbox.pack_start(self.label,False,False,0)<br>


    self.label.show()<br>  <br>  def main(self):<br>    gtk.main()<br><br>if __name__ == &quot;__main__&quot;:<br>  singleton = Singleton_Test()<br>  singleton.main()<br><font color="#888888"><br clear="all">-Alex Goretoy<br>

<a href="http://www.goretoy.com" target="_blank">http://www.goretoy.com</a><br>
<br>
</font></blockquote></div><br>
</div></div></div><br>