mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Replace use of the deprecated QDesktoWidget
It is removed in PyQt6
This commit is contained in:
parent
7d85958b57
commit
d9bdbbab7f
@ -9,15 +9,15 @@ import signal
|
||||
import sys
|
||||
import threading
|
||||
from contextlib import contextmanager
|
||||
from threading import Lock, RLock
|
||||
|
||||
from qt.core import (
|
||||
QT_VERSION, QApplication, QBuffer, QByteArray, QCoreApplication, QDateTime,
|
||||
QDesktopServices, QDialog, QEvent, QFileDialog, QFileIconProvider, QFileInfo, QPalette,
|
||||
QFont, QFontDatabase, QFontInfo, QFontMetrics, QIcon, QLocale, QColor,
|
||||
QNetworkProxyFactory, QObject, QSettings, QSocketNotifier, QStringListModel, Qt,
|
||||
QThread, QTimer, QTranslator, QUrl, pyqtSignal, QIODevice, QDialogButtonBox, QStyle
|
||||
QT_VERSION, QApplication, QBuffer, QByteArray, QColor, QCoreApplication,
|
||||
QDateTime, QDesktopServices, QDialog, QDialogButtonBox, QEvent, QFileDialog,
|
||||
QFileIconProvider, QFileInfo, QFont, QFontDatabase, QFontInfo, QFontMetrics,
|
||||
QGuiApplication, QIcon, QIODevice, QLocale, QNetworkProxyFactory, QObject,
|
||||
QPalette, QSettings, QSocketNotifier, QStringListModel, QStyle, Qt, QThread,
|
||||
QTimer, QTranslator, QUrl, pyqtSignal
|
||||
)
|
||||
from threading import Lock, RLock
|
||||
|
||||
from calibre import as_unicode, prints
|
||||
from calibre.constants import (
|
||||
@ -331,13 +331,15 @@ def default_author_link():
|
||||
|
||||
|
||||
def available_heights():
|
||||
desktop = QCoreApplication.instance().desktop()
|
||||
return list(map(lambda x: x.height(), map(desktop.availableGeometry, range(desktop.screenCount()))))
|
||||
return tuple(s.availableSize().height() for s in QGuiApplication.screens())
|
||||
|
||||
|
||||
def available_height():
|
||||
desktop = QCoreApplication.instance().desktop()
|
||||
return desktop.availableGeometry().height()
|
||||
return QApplication.instance().primaryScreen().availableSize().height()
|
||||
|
||||
|
||||
def available_width():
|
||||
return QApplication.instance().primaryScreen().availableSize().width()
|
||||
|
||||
|
||||
def max_available_height():
|
||||
@ -348,11 +350,6 @@ def min_available_height():
|
||||
return min(available_heights())
|
||||
|
||||
|
||||
def available_width():
|
||||
desktop = QCoreApplication.instance().desktop()
|
||||
return desktop.availableGeometry().width()
|
||||
|
||||
|
||||
def get_screen_dpi():
|
||||
d = QApplication.desktop()
|
||||
return (d.logicalDpiX(), d.logicalDpiY())
|
||||
@ -678,12 +675,16 @@ if not iswindows and not ismacos and 'CALIBRE_NO_NATIVE_FILEDIALOGS' not in os.e
|
||||
has_linux_file_dialog_helper = check_for_linux_native_dialogs()
|
||||
|
||||
if has_windows_file_dialog_helper:
|
||||
from calibre.gui2.win_file_dialogs import choose_files, choose_images, choose_dir, choose_save_file
|
||||
from calibre.gui2.win_file_dialogs import (
|
||||
choose_dir, choose_files, choose_images, choose_save_file
|
||||
)
|
||||
elif has_linux_file_dialog_helper:
|
||||
choose_dir, choose_files, choose_save_file, choose_images = map(
|
||||
linux_native_dialog, 'dir files save_file images'.split())
|
||||
else:
|
||||
from calibre.gui2.qt_file_dialogs import choose_files, choose_images, choose_dir, choose_save_file
|
||||
from calibre.gui2.qt_file_dialogs import (
|
||||
choose_dir, choose_files, choose_images, choose_save_file
|
||||
)
|
||||
choose_files, choose_images, choose_dir, choose_save_file
|
||||
|
||||
|
||||
@ -1042,6 +1043,7 @@ class Application(QApplication):
|
||||
def load_builtin_fonts(self, scan_for_fonts=False):
|
||||
if scan_for_fonts:
|
||||
from calibre.utils.fonts.scanner import font_scanner
|
||||
|
||||
# Start scanning the users computer for fonts
|
||||
font_scanner
|
||||
|
||||
@ -1332,6 +1334,7 @@ def ensure_app(headless=True):
|
||||
if headless and has_headless:
|
||||
_store_app.headless = True
|
||||
import traceback
|
||||
|
||||
# This is needed because as of PyQt 5.4 if sys.execpthook ==
|
||||
# sys.__excepthook__ PyQt will abort the application on an
|
||||
# unhandled python exception in a slot or virtual method. Since ensure_app()
|
||||
@ -1399,7 +1402,7 @@ def elided_text(text, font=None, width=300, pos='middle'):
|
||||
rendered, replacing characters from the left, middle or right (as per pos)
|
||||
of the string with an ellipsis. Results in a string much closer to the
|
||||
limit than Qt's elidedText().'''
|
||||
from qt.core import QFontMetrics, QApplication
|
||||
from qt.core import QApplication, QFontMetrics
|
||||
if font is None:
|
||||
font = QApplication.instance().font()
|
||||
fm = (font if isinstance(font, QFontMetrics) else QFontMetrics(font))
|
||||
@ -1434,6 +1437,7 @@ def form_to_compiled_form(form):
|
||||
def build_forms(srcdir, info=None, summary=False, check_for_migration=False):
|
||||
import re
|
||||
from PyQt5.uic import compileUi
|
||||
|
||||
from polyglot.io import PolyglotStringIO
|
||||
forms = find_forms(srcdir)
|
||||
if info is None:
|
||||
@ -1495,8 +1499,7 @@ empty_index = empty_model.index(0)
|
||||
|
||||
def set_app_uid(val):
|
||||
import ctypes
|
||||
from ctypes import wintypes
|
||||
from ctypes import HRESULT
|
||||
from ctypes import HRESULT, wintypes
|
||||
try:
|
||||
AppUserModelID = ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID
|
||||
except Exception: # Vista has no app uids
|
||||
|
@ -143,7 +143,7 @@ class Completer(QListView): # {{{
|
||||
widget = self.parent()
|
||||
if widget is None:
|
||||
return
|
||||
screen = QApplication.desktop().availableGeometry(widget)
|
||||
screen = widget.screen().availableGeometry()
|
||||
h = (p.sizeHintForRow(0) * min(self.max_visible_items, m.rowCount()) + 3) + 3
|
||||
hsb = p.horizontalScrollBar()
|
||||
if hsb and hsb.isVisible():
|
||||
|
@ -6,7 +6,7 @@
|
||||
import shutil
|
||||
|
||||
from qt.core import (
|
||||
QAbstractListModel, QCheckBox, QComboBox, QCoreApplication, QDialog,
|
||||
QAbstractListModel, QCheckBox, QComboBox, QDialog,
|
||||
QDialogButtonBox, QFont, QFrame, QGridLayout, QHBoxLayout, QIcon, QLabel,
|
||||
QListView, QModelIndex, QScrollArea, QSize, QSizePolicy, QSpacerItem,
|
||||
Qt, QTextEdit, QWidget, QApplication
|
||||
@ -179,8 +179,7 @@ class Config(QDialog):
|
||||
self.buttonBox.rejected.connect(self.reject)
|
||||
|
||||
def sizeHint(self):
|
||||
desktop = QCoreApplication.instance().desktop()
|
||||
geom = desktop.availableGeometry(self)
|
||||
geom = self.screen().availableSize()
|
||||
nh, nw = max(300, geom.height()-100), max(400, geom.width()-70)
|
||||
return QSize(nw, nh)
|
||||
|
||||
|
@ -19,9 +19,7 @@ from qt.core import (
|
||||
|
||||
from calibre.constants import islinux
|
||||
from calibre.ebooks.metadata import rating_to_stars, authors_to_string
|
||||
from calibre.gui2 import (
|
||||
available_height, available_width, config, gprefs, rating_font
|
||||
)
|
||||
from calibre.gui2 import config, gprefs, rating_font
|
||||
from calibre_extensions import pictureflow
|
||||
|
||||
|
||||
@ -261,7 +259,8 @@ class CBDialog(QDialog):
|
||||
|
||||
geom = gprefs.get('cover_browser_dialog_geometry', None)
|
||||
if not geom or not QApplication.instance().safe_restore_geometry(self, geom):
|
||||
h, w = available_height()-60, int(available_width()/1.5)
|
||||
sz = self.screen().availableSize()
|
||||
h, w = sz.height()-60, int(sz.width()/1.5)
|
||||
self.resize(w, h)
|
||||
self.action_fs_toggle = a = QAction(self)
|
||||
self.addAction(a)
|
||||
@ -497,7 +496,6 @@ def test():
|
||||
app = QApplication([])
|
||||
w = QMainWindow()
|
||||
cf = CoverFlow()
|
||||
cf.resize(int(available_width()/1.5), available_height()-60)
|
||||
w.resize(cf.size()+QSize(30, 20))
|
||||
model = DummyImageList()
|
||||
cf.setImages(model)
|
||||
@ -518,7 +516,6 @@ if __name__ == '__main__':
|
||||
app = QApplication([])
|
||||
w = QMainWindow()
|
||||
cf = CoverFlow()
|
||||
cf.resize(int(available_width()/1.5), available_height()-60)
|
||||
w.resize(cf.size()+QSize(30, 20))
|
||||
path = sys.argv[1]
|
||||
model = FileSystemImages(sys.argv[1])
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import textwrap
|
||||
from qt.core import (
|
||||
QAction, QApplication, QBrush, QCheckBox, QCoreApplication, QDialog, QGridLayout,
|
||||
QAction, QApplication, QBrush, QCheckBox, QDialog, QGridLayout,
|
||||
QHBoxLayout, QIcon, QKeySequence, QLabel, QListView, QModelIndex, QPalette,
|
||||
QPixmap, QPushButton, QShortcut, QSize, QSplitter, Qt, QTimer, QToolButton,
|
||||
QVBoxLayout, QWidget, pyqtSignal, QDialogButtonBox
|
||||
@ -198,7 +198,7 @@ class BookInfo(QDialog):
|
||||
self.previous_button.setToolTip(_('Previous [%s]')%
|
||||
str(self.ps.key().toString(QKeySequence.SequenceFormat.NativeText)))
|
||||
|
||||
geom = QCoreApplication.instance().desktop().availableGeometry(self)
|
||||
geom = self.screen().availableSize()
|
||||
screen_height = geom.height() - 100
|
||||
screen_width = geom.width() - 100
|
||||
self.resize(max(int(screen_width/2), 700), screen_height)
|
||||
|
@ -11,7 +11,7 @@ import os
|
||||
import sys
|
||||
import weakref
|
||||
from qt.core import (
|
||||
QApplication, QCoreApplication, QDialog, QDialogButtonBox, QScrollArea, QSize
|
||||
QApplication, QDialog, QDialogButtonBox, QScrollArea, QSize
|
||||
)
|
||||
|
||||
from calibre.customize import PluginInstallationType
|
||||
@ -138,14 +138,12 @@ class Catalog(QDialog, Ui_Dialog):
|
||||
QApplication.instance().safe_restore_geometry(self, bytes(geom))
|
||||
else:
|
||||
self.resize(self.sizeHint())
|
||||
d = QCoreApplication.instance().desktop()
|
||||
g = d.availableGeometry(d.screenNumber(self))
|
||||
g = self.screen().availableSize()
|
||||
self.setMaximumWidth(g.width() - 50)
|
||||
self.setMaximumHeight(g.height() - 50)
|
||||
|
||||
def sizeHint(self):
|
||||
desktop = QCoreApplication.instance().desktop()
|
||||
geom = desktop.availableGeometry(self)
|
||||
geom = self.screen().availableSize()
|
||||
nh, nw = max(300, geom.height()-50), max(400, geom.width()-70)
|
||||
return QSize(nw, nh)
|
||||
|
||||
|
@ -8,7 +8,7 @@ import regex
|
||||
from collections import defaultdict, namedtuple
|
||||
from io import BytesIO
|
||||
from qt.core import (
|
||||
QApplication, QComboBox, QCompleter, QCoreApplication, QDateTime, QDialog,
|
||||
QApplication, QComboBox, QCompleter, QDateTime, QDialog,
|
||||
QDialogButtonBox, QFont, QGridLayout, QInputDialog, QLabel, QLineEdit,
|
||||
QProgressBar, QSize, Qt, QVBoxLayout, pyqtSignal
|
||||
)
|
||||
@ -579,8 +579,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
self.exec()
|
||||
|
||||
def sizeHint(self):
|
||||
desktop = QCoreApplication.instance().desktop()
|
||||
geom = desktop.availableGeometry(self)
|
||||
geom = self.screen().availableSize()
|
||||
nh, nw = max(300, geom.height()-50), max(400, geom.width()-70)
|
||||
return QSize(nw, nh)
|
||||
|
||||
|
@ -601,8 +601,7 @@ class ChooseTheme(Dialog):
|
||||
self.dialog_closed = True
|
||||
|
||||
def sizeHint(self):
|
||||
desktop = QApplication.instance().desktop()
|
||||
h = desktop.availableGeometry(self).height()
|
||||
h = self.screen().availableSize().height()
|
||||
return QSize(900, h - 75)
|
||||
|
||||
def setup_ui(self):
|
||||
|
@ -101,8 +101,7 @@ class ImageView(QDialog):
|
||||
self.maximized_at_last_fullscreen = False
|
||||
self.setWindowFlag(Qt.WindowType.WindowMinimizeButtonHint)
|
||||
self.setWindowFlag(Qt.WindowType.WindowMaximizeButtonHint)
|
||||
dw = QApplication.instance().desktop()
|
||||
self.avail_geom = dw.availableGeometry(parent if parent is not None else self)
|
||||
self.avail_geom = self.screen().availableGeometry()
|
||||
self.current_img = current_img
|
||||
self.current_url = current_url
|
||||
self.factor = 1.0
|
||||
|
@ -41,7 +41,7 @@ CACHE_FORMAT = 'PPM'
|
||||
def auto_height(widget):
|
||||
# On some broken systems, availableGeometry() returns tiny values, we need
|
||||
# a value of at least 1000 for 200 DPI systems.
|
||||
return max(1000, QApplication.instance().desktop().availableGeometry(widget).height()) / 5.0
|
||||
return max(1000, widget.screen().availableSize().height()) / 5.0
|
||||
|
||||
|
||||
class EncodeError(ValueError):
|
||||
|
@ -169,8 +169,7 @@ class Main(MainWindow, Ui_MainWindow):
|
||||
scrollbar_adjust = min(s.width(), s.height())
|
||||
self.graphics_view.resize_for(width+scrollbar_adjust, height+scrollbar_adjust)
|
||||
|
||||
desktop = QCoreApplication.instance().desktop()
|
||||
screen_height = desktop.availableGeometry(self).height() - 25
|
||||
screen_height = self.screen().availableSize().height() - 25
|
||||
height = min(screen_height, height+hdelta+scrollbar_adjust)
|
||||
self.resize(width+scrollbar_adjust, height)
|
||||
self.setWindowTitle(self.renderer.lrf.metadata.title + ' - ' + __appname__)
|
||||
|
@ -680,8 +680,7 @@ class CompareMany(QDialog):
|
||||
|
||||
self.next_item(True)
|
||||
|
||||
desktop = QApplication.instance().desktop()
|
||||
geom = desktop.availableGeometry(parent or self)
|
||||
geom = (parent or self).screen().availableSize()
|
||||
width = max(700, min(950, geom.width()-50))
|
||||
height = max(650, min(1000, geom.height()-100))
|
||||
self.resize(QSize(width, height))
|
||||
|
@ -11,7 +11,7 @@ import os
|
||||
from datetime import datetime
|
||||
from functools import partial
|
||||
from qt.core import (
|
||||
QApplication, QCoreApplication, QDialog, QDialogButtonBox, QFont, QFrame,
|
||||
QApplication, QDialog, QDialogButtonBox, QFont, QFrame,
|
||||
QGridLayout, QGroupBox, QHBoxLayout, QIcon, QInputDialog, QKeySequence, QMenu,
|
||||
QPushButton, QScrollArea, QShortcut, QSize, QSizePolicy, QSpacerItem, QSplitter,
|
||||
Qt, QTabWidget, QToolButton, QVBoxLayout, QWidget, pyqtSignal
|
||||
@ -131,8 +131,7 @@ class MetadataSingleDialogBase(QDialog):
|
||||
# }}}
|
||||
|
||||
def sizeHint(self):
|
||||
desktop = QCoreApplication.instance().desktop()
|
||||
geom = desktop.availableGeometry(self)
|
||||
geom = self.screen().availableSize()
|
||||
nh, nw = max(300, geom.height()-50), max(400, geom.width()-70)
|
||||
return QSize(nw, nh)
|
||||
|
||||
|
@ -1034,7 +1034,7 @@ class TOCEditor(QDialog): # {{{
|
||||
self.explode_done.connect(self.read_toc, type=Qt.ConnectionType.QueuedConnection)
|
||||
self.writing_done.connect(self.really_accept, type=Qt.ConnectionType.QueuedConnection)
|
||||
|
||||
r = QApplication.desktop().availableGeometry(self)
|
||||
r = self.screen().availableSize()
|
||||
self.resize(r.width() - 100, r.height() - 100)
|
||||
geom = self.prefs.get('toc_editor_window_geom', None)
|
||||
if geom is not None:
|
||||
|
@ -222,7 +222,7 @@ class Diff(Dialog):
|
||||
self.view.line_activated.connect(self.line_activated)
|
||||
|
||||
def sizeHint(self):
|
||||
geom = QApplication.instance().desktop().availableGeometry(self)
|
||||
geom = self.screen().availableSize()
|
||||
return QSize(int(0.9 * geom.width()), int(0.8 * geom.height()))
|
||||
|
||||
def setup_ui(self):
|
||||
|
@ -688,7 +688,7 @@ class ThemeEditor(Dialog):
|
||||
self.show_theme()
|
||||
|
||||
def sizeHint(self):
|
||||
g = QApplication.instance().desktop().availableGeometry(self.parent() or self)
|
||||
g = self.screen().availableSize()
|
||||
return QSize(min(1500, g.width() - 25), 650)
|
||||
# }}}
|
||||
|
||||
|
@ -403,7 +403,7 @@ class WebView(RestartingWebEngineView, OpenWithHandler):
|
||||
def __init__(self, parent=None):
|
||||
RestartingWebEngineView.__init__(self, parent)
|
||||
self.inspector = Inspector(self)
|
||||
w = QApplication.instance().desktop().availableGeometry(self).width()
|
||||
w = self.screen().availableSize().width()
|
||||
self._size_hint = QSize(int(w/3), int(w/2))
|
||||
self._page = WebPage(self)
|
||||
self.setPage(self._page)
|
||||
|
@ -374,7 +374,7 @@ class Main(MainWindow):
|
||||
self.status_bar.addWidget(la)
|
||||
|
||||
self.boss(self)
|
||||
g = QApplication.instance().desktop().availableGeometry(self)
|
||||
g = self.screen().availableSize()
|
||||
self.resize(g.width()-50, g.height()-50)
|
||||
|
||||
self.apply_settings()
|
||||
|
@ -494,7 +494,7 @@ class WebView(RestartingWebEngineView):
|
||||
self.tts.event_received.connect(self.tts_event_received)
|
||||
self.dead_renderer_error_shown = False
|
||||
self.render_process_failed.connect(self.render_process_died)
|
||||
w = QApplication.instance().desktop().availableGeometry(self).width()
|
||||
w = self.screen().availableSize().width()
|
||||
QApplication.instance().palette_changed.connect(self.palette_changed)
|
||||
self.show_home_page_on_ready = True
|
||||
self._size_hint = QSize(int(w/3), int(w/2))
|
||||
|
Loading…
x
Reference in New Issue
Block a user