__dict__ for instances?

Marc Christiansen usenet at solar-empire.de
Sun May 13 10:57:40 EDT 2007


Ivan Voras <ivoras at __fer.hr__> scribis:
> While using PyGTK, I want to try and define signal handlers
> automagically, without explicitly writing the long dictionary (i.e. I
> want to use signal_autoconnect()).
> 
> To do this, I need something that will inspect the current "self" and
> return a dictionary that looks like:
> 
> {
>  "method_name" : self.method_name
> }

Nope, at least for PyGTK 2 :) See below.

[...]
> This looks like it should be easy, but I can't find the solution :(

Use the doc, Luke, oops, Ivan :)
Citing the gtk.glade.XML.signal_autoconnect documentation: 
  def signal_autoconnect(dict)
  dict: a mapping or an instance
                        ^^^^^^^^
  
  The signal_autoconnect() method is a variation of the
  gtk.glade.XML.signal_connect method. It uses Python's introspective
  features to look at the keys (if dict is a mapping) or attributes (if
                                                         ^^^^^^^^^^^^^^
  dict is an instance) and tries to match them with the signal handler
  ^^^^^^^^^^^^^^^^^^^
  names given in the interface description. The callbacks referenced by
  each matched key or attribute are connected to their matching signals.
  The argument is called dict due to compatibility reasons since
  originally only the mapping interface was supported. The instance
  variant was introduced in PyGTK 2.0.

So simply using signal_autoconnect(self) should work.

Adiaŭ, Marc



More information about the Python-list mailing list