예제 #1
0
    def load_plugins(self):
        """ Add plugins settings """
        from cutevariant.gui import plugin

        for extension in plugin.find_plugins():

            if "setting" in extension:
                settings_widget_class = extension["setting"]
                if not settings_widget_class.ENABLE:
                    # Skip disabled plugins
                    continue

                widget = settings_widget_class()
                # Create rprefix settings ! For instance [VariantView]
                # widget.prefix_settings = widget.__class__.__name__.replace(
                #     "SettingsWidget", ""
                # )

                if not widget.windowTitle():
                    widget.setWindowTitle(extension["name"])

                if not widget.windowIcon():
                    widget.setWindowIcon(FIcon(0xF0431))

                self.add_section(widget)
예제 #2
0
def test_find_plugins(qtbot, conn):

    fake_mainwindow = MainWindow()

    for plugin_desc in plugin.find_plugins():

        assert "name" in plugin_desc
        assert "title" in plugin_desc
        assert "description" in plugin_desc
        assert "long_description" in plugin_desc
        assert "version" in plugin_desc

        if "widget" in plugin_desc:

            plugin_widget_class = plugin_desc["widget"]
            assert issubclass(plugin_widget_class, plugin.PluginWidget)

            # check mandatory method
            w = plugin_widget_class()
            #  w.on_register(fake_mainwindow) ===> DOESNT WORK ??
            w.mainwindow = fake_mainwindow

            # w.on_open_project(conn) ==> DOESNT WORK ??
            w.conn = conn

            w.on_refresh()
예제 #3
0
    def load(self):
        """Display the plugins and their status"""
        self.view.clear()
        from cutevariant.gui import plugin

        settings = self.create_settings()

        settings_keys = set(settings.allKeys())

        for extension in plugin.find_plugins():
            displayed_title = (
                extension["name"]
                if LOGGER.getEffectiveLevel() == DEBUG
                else extension["title"]
            )
            item = QTreeWidgetItem()
            item.setText(0, displayed_title)
            item.setText(1, extension["description"])
            item.setText(2, extension["version"])

            # Is an extension enabled ?
            is_enabled = False

            # Get activation status
            # Only disabled extensions can be in settings
            key = f"plugins/{extension['name']}/status"
            activated_by_user = (
                settings.value(key) == "true" if key in settings_keys else None
            )

            for sub_extension_type in {
                "widget",
                "dialog",
                "setting",
            } & extension.keys():
                if activated_by_user is None and extension[sub_extension_type].ENABLE:
                    is_enabled = True
                    # Only disabled plugins can be reactivated by the user
                    item.setDisabled(True)
                    break
                if activated_by_user:
                    is_enabled = True
                    break

            item.setCheckState(0, Qt.Checked if is_enabled else Qt.Unchecked)
            # Attach the extension for its further activation/desactivation
            item.setData(0, Qt.UserRole, extension)

            self.view.addTopLevelItem(item)
예제 #4
0
    def register_plugins(self):
        """Dynamically load plugins to the window

        Wrapper of :meth:`register_plugin`

        Two types of plugins can be registered:
        - widget: Added to the GUI,
        - dialog: DialogBox accessible from the tool menu.

        `setting` type is handled separately in :meth:`cutevariant.gui.settings.load_plugins`
        """
        LOGGER.info("MainWindow:: Registering plugins...")

        # Get classes of plugins
        # Don't forget to skip disabled plugins
        for extension in plugin.find_plugins():
            self.register_plugin(extension)
예제 #5
0
    def load_plugins(self):
        """ Add plugins settings """
        from cutevariant.gui import plugin

        for extension in plugin.find_plugins():

            if "setting" in extension:
                settings_widget_class = extension["setting"]
                if not settings_widget_class.ENABLE:
                    # Skip disabled plugins
                    continue

                widget = settings_widget_class()

                if not widget.windowTitle():
                    widget.setWindowTitle(extension["name"])

                if not widget.windowIcon():
                    widget.setWindowIcon(FIcon(0xF0431))

                self.addPanel(widget)