Add UI to edit tweaks to the Prefernces dialog under Advanced

This commit is contained in:
Kovid Goyal 2010-08-10 12:54:42 -06:00
parent 04b2f82a3a
commit ae8ad7c32b
5 changed files with 231 additions and 59 deletions

View File

@ -18,7 +18,7 @@ from calibre.gui2 import error_dialog, config, gprefs, \
open_url, open_local_file, \ open_url, open_local_file, \
ALL_COLUMNS, NONE, info_dialog, choose_files, \ ALL_COLUMNS, NONE, info_dialog, choose_files, \
warning_dialog, ResizableDialog, question_dialog 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 import BOOK_EXTENSIONS
from calibre.ebooks.oeb.iterator import is_supported from calibre.ebooks.oeb.iterator import is_supported
from calibre.library.server import server_config from calibre.library.server import server_config
@ -514,8 +514,18 @@ class ConfigDialog(ResizableDialog, Ui_Dialog):
self.opt_toolbar_text.setCurrentIndex(idx) self.opt_toolbar_text.setCurrentIndex(idx)
self.reset_confirmation_button.clicked.connect(self.reset_confirmation) 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)) 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): def reset_confirmation(self):
from calibre.gui2 import dynamic from calibre.gui2 import dynamic
for key in dynamic.keys(): 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.insertItem(idx-1, self.input_order.takeItem(idx))
self.input_order.setCurrentRow(idx-1) 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): def down_input(self):
idx = self.input_order.currentRow() idx = self.input_order.currentRow()
if idx < self.input_order.count()-1: if idx < self.input_order.count()-1:
@ -852,6 +878,8 @@ class ConfigDialog(ResizableDialog, Ui_Dialog):
return return
if not self.add_save.save_settings(): if not self.add_save.save_settings():
return return
if not self.set_tweaks():
return
wl = self.opt_worker_limit.value() wl = self.opt_worker_limit.value()
if wl%2 != 0: if wl%2 != 0:
wl += 1 wl += 1

View File

@ -718,6 +718,16 @@
</widget> </widget>
<widget class="QWidget" name="page_2"> <widget class="QWidget" name="page_2">
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>&amp;Miscellaneous</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_9">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">
@ -741,27 +751,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="compact_button">
<property name="text">
<string>&amp;Check database integrity</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QPushButton" name="button_osx_symlinks">
<property name="text">
<string>&amp;Install command line tools</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="button_open_config_dir">
<property name="text">
<string>Open calibre &amp;configuration directory</string>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QCheckBox" name="opt_enforce_cpu_limit"> <widget class="QCheckBox" name="opt_enforce_cpu_limit">
<property name="text"> <property name="text">
@ -769,13 +758,155 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="2"> <item row="2" column="0">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>79</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="device_detection_button"> <widget class="QPushButton" name="device_detection_button">
<property name="text"> <property name="text">
<string>Debug &amp;device detection</string> <string>Debug &amp;device detection</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>80</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0" colspan="2">
<widget class="QPushButton" name="compact_button">
<property name="text">
<string>&amp;Check database integrity</string>
</property>
</widget>
</item>
<item row="6" column="0">
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>79</height>
</size>
</property>
</spacer>
</item>
<item row="7" column="0" colspan="2">
<widget class="QPushButton" name="button_open_config_dir">
<property name="text">
<string>Open calibre &amp;configuration directory</string>
</property>
</widget>
</item>
<item row="8" column="0">
<spacer name="verticalSpacer_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>80</height>
</size>
</property>
</spacer>
</item>
<item row="9" column="0" colspan="2">
<widget class="QPushButton" name="button_osx_symlinks">
<property name="text">
<string>&amp;Install command line tools</string>
</property>
</widget>
</item>
<item row="10" column="0">
<spacer name="verticalSpacer_9">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>79</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>&amp;Tweaks</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label_18">
<property name="text">
<string>Values for the tweaks are shown below. Edit them to change the behavior of calibre</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>All available tweaks</string>
</property>
<layout class="QGridLayout" name="gridLayout_11">
<item row="0" column="0">
<widget class="QPlainTextEdit" name="default_tweaks">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
<string>&amp;Current tweaks</string>
</property>
<layout class="QGridLayout" name="gridLayout_10">
<item row="0" column="0">
<widget class="QPlainTextEdit" name="current_tweaks"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="restore_tweaks_to_default_button">
<property name="text">
<string>&amp;Restore to defaults</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="page_4"> <widget class="QWidget" name="page_4">

View File

@ -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? 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 <http://calibre-ebook.com/demo#tutorials>`_ to learn how to create your own columns.
How do I move my |app| library from one computer to another? How do I move my |app| library from one computer to another?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -703,16 +703,21 @@ if prefs['installation_uuid'] is None:
prefs['installation_uuid'] = str(uuid.uuid4()) prefs['installation_uuid'] = str(uuid.uuid4())
# Read tweaks # Read tweaks
def read_tweaks(): def read_raw_tweaks():
make_config_dir() make_config_dir()
default_tweaks = P('default_tweaks.py', data=True) default_tweaks = P('default_tweaks.py', data=True)
tweaks_file = os.path.join(config_dir, 'tweaks.py') tweaks_file = os.path.join(config_dir, 'tweaks.py')
if not os.path.exists(tweaks_file): if not os.path.exists(tweaks_file):
with open(tweaks_file, 'wb') as f: with open(tweaks_file, 'wb') as f:
f.write(default_tweaks) 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 = {}, {} l, g = {}, {}
try: try:
exec open(tweaks_file, 'rb') in g, l exec tweaks in g, l
except: except:
print 'Failed to load custom tweaks file' print 'Failed to load custom tweaks file'
traceback.print_exc() traceback.print_exc()
@ -721,6 +726,13 @@ def read_tweaks():
dl.update(l) dl.update(l)
return dl 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() tweaks = read_tweaks()
def migrate(): def migrate():

View File

@ -194,7 +194,7 @@ class Image(_magick.Image): # {{{
# }}} # }}}
def create_canvas(width, height, bgcolor): def create_canvas(width, height, bgcolor='white'):
canvas = Image() canvas = Image()
canvas.create_canvas(int(width), int(height), str(bgcolor)) canvas.create_canvas(int(width), int(height), str(bgcolor))
return canvas return canvas