コード例 #1
0
    def getConfigFileValue(self,
                           section,
                           option,
                           title,
                           valueList,
                           saveToFile=True):
        '''Get configurable options from the ini file, prompt user if they
    aren't there, and save if needed.

    Args:
      section: In which section of the .ini will we find the value?
      option: Which option in the section has the value?
      title: Title for multi-selection dialogue.
      valueList: Values to populate a multi-selection dialogue.
      saveToFile: Should we save the selection to the .ini?

    Example:
      inputMethod = getConfigFileValue("control", "inputMethod",
                                       "Select Input Method",
                                       ['commandByXMPP',
                                       'commandByTelnet',
                                       'commandByVoice'], False)
    '''
        # Check if option exists in the file
        if self._config.has_option(section, option):
            values = self._config.get(section, option)
            values = values.split(',')
            # Prompt the user to pick an option if the file specified more
            # than one option
            if len(values) > 1:
                setting = utils.pickFromList(droid, title, values)
            else:
                setting = values[0]
        else:
            setting = ''
        # Deal with blank or missing values by prompting user
        if not setting or not self._config.has_option(section, option):
            # Provide an empty text prompt if no list of values provided
            if not valueList:
                setting = droid.getInput(title).result
            # Let the user pick from a list of values
            else:
                setting = utils.pickFromList(droid, title, valueList)
            if saveToFile:
                self._config.set(section, option, setting)
                with open(self.configFilePath, 'wb') as configfile:
                    self._config.write(configfile)
        # Strip whitespace and try turning numbers into floats
        setting = setting.strip()
        try:
            setting = float(setting)
        except ValueError:
            pass
        return setting
コード例 #2
0
ファイル: configuration.py プロジェクト: IoannisIn/cellbots
  def getConfigFileValue(self, section, option, title,
                         valueList, saveToFile=True):
    '''Get configurable options from the ini file, prompt user if they
    aren't there, and save if needed.

    Args:
      section: In which section of the .ini will we find the value?
      option: Which option in the section has the value?
      title: Title for multi-selection dialogue.
      valueList: Values to populate a multi-selection dialogue.
      saveToFile: Should we save the selection to the .ini?

    Example:
      inputMethod = getConfigFileValue("control", "inputMethod",
                                       "Select Input Method",
                                       ['commandByXMPP',
                                       'commandByTelnet',
                                       'commandByVoice'], False)
    '''
    # Check if option exists in the file
    if self._config.has_option(section, option):
      values = self._config.get(section, option)
      values = values.split(',')
      # Prompt the user to pick an option if the file specified more
      # than one option
      if len(values) > 1:
        setting = utils.pickFromList(droid, title, values)
      else:
        setting = values[0]
    else:
      setting = ''
    # Deal with blank or missing values by prompting user
    if not setting or not self._config.has_option(section, option):
      # Provide an empty text prompt if no list of values provided
      if not valueList:
        setting = droid.getInput(title).result
      # Let the user pick from a list of values
      else:
        setting = utils.pickFromList(droid, title, valueList)
      if saveToFile:
        self._config.set(section, option, setting)
        with open(self.configFilePath, 'wb') as configfile:
          self._config.write(configfile)
    # Strip whitespace and try turning numbers into floats
    setting = setting.strip()
    try:
      setting = float(setting)
    except ValueError:
      pass
    return setting
コード例 #3
0
ファイル: cellbot.py プロジェクト: IoannisIn/cellbots
def selectConfigFile(configDir):
  iniFiles = glob.glob(os.path.join(configDir, "*.ini"))
  if len(iniFiles) < 1:
    utils.outputToOperator("ERROR: No config files found in %s!\n" % configDir)
    sys.exit()
  if len(iniFiles) == 1:
    return iniFiles[0]
  else:
    configFile = utils.pickFromList(droid, "Choose a config file to use",
        [os.path.basename(file) for file in iniFiles])
    configFile = os.path.join(configDir, configFile)
    utils.outputToOperator("Using config file %s.\n" % configFile)
    return configFile
コード例 #4
0
ファイル: cellbot.py プロジェクト: starkus92/cellbots
def selectConfigFile(configDir):
    iniFiles = glob.glob(os.path.join(configDir, "*.ini"))
    if len(iniFiles) < 1:
        utils.outputToOperator("ERROR: No config files found in %s!\n" %
                               configDir)
        sys.exit()
    if len(iniFiles) == 1:
        return iniFiles[0]
    else:
        configFile = utils.pickFromList(
            droid, "Choose a config file to use",
            [os.path.basename(file) for file in iniFiles])
        configFile = os.path.join(configDir, configFile)
        utils.outputToOperator("Using config file %s.\n" % configFile)
        return configFile
コード例 #5
0
ファイル: cellbotRemote.py プロジェクト: starkus92/cellbots
 def run(self):
   command = ''
   msg = ''
   while command != "Exit":
     try:
       command = utils.pickFromList(self.unlocked_droid,
           "Pick an action (set down phone to pause)",
           ['Say Hello', 'Point Using Compass', 'Take Picture',
            'Speak Location', 'Voice Command','Exit'])
     except KeyError as e:
       msg = "Sorry, please try that again. %s" % str(e)
       self.droid.makeToast(msg)
     else:
       # Pause sending commands so that robot only does what user selected here
       self.state.pauseSending = True
       if command == "Take Picture":
         self.remoteUplink.sendCmd(self.droid, "picture", True)
         self.droid.ttsSpeak("Asking robot to take a picture")
         self.droid.makeToast("Please wait, this may take a few seconds")
         time.sleep(5)
         msg = "Picture should be taken by now"
       elif command == "Speak Location":
         msg = "Speaking location"
         self.remoteUplink.sendCmd(self.droid, "x", True)
       elif command == "Voice Command":
         try:
           voiceCommand = droid.recognizeSpeech().result
           self.remoteUplink.sendCmd(self.droid, voiceCommand, True)
           msg = "Told the robot to " + voiceCommand
           self.droid.makeToast(msg)
           time.sleep(2)
         except:
           msg = "Could not understand"
       elif command == "Point Using Compass":
         msg = "This feature is currently not available on the robot."
         self.droid.makeToast(msg)
         # try:
         #   direction = utils.pickFromList(self.unlocked_droid,
         #       "Pick a direction", sorted([c for c in self.kCardinals]))
         # except KeyError as e:
         #   msg = "Sorry, please try that again. %s" % str(e)
         #   self.droid.makeToast(msg)
         # else:
         #   self.droid.ttsSpeak("Selected direction %s." % direction)
         #   cmd = "p " + self.kCardinals[direction]
         #  self.remoteUplink.sendCmd(self.droid, cmd, True)
         #  msg = "Asking robot to point " + direction
         #  self.droid.ttsSpeak(msg)
         #  time.sleep(2)
         #  msg = "Robot should be facing " + direction
       elif command == "Say Hello":
         msg = "Asking robot to say hello"
         self.remoteUplink.sendCmd(self.droid, "hi", True)
       elif command == "Exit":
         msg = "Bye bye. Come again."
         if self.sendQuit:
           self.remoteUplink.sendCmd(self.droid, "q", True)
     self.droid.ttsSpeak(msg)
     time.sleep(1)
     # This resumes sending of normal accelerometer stream of commands
     self.state.pauseSending = False
   self.remoteUplink.sendCmd(self.droid, "ws 0 0", True)
   # This will exit the main loop as well. Remove this if you only want to exit
   # the pop-up menu.
   self.state.running = False