def __init__(self, doc): super(DocumentProxy, self).__init__(doc) odml.getImplementation().Document.__init__( self ) # TODO this might already be a different implementation now. and we're not an instance for name in odml.format.Document: if name in odml.format.Document._args: # skip 'sections' setattr(self, name, getattr(doc, name))
def test_pre_post_change(self): res = [] func = lambda context: res.append((context.preChange, context.postChange)) odml.getImplementation().Value._Changed += func a = odml.Value(1) a.value = 2 odml.getImplementation().Value._Changed -= func self.assertEqual(res, [(True, False), (False, True)])
def test_pre_post_change(self): res = [] func = lambda context: res.append( (context.preChange, context.postChange)) odml.getImplementation().Value._Changed += func a = odml.Value(1) a.value = 2 odml.getImplementation().Value._Changed -= func self.assertEqual(res, [(True, False), (False, True)])
class SectionProxy(odml.getImplementation().Section, Proxy): """ A Section that will also pass as a Proxy """ def proxy_remove(self, obj): """ explicitly remove a proxy object without side-effects """ assert isinstance(obj, Proxy) super(SectionProxy, self).remove(obj) def proxy_append(self, obj): """ explicitly append a proxy object without side-effects """ assert isinstance(obj, Proxy) super(SectionProxy, self).append(obj)
class DocumentProxy(EqualityBaseProxy, odml.getImplementation().Document): """ A bare bones DocumentProxy not yet proxing actually much. TODO make it a HookProxy? """ def __init__(self, doc): super(DocumentProxy, self).__init__(doc) odml.getImplementation().Document.__init__( self ) # TODO this might already be a different implementation now. and we're not an instance for name in odml.format.Document: if name in odml.format.Document._args: # skip 'sections' setattr(self, name, getattr(doc, name)) # TODO append also needs to append to original document and care about mappings and stuff # TODO same for insert/remove def proxy_remove(self, obj): self.remove(obj) def proxy_append(self, obj): self.append(obj)
def setUp(self): self.doc = samplefile.SampleFileCreator().create_document() impl = odml.getImplementation() for obj in [impl.Value, impl.Property, impl.Section, impl.Document]: obj._Changed += self.event_success
def tearDown(self): impl = odml.getImplementation() for obj in [impl.Value, impl.Property, impl.Section, impl.Document]: obj._Changed -= self.event_success
def __init__(self, doc): super(DocumentProxy, self).__init__(doc) odml.getImplementation().Document.__init__(self) # TODO this might already be a different implementation now. and we're not an instance for name in odml.format.Document: if name in odml.format.Document._args: # skip 'sections' setattr(self, name, getattr(doc, name))
func = lambda: super(ModificationNotifier, self).remove(obj) self.__fireChange("remove", obj, func) def insert(self, position, obj): func = lambda: super(ModificationNotifier, self).insert(position, obj) self.__fireChange("insert", obj, func) def _reorder(self, childlist, new_index): func = lambda: super(ModificationNotifier, self)._reorder(childlist, new_index) return self.__fireChange("reorder", (childlist, new_index), func) # create a seperate global Event listeners for each class # and provide ModificationNotifier Capabilities name = "event" provides = odml.getImplementation().provides + ["event"] class Value(ModificationNotifier, odml.getImplementation().Value): _Changed = Event("value") class Property(ModificationNotifier, odml.getImplementation().Property): _Changed = Event("prop") class Section(ModificationNotifier, odml.getImplementation().Section): _Changed = Event("sec") class Document(ModificationNotifier, odml.getImplementation().Document):
class Document(ModificationNotifier, odml.getImplementation().Document): _Changed = Event("doc")
class Section(ModificationNotifier, odml.getImplementation().Section): _Changed = Event("sec")
class Property(ModificationNotifier, odml.getImplementation().Property): _Changed = Event("prop")
class Value(ModificationNotifier, odml.getImplementation().Value): _Changed = Event("value")
self.__fireChange("remove", obj, func) def insert(self, position, obj): func = lambda: super(ModificationNotifier, self).insert(position, obj) self.__fireChange("insert", obj, func) def _reorder(self, childlist, new_index): func = lambda: super(ModificationNotifier, self)._reorder( childlist, new_index) return self.__fireChange("reorder", (childlist, new_index), func) # create a seperate global Event listeners for each class # and provide ModificationNotifier Capabilities name = "event" provides = odml.getImplementation().provides + ["event"] class Value(ModificationNotifier, odml.getImplementation().Value): _Changed = Event("value") class Property(ModificationNotifier, odml.getImplementation().Property): _Changed = Event("prop") class Section(ModificationNotifier, odml.getImplementation().Section): _Changed = Event("sec") class Document(ModificationNotifier, odml.getImplementation().Document):