1
|
|
|
from synergine.core.SynergyObjectManager import SynergyObjectManager |
2
|
|
|
from synergine.core.exception.NotFoundError import NotFoundError |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
class Connector(): |
6
|
|
|
""" |
7
|
|
|
Connector is the connection between terminals (Terminal) and Core. |
8
|
|
|
""" |
9
|
|
|
|
10
|
|
|
def __init__(self, synergy_object_manager: SynergyObjectManager, context): |
11
|
|
|
""" |
12
|
|
|
:param synergy_object_manager: The synergy manager |
13
|
|
|
:return: void |
14
|
|
|
""" |
15
|
|
|
self._synergy_object_manager = synergy_object_manager |
16
|
|
|
self._context = context |
17
|
|
|
self._terminals = [] |
18
|
|
|
|
19
|
|
|
def initialize_terminals(self, terminals_classes, configuration): |
20
|
|
|
""" |
21
|
|
|
|
22
|
|
|
:param terminal_classes: list of Terminal classes |
23
|
|
|
:param configuration: ConfigurationManager |
24
|
|
|
:return: void |
25
|
|
|
""" |
26
|
|
|
for terminal_class in terminals_classes: |
27
|
|
|
terminal = terminal_class(configuration, self._context, self._synergy_object_manager) |
28
|
|
|
terminal.initialize() |
29
|
|
|
self._terminals.append(terminal) |
30
|
|
|
|
31
|
|
|
def cycle(self, actions_done): |
32
|
|
|
if True: # Stuff est-ce que 25 fps etc |
33
|
|
|
self._send(actions_done) |
34
|
|
|
|
35
|
|
|
def _send(self, actions_done): |
36
|
|
|
for terminal in self._terminals: |
37
|
|
|
terminal.start_of_cycle() |
38
|
|
|
terminal.receive(actions_done) |
39
|
|
|
terminal.end_of_cycle() |
40
|
|
|
|
41
|
|
|
def terminate(self): |
42
|
|
|
for terminal in self._terminals: |
43
|
|
|
terminal.terminate() |
44
|
|
|
|
45
|
|
|
def get_connection_who_have_to_run_core(self): |
|
|
|
|
46
|
|
|
display_who_run_core = None |
47
|
|
|
for connected_display in self._terminals: |
48
|
|
|
if connected_display.need_to_run_core(): |
49
|
|
|
if display_who_run_core: |
50
|
|
|
raise Exception('Two terminal try to run core. Just one can do it.') |
51
|
|
|
return connected_display |
52
|
|
|
return display_who_run_core |
53
|
|
|
|
54
|
|
|
def send_screen_to_connection(self, screen): |
55
|
|
|
""" |
56
|
|
|
Actually used for Curses |
57
|
|
|
:param screen: |
58
|
|
|
:return:void |
59
|
|
|
""" |
60
|
|
|
display_who_run_core = self.get_connection_who_have_to_run_core() |
61
|
|
|
if not display_who_run_core: |
62
|
|
|
raise Exception('Need Terminal object to do that') |
63
|
|
|
display_who_run_core.initialize_screen(screen) |
64
|
|
|
|
65
|
|
|
def get_terminal(self, terminal_name): |
66
|
|
|
for terminal in self._terminals: |
67
|
|
|
if terminal.get_name() == terminal_name: |
68
|
|
|
return terminal |
69
|
|
|
raise NotFoundError() |
This check looks for invalid names for a range of different identifiers.
You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.
If your project includes a Pylint configuration file, the settings contained in that file take precedence.
To find out more about Pylint, please refer to their site.