Switch app code to PyQt6
This commit is contained in:
@@ -27,7 +27,7 @@ import re
|
||||
|
||||
from enum import Flag, IntEnum
|
||||
|
||||
from PyQt5.QtGui import QColor
|
||||
from PyQt6.QtGui import QColor
|
||||
|
||||
ESCAPES = {r"\*": "*", r"\~": "~", r"\_": "_", r"\[": "[", r"\]": "]", r"\ ": ""}
|
||||
RX_ESC = re.compile("|".join([re.escape(k) for k in ESCAPES.keys()]), flags=re.DOTALL)
|
||||
|
||||
@@ -33,8 +33,8 @@ from pathlib import Path
|
||||
from typing import NamedTuple
|
||||
from zipfile import ZIP_DEFLATED, ZipFile
|
||||
|
||||
from PyQt5.QtCore import QMargins, QSize
|
||||
from PyQt5.QtGui import QColor
|
||||
from PyQt6.QtCore import QMargins, QSize
|
||||
from PyQt6.QtGui import QColor
|
||||
|
||||
from novelwriter import __version__
|
||||
from novelwriter.common import firstFloat, xmlElement, xmlSubElem
|
||||
|
||||
@@ -31,8 +31,8 @@ from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import NamedTuple
|
||||
|
||||
from PyQt5.QtCore import QLocale
|
||||
from PyQt5.QtGui import QColor, QFont
|
||||
from PyQt6.QtCore import QLocale
|
||||
from PyQt6.QtGui import QColor, QFont
|
||||
|
||||
from novelwriter import CONFIG
|
||||
from novelwriter.common import checkInt, fontMatcher, numberToRoman
|
||||
|
||||
@@ -35,7 +35,7 @@ from hashlib import sha256
|
||||
from pathlib import Path
|
||||
from zipfile import ZIP_DEFLATED, ZipFile
|
||||
|
||||
from PyQt5.QtGui import QColor, QFont
|
||||
from PyQt6.QtGui import QColor, QFont
|
||||
|
||||
from novelwriter import __version__
|
||||
from novelwriter.common import xmlElement, xmlIndent, xmlSubElem
|
||||
|
||||
@@ -27,12 +27,12 @@ import logging
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from PyQt5.QtCore import QMarginsF, QSizeF
|
||||
from PyQt5.QtGui import (
|
||||
QColor, QFont, QFontDatabase, QPageSize, QTextBlockFormat, QTextCharFormat,
|
||||
QTextCursor, QTextDocument, QTextFrameFormat
|
||||
from PyQt6.QtCore import QMarginsF, QSizeF
|
||||
from PyQt6.QtGui import (
|
||||
QColor, QFont, QFontDatabase, QPageLayout, QPageSize, QTextBlockFormat,
|
||||
QTextCharFormat, QTextCursor, QTextDocument, QTextFrameFormat
|
||||
)
|
||||
from PyQt5.QtPrintSupport import QPrinter
|
||||
from PyQt6.QtPrintSupport import QPrinter
|
||||
|
||||
from novelwriter import __version__
|
||||
from novelwriter.constants import nwStyles, nwUnicode
|
||||
@@ -129,10 +129,9 @@ class ToQTextDocument(Tokenizer):
|
||||
super().initDocument()
|
||||
|
||||
if pdf:
|
||||
fontDB = QFontDatabase()
|
||||
family = self._textFont.family()
|
||||
style = self._textFont.styleName()
|
||||
self._dpi = 1200 if fontDB.isScalable(family, style) else 72
|
||||
self._dpi = 1200 if QFontDatabase.isScalable(family, style) else 72
|
||||
|
||||
self._document.setUndoRedoEnabled(False)
|
||||
self._document.blockSignals(True)
|
||||
@@ -268,7 +267,6 @@ class ToQTextDocument(Tokenizer):
|
||||
|
||||
def saveDocument(self, path: Path) -> None:
|
||||
"""Save the document as a PDF file."""
|
||||
m = self._pageMargins
|
||||
logger.info("Writing PDF at %d DPI", self._dpi)
|
||||
|
||||
printer = QPrinter(QPrinter.PrinterMode.HighResolution)
|
||||
@@ -277,11 +275,11 @@ class ToQTextDocument(Tokenizer):
|
||||
printer.setResolution(self._dpi)
|
||||
printer.setOutputFormat(QPrinter.OutputFormat.PdfFormat)
|
||||
printer.setPageSize(self._pageSize)
|
||||
printer.setPageMargins(m.left(), m.top(), m.right(), m.bottom(), QPrinter.Unit.Millimeter)
|
||||
printer.setPageMargins(self._pageMargins, QPageLayout.Unit.Millimeter)
|
||||
printer.setOutputFileName(str(path))
|
||||
|
||||
self._document.documentLayout().setPaintDevice(printer)
|
||||
self._document.setPageSize(QSizeF(printer.pageRect().size()))
|
||||
self._document.setPageSize(printer.pageRect(QPrinter.Unit.Millimeter).size())
|
||||
self._document.print(printer)
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user