def __setitem__(self, key, val): if not isinstance(val, WindowNode): raise TypeError, evalFmt( '{self.nodePath} only accepts instance of WindowNode or of its subclasses.' ) if key != id(val): raise ValueError, 'The key should be identical to the ID of the window.' NodeDict.__setitem__(self, key, val)
def __setitem__(self, key, val): if not isinstance(val, AlgorithmNode): raise TypeError, evalFmt( '{self.nodePath} only accepts instance of Algorithm or of its subclasses.' ) if key != val.meta.name: raise ValueError, 'The key should be identical to the name of the algorithm.' NodeDict.__setitem__(self, key, val)
def func(self, *args, **kwargs): callerLocals = sys._getframe(1).f_locals ##################################### #print(method.__name__, True if 'printCode' in callerLocals else False) ##################################### if 'printCode' in callerLocals and callerLocals['printCode']: ret = Application.instance.printAndEval( evalFmt( '{self.nodePath}.{method.__name__}({Scripting.paramsToStr(*args, **kwargs)})' ) ) else: ret = method(self, *args, **kwargs) return ret
def checkCommand(): command = self.xmlrpcCommandSlot.command paramsToStr = Scripting.paramsToStr # used by evalFmt try: if command is not None: nodePath, methodName, args, kwargs = command ret, err = None, None try: ret = self.printAndEval(evalFmt('{nodePath}.{methodName}({paramsToStr(*args, **kwargs)})')) # paramToStr used here except Exception, error: err = error ret = 0 if ret is None else ret self.xmlrpcCommandSlot.returnVal = (ret, err) finally: # Make sure that at any circumstance the checkCommand will be called repeatedly. self.root.after(100, self.xmlrpcCheckCommand)
def paramsToStr(*args, **kwargs): def paramToStr(param): if isinstance(param, ScriptCode): return param.code else: return repr(param) strArgs = ', '.join([paramToStr(arg) for arg in args]) if args else '' strKwargs = ', '.join([evalFmt('{key}={paramToStr(kwargs[key])}') for key in kwargs]) \ if kwargs else '' if strArgs and strKwargs: params = ', '.join((strArgs, strKwargs)) else: params = strArgs if strArgs else strKwargs return params
def getRepr(nodePath=Scripting.rootName): return Application.instance.execute(evalFmt('{nodePath}.__repr__()'))
def getMethodDoc(nodePath, methodName): doc = Application.instance.execute(evalFmt('{nodePath}.{methodName}.__doc__')) return '' if doc is None else doc
def getChildNodes(nodePath=Scripting.rootName): return Application.instance.execute(evalFmt('{nodePath}.childNodes'))
def getitem(nodePath, index): return Application.instance.execute(evalFmt('{nodePath}[{repr(index)}].nodePath'))
def nodePath(self): if isinstance(self.parentNode, FigureList): return evalFmt("{self.parentNode.nodePath}[{self.index}]") else: return ModelNode.nodePath
def nodePath(self): if isinstance(self.parentNode, AlgorithmDict): return evalFmt('{self.parentNode.nodePath}["{self.meta.name}"]') else: return ModelNode.nodePath
def __init__(self, *args, **kwargs): super(WindowNode, self).__init__(*args, **kwargs) self._toplevel = Toplevel() self._toplevel.title(evalFmt('{self.windowName} id={id(self)}')) self._toplevel.protocol('WM_DELETE_WINDOW', self.onClose)
def nodePath(self): if isinstance(self.parentNode, FigureList): return evalFmt('{self.parentNode.nodePath}[{self.index}]') else: return ModelNode.nodePath
def notifyWinQuit(self, win): self.printTip(evalFmt('{win.nodePath} is closed, and its ID becomes defunct for scripting system hereafter')) self.windows.pop(id(win))
def nodePath(self): if isinstance(self.parentNode, WindowDict): return evalFmt("{self.parentNode.nodePath}[{id(self)}]") else: return ModelNode.nodePath
def __init__(self, *args, **kwargs): super(WindowNode, self).__init__(*args, **kwargs) self._toplevel = Toplevel() self._toplevel.title(evalFmt("{self.windowName} id={id(self)}")) self._toplevel.protocol("WM_DELETE_WINDOW", self.onClose)
def append(self, val): if not isinstance(val, DataFigure): raise TypeError, evalFmt("{self.nodePath} only accepts instance of DataFigure or of its subclasses.") NodeList.append(self, val)
def append(self, val): if not isinstance(val, DataFigure): raise TypeError, evalFmt( '{self.nodePath} only accepts instance of DataFigure or of its subclasses.' ) NodeList.append(self, val)
def nodePath(self): if isinstance(self.parentNode, WindowDict): return evalFmt('{self.parentNode.nodePath}[{id(self)}]') else: return ModelNode.nodePath
def run(self): printCode = True #parameters = Scripting.paramsToStr(**self.parameters) paramStr = evalFmt('[([], dict({Scripting.paramsToStr(**self.parameters)}))]*{self.num}') self.algorithm.parallelRunAndPlot(ScriptCode(paramStr))
def __setitem__(self, key, val): if not isinstance(val, AlgorithmNode): raise TypeError, evalFmt('{self.nodePath} only accepts instance of Algorithm or of its subclasses.') if key != val.meta.name: raise ValueError, 'The key should be identical to the name of the algorithm.' NodeDict.__setitem__(self, key, val)
def __setitem__(self, key, val): if not isinstance(val, WindowNode): raise TypeError, evalFmt("{self.nodePath} only accepts instance of WindowNode or of its subclasses.") if key != id(val): raise ValueError, "The key should be identical to the ID of the window." NodeDict.__setitem__(self, key, val)