~tomasgroth/openlp/portable-path

« back to all changes in this revision

Viewing changes to openlp/core/ui/pluginform.py

  • Committer: Tomas Groth
  • Date: 2019-04-30 19:02:42 UTC
  • mfrom: (2829.2.32 openlp)
  • Revision ID: tomasgroth@yahoo.dk-20190430190242-6zwjk8724tyux70m
trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
###############################################################################
5
5
# OpenLP - Open Source Lyrics Projection                                      #
6
6
# --------------------------------------------------------------------------- #
7
 
# Copyright (c) 2008-2018 OpenLP Developers                                   #
 
7
# Copyright (c) 2008-2019 OpenLP Developers                                   #
8
8
# --------------------------------------------------------------------------- #
9
9
# This program is free software; you can redistribute it and/or modify it     #
10
10
# under the terms of the GNU General Public License as published by the Free  #
26
26
 
27
27
from PyQt5 import QtCore, QtWidgets
28
28
 
 
29
from openlp.core.state import State
29
30
from openlp.core.common.i18n import translate
30
31
from openlp.core.common.mixins import RegistryProperties
31
 
from openlp.core.lib import PluginStatus
 
32
from openlp.core.lib.plugin import PluginStatus
32
33
from openlp.core.ui.plugindialog import Ui_PluginViewDialog
33
34
 
 
35
 
34
36
log = logging.getLogger(__name__)
35
37
 
36
38
 
45
47
        super(PluginForm, self).__init__(parent, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint |
46
48
                                         QtCore.Qt.WindowCloseButtonHint)
47
49
        self.active_plugin = None
48
 
        self.programatic_change = False
49
 
        self.setupUi(self)
 
50
        self.programmatic_change = False
 
51
        self.setup_ui(self)
50
52
        self.load()
51
53
        self._clear_details()
52
54
        # Right, now let's put some signals and slots together!
58
60
        Load the plugin details into the screen
59
61
        """
60
62
        self.plugin_list_widget.clear()
61
 
        self.programatic_change = True
 
63
        self.programmatic_change = True
62
64
        self._clear_details()
63
 
        self.programatic_change = True
 
65
        self.programmatic_change = True
64
66
        plugin_list_width = 0
65
 
        for plugin in self.plugin_manager.plugins:
66
 
            item = QtWidgets.QListWidgetItem(self.plugin_list_widget)
67
 
            # We do this just to make 100% sure the status is an integer as
68
 
            # sometimes when it's loaded from the config, it isn't cast to int.
69
 
            plugin.status = int(plugin.status)
70
 
            # Set the little status text in brackets next to the plugin name.
71
 
            if plugin.status == PluginStatus.Disabled:
72
 
                status_text = translate('OpenLP.PluginForm', '{name} (Disabled)')
73
 
            elif plugin.status == PluginStatus.Active:
74
 
                status_text = translate('OpenLP.PluginForm', '{name} (Active)')
75
 
            else:
76
 
                # PluginStatus.Inactive
77
 
                status_text = translate('OpenLP.PluginForm', '{name} (Inactive)')
78
 
            item.setText(status_text.format(name=plugin.name_strings['singular']))
79
 
            # If the plugin has an icon, set it!
80
 
            if plugin.icon:
81
 
                item.setIcon(plugin.icon)
82
 
            self.plugin_list_widget.addItem(item)
83
 
            plugin_list_width = max(plugin_list_width, self.fontMetrics().width(
84
 
                translate('OpenLP.PluginForm', '{name} (Inactive)').format(name=plugin.name_strings['singular'])))
 
67
        for plugin in State().list_plugins():
 
68
            if plugin:
 
69
                item = QtWidgets.QListWidgetItem(self.plugin_list_widget)
 
70
                # We do this just to make 100% sure the status is an integer as
 
71
                # sometimes when it's loaded from the config, it isn't cast to int.
 
72
                plugin.status = int(plugin.status)
 
73
                # Set the little status text in brackets next to the plugin name.
 
74
                if plugin.status == PluginStatus.Disabled:
 
75
                    status_text = translate('OpenLP.PluginForm', '{name} (Disabled)')
 
76
                elif plugin.status == PluginStatus.Active:
 
77
                    status_text = translate('OpenLP.PluginForm', '{name} (Active)')
 
78
                else:
 
79
                    # PluginStatus.Inactive
 
80
                    status_text = translate('OpenLP.PluginForm', '{name} (Inactive)')
 
81
                item.setText(status_text.format(name=plugin.name_strings['singular']))
 
82
                # If the plugin has an icon, set it!
 
83
                if plugin.icon:
 
84
                    item.setIcon(plugin.icon)
 
85
                self.plugin_list_widget.addItem(item)
 
86
                plugin_list_width = max(plugin_list_width, self.fontMetrics().width(
 
87
                    translate('OpenLP.PluginForm', '{name} (Inactive)').format(name=plugin.name_strings['singular'])))
85
88
        self.plugin_list_widget.setFixedWidth(plugin_list_width + self.plugin_list_widget.iconSize().width() + 48)
86
89
 
87
90
    def _clear_details(self):
98
101
        """
99
102
        log.debug('PluginStatus: {status}'.format(status=str(self.active_plugin.status)))
100
103
        self.about_text_browser.setHtml(self.active_plugin.about())
101
 
        self.programatic_change = True
 
104
        self.programmatic_change = True
102
105
        if self.active_plugin.status != PluginStatus.Disabled:
103
106
            self.status_checkbox.setChecked(self.active_plugin.status == PluginStatus.Active)
104
107
            self.status_checkbox.setEnabled(True)
105
108
        else:
106
109
            self.status_checkbox.setChecked(False)
107
110
            self.status_checkbox.setEnabled(False)
108
 
        self.programatic_change = False
 
111
        self.programmatic_change = False
109
112
 
110
113
    def on_plugin_list_widget_selection_changed(self):
111
114
        """
116
119
            return
117
120
        plugin_name_singular = self.plugin_list_widget.currentItem().text().split('(')[0][:-1]
118
121
        self.active_plugin = None
119
 
        for plugin in self.plugin_manager.plugins:
 
122
        for plugin in State().list_plugins():
120
123
            if plugin.name_strings['singular'] == plugin_name_singular:
121
124
                self.active_plugin = plugin
122
125
                break
129
132
        """
130
133
        If the status of a plugin is altered, apply the change
131
134
        """
132
 
        if self.programatic_change or self.active_plugin is None:
 
135
        if self.programmatic_change or self.active_plugin is None:
133
136
            return
134
137
        if status:
135
138
            self.application.set_busy_cursor()