On Sat, Jun 22, 2002 at 03:41:53PM -0400, Gary Jaffe wrote:
> 
> One of the things I love about Python is the ability to create a new class and 
> with just a few lines of test code, use it either as a stand alone program or 
> as something imported into another program.  I am having trouble doing that 
> with pygtk.

This works fine with pygtk, you just have to be a bit more careful, as
always when dealing with mainloops.

> close.  I use mainloop() to get things running and mainquit() to close the 
> window.

This should work fine.

> The first is that when the window created by the acct class closes by calling 
> its mainquit(), the window from the calling program closes and the calling 
> program terminates also.  I tried using hide() on the window from the acct 
> class.  This apparently works OK when it is imported into another program but 
> when run as a stand alone program, I have to kill the python process to get 
> it to terminate.  The gtk docs from 

Are you calling mainquit from the OK handler? The handlers should be
something like this:

    def ok_clicked (self, button):
        self.retvalue = 1 
        self.hide () 
        gtk.mainquit ()
        
    def cancel_clicked (self, button):
        self.retvalue = 0
        self.hide ()
                      
    def run (self):
        self.win.set_transient_for(self.parent.win) 
        self.show ()
        gtk.mainloop ()
        return self.retvalue

> http://developer.gnome.org/doc/API/2.0/gtk/gtk-general.html#gtk-main-quit 
> indicates that main() / mainquit() can be nested.  Is this not true for 
> pygtk?

It works fine for gtk1, and I'm quite sure it does for gtk2.

> The second problem is letting the calling program know when the window from 
> the acct class closes so that it can do something with self.acct.
> 
> Am I going about this the wrong way?  I would like to keep the acct class 
> separate from the calling class as I can use the acct class in many other 
> programs.  I hope I haven't confused everyone as much as apparently I am 
> confused.

Heh. You need to run the app as if it was a dialog:

def call_acct(self, *args):
    a = Acct()   
    acct = a.run()
    print "My account is %s" % acct

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to