CVS: anygui/lib/anygui Attribs.py,1.17,1.18 Models.py,1.18,1.19 Proxies.py,1.21,1.22 __init__.py,1.69,1.70
"Dallas T. Johnston" <[email protected]> Mon, 23 Sep 2002 18:25:44 -0700
| Newsgroups | gmane.comp.python.anygui.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/anygui/anygui/lib/anygui
In directory usw-pr-cvs1:/tmp/cvs-serv11942
Modified Files:
Attribs.py Models.py Proxies.py __init__.py
Log Message:
Added working models (note that some little bugs need to be ironed out).
Index: Attribs.py
===================================================================
RCS file: /cvsroot/anygui/anygui/lib/anygui/Attribs.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -r1.17 -r1.18
*** Attribs.py 11 Sep 2002 01:03:06 -0000 1.17
--- Attribs.py 24 Sep 2002 01:25:41 -0000 1.18
***************
*** 1,4 ****
from Events import link, send
! from Utils import getGetter,getSetter,getterName
# DONE: Add mechanism for internal attributes (not in state[]). Uses
--- 1,4 ----
from Events import link, send
! from Utils import getGetter,getSetter,getterName,uncapitalizeAttribute
# DONE: Add mechanism for internal attributes (not in state[]). Uses
***************
*** 50,53 ****
--- 50,65 ----
if method:
return method()
+
+ # ===== FOR MODELS ===== #
+ if name.startswith('install') and name.endswith('Model'):
+ def metaInstall(model):
+ self.installModel(self, uncapitalizeAttribute(name[7:][:-5]), model)
+ return metaInstall
+ if name.startswith('remove') and name.endswith('Model'):
+ def metaRemove():
+ self.removeModel(self, uncapitalizeAttribute(name[6:][:-5]))
+ return metaRemove
+ # === END FOR MODELS === #
+
if not self.state.has_key(name):
raise AttributeError, name
***************
*** 73,79 ****
names = []
for key, val in optsAndKwdsItems(args, kwds):
! old_val = getattr(self, key, None)
! try: old_val.removed(self, key)
! except: pass
meth = getSetter(self,key)
if meth:
--- 85,91 ----
names = []
for key, val in optsAndKwdsItems(args, kwds):
! #old_val = getattr(self, key, None)
! #try: old_val.removed(self, key)
! #except: pass
meth = getSetter(self,key)
if meth:
***************
*** 81,86 ****
else:
self.state[key] = val
! try: val.assigned(self, key)
! except: pass
names.append(key)
return names
--- 93,98 ----
else:
self.state[key] = val
! #try: val.assigned(self, key)
! #except: pass
names.append(key)
return names
Index: Models.py
===================================================================
RCS file: /cvsroot/anygui/anygui/lib/anygui/Models.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** Models.py 26 Mar 2002 19:23:19 -0000 1.18
--- Models.py 24 Sep 2002 01:25:42 -0000 1.19
***************
*** 11,39 ****
def __init__(self):
self.names = []
! def assigned(self, object, name):
! sync = getattr(object, 'sync', None)
! if sync is not None:
self.names.append(name)
! link(self, sync)
!
def removed(self, object, name):
! sync = getattr(object, 'sync', None)
! if sync is not None:
! unlink(self, sync)
self.names.remove(name)
! def send(self, **kw):
! send(self, names=self.names, **kw)
!
- class Model(Attrib, Assignee):
! def sync(self, event): # FIXME: Wrong signature
! self.send(**event.dict)
def __init__(self, *arg, **kw):
Assignee.__init__(self)
! Attrib.__init__(self, **kw)
--- 11,39 ----
def __init__(self):
self.names = []
+ self.objects = []
! def installed(self, object, name):
! push = getattr(object, 'push', None)
! if push is not None:
self.names.append(name)
! self.objects.append(object)
!
def removed(self, object, name):
! push = getattr(object, 'push', None)
! if push is not None:
! self.objects.remove(object)
self.names.remove(name)
! def send(self, **kwds):
! for object in self.objects:
! object.push(names=self.names)
! send(self, **kwds)
! class Model(Assignee):
def __init__(self, *arg, **kw):
Assignee.__init__(self)
! #Attrib.__init__(self, **kw)
***************
*** 42,49 ****
_value = 0
! def _set_value(self, value):
self._value = value
! def _get_value(self):
return self._value
--- 42,50 ----
_value = 0
! def setValue(self, value):
self._value = value
+ self.send()
! def getValue(self):
return self._value
***************
*** 57,122 ****
class ListModel(Model, UserList):
def __init__(self, *arg, **kw):
Model.__init__(self, **kw)
UserList.__init__(self, *arg, **kw)
!
! def _set_value(self, value):
self.data[:] = list(value)
! def _get_value(self):
return list(self)
def __setitem__(self, i, item):
UserList.__setitem__(self, i, item)
! self.send(__setitem__=(i,item))
def __delitem__(self, i):
UserList.__delitem__(self, i)
! self.send(__delitem__=i)
def __setslice__(self, i, j, other):
UserList.__setslice__(self, i, j, other)
! self.send(__setslice__=(i,j,other))
def __delslice__(self, i, j):
UserList.__delslice__(self, i, j)
! self.send(__delslice__=(i,j))
def __iadd__(self, other):
UserList.__iadd__(self, other)
! self.send(__iadd__=other)
def __imul__(self, n):
UserList.__imul__(self, n)
! self.send(__imul__=n)
def append(self, item):
UserList.append(self, item)
! self.send(append=item)
def insert(self, i, item):
UserList.insert(self, i, item)
! self.send(insert=(i,item))
def pop(self, i=-1):
result = UserList.pop(self, i)
! self.send(pop=i)
return result
def remove(self, item):
UserList.remove(self, item)
! self.send(remove=item)
def reverse(self):
UserList.reverse(self)
! self.send(reverse=1)
def sort(self, *args):
UserList.sort(self, *args)
! self.send(sort=1)
def extend(self, other):
UserList.extend(self, other)
! self.send(extend=other)
--- 58,124 ----
class ListModel(Model, UserList):
+
def __init__(self, *arg, **kw):
Model.__init__(self, **kw)
UserList.__init__(self, *arg, **kw)
!
! def setValue(self, value):
self.data[:] = list(value)
! def getValue(self):
return list(self)
def __setitem__(self, i, item):
UserList.__setitem__(self, i, item)
! self.send()
def __delitem__(self, i):
UserList.__delitem__(self, i)
! self.send()
def __setslice__(self, i, j, other):
UserList.__setslice__(self, i, j, other)
! self.send()
def __delslice__(self, i, j):
UserList.__delslice__(self, i, j)
! self.send()
def __iadd__(self, other):
UserList.__iadd__(self, other)
! self.send()
def __imul__(self, n):
UserList.__imul__(self, n)
! self.send()
def append(self, item):
UserList.append(self, item)
! self.send()
def insert(self, i, item):
UserList.insert(self, i, item)
! self.send()
def pop(self, i=-1):
result = UserList.pop(self, i)
! self.send()
return result
def remove(self, item):
UserList.remove(self, item)
! self.send()
def reverse(self):
UserList.reverse(self)
! self.send()
def sort(self, *args):
UserList.sort(self, *args)
! self.send()
def extend(self, other):
UserList.extend(self, other)
! self.send()
***************
*** 130,134 ****
ListModel.__init__(self, *arg, **kw)
! def _get_value(self):
return str(self)
--- 132,136 ----
ListModel.__init__(self, *arg, **kw)
! def getValue(self):
return str(self)
Index: Proxies.py
===================================================================
RCS file: /cvsroot/anygui/anygui/lib/anygui/Proxies.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -r1.21 -r1.22
*** Proxies.py 11 Sep 2002 01:03:06 -0000 1.21
--- Proxies.py 24 Sep 2002 01:25:42 -0000 1.22
***************
*** 1,3 ****
--- 1,4 ----
from Attribs import Attrib
+ from Models import Model
class Proxy(Attrib):
***************
*** 6,9 ****
--- 7,11 ----
wrapper = None # so self.wrapper is always OK
+ installedModels = {}
def __init__(self, *args, **kwds):
***************
*** 60,63 ****
--- 62,82 ----
state = self._partialState(*names)
self.wrapper.pull(state)
+
+ # ==== MODEL SUPPORT ==== #
+ # This is the logic that needs to go into ModelDelegate,
+ # but that might break encapsulation...
+ # -----------------------------------------------------
+ # After we have pulled the actual values from the widget,
+ # We need to update all installed models with them.
+ for prop in state:
+ try:
+ model = self.installedModels[prop]
+ # lazy update of model... should this be done??
+ # model.setValue(state[prop])
+ state[prop] = model
+ except:
+ pass
+ # == END MODEL SUPPORT == #
+
self.state.update(state)
***************
*** 86,92 ****
# We may need to modify names, so...
names = list(names)
## @@@ unused self.internalPush(names) # @@@ May no longer be needed
! self.wrapper.push(self._partialState(*names,**kwds))
!
## @@@ unused
## def internalPush(self, names): # @@@ May no longer be needed!
--- 105,129 ----
# We may need to modify names, so...
names = list(names)
+
+ # ==== MODEL SUPPORT ==== #
+ # This is the logic that needs to go into ModelDelegate,
+ # but that might break encapsulation...
+ # -----------------------------------------------------
+ # After we have pulled the actual values from the widget,
+ # We need to update all installed models with them.
+ state = self._partialState(*names,**kwds)
+ for prop in state:
+ try:
+ model = self.installedModels[prop]
+ model.setValue(state[prop])
+ state[prop] = model
+ except:
+ pass
+ # == END MODEL SUPPORT == #
+
## @@@ unused self.internalPush(names) # @@@ May no longer be needed
! #self.wrapper.push(self._partialState(*names,**kwds))
! self.wrapper.push(state)
!
## @@@ unused
## def internalPush(self, names): # @@@ May no longer be needed!
***************
*** 124,125 ****
--- 161,171 ----
self.wrapper.destroy()
# @@@ do we need del self.wrapper here ?
+
+ def installModel(self, obj, name, model):
+ self.installedModels[name] = model
+ model.installed(obj, name)
+
+ def removeModel(self, obj, name):
+ self.installedModels[name].removed(obj, name)
+ del self.installedModels[name]
+
Index: __init__.py
===================================================================
RCS file: /cvsroot/anygui/anygui/lib/anygui/__init__.py,v
retrieving revision 1.69
retrieving revision 1.70
diff -C2 -r1.69 -r1.70
*** __init__.py 21 Aug 2002 04:28:45 -0000 1.69
--- __init__.py 24 Sep 2002 01:25:42 -0000 1.70
***************
*** 44,48 ****
from anygui.TextAreas import TextArea
from anygui.ListBoxes import ListBox
! #from anygui.Models import BooleanModel, ListModel, TextModel
from anygui.Events import *
from anygui.Frames import Frame, GroupBox
--- 44,48 ----
from anygui.TextAreas import TextArea
from anygui.ListBoxes import ListBox
! from anygui.Models import BooleanModel, ListModel, TextModel
from anygui.Events import *
from anygui.Frames import Frame, GroupBox
***************
*** 68,71 ****
--- 68,74 ----
RadioButton
RadioGroup
+ BooleanModel
+ ListModel
+ TextModel
any
application
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf