示例#1
0
 def processCommand(self, retval):
    retval = retval.replace("\n", "")
    retval = retval.replace("\r", "")
    retval = retval.strip()
    if retval == "":
       return
    self.addCommandHistory(retval)
    # Macro-style substitutions here:
    if len(retval)>= 1 and retval[0] == ".":
       if len(retval) >= 2:
          if retval[1].isalpha():
             retval = "self" + retval
       else:
          retval = "self" + retval
    # Now process the command, case-like:
    if retval == "run":
       self.inform("Running in thread...")
       self.engine.pleaseRun() # pass in callback, or not
       # self.engine.pleaseRun(self.redraw) # pass in callback
    elif retval == "runtillquit":
       self.done = 0
       self.engine.pleaseRun()
       while not self.done:
          pass
       return 1
    elif retval == "step":
       self.stepEngine()
    elif retval == "info":
       print "-------------------------------------------------------------"
       print "Brain file:\t%s" % self.engine.brainfile
       print "Brain:\t\t%s" % self.engine.brain
       print "Robot:\t\t%s" % self.engine.robot
       print "World:\t\t%s" % self.engine.worldfile
       print "-------------------------------------------------------------"
    elif retval == "help":
       help()
    elif retval == "usage":
       usage()
    elif retval == "update":
       if self.engine.robot != 0:
          self.engine.robot.update()
          self.inform("Done!")
       else:
          self.inform("Define a robot first!")
    elif len(retval) >= 2 and retval[0:2] == "$$":
       os.system(retval[2:])
    elif len(retval) >= 1 and retval[0] == "$":
       pipe = popen(retval[1:])
       for line in pipe.readlines():
          print line.strip()
       pipe.close()
    elif len(retval) >= 1 and retval[0] == "!":
       if retval == "!":
          self.listCommandHistory()
       elif retval == "!!":
          self.processCommand(self.history[-2]) # -1 is !!
       elif "-" in retval:
          start, stop = retval[1:].split("-")
          start, stop = start.strip(), stop.strip()
          if start == "": # neg number
             self.processCommand(self.history[-int(stop) - 1])
          else:  
             for i in range(int(start), int(stop) + 1):
                self.processCommand(self.history[i - 1])
       else:
          val = retval[1:]
          if val.strip().isdigit():
             self.processCommand(self.history[int(val) - 1])
          else:
             self.listCommandHistory(val)               
    elif retval == "about":
       about()
    elif retval == "reload":
       self.engine.reset()
    elif retval == "load robot":
       self.loadRobot()
    elif retval == "load brain":
       self.loadBrain()
    elif retval == "load simulator" or retval == "load server":
       print "Enter simulator or server (e.g., StageSimulator, PlayerServer)"
       self.loadSim()
    elif retval == "stop":
       self.engine.pleaseStop()
       self.inform("Stopped!")
    elif retval == "quit" or retval == "exit" or retval == "bye":
       self.done = 1
       return 1
    elif retval == "edit":
       if self.engine.brainfile != '':
          if os.getenv("EDITOR"): 
             editor = os.getenv("EDITOR")
          else:
             editor = "emacs"
          os.system("%s %s" % (editor, self.engine.brainfile))
          self.inform("Reloading...")
          self.engine.reset()
       else:
          self.inform("Need to load a brain first!")
    elif retval[:8] == "unwatch ":
       self.watcher.unwatch(retval[7:].strip())
    elif retval[:5] == "view ":
       self.objectBrowser(retval[5:])
    elif retval[:6] == "watch ":
       self._populateEnv()
       self.watch(retval[5:].strip())
    elif retval[:7] == "browse ":
       self.objectBrowser(retval[7:].strip())
    else:
       # elif len(retval) > 0 and retval[0] == "!":
       exp1 = """_retval = """ + string.strip(retval)
       _retval = "error"
       exp2 = string.strip(retval)
       # perhaps could do these once, but could change:
       self._populateEnv()
       print ">>> ",
       print retval
       try:
          _retval = eval(exp2, self.environment)
       except:
          try:
             exec exp1 in self.environment
          except:
             try:
                exec exp2 in self.environment
             except:
                print self.formatExceptionInfo()
             else:
                print "Ok"
          else:
             print "Ok"
       else:
          if _retval != None:
             print _retval
    self.updateDeviceList()
    return 0
示例#2
0
 def help(self):
    #self.redirectToTerminal()
    system.help()
    system.usage()
示例#3
0
 def help(self):
     #self.redirectToTerminal()
     system.help()
     system.usage()
示例#4
0
文件: TK.py 项目: brugues/University
 def help(self):
    self.redirectToTerminal()
    system.help()
    system.usage()
    self.redirectToWindow()