Neil Munro | 13 Nov 03:03

More pyGTK questions.

Hey, again, have spent most of the day playing around and reading about python and glade and thus far this is what I have, now I have a few issues I have questions about, firstly how do I get the text associated with a toolbar button and change it for example if you notice the 'play' button when this is pressed I wish for the button to be renamed and re-iconed to 'pause' but have no idea how to do this or even if it's possible, I imagine so, but I don't actually know.

Secondly, while I have discovered a way to close a window by essentially crashing it in program what is the safest way to close a gtk window from within python, in my program here I have an about dialog box that opens, but when it closes it either takes the whole application with it (which I quickly corrected) or crashes un-gracefully and while the window appears to close, it's in fact crashed.

If anyone could provide help I'd again, be grateful, obviously I'm just learning the language, and while my method to learn a language may seem odd, I don't tent to learn from reading up on programming languages, I learn by solving problems I come across, and since I'm a 'scratch my own itch' kinda guy I start writing applications to solve problems I have and learn a new language as I go, it's the most effective way for me to learn a new language by drafting an application and building it.

Attachment (RecordStore.py): text/x-python, 3690 bytes
Attachment (musicdb-gui.glade): application/x-glade, 22 KiB
_______________________________________________
pygtk mailing list   pygtk <at> daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/
Frédéric | 13 Nov 08:03

Re: More pyGTK questions.

On jeudi 13 novembre 2008, Neil Munro wrote:

> Hey, again, have spent most of the day playing around and reading about
> python and glade and thus far this is what I have, now I have a few
> issues I have questions about, firstly how do I get the text associated
> with a toolbar button and change it for example if you notice the 'play'
> button when this is pressed I wish for the button to be renamed and
> re-iconed to 'pause' but have no idea how to do this or even if it's
> possible, I imagine so, but I don't actually know.

Just get the name of you menu entry (using wTree.get_widget() method), and 
change its properties. Then see documentation to retreive the properties 
associated with the menu entry.

> Secondly, while I have discovered a way to close a window by essentially
> crashing it in program what is the safest way to close a gtk window from
> within python, in my program here I have an about dialog box that opens,
> but when it closes it either takes the whole application with it (which
> I quickly corrected) or crashes un-gracefully and while the window
> appears to close, it's in fact crashed.

You don't need to bind OK/Cancel dialogs buttons signals; the dialogs will 
be closed as soon as you press OK or Cancel.

Look at my code, for example:

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

I bind signals just to make some special actions before the dialog is 
closed, but I don't cal a quit method.

--

-- 
    Frédéric

    http://www.gbiloba.org
_______________________________________________
pygtk mailing list   pygtk <at> daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Neil Munro | 13 Nov 18:18

Re: More pyGTK questions.



2008/11/13 Frédéric <frederic.mantegazza <at> gbiloba.org>
On jeudi 13 novembre 2008, Neil Munro wrote:

> Hey, again, have spent most of the day playing around and reading about
> python and glade and thus far this is what I have, now I have a few
> issues I have questions about, firstly how do I get the text associated
> with a toolbar button and change it for example if you notice the 'play'
> button when this is pressed I wish for the button to be renamed and
> re-iconed to 'pause' but have no idea how to do this or even if it's
> possible, I imagine so, but I don't actually know.

Just get the name of you menu entry (using wTree.get_widget() method), and
change its properties. Then see documentation to retreive the properties
associated with the menu entry.

> Secondly, while I have discovered a way to close a window by essentially
> crashing it in program what is the safest way to close a gtk window from
> within python, in my program here I have an about dialog box that opens,
> but when it closes it either takes the whole application with it (which
> I quickly corrected) or crashes un-gracefully and while the window
> appears to close, it's in fact crashed.

You don't need to bind OK/Cancel dialogs buttons signals; the dialogs will
be closed as soon as you press OK or Cancel.

Look at my code, for example:

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

I bind signals just to make some special actions before the dialog is
closed, but I don't cal a quit method.

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.

#!/usr/bin/env python

import sys, os, os.path, gtk.glade, pygtk, gtk
pygtk.require( "2.0" )   

def About( obj ):
    wTree = gtk.glade.XML( "musicdb-gui.glade", "dialog1" )
    dic = { "on_BTN_OK_clicked" : About_OK_clicked,
        "on_dialog1_destroy" : Window_Destroyed }
    wTree.signal_autoconnect ( dic )

def About_OK_clicked( obj ):
    ## Button was clicked. ##
    print "0"

def Window_Destroyed( obj ):
    print "Window closed."

That's what I have so far, I moved that into a separate module to easier manage my code base, am gonna look at my other problem once solving this one. To be quite honest I don't see that I am doing anything fundamentally different that prevents my OK button from closing the window :S

Thanks
Niadh
 

--
   Frédéric

   http://www.gbiloba.org
_______________________________________________
pygtk mailing list   pygtk <at> daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

_______________________________________________
pygtk mailing list   pygtk <at> daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/
Frédéric | 13 Nov 18:56

Re: More pyGTK questions.

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?

--

-- 
    Frédéric

    http://www.gbiloba.org
_______________________________________________
pygtk mailing list   pygtk <at> daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Neil Munro | 13 Nov 19:38

Re: More pyGTK questions.



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 :)


--
   Frédéric

   http://www.gbiloba.org
_______________________________________________
pygtk mailing list   pygtk <at> daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Attachment (RecordStore.py): text/x-python, 3684 bytes
Attachment (recordstoreabout.pyc): application/octet-stream, 893 bytes
Attachment (musicdb-gui.glade): application/x-glade, 22 KiB
_______________________________________________
pygtk mailing list   pygtk <at> daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/
Frédéric | 15 Nov 09:21

Re: More pyGTK questions.

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
_______________________________________________
pygtk mailing list   pygtk <at> daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Gmane