diff --git a/src/calibre/gui2/dialogs/config/toolbar.py b/src/calibre/gui2/dialogs/config/toolbar.py new file mode 100644 index 0000000000..301ea961ea --- /dev/null +++ b/src/calibre/gui2/dialogs/config/toolbar.py @@ -0,0 +1,141 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai + +__license__ = 'GPL v3' +__copyright__ = '2010, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + +from PyQt4.Qt import QWidget, QAbstractListModel, Qt, QIcon, QVariant + +from calibre.gui2.dialogs.config.toolbar_ui import Ui_Form +from calibre.gui2.layout import TOOLBAR_NO_DEVICE, TOOLBAR_DEVICE +from calibre.gui2.init import LIBRARY_CONTEXT_MENU, DEVICE_CONTEXT_MENU +from calibre.gui2 import gprefs, NONE + +DEFAULTS = { + 'toolbar': TOOLBAR_NO_DEVICE, + 'toolbar-device': TOOLBAR_DEVICE, + 'context-menu': LIBRARY_CONTEXT_MENU, + 'context-menu-device': DEVICE_CONTEXT_MENU, +} + +UNREMOVABLE = { + 'toolbar': ['Preferences'], + 'toolbar-device': ['Send To Device', 'Location Manager'], +} + +UNADDABLE = { + 'toolbar': ['Location Manager'], + 'context-menu': ['Location Manager'], + 'context-menu-device': ['Location Manager'], +} + +class FakeAction(object): + + def __init__(self, name, icon, tooltip=None): + self.name = name + self.action_spec = (name, icon, tooltip, None) + +class BaseModel(QAbstractListModel): + + def name_to_action(self, name, gui): + if name == 'Donate': + return FakeAction(name, 'donate.svg') + if name == 'Location Manager': + return FakeAction(name, None) + if name is None: + return FakeAction('--- '+_('Separator')+' ---', None) + return self.gui.iactions[name] + + def rowCount(self, parent): + return len(self._data) + + def data(self, index, role): + row = index.row() + action = self._data[row].action_spec + if role == Qt.DisplayRole: + return QVariant(action[0]) + if role == Qt.DecorationRole: + ic = action[1] + if ic is not None: + return QVariant(QIcon(ic)) + if role == Qt.ToolTipRole and action[2] is not None: + return QVariant(action[2]) + return NONE + + +class AllModel(BaseModel): + + def __init__(self, key, gui): + BaseModel.__init__(self) + current = gprefs.get('action-layout-'+key, DEFAULTS[key]) + all = list(gui.iactions.keys()) + ['Donate'] + all = [x for x in all if x not in current] + [None] + all = [self.name_to_action(x, gui) for x in all] + all.sort() + + self._data = all + +class CurrentModel(BaseModel): + + def __init__(self, key, gui): + BaseModel.__init__(self) + current = gprefs.get('action-layout-'+key, DEFAULTS[key]) + self._data = [self.name_to_action(x, gui) for x in current] + +class ToolbarLayout(QWidget, Ui_Form): + + LOCATIONS = [ + ('toolbar', _('The main toolbar')), + ('toolbar-device', _('The main toolbar when a device is connected')), + ('context-menu', _('The context menu for the books in the ' + 'calibre library')), + ('context-menu-device', _('The context menu for the books on ' + 'the device')) + ] + + def __init__(self, gui, parent=None): + QWidget.__init__(self, parent) + self.setupUi(self) + + self.models = {} + for key, text in self.LOCATIONS: + self.what.addItem(text, key) + all_model = AllModel(key, gui) + current_model = CurrentModel(key, gui) + self.models[key] = (all_model, current_model) + self.what.setCurrentIndex(0) + self.what.currentIndexChanged[int].connect(self.what_changed) + self.what_changed(0) + + self.add_action_button.clicked.connect(self.add_action) + self.remove_action_button.clicked.connect(self.remove_action) + self.action_up_button.clicked.connect(self.action_up) + self.action_down_button.clicked.connect(self.action_down) + + def what_changed(self, idx): + key = unicode(self.what.itemData(idx).toString()) + self.all_actions.setModel(self.models[key][0]) + self.current_actions.setModel(self.models[key][1]) + + def add_action(self, *args): + pass + + def remove_action(self, *args): + pass + + def action_up(self, *args): + pass + + def action_down(self, *args): + pass + +if __name__ == '__main__': + from PyQt4.Qt import QApplication + from calibre.gui2.ui import Main + m = Main(None) + app=QApplication([]) + a = ToolbarLayout(m) + a.show() + app.exec_() + diff --git a/src/calibre/gui2/dialogs/config/toolbar.ui b/src/calibre/gui2/dialogs/config/toolbar.ui new file mode 100644 index 0000000000..ef03e79af7 --- /dev/null +++ b/src/calibre/gui2/dialogs/config/toolbar.ui @@ -0,0 +1,219 @@ + + + Form + + + + 0 + 0 + 831 + 553 + + + + Form + + + + + + Customize the actions in: + + + + + + + QComboBox::AdjustToMinimumContentsLengthWithIcon + + + 20 + + + + + + + A&vailable actions + + + + + + true + + + QAbstractItemView::MultiSelection + + + + 32 + 32 + + + + 10 + + + true + + + + + + + + + + &Current actions + + + + + + true + + + QAbstractItemView::MultiSelection + + + + 32 + 32 + + + + true + + + + + + + + + Move selected action up + + + ... + + + + :/images/arrow-up.svg:/images/arrow-up.svg + + + + 24 + 24 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Move selected action down + + + ... + + + + :/images/arrow-down.svg:/images/arrow-down.svg + + + + 24 + 24 + + + + Ctrl+S + + + + + + + + + + + + + + Add selected actions to toolbar + + + ... + + + + :/images/forward.svg:/images/forward.svg + + + + 24 + 24 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 40 + + + + + + + + Remove selected actions from toolbar + + + ... + + + + :/images/back.svg:/images/back.svg + + + + 24 + 24 + + + + + + + + + + + + +