[Anygui-checkins] CVS: anygui/lib/anygui Attribs.py,1.4,1.5
Brought to you by:
mlh
From: Magnus L. H. <ml...@us...> - 2002-03-23 15:12:18
|
Update of /cvsroot/anygui/anygui/lib/anygui In directory usw-pr-cvs1:/tmp/cvs-serv30584/lib/anygui Modified Files: Attribs.py Log Message: Index: Attribs.py =================================================================== RCS file: /cvsroot/anygui/anygui/lib/anygui/Attribs.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** Attribs.py 23 Mar 2002 14:41:33 -0000 1.4 --- Attribs.py 23 Mar 2002 15:12:14 -0000 1.5 *************** *** 2,5 **** --- 2,27 ---- from Events import link, send + def optsAndKwdItems(args, kwds): + items = kwds.items() + for opt in args: + items.extend(opt.__dict__.items()) + return items + + def modattr(obj, name, value): + old_value = getattr(self, name, None) + # try assigning to the "all-object slice" + try: old_value[:] = value + except: + # try assigning to the "value" attribute of the old-value + try: old_value.value = value + except: + # no in-place mod, so, just set it (bind or re-bind) + obj.__dict__[name] = value + return + # in-place modification has succeeded, alert the old_value (if + # it supplies a suitable method) and any watchers of 'self' + try: old_value.modified() + except: pass + class Attrib: # REWRITE THIS: *************** *** 47,56 **** """ - # FIXME: Needed? - _inhibit_sync = 0 # default Attribs are always sync-enabled - - # FIXME: Fix set() and modify() so they don't call sync repeatedly - # for multiple arguments. - def __init__(self, *args, **kwds): defaults = getattr(self, 'state', {}) --- 69,72 ---- *************** *** 60,137 **** def __setattr__(self, name, value): ! if name[0]!='_': ! try: ! setter = getattr(self, "_set_"+name) ! except AttributeError: ! if hasattr(self, "_get_"+name): ! raise SetAttributeError(self, name) ! else: ! try: getattr(self, name).removed(self, name) ! except: pass ! inhibit_sync = setter(value) ! try: value.assigned(self, name) ! except: pass ! if not inhibit_sync: self.sync(name) ! return ! self.__dict__[name] = value ! if name[0]!='_': ! self.sync(name) def __getattr__(self, name): ! if name[0]=='_': raise GetAttributeError(self, name) ! try: ! getter = getattr(self, "_get_"+name) ! except AttributeError: ! raise GetAttributeError(self, name) ! else: ! return getter() ! ! def _set_or_mod(self, func, *args, **kwds): ! for opt in args: ! # kwds.update(opt.__dict__) # Doesn't work in Jython 2.1a1 ! for key, val in opt.__dict__.items(): ! kwds[key] = val ! for name, value in kwds.items(): ! func(self, name, value) def set(self, *args, **kwds): ! return self._set_or_mod(setattr, *args, **kwds) def rawSet(self, *args, **kwds): ! raise NotImplementedError # FIXME def modify(self, *args, **kwds): ! return self._set_or_mod(self.__class__.modattr, *args, **kwds) def rawModify(self, *args, **kwds): ! raise NotImplementedError # FIXME ! ! def modattr(self, name, value): ! if name[0]!='_': ! try: modifier = getattr(self, '_modify_'+name) ! except AttributeError: pass ! else: ! # found a modifier-method, delegate the task to it ! inhibit_update = modifier(value) ! try: getattr(self, name).modified() ! except: pass ! if not inhibit_update: self.sync(name) ! return ! ! # we need to perform the modification-task directly ! old_value = getattr(self, name, None) ! # try assigning to the "all-object slice" ! try: old_value[:] = value ! except: ! # try assigning to the "value" attribute of the old-value ! try: old_value.value = value ! except: ! # no in-place mod, so, just set it (bind or re-bind) ! setattr(self, name, value) ! return ! # in-place modification has succeeded, alert the old_value (if ! # it supplies a suitable method) and any watchers of 'self' ! try: old_value.modified() ! except: pass ! if name[0]!='_': ! self.sync(name) --- 76,106 ---- def __setattr__(self, name, value): ! if name == 'state': ! self.__dict__[name] = value ! else: self.set(name=value) def __getattr__(self, name): ! assert name != 'state' ! return self.state[name] def set(self, *args, **kwds): ! names = self.rawSet(*args, **kwds) ! self.sync(*names) def rawSet(self, *args, **kwds): ! names = [] ! for key, val in optsAndKwdsItems(args, kwds): ! self.__dict__[key] = val ! names.append(key) ! return names def modify(self, *args, **kwds): ! names = self.rawModify(*args, **Kwds) ! self.sync(*names) def rawModify(self, *args, **kwds): ! names = [] ! for key, val in optsAndKwdsItems(args, kwds): ! modattr(self, key, val) ! names.append(key) ! return names |