Sustav događaja¶
Sustav događaja u Gaphoru pruža API za rukovanje događajima i za pretplatu na događaje.
U Gaphoru upravljamo pretplatama za rukovanje događajima putem usluge EventManager (Upravljač događaja). Gaphor je izrazito vođen događajima:
Promjene u učitanom modelu emitiraju se kao događaji
Promjene u dijagramima emitiraju se kao događaji
Promjene u korisničkom sučelju emitiraju se kao događaji
Although Gaphor depends heavily on GTK for its user interface, Gaphor is using its own event dispatcher. Events can be structured in hierarchies. For example, an AttributeUpdated event is a subtype of ElementUpdated. If we are interested in all changes to elements, we can also register ElementUpdated and receive all AttributeUpdated events as well.
- class gaphor.core.eventmanager.EventManager[source]¶
The Event Manager provides a flexible way to dispatch events.
Event dispatching is a central component in Gaphor. It allows components in Gaphor to react to changes in the application.
Events are dispatched by type.
- class subscribe(self, handler: Callable[[object], None])¶
Register a handler.
Handlers are triggered (executed) when events are emitted through the
handlemethod.
- gaphor.core.event_handler(*event_types)[source]¶
Mark a function/method as an event handler for a particular type of event.
Given a custom event type:
>>> class CustomEvent: ... def __str__(self): ... return type(self).__name__
You can apply this to a handler method or function:
>>> @event_handler(CustomEvent) ... def custom_handler(event: CustomEvent): ... print(event)
This will allow you to let the even be handled by an event manager:
>>> event_manager = EventManager() >>> event_manager.subscribe(custom_handler) >>> event_manager.handle(CustomEvent()) CustomEvent
Under the hood events are handled by the Generics library. For more information about how the Generic library handles events see the Generic documentation.