mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
More PyQt6 nonsense
This commit is contained in:
parent
22bc316836
commit
21d4a3b7cb
@ -10,8 +10,8 @@ import sys
|
|||||||
import threading
|
import threading
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QT_VERSION, QApplication, QBuffer, QByteArray, QColor, QCoreApplication,
|
QT_VERSION, QApplication, QBuffer, QByteArray, QColor, QDateTime,
|
||||||
QDateTime, QDesktopServices, QDialog, QDialogButtonBox, QEvent, QFileDialog,
|
QDesktopServices, QDialog, QDialogButtonBox, QEvent, QFileDialog,
|
||||||
QFileIconProvider, QFileInfo, QFont, QFontDatabase, QFontInfo, QFontMetrics,
|
QFileIconProvider, QFileInfo, QFont, QFontDatabase, QFontInfo, QFontMetrics,
|
||||||
QGuiApplication, QIcon, QIODevice, QLocale, QNetworkProxyFactory, QObject,
|
QGuiApplication, QIcon, QIODevice, QLocale, QNetworkProxyFactory, QObject,
|
||||||
QPalette, QSettings, QSocketNotifier, QStringListModel, QStyle, Qt, QThread,
|
QPalette, QSettings, QSocketNotifier, QStringListModel, QStyle, Qt, QThread,
|
||||||
@ -381,8 +381,8 @@ def min_available_height():
|
|||||||
|
|
||||||
|
|
||||||
def get_screen_dpi():
|
def get_screen_dpi():
|
||||||
d = QApplication.desktop()
|
s = QApplication.instance().primaryScreen()
|
||||||
return (d.logicalDpiX(), d.logicalDpiY())
|
return s.logicalDotsPerInchX(), s.logicalDotsPerInchY()
|
||||||
|
|
||||||
|
|
||||||
_is_widescreen = None
|
_is_widescreen = None
|
||||||
@ -820,8 +820,7 @@ class ResizableDialog(QDialog):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
QDialog.__init__(self, *args)
|
QDialog.__init__(self, *args)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
desktop = QCoreApplication.instance().desktop()
|
geom = self.screen().availableSize()
|
||||||
geom = desktop.availableGeometry(self)
|
|
||||||
nh, nw = max(550, geom.height()-25), max(700, geom.width()-10)
|
nh, nw = max(550, geom.height()-25), max(700, geom.width()-10)
|
||||||
nh = min(self.height(), nh)
|
nh = min(self.height(), nh)
|
||||||
nw = min(self.width(), nw)
|
nw = min(self.width(), nw)
|
||||||
@ -1049,7 +1048,7 @@ class Application(QApplication):
|
|||||||
return restored
|
return restored
|
||||||
|
|
||||||
def ensure_window_on_screen(self, widget):
|
def ensure_window_on_screen(self, widget):
|
||||||
screen_rect = self.desktop().availableGeometry(widget)
|
screen_rect = widget.screen().availableGeometry()
|
||||||
g = widget.geometry()
|
g = widget.geometry()
|
||||||
w = min(screen_rect.width(), g.width())
|
w = min(screen_rect.width(), g.width())
|
||||||
h = min(screen_rect.height(), g.height())
|
h = min(screen_rect.height(), g.height())
|
||||||
|
@ -775,7 +775,7 @@ class CcTemplateDelegate(QStyledItemDelegate): # {{{
|
|||||||
editor = TemplateDialog(parent, text, mi)
|
editor = TemplateDialog(parent, text, mi)
|
||||||
editor.setWindowTitle(_("Edit template"))
|
editor.setWindowTitle(_("Edit template"))
|
||||||
editor.textbox.setTabChangesFocus(False)
|
editor.textbox.setTabChangesFocus(False)
|
||||||
editor.textbox.setTabStopWidth(20)
|
editor.textbox.setTabStopDistance(20)
|
||||||
d = editor.exec()
|
d = editor.exec()
|
||||||
if d:
|
if d:
|
||||||
m.setData(index, (editor.rule[1]), Qt.ItemDataRole.EditRole)
|
m.setData(index, (editor.rule[1]), Qt.ItemDataRole.EditRole)
|
||||||
|
@ -181,7 +181,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
self.replace_button.setEnabled(False)
|
self.replace_button.setEnabled(False)
|
||||||
self.clear_button.clicked.connect(self.clear_button_clicked)
|
self.clear_button.clicked.connect(self.clear_button_clicked)
|
||||||
self.replace_button.clicked.connect(self.replace_button_clicked)
|
self.replace_button.clicked.connect(self.replace_button_clicked)
|
||||||
self.program.setTabStopWidth(20)
|
self.program.setTabStopDistance(20)
|
||||||
self.highlighter = PythonHighlighter(self.program.document())
|
self.highlighter = PythonHighlighter(self.program.document())
|
||||||
|
|
||||||
self.te_textbox = self.template_editor.textbox
|
self.te_textbox = self.template_editor.textbox
|
||||||
|
@ -237,7 +237,7 @@
|
|||||||
<property name="documentTitle">
|
<property name="documentTitle">
|
||||||
<string notr="true"/>
|
<string notr="true"/>
|
||||||
</property>
|
</property>
|
||||||
<property name="tabStopWidth">
|
<property name="tabStopDistance">
|
||||||
<number>30</number>
|
<number>30</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -117,7 +117,7 @@ class TextBrowser(PlainTextEdit): # {{{
|
|||||||
font.setPointSizeF(tprefs['editor_font_size'])
|
font.setPointSizeF(tprefs['editor_font_size'])
|
||||||
self.setFont(font)
|
self.setFont(font)
|
||||||
self.calculate_metrics()
|
self.calculate_metrics()
|
||||||
self.setTabStopWidth(tprefs['editor_tab_stop_width'] * self.space_width)
|
self.setTabStopDistance(tprefs['editor_tab_stop_width'] * self.space_width)
|
||||||
font = self.heading_font = QFont(self.font())
|
font = self.heading_font = QFont(self.font())
|
||||||
font.setPointSizeF(tprefs['editor_font_size'] * 1.5)
|
font.setPointSizeF(tprefs['editor_font_size'] * 1.5)
|
||||||
font.setBold(True)
|
font.setBold(True)
|
||||||
|
@ -226,7 +226,7 @@ class InsertImage(Dialog):
|
|||||||
self.fm = fm = QSortFilterProxyModel(self.view)
|
self.fm = fm = QSortFilterProxyModel(self.view)
|
||||||
self.fm.setDynamicSortFilter(self.for_browsing)
|
self.fm.setDynamicSortFilter(self.for_browsing)
|
||||||
fm.setSourceModel(self.model)
|
fm.setSourceModel(self.model)
|
||||||
fm.setFilterCaseSensitivity(False)
|
fm.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
|
||||||
v.setModel(fm)
|
v.setModel(fm)
|
||||||
l.addWidget(v, 1, 0, 1, 2)
|
l.addWidget(v, 1, 0, 1, 2)
|
||||||
v.pressed.connect(self.pressed)
|
v.pressed.connect(self.pressed)
|
||||||
|
@ -224,10 +224,10 @@ class TextEdit(PlainTextEdit):
|
|||||||
self.setLineWrapMode(QPlainTextEdit.LineWrapMode.WidgetWidth if prefs['editor_line_wrap'] else QPlainTextEdit.LineWrapMode.NoWrap)
|
self.setLineWrapMode(QPlainTextEdit.LineWrapMode.WidgetWidth if prefs['editor_line_wrap'] else QPlainTextEdit.LineWrapMode.NoWrap)
|
||||||
theme = get_theme(prefs['editor_theme'])
|
theme = get_theme(prefs['editor_theme'])
|
||||||
self.apply_theme(theme)
|
self.apply_theme(theme)
|
||||||
w = self.fontMetrics()
|
fm = self.fontMetrics()
|
||||||
self.space_width = w.width(' ')
|
self.space_width = fm.horizontalAdvance(' ')
|
||||||
self.tw = self.smarts.override_tab_stop_width if self.smarts.override_tab_stop_width is not None else prefs['editor_tab_stop_width']
|
self.tw = self.smarts.override_tab_stop_width if self.smarts.override_tab_stop_width is not None else prefs['editor_tab_stop_width']
|
||||||
self.setTabStopWidth(self.tw * self.space_width)
|
self.setTabStopDistance(self.tw * self.space_width)
|
||||||
if dictionaries_changed:
|
if dictionaries_changed:
|
||||||
self.highlighter.rehighlight()
|
self.highlighter.rehighlight()
|
||||||
|
|
||||||
@ -258,9 +258,9 @@ class TextEdit(PlainTextEdit):
|
|||||||
self.tooltip_font.setPointSizeF(font.pointSizeF() - 1.)
|
self.tooltip_font.setPointSizeF(font.pointSizeF() - 1.)
|
||||||
self.setFont(font)
|
self.setFont(font)
|
||||||
self.highlighter.apply_theme(theme)
|
self.highlighter.apply_theme(theme)
|
||||||
w = self.fontMetrics()
|
fm = self.fontMetrics()
|
||||||
self.number_width = max(map(lambda x:w.width(str(x)), range(10)))
|
self.number_width = max(map(lambda x:fm.horizontalAdvance(str(x)), range(10)))
|
||||||
self.size_hint = QSize(self.expected_geometry[0] * w.averageCharWidth(), self.expected_geometry[1] * w.height())
|
self.size_hint = QSize(self.expected_geometry[0] * fm.averageCharWidth(), self.expected_geometry[1] * fm.height())
|
||||||
self.highlight_color = theme_color(theme, 'HighlightRegion', 'bg')
|
self.highlight_color = theme_color(theme, 'HighlightRegion', 'bg')
|
||||||
self.highlight_cursor_line()
|
self.highlight_cursor_line()
|
||||||
self.completion_popup.clear_caches(), self.completion_popup.update()
|
self.completion_popup.clear_caches(), self.completion_popup.update()
|
||||||
@ -276,7 +276,7 @@ class TextEdit(PlainTextEdit):
|
|||||||
self.smarts = sclass(self)
|
self.smarts = sclass(self)
|
||||||
if self.smarts.override_tab_stop_width is not None:
|
if self.smarts.override_tab_stop_width is not None:
|
||||||
self.tw = self.smarts.override_tab_stop_width
|
self.tw = self.smarts.override_tab_stop_width
|
||||||
self.setTabStopWidth(self.tw * self.space_width)
|
self.setTabStopDistance(self.tw * self.space_width)
|
||||||
if isinstance(text, bytes):
|
if isinstance(text, bytes):
|
||||||
text = text.decode('utf-8', 'replace')
|
text = text.decode('utf-8', 'replace')
|
||||||
self.setPlainText(unicodedata.normalize('NFC', str(text)))
|
self.setPlainText(unicodedata.normalize('NFC', str(text)))
|
||||||
|
@ -12,9 +12,9 @@ from qt.core import (
|
|||||||
pyqtSignal
|
pyqtSignal
|
||||||
)
|
)
|
||||||
from qt.webengine import (
|
from qt.webengine import (
|
||||||
QWebEngineContextMenuData, QWebEnginePage, QWebEngineProfile, QWebEngineScript,
|
QWebEngineContextMenuRequest, QWebEnginePage, QWebEngineProfile,
|
||||||
QWebEngineSettings, QWebEngineUrlRequestJob, QWebEngineUrlSchemeHandler,
|
QWebEngineScript, QWebEngineSettings, QWebEngineUrlRequestJob,
|
||||||
QWebEngineView
|
QWebEngineUrlSchemeHandler, QWebEngineView
|
||||||
)
|
)
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
@ -33,13 +33,12 @@ from calibre.gui2.palette import dark_color, dark_link_color, dark_text_color
|
|||||||
from calibre.gui2.tweak_book import TOP, actions, current_container, editors, tprefs
|
from calibre.gui2.tweak_book import TOP, actions, current_container, editors, tprefs
|
||||||
from calibre.gui2.tweak_book.file_list import OpenWithHandler
|
from calibre.gui2.tweak_book.file_list import OpenWithHandler
|
||||||
from calibre.gui2.viewer.web_view import handle_mathjax_request, send_reply
|
from calibre.gui2.viewer.web_view import handle_mathjax_request, send_reply
|
||||||
from calibre.utils.webengine import (
|
|
||||||
Bridge, create_script, from_js, insert_scripts,
|
|
||||||
secure_webengine, to_js
|
|
||||||
)
|
|
||||||
from calibre.gui2.webengine import RestartingWebEngineView
|
from calibre.gui2.webengine import RestartingWebEngineView
|
||||||
from calibre.gui2.widgets2 import HistoryLineEdit2
|
from calibre.gui2.widgets2 import HistoryLineEdit2
|
||||||
from calibre.utils.ipc.simple_worker import offload_worker
|
from calibre.utils.ipc.simple_worker import offload_worker
|
||||||
|
from calibre.utils.webengine import (
|
||||||
|
Bridge, create_script, from_js, insert_scripts, secure_webengine, to_js
|
||||||
|
)
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
from polyglot.queue import Empty, Queue
|
from polyglot.queue import Empty, Queue
|
||||||
from polyglot.urllib import urlparse
|
from polyglot.urllib import urlparse
|
||||||
@ -462,7 +461,7 @@ class WebView(RestartingWebEngineView, OpenWithHandler):
|
|||||||
|
|
||||||
def contextMenuEvent(self, ev):
|
def contextMenuEvent(self, ev):
|
||||||
menu = QMenu(self)
|
menu = QMenu(self)
|
||||||
data = self._page.contextMenuData()
|
data = self.lastContextMenuRequest()
|
||||||
url = data.linkUrl()
|
url = data.linkUrl()
|
||||||
url = str(url.toString(NO_URL_FORMATTING)).strip()
|
url = str(url.toString(NO_URL_FORMATTING)).strip()
|
||||||
text = data.selectedText()
|
text = data.selectedText()
|
||||||
@ -474,7 +473,7 @@ class WebView(RestartingWebEngineView, OpenWithHandler):
|
|||||||
menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect)
|
menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect)
|
||||||
if url.partition(':')[0].lower() in {'http', 'https'}:
|
if url.partition(':')[0].lower() in {'http', 'https'}:
|
||||||
menu.addAction(_('Open link'), partial(safe_open_url, data.linkUrl()))
|
menu.addAction(_('Open link'), partial(safe_open_url, data.linkUrl()))
|
||||||
if QWebEngineContextMenuData.MediaType.MediaTypeImage <= data.mediaType() <= QWebEngineContextMenuData.MediaType.MediaTypeFile:
|
if QWebEngineContextMenuRequest.MediaType.MediaTypeImage.value <= data.mediaType().value <= QWebEngineContextMenuRequest.MediaType.MediaTypeFile.value:
|
||||||
url = data.mediaUrl()
|
url = data.mediaUrl()
|
||||||
if url.scheme() == FAKE_PROTOCOL:
|
if url.scheme() == FAKE_PROTOCOL:
|
||||||
href = url.path().lstrip('/')
|
href = url.path().lstrip('/')
|
||||||
@ -483,7 +482,7 @@ class WebView(RestartingWebEngineView, OpenWithHandler):
|
|||||||
resource_name = c.href_to_name(href)
|
resource_name = c.href_to_name(href)
|
||||||
if resource_name and c.exists(resource_name) and resource_name not in c.names_that_must_not_be_changed:
|
if resource_name and c.exists(resource_name) and resource_name not in c.names_that_must_not_be_changed:
|
||||||
self.add_open_with_actions(menu, resource_name)
|
self.add_open_with_actions(menu, resource_name)
|
||||||
if data.mediaType() == QWebEngineContextMenuData.MediaType.MediaTypeImage:
|
if data.mediaType() == QWebEngineContextMenuRequest.MediaType.MediaTypeImage:
|
||||||
mime = c.mime_map[resource_name]
|
mime = c.mime_map[resource_name]
|
||||||
if mime.startswith('image/'):
|
if mime.startswith('image/'):
|
||||||
menu.addAction(_('Edit %s') % resource_name, partial(self.edit_image, resource_name))
|
menu.addAction(_('Edit %s') % resource_name, partial(self.edit_image, resource_name))
|
||||||
|
@ -385,8 +385,8 @@ class Main(MainWindow):
|
|||||||
for v, h in product(('top', 'bottom'), ('left', 'right')):
|
for v, h in product(('top', 'bottom'), ('left', 'right')):
|
||||||
p = f'dock_{v}_{h}'
|
p = f'dock_{v}_{h}'
|
||||||
pref = tprefs[p] or tprefs.defaults[p]
|
pref = tprefs[p] or tprefs.defaults[p]
|
||||||
area = getattr(Qt, '%sDockWidgetArea' % capitalize({'vertical':h, 'horizontal':v}[pref]))
|
area = getattr(Qt.DockWidgetArea, '%sDockWidgetArea' % capitalize({'vertical':h, 'horizontal':v}[pref]))
|
||||||
self.setCorner(getattr(Qt, '%s%sCorner' % tuple(map(capitalize, (v, h)))), area)
|
self.setCorner(getattr(Qt.Corner, '%s%sCorner' % tuple(map(capitalize, (v, h)))), area)
|
||||||
self.preview.apply_settings()
|
self.preview.apply_settings()
|
||||||
self.live_css.apply_theme()
|
self.live_css.apply_theme()
|
||||||
for bar in (self.global_bar, self.tools_bar, self.plugins_bar):
|
for bar in (self.global_bar, self.tools_bar, self.plugins_bar):
|
||||||
|
@ -314,7 +314,7 @@ def apply_font_settings(page_or_view):
|
|||||||
else:
|
else:
|
||||||
s.resetFontFamily(QWebEngineSettings.FontFamily.SansSerifFont)
|
s.resetFontFamily(QWebEngineSettings.FontFamily.SansSerifFont)
|
||||||
sf = fs.get('standard_font') or 'serif'
|
sf = fs.get('standard_font') or 'serif'
|
||||||
sf = getattr(s, {'serif': 'SerifFont', 'sans': 'SansSerifFont', 'mono': 'FixedFont'}[sf])
|
sf = getattr(QWebEngineSettings.FontFamily, {'serif': 'SerifFont', 'sans': 'SansSerifFont', 'mono': 'FixedFont'}[sf])
|
||||||
s.setFontFamily(QWebEngineSettings.FontFamily.StandardFont, s.fontFamily(sf))
|
s.setFontFamily(QWebEngineSettings.FontFamily.StandardFont, s.fontFamily(sf))
|
||||||
old_minimum = s.fontSize(QWebEngineSettings.FontSize.MinimumFontSize)
|
old_minimum = s.fontSize(QWebEngineSettings.FontSize.MinimumFontSize)
|
||||||
old_base = s.fontSize(QWebEngineSettings.FontSize.DefaultFontSize)
|
old_base = s.fontSize(QWebEngineSettings.FontSize.DefaultFontSize)
|
||||||
|
@ -394,7 +394,7 @@ class FlowLayout(QLayout): # {{{
|
|||||||
self.do_layout(rect, apply_geometry=True)
|
self.do_layout(rect, apply_geometry=True)
|
||||||
|
|
||||||
def expandingDirections(self):
|
def expandingDirections(self):
|
||||||
return Qt.Orientations(0)
|
return Qt.Orientation(0)
|
||||||
|
|
||||||
def minimumSize(self):
|
def minimumSize(self):
|
||||||
size = QSize()
|
size = QSize()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user