From ae8ad7c32ba0025d7b4ee158c7cd995cf9062fd3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 10 Aug 2010 12:54:42 -0600 Subject: [PATCH] Add UI to edit tweaks to the Prefernces dialog under Advanced --- src/calibre/gui2/dialogs/config/__init__.py | 30 ++- src/calibre/gui2/dialogs/config/config.ui | 239 +++++++++++++++----- src/calibre/manual/faq.rst | 3 +- src/calibre/utils/config.py | 16 +- src/calibre/utils/magick/__init__.py | 2 +- 5 files changed, 231 insertions(+), 59 deletions(-) diff --git a/src/calibre/gui2/dialogs/config/__init__.py b/src/calibre/gui2/dialogs/config/__init__.py index 78cac1b887..0f66ed5dd4 100644 --- a/src/calibre/gui2/dialogs/config/__init__.py +++ b/src/calibre/gui2/dialogs/config/__init__.py @@ -18,7 +18,7 @@ from calibre.gui2 import error_dialog, config, gprefs, \ open_url, open_local_file, \ ALL_COLUMNS, NONE, info_dialog, choose_files, \ warning_dialog, ResizableDialog, question_dialog -from calibre.utils.config import prefs +from calibre.utils.config import prefs, read_raw_tweaks, write_tweaks from calibre.ebooks import BOOK_EXTENSIONS from calibre.ebooks.oeb.iterator import is_supported from calibre.library.server import server_config @@ -514,8 +514,18 @@ class ConfigDialog(ResizableDialog, Ui_Dialog): self.opt_toolbar_text.setCurrentIndex(idx) self.reset_confirmation_button.clicked.connect(self.reset_confirmation) + deft, curt = read_raw_tweaks() + self.current_tweaks.setPlainText(curt) + self.default_tweaks.setPlainText(deft) + self.restore_tweaks_to_default_button.clicked.connect(self.restore_tweaks_to_default) + self.category_view.setCurrentIndex(self.category_view.model().index_for_name(initial_category)) + def restore_tweaks_to_default(self, *args): + deft, curt = read_raw_tweaks() + self.current_tweaks.setPlainText(deft) + + def reset_confirmation(self): from calibre.gui2 import dynamic for key in dynamic.keys(): @@ -687,6 +697,22 @@ class ConfigDialog(ResizableDialog, Ui_Dialog): self.input_order.insertItem(idx-1, self.input_order.takeItem(idx)) self.input_order.setCurrentRow(idx-1) + def set_tweaks(self): + raw = unicode(self.current_tweaks.toPlainText()) + raw = re.sub(r'(?m)^#.*fileencoding.*', '# ', raw) + try: + exec raw + except: + import traceback + error_dialog(self, _('Invalid tweaks'), + _('The tweaks you entered are invalid, try resetting the' + ' tweaks to default and changing them one by one until' + ' you find the invalid setting.'), + det_msg=traceback.format_exc(), show=True) + return False + write_tweaks(raw) + return True + def down_input(self): idx = self.input_order.currentRow() if idx < self.input_order.count()-1: @@ -852,6 +878,8 @@ class ConfigDialog(ResizableDialog, Ui_Dialog): return if not self.add_save.save_settings(): return + if not self.set_tweaks(): + return wl = self.opt_worker_limit.value() if wl%2 != 0: wl += 1 diff --git a/src/calibre/gui2/dialogs/config/config.ui b/src/calibre/gui2/dialogs/config/config.ui index 9035e64bb1..1359278512 100644 --- a/src/calibre/gui2/dialogs/config/config.ui +++ b/src/calibre/gui2/dialogs/config/config.ui @@ -719,61 +719,192 @@ - - - &Maximum number of waiting worker processes (needs restart): - - - opt_worker_limit - - - - - - - 2 - - - 10000 - - - 2 - - - - - - - &Check database integrity - - - - - - - &Install command line tools - - - - - - - Open calibre &configuration directory - - - - - - - Limit the max. simultaneous jobs to the available CPU &cores - - - - - - - Debug &device detection + + + 0 + + + &Miscellaneous + + + + + + &Maximum number of waiting worker processes (needs restart): + + + opt_worker_limit + + + + + + + 2 + + + 10000 + + + 2 + + + + + + + Limit the max. simultaneous jobs to the available CPU &cores + + + + + + + Qt::Vertical + + + + 20 + 79 + + + + + + + + Debug &device detection + + + + + + + Qt::Vertical + + + + 20 + 80 + + + + + + + + &Check database integrity + + + + + + + Qt::Vertical + + + + 20 + 79 + + + + + + + + Open calibre &configuration directory + + + + + + + Qt::Vertical + + + + 20 + 80 + + + + + + + + &Install command line tools + + + + + + + Qt::Vertical + + + + 20 + 79 + + + + + + + + + &Tweaks + + + + + + Values for the tweaks are shown below. Edit them to change the behavior of calibre + + + true + + + + + + + All available tweaks + + + + + + true + + + + + + + + + + &Current tweaks + + + + + + + + + + + + &Restore to defaults + + + + + diff --git a/src/calibre/manual/faq.rst b/src/calibre/manual/faq.rst index 3a9f6b912c..deb693c199 100644 --- a/src/calibre/manual/faq.rst +++ b/src/calibre/manual/faq.rst @@ -277,7 +277,8 @@ In |app|, you would instead use tags to mark genre and read status and then just Why doesn't |app| have a column for foo? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -|app| is designed to have columns for the most frequently and widely used fields. If it does not have a coulmn for your favorite field, you can always add a tag to the book for that piece of information. |app| also supports a general purpose "comments" fields for longer items. +|app| is designed to have columns for the most frequently and widely used fields. In addition, you can add any columns you like. Columns can be added via Preferences->Interface. +Watch the tutorial `UI Power tips `_ to learn how to create your own columns. How do I move my |app| library from one computer to another? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/calibre/utils/config.py b/src/calibre/utils/config.py index c8cfbadac5..3d2663cd1d 100644 --- a/src/calibre/utils/config.py +++ b/src/calibre/utils/config.py @@ -703,16 +703,21 @@ if prefs['installation_uuid'] is None: prefs['installation_uuid'] = str(uuid.uuid4()) # Read tweaks -def read_tweaks(): +def read_raw_tweaks(): make_config_dir() default_tweaks = P('default_tweaks.py', data=True) tweaks_file = os.path.join(config_dir, 'tweaks.py') if not os.path.exists(tweaks_file): with open(tweaks_file, 'wb') as f: f.write(default_tweaks) + with open(tweaks_file, 'rb') as f: + return default_tweaks, f.read() + +def read_tweaks(): + default_tweaks, tweaks = read_raw_tweaks() l, g = {}, {} try: - exec open(tweaks_file, 'rb') in g, l + exec tweaks in g, l except: print 'Failed to load custom tweaks file' traceback.print_exc() @@ -721,6 +726,13 @@ def read_tweaks(): dl.update(l) return dl +def write_tweaks(raw): + make_config_dir() + tweaks_file = os.path.join(config_dir, 'tweaks.py') + with open(tweaks_file, 'wb') as f: + f.write(raw) + + tweaks = read_tweaks() def migrate(): diff --git a/src/calibre/utils/magick/__init__.py b/src/calibre/utils/magick/__init__.py index 021e4349e8..073a030361 100644 --- a/src/calibre/utils/magick/__init__.py +++ b/src/calibre/utils/magick/__init__.py @@ -194,7 +194,7 @@ class Image(_magick.Image): # {{{ # }}} -def create_canvas(width, height, bgcolor): +def create_canvas(width, height, bgcolor='white'): canvas = Image() canvas.create_canvas(int(width), int(height), str(bgcolor)) return canvas