Add a checkbox to preferences->plugins to show only user installed plugins

This commit is contained in:
Kovid Goyal 2012-01-21 09:58:51 +05:30
parent c1737d8f19
commit 77a73b84f2
2 changed files with 27 additions and 3 deletions

View File

@ -24,18 +24,27 @@ from calibre.constants import iswindows
class PluginModel(QAbstractItemModel, SearchQueryParser): # {{{ class PluginModel(QAbstractItemModel, SearchQueryParser): # {{{
def __init__(self, *args): def __init__(self, show_only_user_plugins=False):
QAbstractItemModel.__init__(self, *args) QAbstractItemModel.__init__(self)
SearchQueryParser.__init__(self, ['all']) SearchQueryParser.__init__(self, ['all'])
self.show_only_user_plugins = show_only_user_plugins
self.icon = QVariant(QIcon(I('plugins.png'))) self.icon = QVariant(QIcon(I('plugins.png')))
p = QIcon(self.icon).pixmap(32, 32, QIcon.Disabled, QIcon.On) p = QIcon(self.icon).pixmap(32, 32, QIcon.Disabled, QIcon.On)
self.disabled_icon = QVariant(QIcon(p)) self.disabled_icon = QVariant(QIcon(p))
self._p = p self._p = p
self.populate() self.populate()
def toggle_shown_plugins(self, show_only_user_plugins):
self.show_only_user_plugins = show_only_user_plugins
self.populate()
self.reset()
def populate(self): def populate(self):
self._data = {} self._data = {}
for plugin in initialized_plugins(): for plugin in initialized_plugins():
if (getattr(plugin, 'plugin_path', None) is None
and self.show_only_user_plugins):
continue
if plugin.type not in self._data: if plugin.type not in self._data:
self._data[plugin.type] = [plugin] self._data[plugin.type] = [plugin]
else: else:
@ -64,6 +73,7 @@ class PluginModel(QAbstractItemModel, SearchQueryParser): # {{{
if p < 0: if p < 0:
if query in lower(self.categories[c]): if query in lower(self.categories[c]):
ans.add((c, p)) ans.add((c, p))
continue
else: else:
try: try:
plugin = self._data[self.categories[c]][p] plugin = self._data[self.categories[c]][p]
@ -209,7 +219,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
def genesis(self, gui): def genesis(self, gui):
self.gui = gui self.gui = gui
self._plugin_model = PluginModel() self._plugin_model = PluginModel(self.user_installed_plugins.isChecked())
self.plugin_view.setModel(self._plugin_model) self.plugin_view.setModel(self._plugin_model)
self.plugin_view.setStyleSheet( self.plugin_view.setStyleSheet(
"QTreeView::item { padding-bottom: 10px;}") "QTreeView::item { padding-bottom: 10px;}")
@ -226,6 +236,10 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.next_button.clicked.connect(self.find_next) self.next_button.clicked.connect(self.find_next)
self.previous_button.clicked.connect(self.find_previous) self.previous_button.clicked.connect(self.find_previous)
self.changed_signal.connect(self.reload_store_plugins) self.changed_signal.connect(self.reload_store_plugins)
self.user_installed_plugins.stateChanged.connect(self.show_user_installed_plugins)
def show_user_installed_plugins(self, state):
self._plugin_model.toggle_shown_plugins(self.user_installed_plugins.isChecked())
def find(self, query): def find(self, query):
idx = self._plugin_model.find(query) idx = self._plugin_model.find(query)

View File

@ -65,6 +65,16 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QCheckBox" name="user_installed_plugins">
<property name="toolTip">
<string>Show only those plugins that have been installed by you</string>
</property>
<property name="text">
<string>Show only &amp;user installed plugins</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QTreeView" name="plugin_view"> <widget class="QTreeView" name="plugin_view">
<property name="alternatingRowColors"> <property name="alternatingRowColors">