[Python+glade] why need two arguments?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • holmes86
    New Member
    • Aug 2009
    • 5

    [Python+glade] why need two arguments?

    hi,everyone.

    I am a python newbie.and I write a python program with glade,as following:
    Code:
    import sys
    import gtk
    import gtk.glade
    
    class TLaitSignals:
        '''Define TLait singals handler'''
        def test(self):
            return self.signals_dict
        def on_BtnBack_clicked(self):
            gtk.main_quit()
        def on_BtnForward_clicked(self):
            pass
        def gtk_widget_destroy(self):
            gtk.main_quit()
            #sys.exit(0)
        def __init__(self):
            self.signals_dict = {"gtk_widget_destroy" : self.gtk_widget_destroy,}
    
    if __name__ == "__main__":
        gladexml = gtk.glade.XML("ui/TLait-first.glade")
        gladexml.signal_autoconnect(TLaitSignals().test())
        mainWin = gladexml.get_widget("tlait_selectAppVer")
        mainWin.set_default_size(800,600)
        mainWin.show()
        gtk.main()
    when I clicked close button,it report "TypeError: gtk_widget_dest roy() takes exactly 1 argument (2 given)" info.

    if I add any argument to gtk_widget_dest roy() ,for example:
    def gtk_widget_dest roy(self,sfsadf sadfs):
    then it will execute successful. So I don't why need two arguments,where define to need two arguments?
    thanks very much!
  • micmast
    New Member
    • Mar 2008
    • 144

    #2
    usually the second argument is the widget that did the original call. You could play with the second argument, print it, and view what is in it.

    Comment

    • holmes86
      New Member
      • Aug 2009
      • 5

      #3
      micmast,thanks for your reply.
      I print it,as following:
      <gtk.Dialog object at 0xa0a2dc4 (GtkDialog at 0xa158860)>

      but I can't find any define of about gtk.Dialog class, any help will be appreciate.

      Comment

      • Hackworth
        New Member
        • Aug 2009
        • 13

        #4
        I'm not entirely sure about this as I am a wx user not a gtk user, however, it looks as though gtk_widget_dest roy is an event/signal. Of course the first argument is self, while the second (as micmast said) is usually an instance of the widget that called it.

        This is useful for various things, for example if the user entered some data in a dialog, with this method, as it is destroyed you could look up the value of the data entered using the second argument. Make sense? Of course you don't always need to access the calling widget, so the second argument might not come into play.

        To summarize, the second (widget instance) argument is there only if you need it, otherwise just ignore it! :)

        Hope this helps.

        P.S. Here is the doc for gtk.Dialog (Google is your friend.)
        Last edited by Hackworth; Aug 28 '09, 02:25 PM. Reason: Added link for docs

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Not a python guy, but could that trailing comma on line #17 be causing the error (passing a null 2nd argument?)?

          Comment

          • holmes86
            New Member
            • Aug 2009
            • 5

            #6
            I see,thanks Hackworth for your explanation,tha nks everybody again.

            Comment

            Working...