Example #1
0
class Application(App, Observer):
    _mutex = threading.Lock()

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self._watchdog_queue = WatchdogQueue()
        self._gui = None

    def check_alarm_queue(self, dt):
        try:
            watchdog = self._watchdog_queue.get(timeout=0.01)
            logger.debug('Found {0} on the queue'.format(watchdog))
            WatchdogWindow(watchdog=watchdog).open()
            self._watchdog_queue.task_done()
        except Empty:
            logger.debug('There is noting on the queue')

    def notify(self, notifier, **kwargs):
        with Application._mutex:
            if isinstance(notifier, WatchdogList) and self._gui is not None:
                if notifier.alarm_count == 1:
                    self._gui.ids.alarm_label.text = 'There is currently 1 alarm!'
                    self._gui.ids.alarm_label.color = [1, 0, 0, 1]
                elif notifier.alarm_count > 1:
                    self._gui.ids.alarm_label.text = 'There are currently {0} alarms!'.format(notifier.alarm_count)
                    self._gui.ids.alarm_label.color = [1, 0, 0, 1]
                else:
                    self._gui.ids.alarm_label.text = 'There are currently no alarms.'
                    self._gui.ids.alarm_label.color = [0, 1, 0, 1]

    def build(self):
        configuration = Configuration(os.path.join(os.path.dirname(__file__), '..', 'configuration.gui.json'))
        configuration_builder = ConfigurationBuilder(configuration=configuration)
        client = configuration_builder.build_client()

        self._gui = ShipControlGui(client=client, configuration_builder=configuration_builder)
        watchdog_list = configuration_builder.build_watchdog_list(client=client, watchdog_queue=self._watchdog_queue)
        watchdog_list.register_observer(self)
        Clock.schedule_interval(self.check_alarm_queue, 1)

        return self._gui
Example #2
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self._watchdog_queue = WatchdogQueue()
     self._gui = None