Store layout of toolbar and context menus in a config file

This commit is contained in:
Kovid Goyal 2010-08-22 15:04:19 -06:00
parent c2364a6b87
commit ff827175f7
3 changed files with 13 additions and 25 deletions

View File

@ -11,22 +11,8 @@ from PyQt4.Qt import QWidget, QAbstractListModel, Qt, QIcon, \
QVariant, QItemSelectionModel
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, warning_dialog
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'],
}
class FakeAction(object):
@ -86,7 +72,7 @@ class AllModel(BaseModel):
def __init__(self, key, gui):
BaseModel.__init__(self)
current = gprefs.get('action-layout-'+key, DEFAULTS[key])
current = gprefs['action-layout-'+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]
@ -125,7 +111,7 @@ class CurrentModel(BaseModel):
def __init__(self, key, gui):
BaseModel.__init__(self)
current = gprefs.get('action-layout-'+key, DEFAULTS[key])
current = gprefs['action-layout-'+key]
self._data = [self.name_to_action(x, gui) for x in current]
self.key = key
self.gui = gui

View File

@ -13,7 +13,7 @@ from PyQt4.Qt import Qt, QStackedWidget, QMenu, \
from calibre.utils.config import prefs
from calibre.constants import isosx, __appname__, preferred_encoding, \
__version__
from calibre.gui2 import config, is_widescreen
from calibre.gui2 import config, is_widescreen, gprefs
from calibre.gui2.library.views import BooksView, DeviceBooksView
from calibre.gui2.widgets import Splitter
from calibre.gui2.tag_view import TagBrowserWidget
@ -27,14 +27,15 @@ def partial(*args, **kwargs):
_keep_refs.append(ans)
return ans
LIBRARY_CONTEXT_MENU = (
gprefs.defaults['action-layout-context-menu'] = (
'Edit Metadata', 'Send To Device', 'Save To Disk',
'Connect Share', 'Copy To Library', None,
'Convert Books', 'View', 'Open Folder', 'Show Book Details',
'Similar Books', None, 'Remove Books',
)
DEVICE_CONTEXT_MENU = ('View', 'Save To Disk', None, 'Remove Books', None,
gprefs.defaults['action-layout-context-menu-device'] = (
'View', 'Save To Disk', None, 'Remove Books', None,
'Add To Library', 'Edit Collections',
)
@ -48,9 +49,9 @@ class LibraryViewMixin(object): # {{{
m.addSeparator()
elif what in self.iactions:
m.addAction(self.iactions[what].qaction)
populate_menu(lm, LIBRARY_CONTEXT_MENU)
populate_menu(lm, gprefs['action-layout-context-menu'])
dm = QMenu(self)
populate_menu(dm, DEVICE_CONTEXT_MENU)
populate_menu(dm, gprefs['action-layout-context-menu-device'])
ec = self.iactions['Edit Collections'].qaction
self.library_view.set_context_menu(lm, ec)
for v in (self.memory_view, self.card_a_view, self.card_b_view):

View File

@ -19,13 +19,13 @@ from calibre.gui2 import config, gprefs
from calibre.gui2.widgets import ComboBoxWithHelp
from calibre import human_readable
TOOLBAR_NO_DEVICE = (
gprefs.defaults['action-layout-toolbar'] = (
'Add Books', 'Edit Metadata', None, 'Convert Books', 'View', None,
'Choose Library', 'Donate', None, 'Fetch News', 'Save To Disk',
'Connect Share', None, 'Remove Books', None, 'Help', 'Preferences',
)
TOOLBAR_DEVICE = (
gprefs.defaults['action-layout-toolbar-device'] = (
'Add Books', 'Edit Metadata', None, 'Convert Books', 'View',
'Send To Device', None, None, 'Location Manager', None, None,
'Fetch News', 'Save To Disk', 'Connect Share', None,
@ -248,7 +248,8 @@ class ToolBar(QToolBar): # {{{
def build_bar(self):
showing_device = self.location_manager.has_device
actions = TOOLBAR_DEVICE if showing_device else TOOLBAR_NO_DEVICE
actions = '-device' if showing_device else ''
actions = gprefs['action-layout-toolbar'+actions]
self.clear()