diff --git a/src/calibre/gui2/preferences/tweaks.py b/src/calibre/gui2/preferences/tweaks.py index 1c566b1e8a..dd4ac84462 100644 --- a/src/calibre/gui2/preferences/tweaks.py +++ b/src/calibre/gui2/preferences/tweaks.py @@ -10,7 +10,7 @@ import textwrap from collections import OrderedDict from calibre.gui2.preferences import ConfigWidgetBase, test_widget, AbortCommit -from calibre.gui2.preferences.tweaks_ui import Ui_Form +from calibre.gui2.search_box import SearchBox2 from calibre.gui2 import error_dialog, info_dialog from calibre.utils.config import read_raw_tweaks, write_tweaks from calibre.gui2.widgets import PythonHighlighter @@ -19,9 +19,11 @@ from calibre.utils.icu import lower from calibre.utils.search_query_parser import (ParseException, SearchQueryParser) -from PyQt5.Qt import (QAbstractListModel, Qt, QStyledItemDelegate, QStyle, - QStyleOptionViewItem, QFont, QDialogButtonBox, QDialog, QApplication, - QVBoxLayout, QPlainTextEdit, QLabel, QModelIndex, QMenu, QIcon) +from PyQt5.Qt import ( + QAbstractListModel, Qt, QStyledItemDelegate, QStyle, QStyleOptionViewItem, + QFont, QDialogButtonBox, QDialog, QApplication, QVBoxLayout, + QPlainTextEdit, QLabel, QModelIndex, QMenu, QIcon, QListView, QGridLayout, + QSizePolicy, QGroupBox, QWidget, QPushButton, QSplitter, pyqtSignal) ROOT = QModelIndex() @@ -31,6 +33,7 @@ class AdaptSQP(SearchQueryParser): pass class Delegate(QStyledItemDelegate): # {{{ + def __init__(self, view): QStyledItemDelegate.__init__(self, view) self.view = view @@ -321,13 +324,95 @@ class PluginTweaks(QDialog): # {{{ # }}} -class ConfigWidget(ConfigWidgetBase, Ui_Form): +class TweaksView(QListView): + + current_changed = pyqtSignal(object, object) + + def __init__(self, parent=None): + QListView.__init__(self, parent) + self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Expanding) + self.setAlternatingRowColors(True) + self.setSpacing(5) + self.setUniformItemSizes(True) + self.setVerticalScrollMode(self.ScrollPerPixel) + + def currentChanged(self, cur, prev): + QListView.currentChanged(self, cur, prev) + self.current_changed.emit(cur, prev) + +class ConfigWidget(ConfigWidgetBase): + + def setupUi(self, x): + self.l = l = QVBoxLayout(self) + self.la1 = la = QLabel( + _("Values for the tweaks are shown below. Edit them to change the behavior of calibre." + " Your changes will only take effect after a restart of calibre.")) + l.addWidget(la), la.setWordWrap(True) + self.splitter = s = QSplitter(self) + s.setChildrenCollapsible(False) + l.addWidget(s, 10) + + self.lv = lv = QWidget(self) + lv.l = l2 = QVBoxLayout(lv) + l2.setContentsMargins(0, 0, 0, 0) + self.tweaks_view = tv = TweaksView(self) + l2.addWidget(tv) + self.plugin_tweaks_button = b = QPushButton(self) + b.setToolTip(_("Edit tweaks for any custom plugins you have installed")) + b.setText(_("&Plugin tweaks")) + l2.addWidget(b) + s.addWidget(lv) + + self.lv1 = lv = QWidget(self) + s.addWidget(lv) + lv.g = g = QGridLayout(lv) + g.setContentsMargins(0, 0, 0, 0) + + self.search = sb = SearchBox2(self) + sb.sizePolicy().setHorizontalStretch(10) + sb.setSizeAdjustPolicy(sb.AdjustToMinimumContentsLength) + sb.setMinimumContentsLength(10) + g.addWidget(self.search, 0, 0, 1, 1) + self.next_button = b = QPushButton(self) + b.setIcon(QIcon(I("arrow-down.png"))) + b.setText(_("&Next")) + g.addWidget(self.next_button, 0, 1, 1, 1) + self.previous_button = b = QPushButton(self) + b.setIcon(QIcon(I("arrow-up.png"))) + b.setText(_("&Previous")) + g.addWidget(self.previous_button, 0, 2, 1, 1) + + self.hb = hb = QGroupBox(self) + hb.setTitle(_("Help")) + hb.l = l2 = QVBoxLayout(hb) + self.help = h = QPlainTextEdit(self) + l2.addWidget(h) + h.setLineWrapMode(QPlainTextEdit.NoWrap) + h.setReadOnly(True) + g.addWidget(hb, 1, 0, 1, 3) + + self.eb = eb = QGroupBox(self) + g.addWidget(eb, 2, 0, 1, 3) + eb.setTitle(_("Edit tweak")) + eb.g = ebg = QGridLayout(eb) + self.edit_tweak = et = QPlainTextEdit(self) + et.setMinimumWidth(400) + et.setLineWrapMode(QPlainTextEdit.NoWrap) + ebg.addWidget(et, 0, 0, 1, 2) + self.restore_default_button = b = QPushButton(self) + b.setToolTip(_("Restore this tweak to its default value")) + b.setText(_("&Reset this tweak")) + ebg.addWidget(b, 1, 0, 1, 1) + self.apply_button = ab = QPushButton(self) + ab.setToolTip(_("Apply any changes you made to this tweak")) + ab.setText(_("&Apply changes to this tweak")) + ebg.addWidget(ab, 1, 1, 1, 1) def genesis(self, gui): self.gui = gui self.delegate = Delegate(self.tweaks_view) self.tweaks_view.setItemDelegate(self.delegate) - self.tweaks_view.currentChanged = self.current_changed + self.tweaks_view.current_changed.connect(self.current_changed) self.view = self.tweaks_view self.highlighter = PythonHighlighter(self.edit_tweak.document()) self.restore_default_button.clicked.connect(self.restore_to_default) diff --git a/src/calibre/gui2/preferences/tweaks.ui b/src/calibre/gui2/preferences/tweaks.ui deleted file mode 100644 index 5814bdd0a9..0000000000 --- a/src/calibre/gui2/preferences/tweaks.ui +++ /dev/null @@ -1,192 +0,0 @@ - - - Form - - - - 0 - 0 - 756 - 531 - - - - Form - - - - - - Values for the tweaks are shown below. Edit them to change the behavior of calibre. Your changes will only take effect <b>after a restart</b> of calibre. - - - true - - - - - - - - 0 - 10 - - - - Qt::Horizontal - - - false - - - - - - - - 0 - 0 - - - - - 300 - 0 - - - - true - - - 5 - - - true - - - - - - - Edit tweaks for any custom plugins you have installed - - - &Plugin tweaks - - - - - - - - - - - Help - - - - - - QPlainTextEdit::NoWrap - - - true - - - - - - - - - - Edit tweak - - - - - - QPlainTextEdit::NoWrap - - - - - - - Restore this tweak to its default value - - - &Reset this tweak - - - - - - - Apply any changes you made to this tweak - - - &Apply changes to this tweak - - - - - - - - - - - 10 - 0 - - - - QComboBox::AdjustToMinimumContentsLength - - - 10 - - - - - - - &Next - - - - :/images/arrow-down.png:/images/arrow-down.png - - - - - - - &Previous - - - - :/images/arrow-up.png:/images/arrow-up.png - - - - - - - - - - - - SearchBox2 - QComboBox -
calibre/gui2/search_box.h
-
-
- - - - -
diff --git a/src/calibre/gui2/tweak_book/spell.py b/src/calibre/gui2/tweak_book/spell.py index 5b60da0e7f..ba20e8fc1e 100644 --- a/src/calibre/gui2/tweak_book/spell.py +++ b/src/calibre/gui2/tweak_book/spell.py @@ -806,6 +806,7 @@ class WordsView(QTableView): ignore_all = pyqtSignal() add_all = pyqtSignal(object) change_to = pyqtSignal(object, object) + current_changed = pyqtSignal(object, object) def __init__(self, parent=None): QTableView.__init__(self, parent) @@ -864,6 +865,9 @@ class WordsView(QTableView): if words: QApplication.clipboard().setText('\n'.join(words)) + def currentChanged(self, cur, prev): + self.current_changed.emit(cur, prev) + class SpellCheck(Dialog): work_finished = pyqtSignal(object, object, object) @@ -937,7 +941,7 @@ class SpellCheck(Dialog): w.add_all.connect(self.add_all) w.activated.connect(self.word_activated) w.change_to.connect(self.change_to) - w.currentChanged = self.current_word_changed + w.current_changed.connect(self.current_word_changed) state = tprefs.get(self.state_name, None) hh = self.words_view.horizontalHeader() h.addWidget(w)