def connect(old, new, sender_str, receiver_str, existing_connections): sender_name, signal_name = sender_str.split(':') receiver_name, slot_name = receiver_str.split(':') if old == new: return if new not in (sender_name, receiver_name): return signals = [] slots = [] from openalea.core.service.plugin import plugin_instance_exists, plugin_instances if plugin_instance_exists('oalab.applet', sender_name): for sender in plugin_instances('oalab.applet', sender_name): if hasattr(sender, signal_name): signals.append(getattr(sender, signal_name)) if plugin_instance_exists('oalab.applet', receiver_name): for receiver in plugin_instances('oalab.applet', receiver_name): if hasattr(receiver, slot_name): slots.append(getattr(receiver, slot_name)) if signals and slots: for i, signal in enumerate(signals): for j, slot in enumerate(slots): connection = '%s_%d -> %s_%d' % (sender_str, i, receiver_str, j) if connection not in existing_connections: signal.connect(slot) existing_connections.append(connection) else: pass
def connect(old, new, sender_str, receiver_str, existing_connections): sender_name, signal_name = sender_str.split(':') receiver_name, slot_name = receiver_str.split(':') if old == new: return if new not in (sender_name, receiver_name): return signals = [] slots = [] from openalea.core.service.plugin import plugin_instance_exists, plugin_instances if plugin_instance_exists('oalab.applet', sender_name): for sender in plugin_instances('oalab.applet', sender_name): if hasattr(sender, signal_name): signals.append(getattr(sender, signal_name)) if plugin_instance_exists('oalab.applet', receiver_name): for receiver in plugin_instances('oalab.applet', receiver_name): if hasattr(receiver, slot_name): slots.append(getattr(receiver, slot_name)) if signals and slots: for i, signal in enumerate(signals): for j, slot in enumerate(slots): connection = '%s_%d -> %s_%d' % (sender_str, i, receiver_str, j) if connection not in existing_connections: signal.connect(slot) existing_connections.append(connection) else: pass
def initialize(cls, *args, **kwds): from openalea.core.service.plugin import plugin_instance_exists, plugin_instance if plugin_instance_exists('oalab.applet', 'ProjectManager'): from openalea.core.service.project import default_project project_applet = plugin_instance('oalab.applet', 'ProjectManager') project = default_project() project_applet.set_project(project) cls.state = "initialized"
def initialize(cls, *args, **kwds): from openalea.core.service.plugin import plugin_instance_exists, plugin_instance if plugin_instance_exists('oalab.applet', 'ProjectManager'): from openalea.core.service.project import default_project project_applet = plugin_instance('oalab.applet', 'ProjectManager') project = default_project() project_applet.set_project(project) cls.state = "initialized"
def initialize(self): # Connect to ParadigmContainer if available if plugin_instance_exists('oalab.applet', 'EditorManager'): self.paradigm_container = plugin_instance('oalab.applet', 'EditorManager') self.item_double_clicked.connect(self._on_item_double_clicked) self.item_removed.connect(self._on_item_removed) self.item_added.connect(self._on_item_double_clicked) self.project_closed.connect(self._on_project_closed) self.project_open.connect(self._on_project_open)
def set_applet(self, name, properties=None): """ Show applet "name" in current tab. """ # clear view (hide all widgets in current tab) idx = self.currentIndex() old = self._name.get(idx, None) for applet in self._applets.get(idx, {}).values(): applet.hide() if not name: return # If applet has been instantiated before, just show it # Else, instantiate a new one, place it in layout and show it if name in self._applets.get(idx, {}): applet = self._applets[idx][name] applet.show() else: # If applet has never been instantiated in the whole application, # we instantiate it as the "main" instance (ie reachable thanks to plugin_instance) # else, just create a new one. if plugin_instance_exists('oalab.applet', name): applet = new_plugin_instance('oalab.applet', name) else: applet = plugin_instance('oalab.applet', name) if applet is None: return applet.setAttribute(QtCore.Qt.WA_DeleteOnClose) applet.setContextMenuPolicy(QtCore.Qt.NoContextMenu) if hasattr(applet, 'initialize'): applet.initialize() applet.name = name if properties: try: applet.set_properties(properties) except AttributeError: pass tab = self.currentWidget() tab.set_applet(applet) self._applets.setdefault(idx, {})[name] = applet self._name[idx] = name self._redraw_tab(idx) self.appletSet.emit(old, name)
def set_applet(self, name, properties=None): """ Show applet "name" in current tab. """ # clear view (hide all widgets in current tab) idx = self.currentIndex() old = self._name.get(idx, None) for applet in self._applets.get(idx, {}).values(): applet.hide() if not name: return # If applet has been instantiated before, just show it # Else, instantiate a new one, place it in layout and show it if name in self._applets.get(idx, {}): applet = self._applets[idx][name] applet.show() else: # If applet has never been instantiated in the whole application, # we instantiate it as the "main" instance (ie reachable thanks to plugin_instance) # else, just create a new one. if plugin_instance_exists('oalab.applet', name): applet = new_plugin_instance('oalab.applet', name) else: applet = plugin_instance('oalab.applet', name) if applet is None: return applet.setAttribute(QtCore.Qt.WA_DeleteOnClose) applet.setContextMenuPolicy(QtCore.Qt.NoContextMenu) if hasattr(applet, 'initialize'): applet.initialize() applet.name = name if properties: try: applet.set_properties(properties) except AttributeError: pass tab = self.currentWidget() tab.set_applet(applet) self._applets.setdefault(idx, {})[name] = applet self._name[idx] = name self._redraw_tab(idx) self.appletSet.emit(old, name)
def __init__(self, layout=None, **kwds): """ tests: list of function runnable in shell (name changed to run_<funcname>) layout_file """ OALabMainWin.__init__(self, layout=layout, **kwds) self.interp = interpreter() self.interp.user_ns['mainwin'] = self self.interp.user_ns['splittable'] = self.splittable self.interp.user_ns['debug'] = self.debug self.interp.user_ns['QtCore'] = QtCore self.interp.user_ns['QtGui'] = QtGui def applet(name): return plugin_instance('oalab.applet', name) def applets(name): return plugin_instances('oalab.applet', name) self.interp.user_ns['applet'] = applet self.interp.user_ns['applets'] = applets print 'VARIABLES AVAILABLE IN SHELL ...' print '\nAPPLICATION:' print ' - mainwin' print ' - splittable' print ' - QtCore' print ' - QtGui' print '\nAPPLETS:' for plugin in plugins('oalab.applet'): if plugin_instance_exists('oalab.applet', plugin.name): varname = camel_case_to_lower(plugin.name) self.interp.user_ns['plugin_%s' % varname] = plugin self.interp.user_ns[varname] = plugin_instance('oalab.applet', plugin.name) print ' -', varname print '\nFUNCTIONS:' for f in kwds.pop('tests', []): self.interp.user_ns['run_%s' % f.__name__] = f f.func_globals['ns'] = self.interp.user_ns print ' - run_%s' % f.__name__ self.resize(QtCore.QSize(800, 600))
def _get_paradigm_container(self): if plugin_instance_exists('oalab.applet', 'EditorManager'): return plugin_instance('oalab.applet', 'EditorManager')
def _get_paradigm_container(self): if plugin_instance_exists('oalab.applet', 'EditorManager'): return plugin_instance('oalab.applet', 'EditorManager')