Example #1
0
    def test_multiple_instance(self):
        # Assert weakref work correctly and plugin instances have been lost
        assert not plugin_instances('test.c1', 'MyPlugin1')

        objc1c1_0 = plugin_instance('test.c1', 'MyPlugin1')
        objc1c1_1 = new_plugin_instance('test.c1', 'MyPlugin1')
        objc1c1_2 = new_plugin_instance('test.c1', 'MyPlugin1')

        # Assert all object have been created correctly
        assert objc1c1_0
        assert objc1c1_1
        assert objc1c1_2

        # Assert all instances are different as we use new instead of instance
        assert objc1c1_0 is not objc1c1_1
        assert objc1c1_1 is not objc1c1_2

        objc1c2 = new_plugin_instance('test.c1', 'MyPlugin2')

        assert len(plugin_instances('test.c1', 'MyPlugin1')) == 3
        assert len(plugin_instances('test.c1')) == 4

        del objc1c1_2

        assert len(plugin_instances('test.c1', 'MyPlugin1')) == 2
        assert len(plugin_instances('test.c1')) == 3

        del objc1c2

        assert len(plugin_instances('test.c1', 'MyPlugin1')) == 2
        assert len(plugin_instances('test.c1', 'MyPlugin2')) == 0
        assert len(plugin_instances('test.c1')) == 2
    def test_multiple_instance(self):
        # Assert weakref work correctly and plugin instances have been lost
        assert not plugin_instances('test.c1', 'MyPlugin1')

        objc1c1_0 = plugin_instance('test.c1', 'MyPlugin1')
        objc1c1_1 = new_plugin_instance('test.c1', 'MyPlugin1')
        objc1c1_2 = new_plugin_instance('test.c1', 'MyPlugin1')

        # Assert all object have been created correctly
        assert objc1c1_0
        assert objc1c1_1
        assert objc1c1_2

        # Assert all instances are different as we use new instead of instance
        assert objc1c1_0 is not objc1c1_1
        assert objc1c1_1 is not objc1c1_2

        objc1c2 = new_plugin_instance('test.c1', 'MyPlugin2')

        assert len(plugin_instances('test.c1', 'MyPlugin1')) == 3
        assert len(plugin_instances('test.c1')) == 4

        del objc1c1_2

        assert len(plugin_instances('test.c1', 'MyPlugin1')) == 2
        assert len(plugin_instances('test.c1')) == 3

        del objc1c2

        assert len(plugin_instances('test.c1', 'MyPlugin1')) == 2
        assert len(plugin_instances('test.c1', 'MyPlugin2')) == 0
        assert len(plugin_instances('test.c1')) == 2
 def test_proxy_plugin(self):
     from openalea.core.plugin.manager import SimpleClassPluginProxy
     self.pm.add_plugin('test.dynamic4', Algo, plugin_proxy=SimpleClassPluginProxy)
     objc4c1 = plugin_instance('test.dynamic4', 'Algo')
     objc4c1_2 = plugin_instance('test.dynamic4', 'Algo')
     objc4c1_3 = new_plugin_instance('test.dynamic4', 'Algo')
     assert objc4c1
     assert isinstance(objc4c1, Algo)
     assert objc4c1 is objc4c1_2
     assert objc4c1 is not objc4c1_3
Example #4
0
 def test_proxy_plugin(self):
     from openalea.core.plugin.manager import SimpleClassPluginProxy
     self.pm.add_plugin('test.dynamic4',
                        Algo,
                        plugin_proxy=SimpleClassPluginProxy)
     objc4c1 = plugin_instance('test.dynamic4', 'Algo')
     objc4c1_2 = plugin_instance('test.dynamic4', 'Algo')
     objc4c1_3 = new_plugin_instance('test.dynamic4', 'Algo')
     assert objc4c1
     assert isinstance(objc4c1, Algo)
     assert objc4c1 is objc4c1_2
     assert objc4c1 is not objc4c1_3
    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)
Example #6
0
    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 test_plugin_proxy(self):

        from openalea.core.plugin.manager import SimpleClassPluginProxy

        pm = PluginManager()
        pm.set_proxy('oalab.modelclass', SimpleClassPluginProxy)

        clear_plugin_instances()
        w1 = plugin_instance('oalab.modelclass', 'PythonModel')
        w2 = plugin_instance('oalab.modelclass', 'PythonModel')
        w3 = plugin_instance('oalab.modelclass', 'PythonModel')
        w4 = new_plugin_instance('oalab.modelclass', 'PythonModel')

        assert w1
        assert w1 is w2 is w3
        assert w1 is not w4

        assert len(plugin_instances('oalab.modelclass', 'PythonModel')) == 2
Example #8
0
    def test_plugin_proxy(self):

        from openalea.core.plugin.manager import SimpleClassPluginProxy

        pm = PluginManager()
        pm.set_proxy('oalab.modelclass', SimpleClassPluginProxy)

        clear_plugin_instances()
        w1 = plugin_instance('oalab.modelclass', 'PythonModel')
        w2 = plugin_instance('oalab.modelclass', 'PythonModel')
        w3 = plugin_instance('oalab.modelclass', 'PythonModel')
        w4 = new_plugin_instance('oalab.modelclass', 'PythonModel')

        assert w1
        assert w1 is w2 is w3
        assert w1 is not w4

        assert len(plugin_instances('oalab.modelclass', 'PythonModel')) == 2
 def add_applet(self, name):
     applet = new_plugin_instance('oalab.applet', name)
     applet.setAttribute(QtCore.Qt.WA_DeleteOnClose)
     self._applets[name] = applet
     self.addWidget(applet)
Example #10
0
 def add_applet(self, name):
     applet = new_plugin_instance('oalab.applet', name)
     applet.setAttribute(QtCore.Qt.WA_DeleteOnClose)
     self._applets[name] = applet
     self.addWidget(applet)