def select_colormap(): # @GBY must move to plantgl or lpy from openalea.core.control.manager import ControlManager from openalea.plantlab.tools import to_material controls = ControlManager().namespace(interface='IColorList') for v in controls.values(): return to_material(v)
def get_control(name): """ Get a tracked control by name. If multiple control with same name exists, returns a list of controls. """ cm = ControlManager() return cm.control(name)
class Control(Node, AbstractListener): def __init__(self, inputs, outputs): Node.__init__(self, inputs, outputs) AbstractListener.__init__(self) self.cm = ControlManager() self.cm.register_listener(self) def notify(self, sender, event): signal, data = event if signal == 'control_value_changed': self.invalidate() print 'control changed' elif signal == 'control_name_changed': ctrl, name = data self.set_input(0, name) self.set_caption(name) self.notify_listeners(("input_modified", 0)) def __call__(self, inputs): """ inputs is the list of input values """ key = inputs[0] if key in self.cm: obj = self.cm.control(name=key) self.set_caption("%s" % (key, )) if isinstance(obj, list): obj = obj[0] return (obj.value, )
def select_colormap(): # @GBY must move to plantgl or lpy from openalea.core.control.manager import ControlManager from openalea.plantlab.tools import to_material controls = ControlManager().namespace(interface='IColorList') for v in controls.values(): return to_material(v)
class Control(Node, AbstractListener): def __init__(self, inputs, outputs): Node.__init__(self, inputs, outputs) AbstractListener.__init__(self) self.cm = ControlManager() self.cm.register_listener(self) def notify(self, sender, event): signal, data = event if signal == 'control_value_changed': self.invalidate() print 'control changed' elif signal == 'control_name_changed': ctrl, name = data self.set_input(0, name) self.set_caption(name) self.notify_listeners(("input_modified", 0)) def __call__(self, inputs): """ inputs is the list of input values """ key = inputs[0] if key in self.cm: obj = self.cm.control(name=key) self.set_caption("%s" % (key, )) if isinstance(obj, list): obj = obj[0] return (obj.value, )
def _save_controls(self, obj): from openalea.core.control.serialization import ControlSerializer from openalea.core.control.manager import ControlManager cm = ControlManager() controls = cm.controls() if controls: serializer = ControlSerializer() lines = serializer.serialize(controls) else: lines = [] return lines
def _save_controls(self, obj): from openalea.core.control.serialization import ControlSerializer from openalea.core.control.manager import ControlManager cm = ControlManager() controls = cm.controls() if controls: serializer = ControlSerializer() lines = serializer.serialize(controls) else: lines = [] return lines
def __init__(self): import traceback traceback.print_stack(file=sys.__stdout__) self._project = None self._is_proj = False self._debug = False self.gui = True self.tmpdir = path(get_openalea_tmp_dir()) self._config = MainConfig() self.extension = None self.applet = {} self.manager = {} self.package_manager = package_manager self.control_manager = ControlManager() self.project_manager = ProjectManager() self.plugin_manager = PluginManager() self.plugin_instance_manager = PluginInstanceManager() self.manager['control'] = self.control_manager self.manager['package'] = self.package_manager self.manager['project'] = self.project_manager self.manager['plugin'] = self.plugin_manager self.manager['plugin_instance'] = self.plugin_instance_manager self.world = World() self.interpreter = interpreter() # Hack if interpreter is an object from class TerminalInteractiveShell if not hasattr(self.interpreter, "shell"): self.interpreter.shell = self.interpreter if hasattr(self.interpreter.shell, "events"): self.interpreter.shell.events.register("post_execute", self.add_to_history) else: print("You need ipython >= 2.0 to use history.") # self.project_manager.set_shell(self.interpreter.shell) self.interpreter.locals['session'] = self self.old_syspath = sys.path self.load_default() self.__class__.instantiated = True
def sample_controls(): cm = ControlManager() # cc1 = ControlContainer() # cc2 = ControlContainer() cmw = ControlManagerWidget() # cmw.model.set_manager(cc2) cp = ControlPanel() percent = get_interface('IInt', min=0, max=100) c = new_control('i', percent) # cc2.add_control(c) c = new_control('f', 'IFloat') cm.add_control(c)
def decode(mimetype, mimedata): """ decode("openalealab/model", "model1") -> Model("model1") returns an object Model of model1 """ if mimetype == 'openalealab/control': from openalea.core.control.manager import ControlManager identifier, name = mimedata.split(';') control = ControlManager().control(name) if isinstance(control, list): return ControlManager().control(uid=identifier) return control elif mimetype == 'openalealab/data': from openalea.core.project.manager import ProjectManager from openalea.core.path import path pm = ProjectManager() return pm.get('data', path(mimedata).name) else: return str(mimedata)
def decode(mimetype, mimedata): """ decode("openalealab/model", "model1") -> Model("model1") returns an object Model of model1 """ if mimetype == 'openalealab/control': from openalea.core.control.manager import ControlManager identifier, name = mimedata.split(';') control = ControlManager().control(name) if isinstance(control, list): return ControlManager().control(uid=identifier) return control elif mimetype == 'openalealab/data': from openalea.core.service.project import active_project from openalea.core.path import path project = active_project() if project: return project.get_item('data', path(unicode(mimedata)).name) else: return str(mimedata)
def __init__(self): import traceback traceback.print_stack(file=sys.__stdout__) self._project = None self._is_proj = False self._debug = False self.gui = True self.tmpdir = path(get_openalea_tmp_dir()) self._config = MainConfig() self.extension = None self.applet = {} self.manager = {} self.package_manager = package_manager self.control_manager = ControlManager() self.project_manager = ProjectManager() self.plugin_manager = PluginManager() self.plugin_instance_manager = PluginInstanceManager() self.manager['control'] = self.control_manager self.manager['package'] = self.package_manager self.manager['project'] = self.project_manager self.manager['plugin'] = self.plugin_manager self.manager['plugin_instance'] = self.plugin_instance_manager self.world = World() self.interpreter = interpreter() # Hack if interpreter is an object from class TerminalInteractiveShell if not hasattr(self.interpreter, "shell"): self.interpreter.shell = self.interpreter if hasattr(self.interpreter.shell, "events"): self.interpreter.shell.events.register("post_execute", self.add_to_history) else: print("You need ipython >= 2.0 to use history.") # self.project_manager.set_shell(self.interpreter.shell) self.interpreter.locals['session'] = self self.old_syspath = sys.path self.load_default() self.__class__.instantiated = True
def __init__(self, items=None, item_proxy=None, autoload=['entry_points']): # GenericManager GenericManager.__init__(self, items, item_proxy, autoload) self.default_group = "local" # ProjectManager self.tmpdir = Path(get_openalea_tmp_dir()) self._cproject = None self._cwd = Path('.').abspath() self.old_syspath = sys.path self.cm = ControlManager() self.repositories = self.search_path() self.previous_project = "temp" self.shell = interpreter() self.cproject = None
def __init__(self): Observed.__init__(self) AbstractListener.__init__(self) self.tmpdir = Path(get_openalea_tmp_dir()) self._cproject = None self._cwd = Path('.').abspath() self.old_syspath = sys.path self.cm = ControlManager() self.projects = [] self.repositories = self.search_path() self.previous_project = "temp" self.shell = interpreter() # TODO Search in preference file if user has path to append in self.repositories self.cproject = self.default()
def __init__(self, manager=None, parent=None): AbstractListener.__init__(self) Splitter.__init__(self, parent=parent) if manager is None: self._manager = ControlManager() else: self._manager = manager self.model = ControlModel(self._manager) self.view = ControlView() self.view.setModel(self.model) self.view.controlsSelected.connect(self.on_controls_selected) self.model.rowsInserted.connect(self.view.onRowsInserted) self.addWidget(self.view) self._i = 1 self._index = None self._widget_edit = None
import copy from openalea.core.control.manager import ControlManager from openalea.core.project.manager import ProjectManager from openalea.core.service.model import to_model cm = ControlManager() pm = ProjectManager() def get_model(name): data = pm.cproject.get_model(name) if data: model = to_model(data) if model: return copy.copy(model) def namespace(): # Move to runner class (model manager or ParadigmEditor) namespace = {} namespace.update(cm.namespace()) namespace.update(pm.cproject.ns) namespace['Model'] = get_model return namespace
def disp_controls(): cm = ControlManager() import sys for k, v in cm.namespace().items(): print >> sys.__stdout__, k, v
def unregister_control(control): """ Ask application to stop tracking control. """ cm = ControlManager() cm.remove_control(control)
def register_control(control): """ Ask application to track control. """ cm = ControlManager() cm.add_control(control)
__all__ = [ "clear_controls", "create_control", "get_control", "group_controls", "new_control", "register_control", "unregister_control", ] from openalea.core.control.control import Control from openalea.core.control.manager import ControlManager, ControlContainer from openalea.core.plugin import iter_plugins CM = ControlManager() def create_control(name, iname=None, value=None, constraints=None): """ Create a new Control object. This object is local and standalone. To track it, use register service. """ if iname is None and value is None: raise ValueError('You must define a least a value or an interface') control = Control(name, iname, value, constraints=constraints) return control def register_control(control):
def control_namespace(): return ControlManager().namespace()
def __init__(self, inputs, outputs): Node.__init__(self, inputs, outputs) AbstractListener.__init__(self) self.cm = ControlManager() self.cm.register_listener(self)
def stop(self, *args, **kwargs): self.started = False self.ns.clear() from openalea.core.control.manager import ControlManager cm = ControlManager() cm.clear()
def clear_controls(): cm = ControlManager() return cm.clear()
class Session(object): """ Session is a non graphical class that centralize managers for ... - application settings (:class:`~openalea.oalab.config.main.MainConfig`) - projects (:class:`~openalea.oalab.project.manager.ProjectManager`) - world (:class:`~openalea.oalab.world.world.World`) - interpreter (see :mod:`~openalea.vpltk.shell.shell`) """ __metaclass__ = Singleton instantiated = False def __init__(self): import traceback traceback.print_stack(file=sys.__stdout__) self._project = None self._is_proj = False self._debug = False self.gui = True self.tmpdir = path(get_openalea_tmp_dir()) self._config = MainConfig() self.extension = None self.applet = {} self.manager = {} self.package_manager = package_manager self.control_manager = ControlManager() self.project_manager = ProjectManager() self.plugin_manager = PluginManager() self.plugin_instance_manager = PluginInstanceManager() self.manager['control'] = self.control_manager self.manager['package'] = self.package_manager self.manager['project'] = self.project_manager self.manager['plugin'] = self.plugin_manager self.manager['plugin_instance'] = self.plugin_instance_manager self.world = World() self.interpreter = interpreter() # Hack if interpreter is an object from class TerminalInteractiveShell if not hasattr(self.interpreter, "shell"): self.interpreter.shell = self.interpreter if hasattr(self.interpreter.shell, "events"): self.interpreter.shell.events.register("post_execute", self.add_to_history) else: print("You need ipython >= 2.0 to use history.") # self.project_manager.set_shell(self.interpreter.shell) self.interpreter.locals['session'] = self self.old_syspath = sys.path self.load_default() self.__class__.instantiated = True @property def project(self): """ :return: current project if one is opened. Else return None. """ return self.project_manager.cproject def load_config_file(self, filename, path=None): self._config.load_config_file(filename=filename, path=path) def clear(self): self.world.clear() self.control_manager.clear() def load_default(self): self.project_manager.load_default() self.update_namespace() def update_namespace(self): """ Definition: Update namespace """ self.interpreter.locals['world'] = self.world self.interpreter.locals['get_control'] = self.control_manager.control self.interpreter.locals[ 'follow'] = self.control_manager.register_follower self.interpreter.locals[ 'unfollow'] = self.control_manager.unregister_follower if self.project: if self.project.path.exists(): os.chdir(self.project.path) sys.path.insert(0, str(self.project.path / 'lib')) else: os.chdir(self.tmpdir) sys.path.insert(0, str(self.tmpdir / 'lib')) self.interpreter.locals.update(self.project.ns) self.interpreter.locals['project'] = self.project self.interpreter.locals['Model'] = get_model self.interpreter.locals['data'] = self.project.path / 'data' else: # close sys.path = self.old_syspath def add_to_history(self, *args, **kwargs): """ Send the last sent of history to the components that display history """ from openalea.oalab.service.history import display_history records = self.interpreter.shell.history_manager.get_range() input_ = '' # loop all elements in iterator to get last one. # TODO: search method returning directly last input for session, line, input_ in records: pass display_history(input_) config = property(fget=lambda self: self._config.config) @property def debug_plugins(self): return self.plugin_manager.debug @property def debug(self): return self._debug @debug.setter def debug(self, enable): """ If True, add some objects useful for debug in shell namespace: - applet: dict containing weak references to all applets - manager: dict containing all managers """ self._debug = enable env = self.interpreter.locals if self._debug is True: env['manager'] = self.manager env['applet'] = self.applet else: for varname in ('applet', 'manager'): if varname in env: del env[varname]
def __init__(self, inputs, outputs): Node.__init__(self, inputs, outputs) AbstractListener.__init__(self) self.cm = ControlManager() self.cm.register_listener(self)
class Session(object): """ Session is a non graphical class that centralize managers for ... - application settings (:class:`~openalea.oalab.config.main.MainConfig`) - projects (:class:`~openalea.oalab.project.manager.ProjectManager`) - world (:class:`~openalea.oalab.world.world.World`) - interpreter (see :mod:`~openalea.vpltk.shell.shell`) """ __metaclass__ = Singleton instantiated = False def __init__(self): import traceback traceback.print_stack(file=sys.__stdout__) self._project = None self._is_proj = False self._debug = False self.gui = True self.tmpdir = path(get_openalea_tmp_dir()) self._config = MainConfig() self.extension = None self.applet = {} self.manager = {} self.package_manager = package_manager self.control_manager = ControlManager() self.project_manager = ProjectManager() self.plugin_manager = PluginManager() self.plugin_instance_manager = PluginInstanceManager() self.manager['control'] = self.control_manager self.manager['package'] = self.package_manager self.manager['project'] = self.project_manager self.manager['plugin'] = self.plugin_manager self.manager['plugin_instance'] = self.plugin_instance_manager self.world = World() self.interpreter = interpreter() # Hack if interpreter is an object from class TerminalInteractiveShell if not hasattr(self.interpreter, "shell"): self.interpreter.shell = self.interpreter if hasattr(self.interpreter.shell, "events"): self.interpreter.shell.events.register("post_execute", self.add_to_history) else: print("You need ipython >= 2.0 to use history.") # self.project_manager.set_shell(self.interpreter.shell) self.interpreter.locals['session'] = self self.old_syspath = sys.path self.load_default() self.__class__.instantiated = True @property def project(self): """ :return: current project if one is opened. Else return None. """ return self.project_manager.cproject def load_config_file(self, filename, path=None): self._config.load_config_file(filename=filename, path=path) def clear(self): self.world.clear() self.control_manager.clear() def load_default(self): self.project_manager.load_default() self.update_namespace() def update_namespace(self): """ Definition: Update namespace """ self.interpreter.locals['world'] = self.world self.interpreter.locals['get_control'] = self.control_manager.control self.interpreter.locals['follow'] = self.control_manager.register_follower self.interpreter.locals['unfollow'] = self.control_manager.unregister_follower if self.project: if self.project.path.exists(): os.chdir(self.project.path) sys.path.insert(0, str(self.project.path / 'lib')) else: os.chdir(self.tmpdir) sys.path.insert(0, str(self.tmpdir / 'lib')) self.interpreter.locals.update(self.project.ns) self.interpreter.locals['project'] = self.project self.interpreter.locals['Model'] = get_model self.interpreter.locals['data'] = self.project.path / 'data' else: # close sys.path = self.old_syspath def add_to_history(self, *args, **kwargs): """ Send the last sent of history to the components that display history """ from openalea.oalab.service.history import display_history records = self.interpreter.shell.history_manager.get_range() input_ = '' # loop all elements in iterator to get last one. # TODO: search method returning directly last input for session, line, input_ in records: pass display_history(input_) config = property(fget=lambda self: self._config.config) @property def debug_plugins(self): return self.plugin_manager.debug @property def debug(self): return self._debug @debug.setter def debug(self, enable): """ If True, add some objects useful for debug in shell namespace: - applet: dict containing weak references to all applets - manager: dict containing all managers """ self._debug = enable env = self.interpreter.locals if self._debug is True: env['manager'] = self.manager env['applet'] = self.applet else: for varname in ('applet', 'manager'): if varname in env: del env[varname]
def stop(self, *args, **kwargs): self.started = False self.ns.clear() from openalea.core.control.manager import ControlManager cm = ControlManager() cm.clear()