From 0916d15e8ab8f7247b53675461544279830092c6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 25 Aug 2010 19:15:23 -0600 Subject: [PATCH] More work on new preferences infrastructure --- src/calibre/customize/builtins.py | 22 +- src/calibre/gui2/__init__.py | 5 + src/calibre/gui2/layout.py | 6 +- src/calibre/gui2/main.py | 2 +- src/calibre/gui2/preferences/__init__.py | 13 +- src/calibre/gui2/preferences/behavior.ui | 263 ++++++++++++++++++ .../gui2/preferences/custom_columns.ui | 170 +++++++++++ src/calibre/gui2/preferences/look_feel.py | 62 +++++ src/calibre/gui2/preferences/look_feel.ui | 196 +++++++++++++ src/calibre/gui2/ui.py | 5 +- 10 files changed, 731 insertions(+), 13 deletions(-) create mode 100644 src/calibre/gui2/preferences/behavior.ui create mode 100644 src/calibre/gui2/preferences/custom_columns.ui create mode 100644 src/calibre/gui2/preferences/look_feel.py create mode 100644 src/calibre/gui2/preferences/look_feel.ui diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 183f83c047..f7bc29784e 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -5,7 +5,8 @@ __copyright__ = '2008, Kovid Goyal ' import textwrap import os import glob -from calibre.customize import FileTypePlugin, MetadataReaderPlugin, MetadataWriterPlugin +from calibre.customize import FileTypePlugin, MetadataReaderPlugin, \ + MetadataWriterPlugin, PreferencesPlugin, InterfaceActionBase from calibre.constants import numeric_version from calibre.ebooks.metadata.archive import ArchiveExtract, get_cbz_metadata @@ -577,7 +578,7 @@ plugins += [x for x in list(locals().values()) if isinstance(x, type) and \ x.__name__.endswith('MetadataWriter')] plugins += input_profiles + output_profiles -from calibre.customize import InterfaceActionBase +# Interface Actions {{{ class ActionAdd(InterfaceActionBase): name = 'Add Books' @@ -670,3 +671,20 @@ plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog, ActionSendToDevice, ActionHelp, ActionPreferences, ActionSimilarBooks, ActionAddToLibrary, ActionEditCollections, ActionChooseLibrary, ActionCopyToLibrary] + +# }}} + +# Preferences Plugins {{{ + +class LookAndFeel(PreferencesPlugin): + name = 'Look & Feel' + gui_name = _('Look and Feel') + category = _('Interface') + category_order = 1 + name_order = 1 + config_widget = 'calibre.gui2.preferences.look_feel' + +plugins += [LookAndFeel] + +#}}} + diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index d75db1bae1..5ffd8d723a 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -46,6 +46,11 @@ gprefs.defaults['action-layout-context-menu-device'] = ( 'View', 'Save To Disk', None, 'Remove Books', None, 'Add To Library', 'Edit Collections', ) + +gprefs.defaults['show_splash_screen'] = True +gprefs.defaults['toolbar_icon_size'] = 'medium' +gprefs.defaults['toolbar_text'] = 'auto' + # }}} NONE = QVariant() #: Null value to return from the data function of item models diff --git a/src/calibre/gui2/layout.py b/src/calibre/gui2/layout.py index fccef29abe..9b755ccb97 100644 --- a/src/calibre/gui2/layout.py +++ b/src/calibre/gui2/layout.py @@ -219,11 +219,11 @@ class ToolBar(QToolBar): # {{{ self.preferred_width = self.sizeHint().width() def apply_settings(self): - sz = gprefs.get('toolbar_icon_size', 'medium') + sz = gprefs['toolbar_icon_size'] sz = {'small':24, 'medium':48, 'large':64}[sz] self.setIconSize(QSize(sz, sz)) style = Qt.ToolButtonTextUnderIcon - if gprefs.get('toolbar_text', 'auto') == 'never': + if gprefs['toolbar_text'] == 'never': style = Qt.ToolButtonIconOnly self.setToolButtonStyle(style) self.donate_button.set_normal_icon_size(sz, sz) @@ -265,7 +265,7 @@ class ToolBar(QToolBar): # {{{ def resizeEvent(self, ev): QToolBar.resizeEvent(self, ev) style = Qt.ToolButtonTextUnderIcon - p = gprefs.get('toolbar_text', 'auto') + p = gprefs['toolbar_text'] if p == 'never': style = Qt.ToolButtonIconOnly diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index f9d7d80b24..24ba7ef47c 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -241,7 +241,7 @@ class GuiRunner(QObject): QApplication.instance().processEvents() def initialize(self, *args): - if gprefs.get('show_splash_screen', True): + if gprefs['show_splash_screen']: self.show_splash_screen() self.library_path = get_library_path(parent=self.splash_screen) diff --git a/src/calibre/gui2/preferences/__init__.py b/src/calibre/gui2/preferences/__init__.py index 04ba9dd225..abb5f76609 100644 --- a/src/calibre/gui2/preferences/__init__.py +++ b/src/calibre/gui2/preferences/__init__.py @@ -107,6 +107,7 @@ class Setting(object): val = None elif self.datatype == 'choices': idx = self.gui_obj.currentIndex() + if idx < 0: idx = 0 val = unicode(self.gui_obj.itemData(idx).toString()) return val @@ -121,8 +122,9 @@ class ConfigWidgetBase(QWidget, ConfigWidgetInterface): self.setupUi(self) self.settings = {} - def register(self, name, config_obj, widget, gui_name=None): - setting = Setting(name, config_obj, widget, gui_name=gui_name) + def register(self, name, config_obj, gui_name=None, choices=None, setting=Setting): + setting = setting(name, config_obj, self, gui_name=gui_name, + choices=choices) self.register_setting(setting) def register_setting(self, setting): @@ -165,18 +167,19 @@ def test_widget(category, name, gui=None): # {{{ bb.button(bb.Apply).setEnabled(False) w.changed_signal.connect(lambda : bb.button(bb.Apply).setEnable(True)) l = QVBoxLayout() - pl.setLayout(l) + d.setLayout(l) l.addWidget(w) + l.addWidget(bb) if gui is None: from calibre.gui2.ui import Main from calibre.gui2.main import option_parser - from calibre.library.db import db + from calibre.library import db parser = option_parser() opts, args = parser.parse_args([]) actions = tuple(Main.create_application_menubar()) db = db() gui = Main(opts) - gui.initialize(db.library_path, db, None, actions) + gui.initialize(db.library_path, db, None, actions, show_gui=False) w.genesis(gui) if d.exec_() == QDialog.Accepted: w.commit() diff --git a/src/calibre/gui2/preferences/behavior.ui b/src/calibre/gui2/preferences/behavior.ui new file mode 100644 index 0000000000..09d83f29de --- /dev/null +++ b/src/calibre/gui2/preferences/behavior.ui @@ -0,0 +1,263 @@ + + + Form + + + + 0 + 0 + 672 + 563 + + + + Form + + + + + + &Overwrite author and title by default when fetching metadata + + + + + + + Download &social metadata (tags/ratings/etc.) by default + + + + + + + Show notification when &new version is available + + + + + + + Automatically send downloaded &news to ebook reader + + + + + + + &Delete news from library when it is automatically sent to reader + + + + + + + + + Default network &timeout: + + + timeout + + + + + + + Set the default timeout for network fetches (i.e. anytime we go out to the internet to get information) + + + seconds + + + 2 + + + 120 + + + 5 + + + + + + + QComboBox::AdjustToMinimumContentsLengthWithIcon + + + 20 + + + + Normal + + + + + High + + + + + Low + + + + + + + + Job &priority: + + + priority + + + + + + + Preferred &output format: + + + output_format + + + + + + + QComboBox::AdjustToMinimumContentsLengthWithIcon + + + 10 + + + + + + + Restriction to apply when the current library is opened: + + + opt_gui_restriction + + + + + + + + 250 + 16777215 + + + + Apply this restriction on calibre startup if the current library is being used. Also applied when switching to this library. Note that this setting is per library. + + + QComboBox::AdjustToMinimumContentsLengthWithIcon + + + 15 + + + + + + + + + Reset all disabled &confirmation dialogs + + + + + + + Preferred &input format order: + + + + + + + + true + + + QAbstractItemView::SelectRows + + + + + + + + + ... + + + + :/images/arrow-up.svg:/images/arrow-up.svg + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + ... + + + + :/images/arrow-down.svg:/images/arrow-down.svg + + + + + + + + + + + + + + Use internal &viewer for: + + + + + + true + + + QAbstractItemView::NoSelection + + + + + + + + + + + + + diff --git a/src/calibre/gui2/preferences/custom_columns.ui b/src/calibre/gui2/preferences/custom_columns.ui new file mode 100644 index 0000000000..3f26838a07 --- /dev/null +++ b/src/calibre/gui2/preferences/custom_columns.ui @@ -0,0 +1,170 @@ + + + Form + + + + 0 + 0 + 504 + 399 + + + + Form + + + + + + Here you can re-arrange the layout of the columns in the calibre library book list. You can hide columns by unchecking them. You can also create your own, custom columns. + + + true + + + + + + + true + + + QAbstractItemView::SelectRows + + + + + + + + + ... + + + + :/images/arrow-up.svg:/images/arrow-up.svg + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Remove a user-defined column + + + ... + + + + :/images/minus.svg:/images/minus.svg + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Add a user-defined column + + + ... + + + + :/images/plus.svg:/images/plus.svg + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Edit settings of a user-defined column + + + ... + + + + :/images/edit_input.svg:/images/edit_input.svg + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + ... + + + + :/images/arrow-down.svg:/images/arrow-down.svg + + + + + + + + + Add &custom column + + + + + + + + + + diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py new file mode 100644 index 0000000000..eb13dd5429 --- /dev/null +++ b/src/calibre/gui2/preferences/look_feel.py @@ -0,0 +1,62 @@ +#!/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 calibre.gui2.preferences import ConfigWidgetBase, test_widget +from calibre.gui2.preferences.look_feel_ui import Ui_Form +from calibre.gui2 import config, gprefs +from calibre.utils.localization import available_translations, \ + get_language, get_lang +from calibre.utils.config import prefs + +class ConfigWidget(ConfigWidgetBase, Ui_Form): + + def genesis(self, gui): + self.gui = gui + + r = self.register + + r('gui_layout', config, choices= + [(_('Wide'), 'wide'), (_('Narrow'), 'narrow')]) + + r('cover_flow_queue_length', config) + + lang = get_lang() + if lang is None or lang not in available_translations(): + lang = 'en' + items = [(l, get_language(l)) for l in available_translations() \ + if l != lang] + if lang != 'en': + items.append(('en', get_language('en'))) + items.sort(cmp=lambda x, y: cmp(x[1], y[1])) + choices = [(y, x) for x, y in items] + # Default language is the autodetected one + choices = [get_language(lang), lang] + choices + r('language', prefs, choices=choices) + + r('show_avg_rating', config) + r('disable_animations', config) + r('systray_icon', config) + r('show_splash_screen', gprefs) + r('disable_tray_notification', config) + r('use_roman_numerals_for_series_number', config) + r('separate_cover_flow', config) + r('search_as_you_type', config) + + choices = [(_('Small'), 'small'), (_('Medium'), 'medium'), + (_('Large'), 'large')] + r('toolbar_icon_size', gprefs, choices=choices) + + choices = [(_('Automatic'), 'auto'), (_('Always'), 'always'), + (_('Never'), 'never')] + r('toolbar_text', gprefs, choices=choices) + +if __name__ == '__main__': + from PyQt4.Qt import QApplication + app = QApplication([]) + test_widget('Interface', 'Look & Feel') + diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui new file mode 100644 index 0000000000..7c6c736b24 --- /dev/null +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -0,0 +1,196 @@ + + + Form + + + + 0 + 0 + 670 + 385 + + + + Form + + + + + + User Interface &layout (needs restart): + + + opt_gui_layout + + + + + + + + 250 + 16777215 + + + + QComboBox::AdjustToMinimumContentsLengthWithIcon + + + 20 + + + + + + + &Number of covers to show in browse mode (needs restart): + + + opt_cover_flow_queue_length + + + + + + + + + + Choose &language (requires restart): + + + opt_language + + + + + + + QComboBox::AdjustToMinimumContentsLengthWithIcon + + + 20 + + + + + + + Show &average ratings in the tags browser + + + true + + + + + + + Disable all animations. Useful if you have a slow/old computer. + + + Disable &animations + + + + + + + Enable system &tray icon (needs restart) + + + + + + + Show &splash screen at startup + + + + + + + Disable &notifications in system tray + + + + + + + Use &Roman numerals for series + + + true + + + + + + + Show cover &browser in a separate window (needs restart) + + + + + + + Search as you type + + + true + + + + + + + &Toolbar + + + + + + + + + &Icon size: + + + opt_toolbar_icon_size + + + + + + + + + + Show &text under icons: + + + opt_toolbar_text + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index c2635e8b44..f2cd7d5e7b 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -110,7 +110,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{ self.iactions = acmap - def initialize(self, library_path, db, listener, actions): + def initialize(self, library_path, db, listener, actions, show_gui=True): opts = self.opts self.preferences_action, self.quit_action = actions self.library_path = library_path @@ -203,7 +203,8 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{ ####################### Library view ######################## LibraryViewMixin.__init__(self, db) - self.show() + if show_gui: + self.show() if self.system_tray_icon.isVisible() and opts.start_in_tray: self.hide_windows()