Hi all

I have just started out with Python, and am playing around a bit with
pygtk and libglade. I have some experience with structured programming,
but this is my first encounter with object-oriented programming.

I am trying to create a generic function for a Yes/No type dialog box,
but the code seems a bit "clunky" - would anyone care to look at it and
give me some pointers to how this could be done in a sexier fashion?

Also; I seem to be having some problems when the function is called the
second time around; Python gives this error:

  File "main.py", line 142, in dialog_yesno
    label.set_text(text)
AttributeError: 'NoneType' object has no attribute 'set_text'

Any ideas?


Here is the code for my dialog function :


def dialog_yesno(text):
        "Displays a yes/no dialog, returns true on yes, false on no"
        global xml, status

        def yes(obj):
                global status
                status = 1
                print "yes"
                window_yesno.destroy()
                gtk.mainquit()

        def no(obj):
                global status
                status = 0
                print "no"
                window_yesno.destroy()
                gtk.mainquit()

        def destroy(obj):
                obj.destroy()
                gtk.mainquit()


        # get pointers to relevant widgets
        window_yesno = xml.get_widget("window_yesnodialog")
        label = xml.get_widget("yesno_text")
        yesbutton = xml.get_widget("yesno_yes")
        nobutton = xml.get_widget("yesno_no")

        # set the dialog window label
        label.set_text(text)

        # default status is false
        status = 0

        # map signals
        yesbutton.connect("clicked", yes)
        nobutton.connect("clicked", no)
        window_yesno.connect("destroy", destroy)

        # Show the window
        window_yesno.show()

        gtk.mainloop()

        # Return our value
        return status



-- 

Erik Grinaker
Freelance UNIX/Linux systems consultant

"Perfection is acheived not when there is nothing more to add, but
rather when there is nothing more to take away"
- Antoine de Saint-Exup�ry


_______________________________________________
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