mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
More Qt 5.7 compatibility fixes
This commit is contained in:
parent
fc1676e30f
commit
0e961be543
@ -10,7 +10,7 @@ import textwrap
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget, AbortCommit
|
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.gui2 import error_dialog, info_dialog
|
||||||
from calibre.utils.config import read_raw_tweaks, write_tweaks
|
from calibre.utils.config import read_raw_tweaks, write_tweaks
|
||||||
from calibre.gui2.widgets import PythonHighlighter
|
from calibre.gui2.widgets import PythonHighlighter
|
||||||
@ -19,9 +19,11 @@ from calibre.utils.icu import lower
|
|||||||
from calibre.utils.search_query_parser import (ParseException,
|
from calibre.utils.search_query_parser import (ParseException,
|
||||||
SearchQueryParser)
|
SearchQueryParser)
|
||||||
|
|
||||||
from PyQt5.Qt import (QAbstractListModel, Qt, QStyledItemDelegate, QStyle,
|
from PyQt5.Qt import (
|
||||||
QStyleOptionViewItem, QFont, QDialogButtonBox, QDialog, QApplication,
|
QAbstractListModel, Qt, QStyledItemDelegate, QStyle, QStyleOptionViewItem,
|
||||||
QVBoxLayout, QPlainTextEdit, QLabel, QModelIndex, QMenu, QIcon)
|
QFont, QDialogButtonBox, QDialog, QApplication, QVBoxLayout,
|
||||||
|
QPlainTextEdit, QLabel, QModelIndex, QMenu, QIcon, QListView, QGridLayout,
|
||||||
|
QSizePolicy, QGroupBox, QWidget, QPushButton, QSplitter, pyqtSignal)
|
||||||
|
|
||||||
ROOT = QModelIndex()
|
ROOT = QModelIndex()
|
||||||
|
|
||||||
@ -31,6 +33,7 @@ class AdaptSQP(SearchQueryParser):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class Delegate(QStyledItemDelegate): # {{{
|
class Delegate(QStyledItemDelegate): # {{{
|
||||||
|
|
||||||
def __init__(self, view):
|
def __init__(self, view):
|
||||||
QStyledItemDelegate.__init__(self, view)
|
QStyledItemDelegate.__init__(self, view)
|
||||||
self.view = 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 <b>after a restart</b> 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):
|
def genesis(self, gui):
|
||||||
self.gui = gui
|
self.gui = gui
|
||||||
self.delegate = Delegate(self.tweaks_view)
|
self.delegate = Delegate(self.tweaks_view)
|
||||||
self.tweaks_view.setItemDelegate(self.delegate)
|
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.view = self.tweaks_view
|
||||||
self.highlighter = PythonHighlighter(self.edit_tweak.document())
|
self.highlighter = PythonHighlighter(self.edit_tweak.document())
|
||||||
self.restore_default_button.clicked.connect(self.restore_to_default)
|
self.restore_default_button.clicked.connect(self.restore_to_default)
|
||||||
|
@ -1,192 +0,0 @@
|
|||||||
<?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>756</width>
|
|
||||||
<height>531</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>Form</string>
|
|
||||||
</property>
|
|
||||||
<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. Your changes will only take effect <b>after a restart</b> of calibre.</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QSplitter" name="splitter">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>10</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="childrenCollapsible">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<widget class="QWidget" name="layoutWidget">
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
|
||||||
<item>
|
|
||||||
<widget class="QListView" name="tweaks_view">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>300</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="alternatingRowColors">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="spacing">
|
|
||||||
<number>5</number>
|
|
||||||
</property>
|
|
||||||
<property name="uniformItemSizes">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="plugin_tweaks_button">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Edit tweaks for any custom plugins you have installed</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>&Plugin tweaks</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<widget class="QWidget" name="layoutWidget">
|
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
|
||||||
<item row="1" column="0" colspan="3">
|
|
||||||
<widget class="QGroupBox" name="groupBox">
|
|
||||||
<property name="title">
|
|
||||||
<string>Help</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QPlainTextEdit" name="help">
|
|
||||||
<property name="lineWrapMode">
|
|
||||||
<enum>QPlainTextEdit::NoWrap</enum>
|
|
||||||
</property>
|
|
||||||
<property name="readOnly">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0" colspan="3">
|
|
||||||
<widget class="QGroupBox" name="groupBox_2">
|
|
||||||
<property name="title">
|
|
||||||
<string>Edit tweak</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<item row="0" column="0" colspan="2">
|
|
||||||
<widget class="QPlainTextEdit" name="edit_tweak">
|
|
||||||
<property name="lineWrapMode">
|
|
||||||
<enum>QPlainTextEdit::NoWrap</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QPushButton" name="restore_default_button">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Restore this tweak to its default value</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>&Reset this tweak</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QPushButton" name="apply_button">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Apply any changes you made to this tweak</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>&Apply changes to this tweak</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="SearchBox2" name="search">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
|
||||||
<horstretch>10</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="sizeAdjustPolicy">
|
|
||||||
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
|
|
||||||
</property>
|
|
||||||
<property name="minimumContentsLength">
|
|
||||||
<number>10</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QPushButton" name="next_button">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Next</string>
|
|
||||||
</property>
|
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="../../../../resources/images.qrc">
|
|
||||||
<normaloff>:/images/arrow-down.png</normaloff>:/images/arrow-down.png</iconset>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="2">
|
|
||||||
<widget class="QPushButton" name="previous_button">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Previous</string>
|
|
||||||
</property>
|
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="../../../../resources/images.qrc">
|
|
||||||
<normaloff>:/images/arrow-up.png</normaloff>:/images/arrow-up.png</iconset>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>SearchBox2</class>
|
|
||||||
<extends>QComboBox</extends>
|
|
||||||
<header>calibre/gui2/search_box.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<resources>
|
|
||||||
<include location="../../../../resources/images.qrc"/>
|
|
||||||
</resources>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
@ -806,6 +806,7 @@ class WordsView(QTableView):
|
|||||||
ignore_all = pyqtSignal()
|
ignore_all = pyqtSignal()
|
||||||
add_all = pyqtSignal(object)
|
add_all = pyqtSignal(object)
|
||||||
change_to = pyqtSignal(object, object)
|
change_to = pyqtSignal(object, object)
|
||||||
|
current_changed = pyqtSignal(object, object)
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QTableView.__init__(self, parent)
|
QTableView.__init__(self, parent)
|
||||||
@ -864,6 +865,9 @@ class WordsView(QTableView):
|
|||||||
if words:
|
if words:
|
||||||
QApplication.clipboard().setText('\n'.join(words))
|
QApplication.clipboard().setText('\n'.join(words))
|
||||||
|
|
||||||
|
def currentChanged(self, cur, prev):
|
||||||
|
self.current_changed.emit(cur, prev)
|
||||||
|
|
||||||
class SpellCheck(Dialog):
|
class SpellCheck(Dialog):
|
||||||
|
|
||||||
work_finished = pyqtSignal(object, object, object)
|
work_finished = pyqtSignal(object, object, object)
|
||||||
@ -937,7 +941,7 @@ class SpellCheck(Dialog):
|
|||||||
w.add_all.connect(self.add_all)
|
w.add_all.connect(self.add_all)
|
||||||
w.activated.connect(self.word_activated)
|
w.activated.connect(self.word_activated)
|
||||||
w.change_to.connect(self.change_to)
|
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)
|
state = tprefs.get(self.state_name, None)
|
||||||
hh = self.words_view.horizontalHeader()
|
hh = self.words_view.horizontalHeader()
|
||||||
h.addWidget(w)
|
h.addWidget(w)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user