2026-01-11 19:42:31 -06:00
|
|
|
# Python imports
|
|
|
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
|
|
|
|
|
|
# Application imports
|
2026-01-18 13:52:28 -06:00
|
|
|
from ..singleton import Singleton
|
|
|
|
|
from ..event_factory import Code_Event_Types
|
2026-01-11 19:42:31 -06:00
|
|
|
|
2026-01-18 13:52:28 -06:00
|
|
|
from .controller_base import ControllerBase
|
|
|
|
|
from .controller_context import ControllerContext
|
2026-01-11 19:42:31 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ControllerManagerException(Exception):
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ControllerManager(Singleton, dict):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(ControllerManager, self).__init__()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _crete_controller_context(self) -> ControllerContext:
|
|
|
|
|
controller_context = ControllerContext()
|
|
|
|
|
controller_context.message_to = self.message_to
|
2026-01-18 13:52:28 -06:00
|
|
|
controller_context.message = self.message
|
2026-01-11 19:42:31 -06:00
|
|
|
|
|
|
|
|
return controller_context
|
|
|
|
|
|
|
|
|
|
def register_controller(self, name: str, controller: ControllerBase):
|
|
|
|
|
if not name or controller == None:
|
|
|
|
|
raise ControllerManagerException("Must pass in a 'name' and 'controller'...")
|
|
|
|
|
|
2026-01-13 00:00:35 -06:00
|
|
|
if name in self.keys():
|
|
|
|
|
raise ControllerManagerException(f"Can't bind controller to registered name of '{name}'...")
|
|
|
|
|
|
|
|
|
|
controller.set_controller_context( self._crete_controller_context() )
|
2026-01-11 19:42:31 -06:00
|
|
|
|
|
|
|
|
self[name] = controller
|
|
|
|
|
|
2026-01-13 00:00:35 -06:00
|
|
|
def get_controllers_key_list(self) -> list[str]:
|
|
|
|
|
return self.keys()
|
2026-01-11 19:42:31 -06:00
|
|
|
|
2026-01-18 00:53:10 -06:00
|
|
|
def message_to(self, name: str, event: Code_Event_Types.CodeEvent):
|
2026-01-11 19:42:31 -06:00
|
|
|
self[name]._controller_message(event)
|
|
|
|
|
|
2026-01-18 13:52:28 -06:00
|
|
|
def message(self, event: Code_Event_Types.CodeEvent):
|
2026-01-11 19:42:31 -06:00
|
|
|
for key in self.keys():
|
|
|
|
|
self[key]._controller_message(event)
|