Changeset 284
- Timestamp:
- 09/18/02 20:33:49 (6 years ago)
- Files:
-
- trunk/RBFoundation/RBFoundation/LazyProperty.py (added)
- trunk/RBFoundation/RBFoundation/WeakBind.py (modified) (9 diffs)
- trunk/RBFoundation/RBFoundation/XMLClassBuilder.py (modified) (1 diff)
- trunk/RBSkinning/RBSkinning/SkinContext.py (modified) (3 diffs)
- trunk/RBSkinning/RBSkinning/XMLSkinner.py (modified) (6 diffs)
- trunk/RBSkinning/RBSkinning/dotSkin/DOTSkinObject.py (modified) (1 diff)
- trunk/RBSkinning/RBSkinning/dotSkin/edge.py (modified) (1 diff)
- trunk/RBSkinning/RBSkinning/dotSkin/graph.py (modified) (1 diff)
- trunk/RBSkinning/RBSkinning/dotSkin/invisible.py (added)
- trunk/RBSkinning/RBSkinning/dotSkin/subgraph.py (modified) (1 diff)
- trunk/RBSkinning/RBSkinning/wxTools/wxActiveXWrapper.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBFoundation/RBFoundation/WeakBind.py
r280 r284 72 72 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 73 73 74 def __init__(self, callback):75 if callbackis None:74 def __init__(self, Callable, *weakrefArgs, **weakrefKw): 75 if Callable is None: 76 76 # A "None" method... it should expire immediately 77 77 pass 78 elif isinstance( callback, BoundCallableBase):78 elif isinstance(Callable, BoundCallableBase): 79 79 # One of those weird instances where we are proxying for an object very similar to ourself... 80 80 # keep a hard reference to the BoundCallableBase 81 self.im_func = callback82 elif isinstance( callback, typesMethods):81 self.im_func = Callable 82 elif isinstance(Callable, typesMethods): 83 83 # Wrap up the method and potential instance 84 if getattr( callback, 'im_self', None) is not None:85 self.im_self = weakref.ref( callback.im_self)86 self.im_func = getattr( callback, 'im_func', callback)87 elif isinstance( callback, typesInstances):84 if getattr(Callable, 'im_self', None) is not None: 85 self.im_self = weakref.ref(Callable.im_self, *weakrefArgs, **weakrefKw) 86 self.im_func = getattr(Callable, 'im_func', Callable) 87 elif isinstance(Callable, typesInstances): 88 88 # This is a "callable object", make a weakref to it 89 self.im_self = weakref.ref( callback)89 self.im_self = weakref.ref(Callable, *weakrefArgs, **weakrefKw) 90 90 self.im_func = None 91 elif callable( callback):91 elif callable(Callable): 92 92 # What the heck is it? well... its supposed to be callable... 93 self.im_func = callback93 self.im_func = Callable 94 94 95 95 def __nonzero__(self): … … 99 99 return self.im_func and 1 or 0 100 100 101 #def __call__(self, *args, **kw): 102 # return self._DoCall(args, kw) 101 def __hash__(self): 102 if self.im_self is not None: 103 return hash(self.im_self) 104 else: 105 return hash(self.im_func) 103 106 104 107 def __eq__(self, other): 105 108 if isinstance(other, WeakBoundCallable): 106 109 return (self.im_self == other.im_self) and (self.im_func == other.im_func) 110 elif isinstance(other, weakref.ReferenceType): 111 return self.im_func == other or self.im_self == other 107 112 elif callable(other): 108 113 return self == WeakBoundCallable(other) … … 121 126 else: raise weakref.ReferenceError, "weakly-referenced object no longer exists" 122 127 else: return self.im_func(*args, **kw) 128 129 #def __call__(self, *args, **kw): 130 # return self._DoCall(args, kw) 123 131 __call__ = _DoCall 124 132 … … 136 144 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 137 145 138 callback= None146 Callable = None 139 147 140 148 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 142 150 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 143 151 144 def __init__(self, callback):145 if callbackis None:152 def __init__(self, Callable): 153 if Callable is None: 146 154 pass # A "None" method... it should expire immediately 147 elif callable( callback):148 self. callback = callback155 elif callable(Callable): 156 self.Callable = Callable 149 157 150 158 def __nonzero__(self): 151 return self. callbackis not None and 1 or 0159 return self.Callable is not None and 1 or 0 152 160 153 161 #def __call__(self, *args, **kw): … … 156 164 def __eq__(self, other): 157 165 if isinstance(other, StrongBoundCallable): 158 return self. callback == other.callback166 return self.Callable == other.Callable 159 167 elif callable(other): 160 168 return self == StrongBoundCallable(other) … … 165 173 166 174 def _DoCall(self, *args, **kw): 167 return self.callback(*args, **kw) 175 return self.Callable(*args, **kw) 176 177 #def __call__(self, *args, **kw): 178 # return self._DoCall(args, kw) 168 179 __call__ = _DoCall 169 180 170 181 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 171 182 172 def BindCallable( callback, BindClass=BoundCallable):183 def BindCallable(Callable, BindClass=BoundCallable, *args, **kw): 173 184 """Binds a callable object using BindClass only if needed.""" 174 if isinstance( callback, BoundCallableBase):185 if isinstance(Callable, BoundCallableBase): 175 186 # It's already bound in some form or another, 176 187 # but we have to guard it from being wrapped 177 188 # again, because it is itself an instance. 178 return callback 179 elif isinstance(callback, typesRequireBinding): 180 # Well if it requires binding, then we should 181 # do so! 182 return BindClass(callback) 189 return Callable 190 elif isinstance(Callable, typesRequireBinding): 191 # Well if it requires binding, then we should do so! 192 return BindClass(Callable, *args, **kw) 183 193 else: 184 194 # not quite sure what it is, but it does not require binding 185 return callback186 187 def WeakBindCallable( callback):195 return Callable 196 197 def WeakBindCallable(Callable, *args, **kw): 188 198 """Weakly binds a callable object only if needed.""" 189 return BindCallable( callback, WeakBoundCallable)190 191 def StrongBindCallable( callback):199 return BindCallable(Callable, WeakBoundCallable, *args, **kw) 200 201 def StrongBindCallable(Callable, *args, **kw): 192 202 """Strongly binds a callable object only if needed.""" 193 return BindCallable( callback, StrongBoundCallable)203 return BindCallable(Callable, StrongBoundCallable, *args, **kw) 194 204 195 205 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 207 217 return self 208 218 219 def onrelease(wr): 220 print "Released wr:", wr 221 209 222 a = _Test() 210 223 assert(sys.getrefcount(a) == 2) 211 224 212 b1 = BindCallable(a.me)225 b1 = WeakBindCallable(a.me, onrelease) 213 226 assert(b1) 214 227 assert(sys.getrefcount(a) == 2) 215 228 216 b2 = BindCallable(a.me)229 b2 = WeakBindCallable(a.me, onrelease) 217 230 assert(b2) 218 231 assert(sys.getrefcount(a) == 2) … … 226 239 assert(b2 == b1) 227 240 228 b3 = BindCallable(a.you)241 b3 = WeakBindCallable(a.you, onrelease) 229 242 assert(not b1 == b3) 230 243 assert(b1 != b3) trunk/RBFoundation/RBFoundation/XMLClassBuilder.py
r269 r284 205 205 return self.NextFactorySet._GetElementFactory(*args, **kw) 206 206 207 raise KeyError, "Could not find a class to build for node %r" % node207 raise KeyError, "Could not find a class to build for node %r" % (node,) 208 208 209 209 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBSkinning/RBSkinning/SkinContext.py
r280 r284 26 26 from __future__ import generators 27 27 28 myStat = {}29 28 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 30 29 #~ Class … … 36 35 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 37 36 38 def __init__(self, NextContext ):37 def __init__(self, NextContext, Data={}): 39 38 self._NextContext = NextContext 39 self.__dict__.update(Data) 40 40 41 41 def __getattribute__(self, name): … … 62 62 #~ Protected Methods 63 63 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 64 65 def _update(self, Data): 66 self.__dict__.update(Data) 64 67 65 68 def _OwnerContext(self, name, returnLast=0): trunk/RBSkinning/RBSkinning/XMLSkinner.py
r253 r284 53 53 self._elements, self._LastCompleteElement = [], None 54 54 parser = self._CreateParser() 55 self.context = SkinContext.SkinContext(contextIn )55 self.context = SkinContext.SkinContext(contextIn, kwAddedContext) 56 56 self.context.__skinner__ = weakref.ref(self) 57 57 self.context.__root__ = rootPath 58 self.context.__dict__.update(kwAddedContext)59 58 60 59 parser.Parse(xml) … … 77 76 self._elements, self._LastCompleteElement = [], None 78 77 parser = self._CreateParser() 79 self.context = SkinContext.SkinContext(contextIn )78 self.context = SkinContext.SkinContext(contextIn, kwAddedContext) 80 79 self.context.__skinner__ = weakref.ref(self) 81 80 self.context.__root__ = rootPath 82 self.context.__dict__.update(kwAddedContext)83 81 84 82 parser.ParseFile(file) … … 99 97 100 98 parentContext = GraftElements[-1].context 101 self.context = SkinContext.SkinContext(parentContext )99 self.context = SkinContext.SkinContext(parentContext, kwAddedContext) 102 100 self.context.__skinner__ = weakref.ref(self) 103 101 self.context.__root__ = rootPath 104 self.context.__dict__.update(kwAddedContext)105 102 self._LastCompleteElement.context = self.context 106 103 … … 128 125 129 126 parentContext = GraftElements[-1].context 130 self.context = SkinContext.SkinContext(parentContext )127 self.context = SkinContext.SkinContext(parentContext, kwAddedContext) 131 128 self.context.__skinner__ = weakref.ref(self) 132 129 self.context.__root__ = rootPath 133 self.context.__dict__.update(kwAddedContext)134 130 self._LastCompleteElement.context = self.context 135 131 … … 151 147 parser = self._CreateParser() 152 148 element.context.__skinner__ = weakref.ref(self) 153 element.context._ _dict__.update(kwAddedContext)149 element.context._update(kwAddedContext) 154 150 155 151 parser.Parse(xml) … … 171 167 element.context.__skinner__ = weakref.ref(self) 172 168 if rootPath: element.context.__root__ = rootPath 173 element.context._ _dict__.update(kwAddedContext)169 element.context._update(kwAddedContext) 174 170 175 171 parser.ParseFile(file) trunk/RBSkinning/RBSkinning/dotSkin/DOTSkinObject.py
r253 r284 56 56 result = [] 57 57 for each in self.Elements(): 58 result.append(each._toDOT(joinstr)) 58 try: toDOT = each._toDOT 59 except AttributeError: pass 60 else: result.append(toDOT(joinstr)) 59 61 if joinstr is not None: 60 62 return joinstr.join(result) trunk/RBSkinning/RBSkinning/dotSkin/edge.py
r253 r284 42 42 if data: result.append(data) 43 43 else: 44 result.append(each._toDOT(joinstr='', close=0)) 44 try: toDOT = each._toDOT 45 except AttributeError: pass 46 else: result.append(toDOT(joinstr='', close=0)) 45 47 result = self.context.DOTEdgeJoin.join(result) 46 48 trunk/RBSkinning/RBSkinning/dotSkin/graph.py
r263 r284 56 56 57 57 for each in self.Elements(): 58 result.append(each._toDOT(joinstr)) 58 try: toDOT = each._toDOT 59 except AttributeError: pass 60 else: result.append(toDOT(joinstr)) 59 61 60 62 if close: result.append('}') trunk/RBSkinning/RBSkinning/dotSkin/subgraph.py
r263 r284 37 37 _DOTStartFormat = 'subgraph %s {' 38 38 39 def SkinInitialize(self): 40 pass 41 39 42 def _toDOT(self, joinstr='\n', close=1): 40 43 if close: trunk/RBSkinning/RBSkinning/wxTools/wxActiveXWrapper.py
r282 r284 78 78 return pywin.mfc.activex.Control.__getattr__(self, attr) 79 79 except AttributeError: 80 return getattr(eo._eventObj, attr) 80 if self._eventObj: 81 return getattr(self._eventObj, attr) 82 else: raise 81 83 82 84 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
