Connecting Tech Pros Worldwide Help | Site Map

[Python+glade] why need two arguments?

Newbie
 
Join Date: Aug 2009
Posts: 5
#1: Aug 27 '09
hi,everyone.

I am a python newbie.and I write a python program with glade,as following:
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. import gtk
  3. import gtk.glade
  4.  
  5. class TLaitSignals:
  6.     '''Define TLait singals handler'''
  7.     def test(self):
  8.         return self.signals_dict
  9.     def on_BtnBack_clicked(self):
  10.         gtk.main_quit()
  11.     def on_BtnForward_clicked(self):
  12.         pass
  13.     def gtk_widget_destroy(self):
  14.         gtk.main_quit()
  15.         #sys.exit(0)
  16.     def __init__(self):
  17.         self.signals_dict = {"gtk_widget_destroy" : self.gtk_widget_destroy,}
  18.  
  19. if __name__ == "__main__":
  20.     gladexml = gtk.glade.XML("ui/TLait-first.glade")
  21.     gladexml.signal_autoconnect(TLaitSignals().test())
  22.     mainWin = gladexml.get_widget("tlait_selectAppVer")
  23.     mainWin.set_default_size(800,600)
  24.     mainWin.show()
  25.     gtk.main()
  26.  
  27.  
when I clicked close button,it report "TypeError: gtk_widget_destroy() takes exactly 1 argument (2 given)" info.

if I add any argument to gtk_widget_destroy() ,for example:
def gtk_widget_destroy(self,sfsadfsadfs):
then it will execute successful. So I don't why need two arguments,where define to need two arguments?
thanks very much!
micmast's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Belgium
Posts: 136
#2: Aug 27 '09

re: [Python+glade] why need two arguments?


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.
Newbie
 
Join Date: Aug 2009
Posts: 5
#3: Aug 28 '09

re: [Python+glade] why need two arguments?


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.
Newbie
 
Join Date: Aug 2009
Location: Louisville
Posts: 13
#4: Aug 28 '09

re: [Python+glade] why need two arguments?


I'm not entirely sure about this as I am a wx user not a gtk user, however, it looks as though gtk_widget_destroy 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.)
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#5: Aug 28 '09

re: [Python+glade] why need two arguments?


Not a python guy, but could that trailing comma on line #17 be causing the error (passing a null 2nd argument?)?
Newbie
 
Join Date: Aug 2009
Posts: 5
#6: Aug 31 '09

re: [Python+glade] why need two arguments?


I see,thanks Hackworth for your explanation,thanks everybody again.
Reply