コード例 #1
0
ファイル: proxy.py プロジェクト: maayanktyagi/python-odml
 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))
コード例 #2
0
ファイル: eventtest.py プロジェクト: asobolev/python-odml
 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)])
コード例 #3
0
ファイル: eventtest.py プロジェクト: asobolev/python-odml
 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)])
コード例 #4
0
ファイル: proxy.py プロジェクト: maayanktyagi/python-odml
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)
コード例 #5
0
ファイル: proxy.py プロジェクト: maayanktyagi/python-odml
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)
コード例 #6
0
ファイル: eventtest.py プロジェクト: asobolev/python-odml
 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
コード例 #7
0
ファイル: eventtest.py プロジェクト: asobolev/python-odml
 def tearDown(self):
     impl = odml.getImplementation()
     for obj in [impl.Value, impl.Property, impl.Section, impl.Document]:
         obj._Changed -= self.event_success
コード例 #8
0
ファイル: eventtest.py プロジェクト: asobolev/python-odml
 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
コード例 #9
0
ファイル: eventtest.py プロジェクト: asobolev/python-odml
 def tearDown(self):
     impl = odml.getImplementation()
     for obj in [impl.Value, impl.Property, impl.Section, impl.Document]:
         obj._Changed -= self.event_success
コード例 #10
0
ファイル: proxy.py プロジェクト: asobolev/python-odml
 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))
コード例 #11
0
ファイル: event.py プロジェクト: G-Node/python-odml
        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):
コード例 #12
0
class Document(ModificationNotifier, odml.getImplementation().Document):
    _Changed = Event("doc")
コード例 #13
0
class Section(ModificationNotifier, odml.getImplementation().Section):
    _Changed = Event("sec")
コード例 #14
0
class Property(ModificationNotifier, odml.getImplementation().Property):
    _Changed = Event("prop")
コード例 #15
0
class Value(ModificationNotifier, odml.getImplementation().Value):
    _Changed = Event("value")
コード例 #16
0
        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):