class KeypadApp: # pylint: disable=R0903 ## __slots__ allow us to explicitly declare data members __slots__ = ['_config_mgr', '_logger', '_log_store', '_state_object'] ## KeypadApp class constructor. # @param self The object pointer. def __init__(self): ## Instance of a configuration manager class. self._config_mgr = None self._logger = Logger() self._log_store = LogStore() self._logger.WriteToConsole = True self._logger.ExternalLogger = self self._logger.Initialise() ## Instance of the keypad state object. self._state_object = None ## Start the application, this will not exit until both the GUI and the # Twisted reactor have been destroyed. The only exception is if any # elements of the startup fail (e.g. loading the configuration). # @param self The object pointer. def start_app(self): self._config_mgr = ConfigurationManager() config = self._config_mgr.parse_config_file('configuration.json') if not config: self._logger.Log(LogType.Error, self._config_mgr.last_error_msg) return wx_app = wx.App() reactor.registerWxApp(wx_app) self._state_object = KeypadStateObject(config, self._logger) keypad_api_ctrl = KeypadApiController(config, self._state_object, self._log_store, self._logger) api_server = server.Site(keypad_api_ctrl) reactor.listenTCP(config.keypadController.networkPort, api_server) check_panel_loop = LoopingCall(self._state_object.check_panel) check_panel_loop.start(0.01, now=False) reactor.run() ## Stop the application. # @param self The object pointer. def stop_app(self): self._logger.Log(LogType.Info, 'Stopping keypad controller, cleaning up...') def add_log_event(self, current_time, log_level, msg): self._log_store.AddLogEvent(current_time, log_level, msg)
class PowerConsoleApp: # pylint: disable=R0903 ## __slots__ allow us to explicitly declare data members __slots__ = ['_config_mgr', '_logger'] ## KeypadApp class constructor. # @param self The object pointer. def __init__(self): ## Instance of a configuration manager class. self._config_mgr = None formatter = logging.Formatter( "%(asctime)s [%(levelname)s] %(message)s", "%Y-%m-%d %H:%M:%S") ## Instance of a logger. self._logger = logging.getLogger('system log') console_stream = logging.StreamHandler() console_stream.setFormatter(formatter) self._logger.setLevel(logging.DEBUG) self._logger.addHandler(console_stream) ## Start the application, this will not exit until both the GUI and the # Twisted reactor have been destroyed. The only exception is if any # elements of the startup fail (e.g. loading the configuration). # @param self The object pointer. def start_app(self): if not os.getenv('PWRCON_CONFIG'): self._logger.error('PWRCON_CONFIG environment variable missing!') sys.exit(1) config_file = os.getenv('PWRCON_CONFIG') self._config_mgr = ConfigurationManager() config = self._config_mgr.parse_config_file(config_file) if not config: print(f"ERROR: {self._config_mgr.last_error_msg}") return wx_app = wx.App() main_window = MainWindow(config) main_window.Show() wx_app.MainLoop() ## Stop the application. # @param self The object pointer. def stop_app(self): self._logger.info('Stopping power console, cleaning up...')