class ZmApplet(object): def __init__(self): def get_input_handlers(controller, app_config): handlers = [PygameInputHandler(controller, app_config)] try: from pi_input_handler import PiInputHandler handlers.append(PiInputHandler(controller, app_config)) except ImportError: print('Unable to import raspberrypi input handler') return handlers def get_zoneminder_client(app_config): zm_client = ZoneMinderClient(app_config.config[SERVER_HOST], app_config.config[SERVER_PORT], app_config.config[ZM_WEB_PATH], app_config.config[USER_NAME], app_config.config[PASSWORD], app_config.config[ZMS_WEB_PATH]) return zm_client config = AppConfig() event_bus = EventBus() client = get_zoneminder_client(config) self.app_state = AppState() self.app_context = AppContext(config, client, event_bus) self.display = PygameDisplay(config) self.display.init() self.app_context.display_size = self.display.get_display_size() zm_stream_component = MonitorStreamComponent(self.app_context) group_selector_component = GroupSelectorComponent(self.app_context) monitor_selector_component = MonitorSelectorComponent(self.app_context) shutdown_prompt_component = ShutdownPromptSelector(self.app_context) menu_selector = MenuSelector(self.app_context) startup_component = StartUpComponent(self.app_context) self.component_manager = AppComponentManager( self.display, event_bus, startup_component, zm_stream_component, [ group_selector_component, monitor_selector_component, shutdown_prompt_component, menu_selector ]) self.input_manager = InputManager(get_input_handlers( event_bus, config)) self.app_controller = AppController(self.app_context, self.input_manager, self.app_state) self.task_manager = TaskManager(event_bus) def run(self): self.app_controller.activate() clock = pygame.time.Clock() time_elapsed = 0 while self.app_state.is_running and not self.app_state.shutdown_system: self.input_manager.process_inputs() self.task_manager.update() self.app_context.event_bus.process_queue() self.component_manager.update(time_elapsed) self.display.update() time_elapsed = clock.tick(10) if self.app_state.shutdown_system: os.system('sudo halt') pygame.quit()