def demo_menu(self, mt, opts): """ displays a menu """ demos = ["make foo", "do bar", "baz everything"] while True: menu = Menu( mt, title=['Menu demo', '-------------'], choices=demos, prompt='Your taste', line_skip=2, margin_top=2, prompt_line=20, addit=[(0, 23, ' SOMMAIRE: quit '.center(40, '-'))] ) choice = menu.get_choice() if choice: mt.display_text_center(' selected demo : %s ' % demos[choice - 1], 23, pad_char='-') time.sleep(3) else: break
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
def run(self): """ Application run mainline """ self._log.info('creating Minitel instance on %s', self._minitel_port) self._mt = Minitel(self._minitel_port) # , debug=self._debug) self._mt.clear_all() self._mt.display_status( self._mt.text_style_sequence(inverse=True) + u'Démonstration YouPinitel'.ljust(self._mt.get_screen_width()) ) if self._arm_port: arm_type = 'AX12' if AX12_ARM else 'Youpi' if not AX12_ARM: self._arm_baudrate = 9600 self._log.info('creating %s arm interface instance on %s (baudrate=%d)', arm_type, self._arm_port, self._arm_baudrate) if AX12_ARM: intf = USB2AX(self._arm_port, baudrate=self._arm_baudrate) self._arm = GestureController(intf) self._arm.configure_joints(self._cfg_arm['joints']) else: self._log.info('initializing Youpi interface and arm') self._mt.display_text_center("Initialisation du bras", y=5) self._mt.display_text_center(u"Veuillez patienter...", y=7) intf = YoupiArduinoInterface(self._arm_port) intf.wait_for_ready() self._mt.clear_screen() self._arm = YoupiArmController(intf) # self._arm.base.set_goal_angle(150) # while math.fabs(self._arm.base.get_current_angle() - 150) >= 1: # time.sleep(0.1) self.pose_home = dict(self._arm.get_pose()) self._log.info('Youpi home pose:') for n, a in self.pose_home.iteritems(): self._log.info('- %-10s : %5.1f', n, a) elif self._arm_busname: self._log.info("connecting to arm nROS controller '%s'", self._arm_busname) bus = dbus.SessionBus() self._arm = bus.get_object(self._arm_busname, DEFAULT_SERVICE_OBJECT_PATH) self._arm.joints = dict([ (n, bus.get_object(self._arm_busname, '/joint/%s' % n)) for n in self._arm.get_joint_names() ]) else: raise Exception('no arm controller connection was configured') title = 'Menu principal' while True: self._log.info('displaying main menu') menu = Menu( self._mt, title=[title, '-' * len(title)], choices=[t[0] for t in self._demos], prompt='Votre choix', line_skip=2, margin_top=1, prompt_line=20, addit=[(0, 23, ' SOMMAIRE: fin '.center(40, '-'))] ) choice = menu.get_choice() if choice: label, method = self._demos[choice - 1] self._log.info('selected demo : %s', label) method() else: break self._mt.clear_all() self._mt.display_text(u"Damien & Eric vous disent à bientôt.")