Let ElementFactory manage the ElementDispatcher
The dispatcher is only used in model elements and therefore does not need to be available as system wide service.
This commit is contained in:
@ -59,5 +59,6 @@ element_dispatcher
|
||||
elements reaching from the root (e.g. from a diagram item) to the element of
|
||||
interest and will only signal in case this element changes.
|
||||
This makes complex dispatching very efficient.
|
||||
The dispatcher functionality is available through `Element.watcher()`.
|
||||
|
||||
.. autoclass:: gaphor.UML.elementdispatcher.ElementDispatcher
|
||||
|
@ -115,7 +115,8 @@ class Element:
|
||||
model.handle(event)
|
||||
|
||||
def watcher(self, default_handler=None):
|
||||
return EventWatcher(self, default_handler)
|
||||
dispatcher = self.model.element_dispatcher if self.model else None
|
||||
return EventWatcher(self, dispatcher, default_handler)
|
||||
|
||||
# OCL methods: (from SMW by Ivan Porres (http://www.abo.fi/~iporres/smw))
|
||||
|
||||
|
@ -20,10 +20,9 @@ class EventWatcher:
|
||||
A helper for easy registering and unregistering event handlers.
|
||||
"""
|
||||
|
||||
element_dispatcher = inject("element_dispatcher")
|
||||
|
||||
def __init__(self, element, default_handler=None):
|
||||
def __init__(self, element, element_dispatcher, default_handler=None):
|
||||
self.element = element
|
||||
self.element_dispatcher = element_dispatcher
|
||||
self.default_handler = default_handler
|
||||
self._watched_paths = dict()
|
||||
|
||||
|
@ -6,6 +6,7 @@ from contextlib import contextmanager
|
||||
|
||||
from gaphor.UML.diagram import Diagram
|
||||
from gaphor.UML.element import Element, UnlinkEvent
|
||||
from gaphor.UML.elementdispatcher import ElementDispatcher
|
||||
from gaphor.UML.event import (
|
||||
ElementChangeEvent,
|
||||
ElementCreateEvent,
|
||||
@ -33,6 +34,9 @@ class ElementFactory(Service):
|
||||
|
||||
def __init__(self, event_manager=None):
|
||||
self.event_manager = event_manager
|
||||
self.element_dispatcher = (
|
||||
ElementDispatcher(event_manager) if event_manager else None
|
||||
)
|
||||
self._elements = odict.odict()
|
||||
self._observers = list()
|
||||
self._block_events = 0
|
||||
|
@ -216,16 +216,13 @@ A.two = association("two", A, lower=0, upper=2, composite=True)
|
||||
|
||||
|
||||
class ElementDispatcherAsServiceTestCase(TestCase):
|
||||
|
||||
services = TestCase.services + ["element_dispatcher"]
|
||||
|
||||
def A(self):
|
||||
return self.element_factory.create(A)
|
||||
|
||||
def setUp(self):
|
||||
super(ElementDispatcherAsServiceTestCase, self).setUp()
|
||||
self.events = []
|
||||
self.dispatcher = Application.get_service("element_dispatcher")
|
||||
self.dispatcher = self.element_factory.element_dispatcher
|
||||
|
||||
def tearDown(self):
|
||||
super(ElementDispatcherAsServiceTestCase, self).tearDown()
|
||||
@ -324,7 +321,7 @@ class ElementDispatcherAsServiceTestCase(TestCase):
|
||||
"""
|
||||
A = self.A
|
||||
a = A()
|
||||
watcher = EventWatcher(a, self._handler)
|
||||
watcher = EventWatcher(a, self.dispatcher, self._handler)
|
||||
watcher.watch("one.two.one.two")
|
||||
# watcher.watch('one.one.one.one')
|
||||
watcher.subscribe_all()
|
||||
@ -348,7 +345,7 @@ class ElementDispatcherAsServiceTestCase(TestCase):
|
||||
"""
|
||||
A = self.A
|
||||
a = A()
|
||||
watcher = EventWatcher(a, self._handler)
|
||||
watcher = EventWatcher(a, self.dispatcher, self._handler)
|
||||
watcher.watch("one.two.one.two")
|
||||
# watcher.watch('one.one.one.one')
|
||||
watcher.subscribe_all()
|
||||
@ -374,7 +371,7 @@ class ElementDispatcherAsServiceTestCase(TestCase):
|
||||
"""
|
||||
A = self.A
|
||||
a = A()
|
||||
watcher = EventWatcher(a, self._handler)
|
||||
watcher = EventWatcher(a, self.dispatcher, self._handler)
|
||||
watcher.watch("one.two.one.two")
|
||||
# watcher.watch('one.one.one.one')
|
||||
watcher.subscribe_all()
|
||||
@ -402,7 +399,7 @@ class ElementDispatcherAsServiceTestCase(TestCase):
|
||||
"""
|
||||
A = self.A
|
||||
a = A()
|
||||
watcher = EventWatcher(a, self._handler)
|
||||
watcher = EventWatcher(a, self.dispatcher, self._handler)
|
||||
watcher.watch("one.two.one.two")
|
||||
# watcher.watch('one.one.one.one')
|
||||
watcher.subscribe_all()
|
||||
|
@ -29,7 +29,7 @@ class ComponentLookupError(LookupError):
|
||||
pass
|
||||
|
||||
|
||||
_ESSENTIAL_SERVICES = ["component_registry", "event_manager", "element_dispatcher"]
|
||||
_ESSENTIAL_SERVICES = ["component_registry", "event_manager"]
|
||||
|
||||
|
||||
class _Application:
|
||||
|
@ -12,9 +12,6 @@ from gaphor.diagram.classes.association import AssociationItem
|
||||
|
||||
|
||||
class AssociationItemTestCase(TestCase):
|
||||
|
||||
services = TestCase.services + ["element_dispatcher"]
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.assoc = self.create(AssociationItem)
|
||||
@ -73,7 +70,6 @@ class AssociationItemTestCase(TestCase):
|
||||
assert a.subject.memberEnd[1] is a.tail_end.subject
|
||||
assert a.subject.memberEnd[0].name is None
|
||||
|
||||
dispatcher = self.get_service("element_dispatcher")
|
||||
a.subject.memberEnd[0].name = "blah"
|
||||
self.diagram.canvas.update()
|
||||
|
||||
|
@ -49,7 +49,7 @@ class TestCaseExtras:
|
||||
|
||||
class TestCase(TestCaseExtras, unittest.TestCase):
|
||||
|
||||
services = ["element_factory", "element_dispatcher", "sanitizer"]
|
||||
services = ["element_factory", "sanitizer"]
|
||||
|
||||
def setUp(self):
|
||||
Application.init(services=self.services)
|
||||
|
@ -11,13 +11,7 @@ from gaphor.ui.mainwindow import DiagramPage
|
||||
class DiagramPageTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
Application.init(
|
||||
services=[
|
||||
"element_factory",
|
||||
"main_window",
|
||||
"action_manager",
|
||||
"properties",
|
||||
"element_dispatcher",
|
||||
]
|
||||
services=["element_factory", "main_window", "action_manager", "properties"]
|
||||
)
|
||||
main_window = Application.get_service("main_window")
|
||||
main_window.open()
|
||||
|
@ -16,7 +16,7 @@ class WindowOwner:
|
||||
|
||||
class DiagramToolboxTestCase(TestCase):
|
||||
|
||||
services = ["element_factory", "properties", "element_dispatcher"]
|
||||
services = ["element_factory", "properties"]
|
||||
|
||||
def setUp(self):
|
||||
TestCase.setUp(self)
|
||||
|
@ -28,7 +28,6 @@ class DiagramItemConnectorTestCase(unittest.TestCase):
|
||||
"properties_manager",
|
||||
"action_manager",
|
||||
"properties",
|
||||
"element_dispatcher",
|
||||
]
|
||||
)
|
||||
self.main_window = Application.get_service("main_window")
|
||||
@ -77,7 +76,6 @@ class HandleToolTestCase(unittest.TestCase):
|
||||
"properties_manager",
|
||||
"action_manager",
|
||||
"properties",
|
||||
"element_dispatcher",
|
||||
]
|
||||
)
|
||||
self.component_registry = Application.get_service("component_registry")
|
||||
|
@ -62,7 +62,6 @@ gaphorconvert = 'gaphor.tools.gaphorconvert:main'
|
||||
"main_window" = "gaphor.ui.mainwindow:MainWindow"
|
||||
"copy" = "gaphor.services.copyservice:CopyService"
|
||||
"sanitizer" = "gaphor.services.sanitizerservice:SanitizerService"
|
||||
"element_dispatcher" = "gaphor.UML.elementdispatcher:ElementDispatcher"
|
||||
"xmi_export" = "gaphor.plugins.xmiexport:XMIExport"
|
||||
"diagram_layout" = "gaphor.plugins.diagramlayout:DiagramLayout"
|
||||
"pynsource" = "gaphor.plugins.pynsource:PyNSource"
|
||||
|
1
setup.py
1
setup.py
@ -113,7 +113,6 @@ setup(
|
||||
"main_window = gaphor.ui.mainwindow:MainWindow",
|
||||
"copy = gaphor.services.copyservice:CopyService",
|
||||
"sanitizer = gaphor.services.sanitizerservice:SanitizerService",
|
||||
"element_dispatcher = gaphor.UML.elementdispatcher:ElementDispatcher",
|
||||
"xmi_export = gaphor.plugins.xmiexport:XMIExport",
|
||||
"diagram_layout = gaphor.plugins.diagramlayout:DiagramLayout",
|
||||
"pynsource = gaphor.plugins.pynsource:PyNSource",
|
||||
|
Reference in New Issue
Block a user