def start(self, *args, **kwargs): """ Load controls if available, execute all files in startup. """ self._load_controls() self.started = True self.ns.clear() loading_code = [ 'import sys', 'sys.path.insert(0, %r)' % str(self.path / 'lib') ] loading_code = '\n'.join(loading_code) loading = ModelFactory(mimetype='text/x-python') ns = loading.run_code(loading_code, self.ns) self.ns.update(ns) self.ns['get_model'] = self.get_runnable_model for startup in self.startup.values(): model = to_model(startup) ns = model.run_code(startup.read(), self.ns) self.ns.update(ns) interpreter = kwargs.get('shell') if interpreter: #interpreter.shell.user_ns.clear() interpreter.shell.init_user_ns() interpreter.shell.user_ns.update(self.ns)
def __init__(self, **kwds): self.parent = kwds.pop('parent', None) self._widget = None mode_name, name_value = check_mutually_exclusive(kwds, 'name', 'filepath') mode_model, model_value = check_mutually_exclusive(kwds, 'model', 'data') _, code = check_mutually_exclusive(kwds, 'code', 'content') if name_value and model_value: raise ValueError('model/data and filename/name/content/code are mutually exclusive') if mode_name or mode_model: self._type = Model else: self._type = Data if name_value and self._type == Model: self._obj = ModelFactory(name=name_value, mimetype=self.mimetype_model, code=code) elif name_value and self._type == Data: self._obj = DataFactory(path=name_value, mimetype=self.mimetype_data, default_content=code) elif model_value: self._obj = model_value else: self._obj = ModelFactory(name='NewModel', mimetype=self.mimetype_model) self._type = Model if self._type == Model: self._model = self._obj else: self._model = to_model(self._obj)
def start(self, *args, **kwargs): """ Load controls if available, execute all files in startup. """ self._load_controls() self.started = True self.ns.clear() loading_code = [ 'import sys', 'sys.path.insert(0, %r)' % str(self.path / 'lib') ] loading_code = '\n'.join(loading_code) loading = ModelFactory(mimetype='text/x-python') ns = loading.run_code(loading_code, self.ns) self.ns.update(ns) self.ns['get_model'] = self.get_runnable_model for startup in self.startup.values(): model = to_model(startup) ns = model.run_code(startup.read(), self.ns) self.ns.update(ns) interpreter = kwargs.get('shell') if interpreter: #interpreter.shell.user_ns.clear() interpreter.shell.init_user_ns() interpreter.shell.user_ns.update(self.ns)
def get_runnable_model(self, name): data = self.get_model(name) if data: model = to_model(data) if model: return copy.copy(model)
def get_runnable_model(self, name): data = self.get_model(name) if data: model = to_model(data) if model: return copy.copy(model)
def get_model(name): data = pm.cproject.get_model(name) if data: model = to_model(data) if model: return copy.copy(model)