mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add UI to edit tweaks to the Prefernces dialog under Advanced
This commit is contained in:
parent
04b2f82a3a
commit
ae8ad7c32b
@ -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
|
||||
|
@ -718,6 +718,16 @@
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_2">
|
||||
<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>&Miscellaneous</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_9">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
@ -741,27 +751,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="compact_button">
|
||||
<property name="text">
|
||||
<string>&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>&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 &configuration directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="opt_enforce_cpu_limit">
|
||||
<property name="text">
|
||||
@ -769,13 +758,155 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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">
|
||||
<property name="text">
|
||||
<string>Debug &device detection</string>
|
||||
</property>
|
||||
</widget>
|
||||
</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>&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 &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>&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>&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>&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>&Restore to defaults</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_4">
|
||||
|
@ -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 <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?
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -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():
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user