mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Preferences widget for tweaks
This commit is contained in:
parent
410359d2f6
commit
4da5368ca5
@ -793,9 +793,18 @@ class Plugins(PreferencesPlugin):
|
|||||||
name_order = 1
|
name_order = 1
|
||||||
config_widget = 'calibre.gui2.preferences.plugins'
|
config_widget = 'calibre.gui2.preferences.plugins'
|
||||||
|
|
||||||
|
class Tweaks(PreferencesPlugin):
|
||||||
|
name = 'Tweaks'
|
||||||
|
gui_name = _('Tweaks')
|
||||||
|
category = 'Advanced'
|
||||||
|
gui_category = _('Advanced')
|
||||||
|
category_order = 5
|
||||||
|
name_order = 2
|
||||||
|
config_widget = 'calibre.gui2.preferences.tweaks'
|
||||||
|
|
||||||
plugins += [LookAndFeel, Behavior, Columns, Toolbar, InputOptions,
|
plugins += [LookAndFeel, Behavior, Columns, Toolbar, InputOptions,
|
||||||
CommonOptions, OutputOptions, Adding, Saving, Sending, Email, Server,
|
CommonOptions, OutputOptions, Adding, Saving, Sending, Email, Server,
|
||||||
Plugins]
|
Plugins, Tweaks]
|
||||||
|
|
||||||
#}}}
|
#}}}
|
||||||
|
|
||||||
|
57
src/calibre/gui2/preferences/tweaks.py
Normal file
57
src/calibre/gui2/preferences/tweaks.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||||
|
|
||||||
|
__license__ = 'GPL v3'
|
||||||
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
from calibre.gui2.preferences import ConfigWidgetBase, test_widget, AbortCommit
|
||||||
|
from calibre.gui2.preferences.tweaks_ui import Ui_Form
|
||||||
|
from calibre.gui2 import error_dialog
|
||||||
|
from calibre.utils.config import read_raw_tweaks, write_tweaks
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||||
|
|
||||||
|
def genesis(self, gui):
|
||||||
|
self.gui = gui
|
||||||
|
self.current_tweaks.textChanged.connect(self.changed)
|
||||||
|
|
||||||
|
def changed(self, *args):
|
||||||
|
self.changed_signal.emit()
|
||||||
|
|
||||||
|
def initialize(self):
|
||||||
|
deft, curt = read_raw_tweaks()
|
||||||
|
self.current_tweaks.blockSignals(True)
|
||||||
|
self.current_tweaks.setPlainText(curt.decode('utf-8'))
|
||||||
|
self.current_tweaks.blockSignals(False)
|
||||||
|
|
||||||
|
self.default_tweaks.setPlainText(deft.decode('utf-8'))
|
||||||
|
|
||||||
|
def restore_defaults(self):
|
||||||
|
ConfigWidgetBase.restore_defaults(self)
|
||||||
|
deft, curt = read_raw_tweaks()
|
||||||
|
self.current_tweaks.setPlainText(deft.decode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
|
def commit(self):
|
||||||
|
raw = unicode(self.current_tweaks.toPlainText()).encode('utf-8')
|
||||||
|
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)
|
||||||
|
raise AbortCommit('abort')
|
||||||
|
write_tweaks(raw)
|
||||||
|
return ConfigWidgetBase.commit(self)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from PyQt4.Qt import QApplication
|
||||||
|
app = QApplication([])
|
||||||
|
test_widget('Advanced', 'Tweaks')
|
||||||
|
|
59
src/calibre/gui2/preferences/tweaks.ui
Normal file
59
src/calibre/gui2/preferences/tweaks.ui
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Form</class>
|
||||||
|
<widget class="QWidget" name="Form">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>660</width>
|
||||||
|
<height>351</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<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>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
x
Reference in New Issue
Block a user