def loadBrain(self,file): """Finds and loads the brain file.""" if self.robot is 0: raise 'No robot loaded when loading brain' if file[-3:] != '.py': file = file + '.py' if system.file_exists(file): try: self.brain.window.destroy() except: pass try: self.brain.destroy() except: pass self.brain = system.loadINIT(file, self) self.brainfile = file elif (os.getenv('PYROBOT') != None and system.file_exists(os.getenv('PYROBOT') + \ '/plugins/brains/' + file)): try: self.brain.window.destroy() except: pass try: self.brain.destroy() except: pass self.brain = system.loadINIT(os.getenv('PYROBOT') + \ '/plugins/brains/' + file, self) self.brainfile = os.getenv('PYROBOT') + '/plugins/brains/' + file else: raise "File not found: '%s'; is PYROBOT set?" % file
def loadBrain(self,file): """Finds and loads the brain file.""" if self.robot is 0: raise Except('No robot loaded when loading brain') if file[-3:] != '.py': file = file + '.py' if system.file_exists(file): try: self.brain.window.destroy() except: pass try: self.brain.destroy() except: pass self.brain = system.loadINIT(file, self) self.brainfile = file elif (pyrobotdir() != None and system.file_exists(pyrobotdir() + \ '/plugins/brains/' + file)): try: self.brain.window.destroy() except: pass try: self.brain.destroy() except: pass self.brain = system.loadINIT(pyrobotdir() + \ '/plugins/brains/' + file, self) self.brainfile = pyrobotdir() + '/plugins/brains/' + file else: raise Exception("Pyrobot File not found: '%s'" % file)
def loadBrain(self, file): """Finds and loads the brain file.""" if self.robot is 0: raise 'No robot loaded when loading brain' if file[-3:] != '.py': file = file + '.py' if system.file_exists(file): try: self.brain.window.destroy() except: pass try: self.brain.destroy() except: pass self.brain = system.loadINIT(file, self) self.brainfile = file elif (os.getenv('PYROBOT') != None and system.file_exists(os.getenv('PYROBOT') + \ '/plugins/brains/' + file)): try: self.brain.window.destroy() except: pass try: self.brain.destroy() except: pass self.brain = system.loadINIT(os.getenv('PYROBOT') + \ '/plugins/brains/' + file, self) self.brainfile = os.getenv('PYROBOT') + '/plugins/brains/' + file else: raise "File not found: '%s'; is PYROBOT set?" % file
def loadBrain(self, file): """Finds and loads the brain file.""" if self.robot is 0: raise Except('No robot loaded when loading brain') if file[-3:] != '.py': file = file + '.py' if system.file_exists(file): try: self.brain.window.destroy() except: pass try: self.brain.destroy() except: pass self.brain = system.loadINIT(file, self) self.brainfile = file elif (pyrobotdir() != None and system.file_exists(pyrobotdir() + \ '/plugins/brains/' + file)): try: self.brain.window.destroy() except: pass try: self.brain.destroy() except: pass self.brain = system.loadINIT(pyrobotdir() + \ '/plugins/brains/' + file, self) self.brainfile = pyrobotdir() + '/plugins/brains/' + file else: raise Exception("Pyrobot File not found: '%s'" % file)
def load(self, file = None): cp = ConfigParser.ConfigParser() if file_exists( environ['PYROBOT'] + "/.pyrobot"): # $PYROBOT? self.processFile( environ['PYROBOT'] + "/.pyrobot", cp) if file_exists( environ['PYROBOT'] + "/pyrobot.ini"): # $PYRO? self.processFile( environ['PYROBOT'] + "/pyrobot.ini", cp) if file_exists( environ['PYROBOT'] + "/.pyrobot-" + environ['HOSTNAME']): # $PYRO-HOSTNAME? self.processFile( environ['PYROBOT'] + "/.pyrobot-" + environ['HOSTNAME'], cp) if file_exists( environ['PYROBOT'] + "/pyrobot-" + environ['HOSTNAME'] + ".ini"): # $PYRO-HOSTNAME? self.processFile( environ['PYROBOT'] + "/pyrobot-" + environ['HOSTNAME'] + ".ini", cp) if file_exists( environ['HOME'] + "/.pyrobot"): # home dir? self.processFile( environ['HOME'] + "/.pyrobot", cp) if file_exists( environ['HOME'] + "/pyrobot.ini"): # home dir? self.processFile( environ['HOME'] + "/pyrobot.ini", cp) if file_exists(".pyrobot"): # current dir? self.processFile( ".pyrobot", cp) if file_exists("pyrobot.ini"): # current dir? self.processFile( "pyrobot.ini", cp) if file and file_exists(file): self.processFile( file, cp)
def load(self, file = None): cp = ConfigParser.ConfigParser() if file_exists( pyrobotdir() + "/.pyrobot"): self.processFile( pyrobotdir() + "/.pyrobot", cp) if file_exists( pyrobotdir() + "/pyrobot.ini"): # $PYRO? self.processFile( pyrobotdir() + "/pyrobot.ini", cp) if file_exists( pyrobotdir() + "/.pyrobot-" + environ['HOSTNAME']): # $PYRO-HOSTNAME? self.processFile( pyrobotdir() + "/.pyrobot-" + environ['HOSTNAME'], cp) if file_exists( pyrobotdir() + "/pyrobot-" + environ['HOSTNAME'] + ".ini"): # $PYRO-HOSTNAME? self.processFile( pyrobotdir() + "/pyrobot-" + environ['HOSTNAME'] + ".ini", cp) if file_exists( environ['HOME'] + "/.pyrobot"): # home dir? self.processFile( environ['HOME'] + "/.pyrobot", cp) if file_exists( environ['HOME'] + "/pyrobot.ini"): # home dir? self.processFile( environ['HOME'] + "/pyrobot.ini", cp) if file_exists(".pyrobot"): # current dir? self.processFile( ".pyrobot", cp) if file_exists("pyrobot.ini"): # current dir? self.processFile( "pyrobot.ini", cp) if file and file_exists(file): self.processFile( file, cp)
def loadMapFile(self, file): import os if file[-3:] != ".py": file = file + ".py" if system.file_exists(file): grid = system.loadINIT(file) elif system.file_exists(pyrobotdir() + "/plugins/maps/" + file): grid = system.loadINIT(pyrobotdir() + "/plugins/plots/" + file) else: raise "Map file not found: " + file self.setGrid(grid)
def startDevices(self, item, override=FALSE, **args): print("pyrobot/robot/__init.py__ startDevices") #error occured """Load devices can take a dict, list, builtin name, or filename """ # Item can be: dict, list, or string. string can be name or filename if type(item) == type({}): # this is the only one that does anything retval = [] for dev in list(item.keys()): deviceNumber = self._getNextDeviceNumber(dev) print("Loading device %s[%d]..." % (dev, deviceNumber)) self.__dict__[dev][deviceNumber] = item[dev] item[dev].setTitle(dev + "[" + str(deviceNumber) + "]") item[dev].index = deviceNumber retval.append(item[dev]) # return object return retval elif item in self.builtinDevices: # built-in name # deviceBuiltin returns dictionary print("pyrobot/robot/__init.py__ items") #error occured print("pyrobot/robot/__init.py__ builtinDevice") #error occured print(self.builtinDevices) #error occured print(type(self.builtinDevices)) #error occured print("pyrobot/robot/__init.py__ item %s" % item) #error occured #deviceList = self.startDeviceBuiltin(item) #error occured deviceList = self.startDeviceBuiltin(item) #error occured print(type(deviceList)) if type(deviceList) == type( "device"): # loaded it here, from the robot return [deviceList] else: return self.startDevices(deviceList, **args) # dict of objs elif isinstance(item, (type((1, )), type([ 1, ]))): retval = [] for i in item: retval.append(self.startDevice(i, **args)) return retval else: # from a file file = item if file == None: return [] if len(file) > 3 and file[-3:] != '.py': file = file + '.py' if system.file_exists(file): return self.startDevices(system.loadINIT(file, self), **args) elif system.file_exists(os.getenv('PYROBOT') + \ '/plugins/devices/' + file): return self.startDevices( system.loadINIT(os.getenv('PYROBOT') + \ '/plugins/devices/'+ \ file, self), **args) else: print('Device file not found: ' + file) return []
def loadMapFile(self, file): import os if file[-3:] != '.py': file = file + '.py' if system.file_exists(file): grid = system.loadINIT(file) elif system.file_exists(os.getenv('PYROBOT') + \ '/plugins/maps/' + file): grid = system.loadINIT(os.getenv('PYROBOT') + \ '/plugins/plots/' + file) else: raise 'Map file not found: ' + file self.setGrid(grid)
def fileloaddialog(self, type, skel, olddir = ''): """ Read a line from user """ print "\n%s Filename: " % type, retval = sys.stdin.readline() retval = retval.replace("\n", "") retval = retval.replace("\r", "") if file_exists(retval): return retval elif file_exists(olddir +"/" + retval): return olddir +"/" + retval else: # hope this is in the path! return retval
def loadRobot(self, file): """Finds and loads the robot.""" if file[-3:] != '.py': file = file + '.py' if system.file_exists(file): self.robot = system.loadINIT(file) self.robotfile = file elif (os.getenv('PYROBOT') != None and system.file_exists(os.getenv('PYROBOT') + \ '/plugins/robots/' + file)): self.robot = system.loadINIT(os.getenv('PYROBOT') + \ '/plugins/robots/' + file) self.robotfile = os.getenv('PYROBOT') + '/plugins/robots/' + file else: raise "Robot file not found: '%s'; is PYROBOT set?" % file
def loadRobot(self,file): """Finds and loads the robot.""" if file[-3:] != '.py': file = file + '.py' if system.file_exists(file): self.robot = system.loadINIT(file) self.robotfile = file elif (os.getenv('PYROBOT') != None and system.file_exists(os.getenv('PYROBOT') + \ '/plugins/robots/' + file)): self.robot = system.loadINIT(os.getenv('PYROBOT') + \ '/plugins/robots/' + file) self.robotfile = os.getenv('PYROBOT') + '/plugins/robots/' + file else: raise "Robot file not found: '%s'; is PYROBOT set?" % file
def loadRobot(self,file): """Finds and loads the robot.""" if file[-3:] != '.py': file = file + '.py' if system.file_exists(file): self.robot = system.loadINIT(file) self.robotfile = file elif (pyrobotdir() != None and system.file_exists(pyrobotdir() + \ '/plugins/robots/' + file)): self.robot = system.loadINIT(pyrobotdir() + \ '/plugins/robots/' + file) self.robotfile = pyrobotdir() + '/plugins/robots/' + file else: raise Exception("Pyrobot Robot file not found: '%s'" % file)
def loadRobot(self, file): """Finds and loads the robot.""" if file[-3:] != '.py': file = file + '.py' if system.file_exists(file): self.robot = system.loadINIT(file) self.robotfile = file elif (pyrobotdir() != None and system.file_exists(pyrobotdir() + \ '/plugins/robots/' + file)): self.robot = system.loadINIT(pyrobotdir() + \ '/plugins/robots/' + file) self.robotfile = pyrobotdir() + '/plugins/robots/' + file else: raise Exception("Pyrobot Robot file not found: '%s'" % file)
def fileloaddialog(self, type, skel, olddir=''): """ Read a line from user """ print("pyrobot/gui/__init__.py fileloaddialog entered") print("\n%s Filename: " % type, end=' ') retval = sys.stdin.readline() retval = retval.replace("\n", "") retval = retval.replace("\r", "") print("pyrobot/gui/__init__.py retval") print(retval) if file_exists(retval): print("pyrobot/gui/__init__.py fileloaddialog exists") return retval elif file_exists(olddir + "/" + retval): return olddir + "/" + retval else: # hope this is in the path! return retval
def startDevices(self, item, override = False, **args): """Load devices can take a dict, list, builtin name, or filename """ # Item can be: dict, list, or string. string can be name or filename if type(item) == type({}): # this is the only one that does anything retval = [] for dev in item.keys(): deviceNumber = self._getNextDeviceNumber(dev) print "Loading device %s[%d]..." % (dev, deviceNumber) self.__dict__[dev][deviceNumber] = item[dev] item[dev].setTitle( dev + "[" + str(deviceNumber) + "]" ) item[dev].index = deviceNumber retval.append(item[dev]) # return object return retval elif item in self.builtinDevices: # built-in name # deviceBuiltin returns dictionary deviceList = self.startDeviceBuiltin(item) if type(deviceList) == type("device"): # loaded it here, from the robot return [ deviceList ] else: return self.startDevices( deviceList, **args ) # dict of objs elif isinstance(item, (type((1,)), type([1,]))): retval = [] for i in item: retval.append( self.startDevice(i, **args) ) return retval else: # from a file file = item if file == None: return [] if len(file) > 3 and file[-3:] != '.py': file = file + '.py' if system.file_exists(file): return self.startDevices( system.loadINIT(file, self), **args ) elif system.file_exists(pyrobotdir() + \ '/plugins/devices/' + file): return self.startDevices( system.loadINIT(pyrobotdir() + \ '/plugins/devices/'+ \ file, self), **args) else: print 'Device file not found: ' + file return []
def __init__(self, name = 'abstract gui', options = {}, engine = 0): """ Child classes should do initialization pertaining to the creation of the GUI in the constructor. """ self.watcher = None self.triedToStop = 0 self.alreadyCleanedUp = 0 self.engine = engine self.engine.gui = self self.prevsighandler = signal.signal(signal.SIGINT, self.INThandler) self.history = [] self.history_pointer = 0 self.MAXHISTORY = 1000 self.environment = {} self.environment["gui"] = self self.lastDir = {} if file_exists(os.getenv('HOME') + "/.pyrobothist"): fp = open(os.getenv('HOME') + "/.pyrobothist", "r") self.history = map( string.strip, fp.readlines()) fp.close() self.history_pointer = len(self.history)
def __init__(self, name = 'abstract gui', options = {}, engine = 0): """ Child classes should do initialization pertaining to the creation of the GUI in the constructor. """ self.watcher = None self.triedToStop = 0 self.alreadyCleanedUp = 0 self.engine = engine self.engine.gui = self self.prevsighandler = signal.signal(signal.SIGINT, self.INThandler) self.history = [] self.history_pointer = 0 self.MAXHISTORY = 1000 self.environment = {} self.environment["gui"] = self self._populateEnv() self.lastDir = {} if file_exists(os.getenv('HOME') + "/.pyrobothist"): fp = open(os.getenv('HOME') + "/.pyrobothist", "r") self.history = map( string.strip, fp.readlines()) fp.close() self.history_pointer = len(self.history)
def __init__(self, pattern=None, start=0, stop=19, char="?", interval=1.0, visionSystem=None, verbose=0): """ pattern is a filename with indicators on where to put digits for the sequence. Absolute or relative filenames can be used. For example, 'image???-.ppm' would start at 'image000.ppm' and continue up to stop. char is the character that should be replaced in the pattern. interval = how often do I get new image As an example, to load som-0.ppm through som-19.ppm, we could call FakeCamera('vision/snaps/som-?.ppm', 0, 19) """ if pattern == None: pattern = "vision/snaps/som-?.ppm" self.pattern = pattern self.stop = stop self.start = start self.current = start self.setUpdateInterval(interval) self.verbose = verbose self.lastUpdate = 0 #create a matchdata object that we will store self.match = re.search(re.escape(char) + "+", pattern) #create a format string that we can use to replace the #replace characters if self.match: self.fstring = "%%0%dd" % len(self.match.group()) currname = self.pattern[:self.match.start()] + \ self.fstring % self.current + \ self.pattern[self.match.end():] else: currname = self.pattern if system.file_exists(currname): self.path = '' elif system.file_exists(os.getenv('PYROBOT') + "/" + currname): self.path = os.getenv('PYROBOT') + "/" else: raise ValueError("file not found: '%s'" % currname) if self.verbose: print("info: reading file '%s'..." % (self.path + currname)) self._dev = Fake(self.path + currname) # connect vision system: -------------------------- if visionSystem: self.vision = visionSystem self.vision.registerCameraDevice(self._dev) self.width = self.vision.getWidth() self.height = self.vision.getHeight() self.depth = self.vision.getDepth() self._cbuf = self.vision.getMMap() else: self.vision = None self.width = 0 self.height = 0 self.depth = 0 self._cbuf = None # ------------------------------------------------- self.rgb = (0, 1, 2) # offsets to RGB self.format = "RGB" Camera.__init__(self, self.width, self.height, self.depth, "Fake Camera View") self.subtype = "simulated" self.source = self.pattern self.data = CBuffer(self._cbuf) self.oldStart = None self.oldStop = None
def loadSimulator(self, file, worldfile): """Finds and loads the simulator.""" import string options = string.split(file) guiflag = '' simulatorName = file.split('/')[-1] pyroPID = os.getpid() if simulatorName[-6:] == "Server": configDirName = simulatorName[:-6] if system.file_exists(worldfile): pass # leave it alone elif (pyrobotdir() != None and system.file_exists( pyrobotdir() + \ '/plugins/configs/%s/%s' % (configDirName, worldfile))): worldfile = pyrobotdir() + \ '/plugins/configs/%s/%s' % (configDirName, worldfile) if self.config.get("pyrobot", "gui") .lower() == 'tty': guiflag = '-g' if system.file_exists(options[0]): os.system(file + (" %d " % pyroPID) + guiflag + " " + worldfile + " &") elif (pyrobotdir() != None and system.file_exists(pyrobotdir() + \ '/plugins/simulators/' + options[0])): os.system(pyrobotdir() + '/plugins/simulators/' + file + \ (" %d " % pyroPID) + guiflag + " " + worldfile + " &") else: raise Exception("Pyrobot Server file not found: '%s'" % file) else: # Ends with "Simulator" simDirName = simulatorName[:-9] if system.file_exists(worldfile): pass # leave it alone elif (pyrobotdir() != None and system.file_exists( pyrobotdir() + \ '/plugins/worlds/%s/%s' % (simDirName, worldfile))): worldfile = pyrobotdir() + \ '/plugins/worlds/%s/%s' % (simDirName, worldfile) if self.config.get("pyrobot", "gui") .lower() == 'tty': guiflag = '-g' if system.file_exists(options[0]): os.system(file + (" %d " % pyroPID)+ guiflag + " " + worldfile + " &") elif (pyrobotdir() != None and system.file_exists(pyrobotdir() + \ '/plugins/simulators/' + options[0])): os.system(pyrobotdir() + '/plugins/simulators/' + file + \ (" %d " % pyroPID) + guiflag + " " + worldfile + " &") else: raise Exception("Pyrobot Simulator file not found: '%s'" % file) print "Loading.", sys.stdout.flush() wait = None if type(share.config) != type(0): wait = share.config.get("gui", "sim_start_delay") if wait == None: time.sleep(1) # default elif wait: time.sleep(float(wait)) print ".", sys.stdout.flush()
def __init__(self, pattern = None, start = 0, stop = 19, char = "?", interval = 1.0, visionSystem = None, verbose = 0): """ pattern is a filename with indicators on where to put digits for the sequence. Absolute or relative filenames can be used. For example, 'image???-.ppm' would start at 'image000.ppm' and continue up to stop. char is the character that should be replaced in the pattern. interval = how often do I get new image As an example, to load som-0.ppm through som-19.ppm, we could call FakeCamera('vision/snaps/som-?.ppm', 0, 19) """ if pattern == None: pattern = "vision/snaps/som-?.ppm" self.pattern = pattern self.stop = stop self.start = start self.current = start self.setUpdateInterval(interval) self.verbose = verbose self.lastUpdate = 0 #create a matchdata object that we will store self.match = re.search(re.escape(char) + "+", pattern) #create a format string that we can use to replace the #replace characters if self.match: self.fstring = "%%0%dd" % len(self.match.group()) currname = self.pattern[:self.match.start()] + \ self.fstring % self.current + \ self.pattern[self.match.end():] else: currname = self.pattern if system.file_exists(currname): self.path = '' elif system.file_exists( pyrobotdir() + "/" + currname): self.path = pyrobotdir() + "/" else: raise ValueError, "file not found: '%s'" % currname if self.verbose: print "info: reading file '%s'..." % (self.path + currname) self._dev = Fake(self.path + currname) # connect vision system: -------------------------- if visionSystem: self.vision = visionSystem self.vision.registerCameraDevice(self._dev) self.width = self.vision.getWidth() self.height = self.vision.getHeight() self.depth = self.vision.getDepth() self._cbuf = self.vision.getMMap() else: self.vision = None self.width = 0 self.height = 0 self.depth = 0 self._cbuf = None # ------------------------------------------------- self.rgb = (0, 1, 2) # offsets to RGB self.format = "RGB" Camera.__init__(self, self.width, self.height, self.depth, "Fake Camera View") self.subtype = "simulated" self.source = self.pattern self.data = CBuffer(self._cbuf) self.oldStart = None self.oldStop = None
def loadSimulator(self, file, worldfile): """Finds and loads the simulator.""" import string #options = string.split(file) options = file.split() guiflag = '' simulatorName = file.split('/')[-1] pyroPID = os.getpid() if simulatorName[-6:] == "Server": configDirName = simulatorName[:-6] if system.file_exists(worldfile): pass # leave it alone elif (os.getenv('PYROBOT') != None and system.file_exists( os.getenv('PYROBOT') + \ '/plugins/configs/%s/%s' % (configDirName, worldfile))): worldfile = os.getenv('PYROBOT') + \ '/plugins/configs/%s/%s' % (configDirName, worldfile) if self.config.get("pyrobot", "gui").lower() == 'tty': guiflag = '-g' if system.file_exists(options[0]): os.system(file + (" %d " % pyroPID) + guiflag + " " + worldfile + " &") elif (os.getenv('PYROBOT') != None and system.file_exists(os.getenv('PYROBOT') + \ '/plugins/simulators/' + options[0])): os.system(os.getenv('PYROBOT') + '/plugins/simulators/' + file + \ (" %d " % pyroPID) + guiflag + " " + worldfile + " &") else: raise "Server file not found: '%s'; is PYROBOT set?" % file else: # Ends with "Simulator" simDirName = simulatorName[:-9] if system.file_exists(worldfile): pass # leave it alone elif (os.getenv('PYROBOT') != None and system.file_exists( os.getenv('PYROBOT') + \ '/plugins/worlds/%s/%s' % (simDirName, worldfile))): worldfile = os.getenv('PYROBOT') + \ '/plugins/worlds/%s/%s' % (simDirName, worldfile) if self.config.get("pyrobot", "gui").lower() == 'tty': guiflag = '-g' if system.file_exists(options[0]): os.system(file + (" %d " % pyroPID) + guiflag + " " + worldfile + " &") elif (os.getenv('PYROBOT') != None and system.file_exists(os.getenv('PYROBOT') + \ '/plugins/simulators/' + options[0])): os.system(os.getenv('PYROBOT') + '/plugins/simulators/' + file + \ (" %d " % pyroPID) + guiflag + " " + worldfile + " &") else: raise "Simulator file not found: '%s'; is PYROBOT set?" % file print("Loading.", end=' ') sys.stdout.flush() wait = None if type(share.config) != type(0): wait = share.config.get("gui", "sim_start_delay") if wait == None: time.sleep(1) # default elif wait: time.sleep(float(wait)) print(".", end=' ') sys.stdout.flush()