[pygtk] More pyGTK questions.

Frédéric frederic.mantegazza at gbiloba.org
Sat Nov 15 17:21:20 WST 2008


On jeudi 13 novembre 2008, Neil Munro wrote:

> 2008/11/13 Frédéric <frederic.mantegazza at gbiloba.org>
>
> > On jeudi 13 novembre 2008, Neil Munro wrote:
> > > I've gotten rid of the quit methods etc since I don't need them but
> > > every time I hit my ok button (which should just close the about
> > > window) does nothing except the code that acknowledges something
> > > happens.
> >
> > Could you provide the complete code and glade file?
>
> I have attached the files :)

Ok, I found you problem: you never call the dialog1 destroy() method, so it 
remains on the screen.

Your design uses functions, and you don't have any reference on the dialog1 
widget; so you can't call the destroy() method. I suggest you use objects, 
instead of functions (see below).

As a quick hack, just add a callback in GUI to handle the help > about 
menu, like others. In this callback, you can just do:
    
    def About(self, obj):
        wTree = gtk.glade.XML( "musicdb-gui.glade", "dialog1" )
        dialog = wTree.get_widget('dialog1')
        dialog.run()
        dialog.destroy()

Calling the run() method launchs the event loop for the dialog, so that it 
becomes modal (you can't do anything else until you close it). When the 
dialog is closed (hitting the OK button, or the X window button), the 
run() ends, and the destroy() method is called.

If you want to add callbacks, I suggest you move the entire About() code in 
a separate object, so called a controller. There, you will have the same 
structure than your main controller (GUI class), with its own callbacks, 
and so.

Have a look at:

http://trac.gbiloba.org/papywizard/browser/trunk/papywizard/controller/abstractController.py

and

http://trac.gbiloba.org/papywizard/browser/trunk/papywizard/controller/helpAboutController.py

The AbstractController handles all common things to do when I need to open 
a new modal dialog. HelpAboutController inherits it. This controller is 
called from:

http://trac.gbiloba.org/papywizard/browser/trunk/papywizard/controller/mainController.py

see lines 112 and 535.

Also note that there is a special widget for About dialogs:

    http://www.pygtk.org/docs/pygtk/class-gtkaboutdialog.html

If you code grows, I also suggest you separate the gui in several glade 
files, one for each dialog, like you will do for controllers.

Hope this helps ;o)

-- 
    Frédéric

    http://www.gbiloba.org


More information about the pygtk mailing list