コード例 #1
0
    def loop(self):
        if not self._actions:
            raise ApplicationError(
                'actions list as not been initialized by decorators')

        title = 'Menu principal'

        addit = [(0, 23, ' SOMMAIRE: fin '.center(40, '-'))
                 ] if self._exit_allowed else []
        while True:
            msg = u'displaying main menu'
            self.log_info(msg)
            self.display_text(msg)

            menu = Menu(self._mt,
                        title=[title, '-' * len(title)],
                        choices=[t[0] for t in self._actions],
                        prompt='Votre choix',
                        line_skip=2,
                        margin_top=1,
                        prompt_line=20,
                        addit=addit,
                        cancelable=self._exit_allowed)

            try:
                choice = menu.get_choice()

                self.log_info('selected choice : %s', choice)
                if self.terminated:
                    return True

                if not choice:
                    if self._exit_allowed:
                        return True
                    else:
                        continue

                label, method = self._actions[choice - 1]

                self.log_info('invoking action : %s', label)
                self.display_text(label)

                method(self)

                if self.terminated:
                    return True

            except DeviceCommunicationError as e:
                if 'Interrupted system call' in str(
                        e):  # we got an interruption signal from the outside
                    self.log_info('system call interrupted by external signal')
                    return True
                else:
                    self.log_error_banner(e, unexpected=True)
                    self.log_exception(e)

            except KeyboardInterrupt:
                self.log_info('external interrupt caught')
                return True