On Thu, Jan 16, 2003 at 05:36:21PM -0200, Johan Dahlin wrote:

>   wtree.signal_autoconnect(self)

This is very cool.

But one problem with glade is that you can't have a generic handler name.  
If you have "on_row_expanded" in 2 instances, both bound methods will be
called. So I wrote a little function to "decorate" an instance with aliases
for the generic methods:

GLADE_HANDLER_PREFIX = 'on_'

def set_handler_attributes(instance, name):
    local_handlers = [attrname for attrname in dir(instance)
                      if attrname.startswith(GLADE_HANDLER_PREFIX)]
    hlen = len(GLADE_HANDLER_PREFIX)
    for attrname in local_handlers:
        glade_handler = attrname[:hlen] + name + '_' + attrname[hlen:]
        local_attr = getattr(instance, attrname)
        setattr(instance, glade_handler, local_attr)
    return instance

So 'on_row_expanded' will get an alias like 'on_foo_row_expanded', which is
the default naming convention glade uses if you name your widget 'foo'.

Then you use it like:

wtree.signal_autoconnect(set_handler_attributes(instance, 'foo'))
wtree.signal_autoconnect(set_handler_attributes(instance, 'bar'))

etc.
 
The nice thing about doing it this way is that your objects don't have to
"know" anything about the specifics of the UI beyond providing generic
handlers for signals according to the 'on_<signal-name>' convention. 

Dave Cook
_______________________________________________
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