|
1
|
|
|
from synergine.core.ActionManager import ActionManager |
|
2
|
|
|
from synergine.synergy.collection.SynergyCollection import SynergyCollection |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class EventManager(): |
|
6
|
|
|
""" |
|
7
|
|
|
Manager of collection events. |
|
8
|
|
|
""" |
|
9
|
|
|
|
|
10
|
|
|
def __init__(self, synergy_manager): |
|
11
|
|
|
self._synergy_manager = synergy_manager |
|
12
|
|
|
self._collections_mechanisms_steps = {} |
|
13
|
|
|
self._mechanisms_steps = [] |
|
14
|
|
|
self._action_manager = ActionManager() |
|
15
|
|
|
|
|
16
|
|
|
def refresh(self): |
|
17
|
|
|
self._mechanisms_steps = [] |
|
18
|
|
|
actions = self._get_actions() |
|
19
|
|
|
actions_steps = self._action_manager.get_steps_for_actions(actions) |
|
20
|
|
|
for step_actions in actions_steps: |
|
21
|
|
|
step_events = self._get_events_for_actions(step_actions) |
|
22
|
|
|
step_mechanisms = self._get_mechanisms_for_events(step_events) |
|
23
|
|
|
self._mechanisms_steps.append(step_mechanisms) |
|
24
|
|
|
|
|
25
|
|
|
def _get_actions(self): |
|
26
|
|
|
actions = [] |
|
27
|
|
|
for collection in self._synergy_manager.get_collections(): |
|
28
|
|
|
for action in collection.get_actions(): |
|
29
|
|
|
if action not in actions: |
|
30
|
|
|
actions.append(action) |
|
31
|
|
|
return actions |
|
32
|
|
|
|
|
33
|
|
|
def _get_events_for_actions(self, actions): |
|
34
|
|
|
events_definition = {} |
|
35
|
|
|
events = [] |
|
36
|
|
|
for action in actions: |
|
37
|
|
|
action_event_class = action.get_listened_class() |
|
38
|
|
|
if action_event_class not in events_definition: |
|
39
|
|
|
events_definition[action_event_class] = [action] |
|
40
|
|
|
else: |
|
41
|
|
|
events_definition[action_event_class].append(action) |
|
42
|
|
|
for event_class in events_definition: |
|
43
|
|
|
events.append(event_class(events_definition[event_class])) |
|
44
|
|
|
return events |
|
45
|
|
|
|
|
46
|
|
|
def _get_mechanisms_for_events(self, events): |
|
47
|
|
|
mechanisms_definition = {} |
|
48
|
|
|
mechanisms = [] |
|
49
|
|
|
for event in events: |
|
50
|
|
|
event_mechanism_class = event.get_mechanism() |
|
51
|
|
|
if event_mechanism_class not in mechanisms_definition: |
|
52
|
|
|
mechanisms_definition[event_mechanism_class] = [event] |
|
53
|
|
|
else: |
|
54
|
|
|
mechanisms_definition[event_mechanism_class].append(event) |
|
55
|
|
|
for mechanism_class in mechanisms_definition: |
|
56
|
|
|
# Note: Eerur de nommage event_class = mechanism class la |
|
57
|
|
|
mechanisms.append(mechanism_class(mechanisms_definition[mechanism_class])) |
|
58
|
|
|
return mechanisms |
|
59
|
|
|
|
|
60
|
|
|
def get_mechanisms_steps(self): |
|
61
|
|
|
return self._mechanisms_steps |