mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When adding a GUI plugin, prompt the user for where the plugin should be displayed
This commit is contained in:
parent
438c87e022
commit
b66e308c27
61
src/calibre/gui2/dialogs/choose_plugin_toolbars.py
Normal file
61
src/calibre/gui2/dialogs/choose_plugin_toolbars.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||||
|
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import,
|
||||||
|
print_function)
|
||||||
|
|
||||||
|
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
||||||
|
__docformat__ = 'restructuredtext en'
|
||||||
|
__license__ = 'GPL v3'
|
||||||
|
|
||||||
|
|
||||||
|
from PyQt4.Qt import QDialog, QVBoxLayout, QLabel, QDialogButtonBox, \
|
||||||
|
QListWidget, QAbstractItemView
|
||||||
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
|
class ChoosePluginToolbarsDialog(QDialog):
|
||||||
|
|
||||||
|
def __init__(self, parent, plugin, locations):
|
||||||
|
QDialog.__init__(self, parent)
|
||||||
|
self.locations = locations
|
||||||
|
|
||||||
|
self.setWindowTitle(
|
||||||
|
_('Add "%s" to toolbars or menus')%plugin.name)
|
||||||
|
|
||||||
|
self._layout = QVBoxLayout(self)
|
||||||
|
self.setLayout(self._layout)
|
||||||
|
|
||||||
|
self._header_label = QLabel(
|
||||||
|
_('Select the toolbars and/or menus to add "%s" to:') %
|
||||||
|
plugin.name)
|
||||||
|
self._layout.addWidget(self._header_label)
|
||||||
|
|
||||||
|
self._locations_list = QListWidget(self)
|
||||||
|
self._locations_list.setSelectionMode(QAbstractItemView.MultiSelection)
|
||||||
|
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
|
||||||
|
QtGui.QSizePolicy.Minimum)
|
||||||
|
sizePolicy.setHorizontalStretch(0)
|
||||||
|
sizePolicy.setVerticalStretch(0)
|
||||||
|
self._locations_list.setSizePolicy(sizePolicy)
|
||||||
|
for key, text in locations:
|
||||||
|
self._locations_list.addItem(text)
|
||||||
|
self._layout.addWidget(self._locations_list)
|
||||||
|
|
||||||
|
self._footer_label = QLabel(
|
||||||
|
_('You can also customise the plugin locations '
|
||||||
|
'using <b>Preferences -> Customise the toolbar</b>'))
|
||||||
|
self._layout.addWidget(self._footer_label)
|
||||||
|
|
||||||
|
button_box = QDialogButtonBox(QDialogButtonBox.Ok |
|
||||||
|
QDialogButtonBox.Cancel)
|
||||||
|
button_box.accepted.connect(self.accept)
|
||||||
|
button_box.rejected.connect(self.reject)
|
||||||
|
self._layout.addWidget(button_box)
|
||||||
|
self.resize(self.sizeHint())
|
||||||
|
|
||||||
|
def selected_locations(self):
|
||||||
|
selected = []
|
||||||
|
for row in self._locations_list.selectionModel().selectedRows():
|
||||||
|
selected.append(self.locations[row.row()])
|
||||||
|
return selected
|
||||||
|
|
@ -16,9 +16,10 @@ from calibre.customize.ui import initialized_plugins, is_disabled, enable_plugin
|
|||||||
disable_plugin, plugin_customization, add_plugin, \
|
disable_plugin, plugin_customization, add_plugin, \
|
||||||
remove_plugin
|
remove_plugin
|
||||||
from calibre.gui2 import NONE, error_dialog, info_dialog, choose_files, \
|
from calibre.gui2 import NONE, error_dialog, info_dialog, choose_files, \
|
||||||
question_dialog
|
question_dialog, gprefs
|
||||||
from calibre.utils.search_query_parser import SearchQueryParser
|
from calibre.utils.search_query_parser import SearchQueryParser
|
||||||
from calibre.utils.icu import lower
|
from calibre.utils.icu import lower
|
||||||
|
from calibre.utils.ordered_dict import OrderedDict
|
||||||
|
|
||||||
class PluginModel(QAbstractItemModel, SearchQueryParser): # {{{
|
class PluginModel(QAbstractItemModel, SearchQueryParser): # {{{
|
||||||
|
|
||||||
@ -281,6 +282,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
self._plugin_model.populate()
|
self._plugin_model.populate()
|
||||||
self._plugin_model.reset()
|
self._plugin_model.reset()
|
||||||
self.changed_signal.emit()
|
self.changed_signal.emit()
|
||||||
|
self.check_for_add_to_toolbars(plugin)
|
||||||
info_dialog(self, _('Success'),
|
info_dialog(self, _('Success'),
|
||||||
_('Plugin <b>{0}</b> successfully installed under <b>'
|
_('Plugin <b>{0}</b> successfully installed under <b>'
|
||||||
' {1} plugins</b>. You may have to restart calibre '
|
' {1} plugins</b>. You may have to restart calibre '
|
||||||
@ -342,6 +344,37 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
plugin.name + _(' cannot be removed. It is a '
|
plugin.name + _(' cannot be removed. It is a '
|
||||||
'builtin plugin. Try disabling it instead.')).exec_()
|
'builtin plugin. Try disabling it instead.')).exec_()
|
||||||
|
|
||||||
|
def check_for_add_to_toolbars(self, plugin):
|
||||||
|
from calibre.gui2.preferences.toolbar import ConfigWidget
|
||||||
|
from calibre.customize import InterfaceActionBase
|
||||||
|
|
||||||
|
if not isinstance(plugin, InterfaceActionBase):
|
||||||
|
return
|
||||||
|
|
||||||
|
all_locations = OrderedDict(ConfigWidget.LOCATIONS)
|
||||||
|
plugin_action = plugin.load_actual_plugin(self.gui)
|
||||||
|
installed_actions = OrderedDict([
|
||||||
|
(key, list(gprefs.get('action-layout-'+key, [])))
|
||||||
|
for key in all_locations])
|
||||||
|
|
||||||
|
# If already installed in a GUI container, do nothing
|
||||||
|
for action_names in installed_actions.itervalues():
|
||||||
|
if plugin_action.name in action_names:
|
||||||
|
return
|
||||||
|
|
||||||
|
allowed_locations = [(key, text) for key, text in
|
||||||
|
all_locations.iteritems() if key
|
||||||
|
not in plugin_action.dont_add_to]
|
||||||
|
if not allowed_locations:
|
||||||
|
return # This plugin doesn't want to live in the GUI
|
||||||
|
|
||||||
|
from calibre.gui2.dialogs.choose_plugin_toolbars import ChoosePluginToolbarsDialog
|
||||||
|
d = ChoosePluginToolbarsDialog(self, plugin_action, allowed_locations)
|
||||||
|
if d.exec_() == d.Accepted:
|
||||||
|
for key, text in d.selected_locations():
|
||||||
|
installed_actions = list(gprefs['action-layout-'+key])
|
||||||
|
installed_actions.append(plugin_action.name)
|
||||||
|
gprefs['action-layout-'+key] = tuple(installed_actions)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from PyQt4.Qt import QApplication
|
from PyQt4.Qt import QApplication
|
||||||
|
Loading…
x
Reference in New Issue
Block a user