def uSymbol2Symbol(uSymbol,x,y,color): if isFunctionType(uSymbol): symbol = uSymbol(x, y, 5, color) elif isClassType(uSymbol) is type and issubclass(uSymbol,Widget): size = 10. symbol = uSymbol() symbol.x = x - (size/2) symbol.y = y - (size/2) try: symbol.size = size symbol.color = color except: pass elif isinstance(uSymbol,Marker) or isinstance(uSymbol,Flag): symbol = uSymbol.clone() if isinstance(uSymbol,Marker): symbol.fillColor = symbol.fillColor or color symbol.x, symbol.y = x, y else: symbol = None return symbol
def uSymbol2Symbol(uSymbol, x, y, color): if isFunctionType(uSymbol): symbol = uSymbol(x, y, 5, color) elif isClassType(uSymbol) is type and issubclass(uSymbol, Widget): size = 10. symbol = uSymbol() symbol.x = x - (size / 2) symbol.y = y - (size / 2) try: symbol.size = size symbol.color = color except: pass elif isinstance(uSymbol, Marker) or isinstance(uSymbol, Flag): symbol = uSymbol.clone() if isinstance(uSymbol, Marker): symbol.fillColor = symbol.fillColor or color symbol.x, symbol.y = x, y else: symbol = None return symbol
def getObjectsDefinedIn(modulename, directory=None): """Returns two tuple of (functions, classes) defined in the given module. 'directory' must be the directory containing the script; modulename should not include the .py suffix""" if directory: searchpath = [directory] else: searchpath = sys.path # searches usual Python path #might be a package. If so, check the top level #package is there, then recalculate the path needed words = modulename.split('.') if len(words) > 1: packagename = words[0] packagefound = imp.find_module(packagename, searchpath) assert packagefound, "Package %s not found" % packagename (file, packagepath, description) = packagefound #now the full path should be known, if it is in the #package directory = os.path.join(*([packagepath] + words[1:-1])) modulename = words[-1] searchpath = [directory] #find and import the module. found = imp.find_module(modulename, searchpath) assert found, "Module %s not found" % modulename (file, pathname, description) = found mod = imp.load_module(modulename, file, pathname, description) #grab the code too, minus trailing newlines lines = [s.rstrip() for s in open(pathname, 'r').readlines()] result = Struct() result.functions = [] result.classes = [] result.doc = mod.__doc__ for name in dir(mod): value = getattr(mod, name) if isFunctionType(value): path, file = os.path.split(value.__code__.co_filename) root, ext = os.path.splitext(file) #we're possibly interested in it if root == modulename: #it was defined here funcObj = value fn = Struct() fn.name = name fn.proto = getFunctionPrototype(funcObj, lines) if funcObj.__doc__: fn.doc = dedent(funcObj.__doc__) else: fn.doc = '(no documentation string)' #is it official? if name[0:1] == '_': fn.status = 'private' elif name[-1] in '0123456789': fn.status = 'experimental' else: fn.status = 'official' result.functions.append(fn) elif isClassType(value): if value.__module__ == modulename: cl = Struct() cl.name = name if value.__doc__: cl.doc = dedent(value.__doc__) else: cl.doc = "(no documentation string)" cl.bases = [] for base in value.__bases__: cl.bases.append(base.__name__) if name[0:1] == '_': cl.status = 'private' elif name[-1] in '0123456789': cl.status = 'experimental' else: cl.status = 'official' cl.methods = [] #loop over dict finding methods defined here # Q - should we show all methods? # loop over dict finding methods defined here items = value.__dict__.items() for (key2, value2) in items: if not isFunctionType(value2): continue # not a method elif os.path.splitext( value2.__code__.co_filename)[0] == modulename: continue # defined in base class else: #we want it meth = Struct() meth.name = key2 name2 = value2.__code__.co_name meth.proto = getFunctionPrototype(value2, lines) if name2 != key2: meth.doc = 'pointer to ' + name2 meth.proto = (meth.proto).replace(name2, key2) else: if value2.__doc__: meth.doc = dedent(value2.__doc__) else: meth.doc = "(no documentation string)" #is it official? if key2[0:1] == '_': meth.status = 'private' elif key2[-1] in '0123456789': meth.status = 'experimental' else: meth.status = 'official' cl.methods.append(meth) result.classes.append(cl) return result
def getObjectsDefinedIn(modulename, directory=None): """Returns two tuple of (functions, classes) defined in the given module. 'directory' must be the directory containing the script; modulename should not include the .py suffix""" if directory: searchpath = [directory] else: searchpath = sys.path # searches usual Python path #might be a package. If so, check the top level #package is there, then recalculate the path needed words = modulename.split('.') if len(words) > 1: packagename = words[0] packagefound = imp.find_module(packagename, searchpath) assert packagefound, "Package %s not found" % packagename (file, packagepath, description) = packagefound #now the full path should be known, if it is in the #package directory = os.path.join(*([packagepath] + words[1:-1])) modulename = words[-1] searchpath = [directory] #find and import the module. found = imp.find_module(modulename, searchpath) assert found, "Module %s not found" % modulename (file, pathname, description) = found mod = imp.load_module(modulename, file, pathname, description) #grab the code too, minus trailing newlines lines = [s.rstrip() for s in open(pathname, 'r').readlines()] result = Struct() result.functions = [] result.classes = [] result.doc = mod.__doc__ for name in dir(mod): value = getattr(mod, name) if isFunctionType(value): path, file = os.path.split(value.__code__.co_filename) root, ext = os.path.splitext(file) #we're possibly interested in it if root == modulename: #it was defined here funcObj = value fn = Struct() fn.name = name fn.proto = getFunctionPrototype(funcObj, lines) if funcObj.__doc__: fn.doc = dedent(funcObj.__doc__) else: fn.doc = '(no documentation string)' #is it official? if name[0:1] == '_': fn.status = 'private' elif name[-1] in '0123456789': fn.status = 'experimental' else: fn.status = 'official' result.functions.append(fn) elif isClassType(value): if value.__module__ == modulename: cl = Struct() cl.name = name if value.__doc__: cl.doc = dedent(value.__doc__) else: cl.doc = "(no documentation string)" cl.bases = [] for base in value.__bases__: cl.bases.append(base.__name__) if name[0:1] == '_': cl.status = 'private' elif name[-1] in '0123456789': cl.status = 'experimental' else: cl.status = 'official' cl.methods = [] #loop over dict finding methods defined here # Q - should we show all methods? # loop over dict finding methods defined here items = value.__dict__.items() for (key2, value2) in items: if not isFunctionType(value2): continue # not a method elif os.path.splitext(value2.__code__.co_filename)[0] == modulename: continue # defined in base class else: #we want it meth = Struct() meth.name = key2 name2 = value2.__code__.co_name meth.proto = getFunctionPrototype(value2, lines) if name2!=key2: meth.doc = 'pointer to '+name2 meth.proto = (meth.proto).replace(name2,key2) else: if value2.__doc__: meth.doc = dedent(value2.__doc__) else: meth.doc = "(no documentation string)" #is it official? if key2[0:1] == '_': meth.status = 'private' elif key2[-1] in '0123456789': meth.status = 'experimental' else: meth.status = 'official' cl.methods.append(meth) result.classes.append(cl) return result