[shpy-commit] r2882 - shpy/trunk/dist/shpy/ui_pygame
mwh@codespeak.net
mwh@codespeak.net
Fri, 23 Jan 2004 15:19:36 +0100 (MET)
Author: mwh
Date: Fri Jan 23 15:19:36 2004
New Revision: 2882
Modified:
shpy/trunk/dist/shpy/ui_pygame/decorate.py
Log:
Oops, missed a file!
Modified: shpy/trunk/dist/shpy/ui_pygame/decorate.py
==============================================================================
--- shpy/trunk/dist/shpy/ui_pygame/decorate.py (original)
+++ shpy/trunk/dist/shpy/ui_pygame/decorate.py Fri Jan 23 15:19:36 2004
@@ -3,9 +3,19 @@
from shpy.net.structure import Structure, ATOMIC
-class Decorator:
+class structureproperty(object):
+ def __init__(self, name):
+ self.name = name
+ def __get__(self, ob, cls=None):
+ if ob is None:
+ return self
+ return ob.decorate(getattr(ob._value, self.name))
+ def __set__(self, ob, value):
+ setattr(ob._value, self.name, undecorate(value))
+ ob.changed()
+
+class Decorator(object):
#typeid = 'structure:0' # should always be overridden by subclasses
- #slots = ()
def __init__(self, **kwds):
if not hasattr(self.__class__, '_typeid2class'):
@@ -13,7 +23,8 @@
_value = Structure(typeid = self.__class__.typeid)
self.__dict__['_value'] = _value
for key, value in kwds.items():
- if key not in self.__class__.slots:
+ if key != getattr(getattr(self.__class__, key, None),
+ 'name', None):
raise TypeError, 'no %r slot allowed' % (key,)
setattr(self._value, key, undecorate(value))
self.init_more()
@@ -22,26 +33,6 @@
def init_more(self):
pass
- def __eq__(self, other):
- return self.__class__ is other.__class__ and self._value is other._value
-
- def __ne__(self, other):
- return not (self == other)
-
- def __hash__(self):
- return id(self._value)
-
- def __getattr__(self, attr):
- x = getattr(self._value, attr)
- return self.decorate(x)
-
- def __setattr__(self, attr, value):
- if attr not in self.__class__.slots:
- self.__dict__[attr] = value
- else:
- setattr(self._value, attr, undecorate(value))
- self.changed()
-
def changed(self):
self._changedict[self._value] = True
@@ -55,7 +46,9 @@
classobj = typeid2class[value.typeid]
except KeyError:
raise DecorateError, 'no decorator for %r' % (value.typeid,)
- decorator = new.instance(classobj, {'_value': value})
+ #decorator = new.instance(classobj, {'_value': value})
+ decorator = classobj.__new__(classobj)
+ decorator.__dict__ = {'_value': value}
decorator.init_more()
cls._decoratorcache[value] = decorator
return decorator
@@ -70,7 +63,7 @@
class List(Decorator):
typeid = 'list:0'
- slots = 'listitems',
+ listitems = structureproperty('listitems')
def __init__(self, items=[]):
Decorator.__init__(self)
@@ -139,10 +132,10 @@
typeid2class = {}
decoratorcache = {}
for existingcls in classes:
- newcls = new.classobj(existingcls.__name__, (existingcls,),
- {'_typeid2class': typeid2class,
- '_changedict': changedict,
- '_decoratorcache': decoratorcache})
+ newcls = type(existingcls.__name__, (existingcls,),
+ {'_typeid2class': typeid2class,
+ '_changedict': changedict,
+ '_decoratorcache': decoratorcache})
typeid2class[existingcls.typeid] = newcls
result[existingcls.__name__] = newcls
return result