(I wonder how many spam filters will flag this subject line)
So I've done a little profiling and run-down of how gtk.py is being
called, and I've managed to shave a second off startup time of a couple
of our applications using some simple changes to GtkObject. I'm
sending out the change for review and likely checkin (it seems like a
free lunch, no applications I have are broken).
Can anybody still using 0.6.x give it a spin? I don't think the
semantics have changed at all, but maybe you use some evil __eq__ hack
that I'm unaware of. Comments are appreciated.
Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL
Index: gtk.py
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/gtk.py,v
retrieving revision 1.42.2.20
diff -u -r1.42.2.20 gtk.py
--- gtk.py 12 Nov 2002 17:56:56 -0000 1.42.2.20
+++ gtk.py 19 Mar 2003 17:25:13 -0000
@@ -40,9 +40,18 @@
get_type = _gtk.gtk_object_get_type
def __init__(self, _obj=None):
if _obj: self._o = _obj; return
+ raise AssertionError, "GtkObject is an abstract type"
def set(self, dict):
_filtprops(dict)
_gtk.gtk_object_set(self._o, dict)
+ def __nonzero__(self):
+ return 1
+ def __eq__(self, other):
+ if hasattr(other, '_o'):
+ return hash(self._o) == hash(other._o)
+ else:
+ # GtkObjects *always* have _o
+ return 0
def __getitem__(self, key):
ret = _gtk.gtk_object_get(self._o, key)
if type(ret) == _gtk.GtkObjectType:
@@ -64,40 +73,6 @@
return cmp(id(self), id(other))
def __hash__(self):
return hash(self._o)
- def __getattr__(self, attr):
- # this function allows setting attributes on an object so that
- # they will always be available with the object. Due to
- # reference counting problems, we can't always pass the
- # same GtkObject instance to a callback.
- #if attr[0] == '_' or not self.__dict__.has_key('_o'):
- # raise AttributeError, attr
- #dict = self.get_data('Python-Attributes')
- #if dict and dict.has_key(attr):
- # return dict[attr]
- raise AttributeError, attr
- #def __setattr__(self, attr, value):
- # if attr[0] == '_' or self.__dict__.has_key(attr) or \
- # not self.__dict__.has_key('_o'):
- # self.__dict__[attr] = value
- # dict = self.get_data('Python-Attributes')
- # if not dict:
- # dict = {}
- # self.set_data('Python-Attributes', dict)
- # dict[attr] = value
- #def __delattr__(self, attr):
- # if self.__dict__.has_key(attr):
- # del self.__dict__[attr]
- # return
- # if not self.__dict__.has_key('_o'):
- # raise AttributeError, \
- # 'delete non-existing instance attribute'
- # dict = self.get_data('Python-Attributes')
- # if dict and dict.has_key(attr):
- # del dict[attr]
- # else:
- # raise AttributeError, \
- # 'delete non-existing instance attribute'
-
def flags(self, mask=None):
if mask:
return _gtk.GTK_OBJECT_FLAGS(self._o) & mask
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/