On Sun, Aug 10, 2003 at 03:55:56AM +0200, Jan Weil wrote:
> Good night,
> 
> class MyObject:
>     def __init__(self):
>         if issubclass(self.__class__, gobject.GObject):
>             self.properties = []
>             for param in gobject.list_properties(self):
>                 self.properties.append(param.name)
> 
>     def __setattr__(self, key, value):
>         self.__dict__[key] = value
>         if hasattr(self, "properties") and key in self.properties:
>             self.set_property(key, value)
> 
>     def __getattr__(self, key):
>         if hasattr(self, "properties") and key in self.properties:
>             return self.get_property(key)
>         else:
>             return self.__dict__.get(key, None)

You could get away with something a bit simpler even:

class MyObject:
    def __init__(self):
        if issubclass(self.__class__, gobject.GObject):
            self.__properties = list(gobject.list_properties(self))
        else:
            self.__properties = []

    def __setattr__(self, key, value):
        if self.__properties and key in self.__properties:
            self.set_property(key, value)
        else:
            self.__dict__[key] = value

    def __getattr__(self, key):
        if self.__properties and key in self.__properties:
            return self.get_property(key)
        else:
            return self.__dict__.get(key, None)

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL
_______________________________________________
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