Drop the qApp macro
This commit is contained in:
@@ -26,12 +26,12 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from PyQt5.QtGui import QCloseEvent, QFont, QKeyEvent, QKeySequence
|
|
||||||
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
|
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
|
||||||
|
from PyQt5.QtGui import QCloseEvent, QFont, QKeyEvent, QKeySequence
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QAbstractButton, QCompleter, QDialog, QDialogButtonBox, QFileDialog,
|
QAbstractButton, QApplication, QCompleter, QDialog, QDialogButtonBox,
|
||||||
QFontDialog, QHBoxLayout, QLineEdit, QPushButton, QVBoxLayout, QWidget,
|
QFileDialog, QFontDialog, QHBoxLayout, QLineEdit, QPushButton, QVBoxLayout,
|
||||||
qApp
|
QWidget
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
@@ -742,7 +742,7 @@ class GuiPreferences(QDialog):
|
|||||||
logger.debug("Close: GuiPreferences")
|
logger.debug("Close: GuiPreferences")
|
||||||
self._saveWindowSize()
|
self._saveWindowSize()
|
||||||
event.accept()
|
event.accept()
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
self.done(nwConst.DLG_FINISHED)
|
self.done(nwConst.DLG_FINISHED)
|
||||||
self.deleteLater()
|
self.deleteLater()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from PyQt5.QtGui import QCloseEvent, QColor, QIcon, QPixmap
|
|
||||||
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
|
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
|
||||||
|
from PyQt5.QtGui import QCloseEvent, QColor, QIcon, QPixmap
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QColorDialog, QDialog, QDialogButtonBox, QHBoxLayout, QLineEdit,
|
QApplication, QColorDialog, QDialog, QDialogButtonBox, QHBoxLayout,
|
||||||
QPushButton, QStackedWidget, QTreeWidget, QTreeWidgetItem, QVBoxLayout,
|
QLineEdit, QPushButton, QStackedWidget, QTreeWidget, QTreeWidgetItem,
|
||||||
QWidget, qApp
|
QVBoxLayout, QWidget
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
@@ -195,7 +195,7 @@ class GuiProjectSettings(QDialog):
|
|||||||
project.data.setAutoReplace(newList)
|
project.data.setAutoReplace(newList)
|
||||||
|
|
||||||
self.newProjectSettingsReady.emit(rebuildTrees)
|
self.newProjectSettingsReady.emit(rebuildTrees)
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ import logging
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from PyQt5.QtGui import QCloseEvent
|
|
||||||
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
|
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
|
||||||
|
from PyQt5.QtGui import QCloseEvent
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QAbstractItemView, QDialog, QDialogButtonBox, QFileDialog, QHBoxLayout,
|
QAbstractItemView, QApplication, QDialog, QDialogButtonBox, QFileDialog,
|
||||||
QLineEdit, QListWidget, QVBoxLayout, qApp
|
QHBoxLayout, QLineEdit, QListWidget, QVBoxLayout
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
@@ -177,7 +177,7 @@ class GuiWordList(QDialog):
|
|||||||
userDict.add(word)
|
userDict.add(word)
|
||||||
userDict.save()
|
userDict.save()
|
||||||
self.newWordListReady.emit()
|
self.newWordListReady.emit()
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
self.close()
|
self.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ import logging
|
|||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from PyQt5.QtGui import QFont, QFontDatabase
|
|
||||||
from PyQt5.QtCore import Qt, pyqtSlot
|
from PyQt5.QtCore import Qt, pyqtSlot
|
||||||
|
from PyQt5.QtGui import QFont, QFontDatabase
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QWidget, qApp, QDialog, QGridLayout, QStyle, QPlainTextEdit, QLabel,
|
QApplication, QWidget, QDialog, QGridLayout, QStyle, QPlainTextEdit,
|
||||||
QDialogButtonBox
|
QLabel, QDialogButtonBox
|
||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING: # pragma: no cover
|
if TYPE_CHECKING: # pragma: no cover
|
||||||
@@ -74,7 +74,7 @@ class NWErrorMessage(QDialog):
|
|||||||
# Widgets
|
# Widgets
|
||||||
self.msgIcon = QLabel()
|
self.msgIcon = QLabel()
|
||||||
self.msgIcon.setPixmap(
|
self.msgIcon.setPixmap(
|
||||||
qApp.style().standardIcon(QStyle.SP_MessageBoxCritical).pixmap(64, 64)
|
QApplication.style().standardIcon(QStyle.SP_MessageBoxCritical).pixmap(64, 64)
|
||||||
)
|
)
|
||||||
self.msgHead = QLabel()
|
self.msgHead = QLabel()
|
||||||
self.msgHead.setOpenExternalLinks(True)
|
self.msgHead.setOpenExternalLinks(True)
|
||||||
@@ -179,14 +179,14 @@ class NWErrorMessage(QDialog):
|
|||||||
def exceptionHandler(exType: type, exValue: BaseException, exTrace: TracebackType) -> None:
|
def exceptionHandler(exType: type, exValue: BaseException, exTrace: TracebackType) -> None:
|
||||||
"""Function to catch unhandled global exceptions."""
|
"""Function to catch unhandled global exceptions."""
|
||||||
from traceback import print_tb
|
from traceback import print_tb
|
||||||
from PyQt5.QtWidgets import qApp
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
|
||||||
logger.critical("%s: %s", exType.__name__, str(exValue))
|
logger.critical("%s: %s", exType.__name__, str(exValue))
|
||||||
print_tb(exTrace)
|
print_tb(exTrace)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nwGUI = None
|
nwGUI = None
|
||||||
for qWin in qApp.topLevelWidgets():
|
for qWin in QApplication.topLevelWidgets():
|
||||||
if qWin.objectName() == "GuiMain":
|
if qWin.objectName() == "GuiMain":
|
||||||
nwGUI = qWin
|
nwGUI = qWin
|
||||||
break
|
break
|
||||||
@@ -209,7 +209,7 @@ def exceptionHandler(exType: type, exValue: BaseException, exTrace: TracebackTyp
|
|||||||
logger.critical("Could not close the project before exiting")
|
logger.critical("Could not close the project before exiting")
|
||||||
logger.critical(formatException(exc))
|
logger.critical(formatException(exc))
|
||||||
|
|
||||||
qApp.exit(1)
|
QApplication.exit(1)
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.critical(formatException(exc))
|
logger.critical(formatException(exc))
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ from PyQt5.QtGui import (
|
|||||||
QPixmap, QResizeEvent, QTextBlock, QTextCursor, QTextDocument, QTextOption
|
QPixmap, QResizeEvent, QTextBlock, QTextCursor, QTextDocument, QTextOption
|
||||||
)
|
)
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QAction, QFrame, QGridLayout, QHBoxLayout, QLabel, QLineEdit, QMenu,
|
QAction, QApplication, QFrame, QGridLayout, QHBoxLayout, QLabel, QLineEdit,
|
||||||
QPlainTextEdit, QShortcut, QToolBar, QVBoxLayout, QWidget, qApp
|
QMenu, QPlainTextEdit, QShortcut, QToolBar, QVBoxLayout, QWidget
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
@@ -393,13 +393,13 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
self.clearEditor()
|
self.clearEditor()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
qApp.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
||||||
self._docHandle = tHandle
|
self._docHandle = tHandle
|
||||||
|
|
||||||
self._allowAutoReplace(False)
|
self._allowAutoReplace(False)
|
||||||
self._qDocument.setTextContent(docText, tHandle)
|
self._qDocument.setTextContent(docText, tHandle)
|
||||||
self._allowAutoReplace(True)
|
self._allowAutoReplace(True)
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
|
|
||||||
self._lastEdit = time()
|
self._lastEdit = time()
|
||||||
self._lastActive = time()
|
self._lastActive = time()
|
||||||
@@ -423,12 +423,12 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
self.setPlainText("")
|
self.setPlainText("")
|
||||||
self.setCursorPosition(0)
|
self.setCursorPosition(0)
|
||||||
|
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
self.setDocumentChanged(False)
|
self.setDocumentChanged(False)
|
||||||
self._qDocument.clearUndoRedoStacks()
|
self._qDocument.clearUndoRedoStacks()
|
||||||
self.docToolBar.setVisible(CONFIG.showEditToolBar)
|
self.docToolBar.setVisible(CONFIG.showEditToolBar)
|
||||||
|
|
||||||
qApp.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
|
|
||||||
# Update the status bar
|
# Update the status bar
|
||||||
if self._nwItem is not None:
|
if self._nwItem is not None:
|
||||||
@@ -445,11 +445,11 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
"""Replace the text of the current document with the provided
|
"""Replace the text of the current document with the provided
|
||||||
text. This also clears undo history.
|
text. This also clears undo history.
|
||||||
"""
|
"""
|
||||||
qApp.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
||||||
self.setPlainText(text)
|
self.setPlainText(text)
|
||||||
self.updateDocMargins()
|
self.updateDocMargins()
|
||||||
self.setDocumentChanged(True)
|
self.setDocumentChanged(True)
|
||||||
qApp.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
return
|
return
|
||||||
|
|
||||||
def saveText(self) -> bool:
|
def saveText(self) -> bool:
|
||||||
@@ -536,7 +536,7 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
while self.cursorRect().bottom() > vH and count < 100000:
|
while self.cursorRect().bottom() > vH and count < 100000:
|
||||||
vBar.setValue(vBar.value() + 1)
|
vBar.setValue(vBar.value() + 1)
|
||||||
count += 1
|
count += 1
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
return
|
return
|
||||||
|
|
||||||
def updateDocMargins(self) -> None:
|
def updateDocMargins(self) -> None:
|
||||||
@@ -699,9 +699,9 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
"""
|
"""
|
||||||
logger.debug("Running spell checker")
|
logger.debug("Running spell checker")
|
||||||
start = time()
|
start = time()
|
||||||
qApp.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
||||||
self._qDocument.syntaxHighlighter.rehighlight()
|
self._qDocument.syntaxHighlighter.rehighlight()
|
||||||
qApp.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
logger.debug("Document highlighted in %.3f ms", 1000*(time() - start))
|
logger.debug("Document highlighted in %.3f ms", 1000*(time() - start))
|
||||||
self.statusMessage.emit(self.tr("Spell check complete"))
|
self.statusMessage.emit(self.tr("Spell check complete"))
|
||||||
return
|
return
|
||||||
@@ -814,7 +814,7 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
|
|
||||||
def anyFocus(self) -> bool:
|
def anyFocus(self) -> bool:
|
||||||
"""Check if any widget or child widget has focus."""
|
"""Check if any widget or child widget has focus."""
|
||||||
return self.hasFocus() or self.isAncestorOf(qApp.focusWidget())
|
return self.hasFocus() or self.isAncestorOf(QApplication.focusWidget())
|
||||||
|
|
||||||
def revealLocation(self) -> None:
|
def revealLocation(self) -> None:
|
||||||
"""Tell the user where on the file system the file in the editor
|
"""Tell the user where on the file system the file in the editor
|
||||||
@@ -991,7 +991,7 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
pressed, check if we're clicking on a tag, and trigger the
|
pressed, check if we're clicking on a tag, and trigger the
|
||||||
follow tag function.
|
follow tag function.
|
||||||
"""
|
"""
|
||||||
if qApp.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier:
|
if QApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier:
|
||||||
self._processTag(self.cursorForPosition(event.pos()))
|
self._processTag(self.cursorForPosition(event.pos()))
|
||||||
super().mouseReleaseEvent(event)
|
super().mouseReleaseEvent(event)
|
||||||
return
|
return
|
||||||
@@ -1912,7 +1912,7 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
).format(tag)):
|
).format(tag)):
|
||||||
itemClass = nwKeyWords.KEY_CLASS.get(tBits[0], nwItemClass.NO_CLASS)
|
itemClass = nwKeyWords.KEY_CLASS.get(tBits[0], nwItemClass.NO_CLASS)
|
||||||
self.requestNewNoteCreation.emit(tag, itemClass)
|
self.requestNewNoteCreation.emit(tag, itemClass)
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
self._qDocument.syntaxHighlighter.rehighlightBlock(block)
|
self._qDocument.syntaxHighlighter.rehighlightBlock(block)
|
||||||
|
|
||||||
return nwTrinary.POSITIVE if exist else nwTrinary.NEGATIVE
|
return nwTrinary.POSITIVE if exist else nwTrinary.NEGATIVE
|
||||||
@@ -2627,7 +2627,7 @@ class GuiDocEditSearch(QFrame):
|
|||||||
|
|
||||||
def updateTheme(self) -> None:
|
def updateTheme(self) -> None:
|
||||||
"""Update theme elements."""
|
"""Update theme elements."""
|
||||||
qPalette = qApp.palette()
|
qPalette = QApplication.palette()
|
||||||
self.setPalette(qPalette)
|
self.setPalette(qPalette)
|
||||||
self.searchBox.setPalette(qPalette)
|
self.searchBox.setPalette(qPalette)
|
||||||
self.replaceBox.setPalette(qPalette)
|
self.replaceBox.setPalette(qPalette)
|
||||||
@@ -2714,7 +2714,7 @@ class GuiDocEditSearch(QFrame):
|
|||||||
def _doSearch(self) -> None:
|
def _doSearch(self) -> None:
|
||||||
"""Call the search action function for the document editor."""
|
"""Call the search action function for the document editor."""
|
||||||
self.docEditor.findNext(goBack=(
|
self.docEditor.findNext(goBack=(
|
||||||
qApp.keyboardModifiers() == Qt.KeyboardModifier.ShiftModifier)
|
QApplication.keyboardModifiers() == Qt.KeyboardModifier.ShiftModifier)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ from PyQt5.QtGui import (
|
|||||||
QTextOption
|
QTextOption
|
||||||
)
|
)
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QAction, QFrame, QHBoxLayout, QLabel, QMenu, QTextBrowser, QToolButton,
|
QAction, QApplication, QFrame, QHBoxLayout, QLabel, QMenu, QTextBrowser,
|
||||||
QWidget, qApp
|
QToolButton, QWidget
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
@@ -195,7 +195,7 @@ class GuiDocViewer(QTextBrowser):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
logger.debug("Generating preview for item '%s'", tHandle)
|
logger.debug("Generating preview for item '%s'", tHandle)
|
||||||
qApp.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
||||||
|
|
||||||
sPos = self.verticalScrollBar().value()
|
sPos = self.verticalScrollBar().value()
|
||||||
aDoc = ToHtml(SHARED.project)
|
aDoc = ToHtml(SHARED.project)
|
||||||
@@ -217,7 +217,7 @@ class GuiDocViewer(QTextBrowser):
|
|||||||
logger.error("Failed to generate preview for document with handle '%s'", tHandle)
|
logger.error("Failed to generate preview for document with handle '%s'", tHandle)
|
||||||
logException()
|
logException()
|
||||||
self.setText(self.tr("An error occurred while generating the preview."))
|
self.setText(self.tr("An error occurred while generating the preview."))
|
||||||
qApp.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Refresh the tab stops
|
# Refresh the tab stops
|
||||||
@@ -250,7 +250,7 @@ class GuiDocViewer(QTextBrowser):
|
|||||||
# Since we change the content while it may still be rendering, we mark
|
# Since we change the content while it may still be rendering, we mark
|
||||||
# the document dirty again to make sure it's re-rendered properly.
|
# the document dirty again to make sure it's re-rendered properly.
|
||||||
self.redrawText()
|
self.redrawText()
|
||||||
qApp.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
self.documentLoaded.emit(tHandle)
|
self.documentLoaded.emit(tHandle)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -25,14 +25,14 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from time import time
|
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
|
from time import time
|
||||||
|
|
||||||
from PyQt5.QtGui import QTextBlock, QTextCursor, QTextDocument
|
from PyQt5.QtGui import QTextBlock, QTextCursor, QTextDocument
|
||||||
from PyQt5.QtCore import QObject, pyqtSlot
|
from PyQt5.QtCore import QObject, pyqtSlot
|
||||||
from PyQt5.QtWidgets import QPlainTextDocumentLayout, qApp
|
from PyQt5.QtWidgets import QApplication, QPlainTextDocumentLayout
|
||||||
from novelwriter import SHARED
|
|
||||||
|
|
||||||
|
from novelwriter import SHARED
|
||||||
from novelwriter.gui.dochighlight import GuiDocHighlighter, TextBlockData
|
from novelwriter.gui.dochighlight import GuiDocHighlighter, TextBlockData
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -86,7 +86,7 @@ class GuiTextDocument(QTextDocument):
|
|||||||
self.setUndoRedoEnabled(True)
|
self.setUndoRedoEnabled(True)
|
||||||
self.blockSignals(False)
|
self.blockSignals(False)
|
||||||
self._syntax.rehighlight()
|
self._syntax.rehighlight()
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
|
|
||||||
tEnd = time()
|
tEnd = time()
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ from time import time
|
|||||||
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
|
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
|
||||||
from PyQt5.QtGui import QCursor, QKeyEvent
|
from PyQt5.QtGui import QCursor, QKeyEvent
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QFrame, QHBoxLayout, QHeaderView, QLabel, QLineEdit, QToolBar, QTreeWidget,
|
QApplication, QFrame, QHBoxLayout, QHeaderView, QLabel, QLineEdit,
|
||||||
QTreeWidgetItem, QVBoxLayout, QWidget, qApp
|
QToolBar, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
@@ -257,7 +257,7 @@ class GuiProjectSearch(QWidget):
|
|||||||
def _processSearch(self) -> None:
|
def _processSearch(self) -> None:
|
||||||
"""Perform a search."""
|
"""Perform a search."""
|
||||||
if not self._blocked:
|
if not self._blocked:
|
||||||
qApp.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
||||||
start = time()
|
start = time()
|
||||||
SHARED.mainGui.saveDocument()
|
SHARED.mainGui.saveDocument()
|
||||||
self._blocked = True
|
self._blocked = True
|
||||||
@@ -271,7 +271,7 @@ class GuiProjectSearch(QWidget):
|
|||||||
self._displayResultSet(item, results, capped)
|
self._displayResultSet(item, results, capped)
|
||||||
logger.debug("Search took %.3f ms", 1000*(time() - start))
|
logger.debug("Search took %.3f ms", 1000*(time() - start))
|
||||||
self._time = time()
|
self._time = time()
|
||||||
qApp.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
self._blocked = False
|
self._blocked = False
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -355,7 +355,7 @@ class GuiProjectSearch(QWidget):
|
|||||||
for i in range(tItem.childCount()):
|
for i in range(tItem.childCount()):
|
||||||
self.searchResult.setFirstColumnSpanned(i, parent, True)
|
self.searchResult.setFirstColumnSpanned(i, parent, True)
|
||||||
|
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from time import time
|
from time import time
|
||||||
from typing import TYPE_CHECKING, Literal
|
from typing import TYPE_CHECKING, Literal
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot, QLocale
|
from PyQt5.QtCore import pyqtSlot, QLocale
|
||||||
from PyQt5.QtWidgets import qApp, QStatusBar, QLabel
|
from PyQt5.QtWidgets import QApplication, QStatusBar, QLabel
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
from novelwriter.common import formatTime
|
from novelwriter.common import formatTime
|
||||||
@@ -198,7 +198,7 @@ class GuiMainStatus(QStatusBar):
|
|||||||
def setStatusMessage(self, message: str) -> None:
|
def setStatusMessage(self, message: str) -> None:
|
||||||
"""Set the status bar message to display."""
|
"""Set the status bar message to display."""
|
||||||
self.showMessage(message, nwConst.STATUS_MSG_TIMEOUT)
|
self.showMessage(message, nwConst.STATUS_MSG_TIMEOUT)
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
@@ -240,7 +240,7 @@ class GuiMainStatus(QStatusBar):
|
|||||||
import tracemalloc
|
import tracemalloc
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
widgets = qApp.allWidgets()
|
widgets = QApplication.allWidgets()
|
||||||
if not self._debugInfo:
|
if not self._debugInfo:
|
||||||
if tracemalloc.is_tracing():
|
if tracemalloc.is_tracing():
|
||||||
self._traceMallocRef = "Total"
|
self._traceMallocRef = "Total"
|
||||||
|
|||||||
+10
-10
@@ -30,16 +30,16 @@ from math import ceil
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from PyQt5.QtCore import QSize, Qt
|
from PyQt5.QtCore import QSize, Qt
|
||||||
from PyQt5.QtWidgets import qApp
|
|
||||||
from PyQt5.QtGui import (
|
from PyQt5.QtGui import (
|
||||||
QPalette, QColor, QIcon, QFont, QFontMetrics, QFontDatabase, QPixmap
|
QPalette, QColor, QIcon, QFont, QFontMetrics, QFontDatabase, QPixmap
|
||||||
)
|
)
|
||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
|
||||||
from novelwriter import CONFIG
|
from novelwriter import CONFIG
|
||||||
from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType
|
|
||||||
from novelwriter.error import logException
|
|
||||||
from novelwriter.common import NWConfigParser, cssCol, minmax
|
from novelwriter.common import NWConfigParser, cssCol, minmax
|
||||||
from novelwriter.constants import nwLabels
|
from novelwriter.constants import nwLabels
|
||||||
|
from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType
|
||||||
|
from novelwriter.error import logException
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -144,15 +144,15 @@ class GuiTheme:
|
|||||||
self.getHeaderDecorationNarrow = self.iconCache.getHeaderDecorationNarrow
|
self.getHeaderDecorationNarrow = self.iconCache.getHeaderDecorationNarrow
|
||||||
|
|
||||||
# Extract Other Info
|
# Extract Other Info
|
||||||
self.guiDPI = qApp.primaryScreen().logicalDotsPerInchX()
|
self.guiDPI = QApplication.primaryScreen().logicalDotsPerInchX()
|
||||||
self.guiScale = qApp.primaryScreen().logicalDotsPerInchX()/96.0
|
self.guiScale = QApplication.primaryScreen().logicalDotsPerInchX()/96.0
|
||||||
CONFIG.guiScale = self.guiScale
|
CONFIG.guiScale = self.guiScale
|
||||||
logger.debug("GUI DPI: %.1f", self.guiDPI)
|
logger.debug("GUI DPI: %.1f", self.guiDPI)
|
||||||
logger.debug("GUI Scale: %.2f", self.guiScale)
|
logger.debug("GUI Scale: %.2f", self.guiScale)
|
||||||
|
|
||||||
# Fonts
|
# Fonts
|
||||||
self.guiFont = qApp.font()
|
self.guiFont = QApplication.font()
|
||||||
self.guiFontB = qApp.font()
|
self.guiFontB = QApplication.font()
|
||||||
self.guiFontB.setBold(True)
|
self.guiFontB.setBold(True)
|
||||||
|
|
||||||
qMetric = QFontMetrics(self.guiFont)
|
qMetric = QFontMetrics(self.guiFont)
|
||||||
@@ -255,7 +255,7 @@ class GuiTheme:
|
|||||||
self._setPalette(parser, sec, "link", QPalette.ColorRole.Link)
|
self._setPalette(parser, sec, "link", QPalette.ColorRole.Link)
|
||||||
self._setPalette(parser, sec, "linkvisited", QPalette.ColorRole.LinkVisited)
|
self._setPalette(parser, sec, "linkvisited", QPalette.ColorRole.LinkVisited)
|
||||||
else:
|
else:
|
||||||
self._guiPalette = qApp.style().standardPalette()
|
self._guiPalette = QApplication.style().standardPalette()
|
||||||
|
|
||||||
# GUI
|
# GUI
|
||||||
sec = "GUI"
|
sec = "GUI"
|
||||||
@@ -284,7 +284,7 @@ class GuiTheme:
|
|||||||
self.iconCache.loadTheme(self.themeIcons or defaultIcons)
|
self.iconCache.loadTheme(self.themeIcons or defaultIcons)
|
||||||
|
|
||||||
# Apply Styles
|
# Apply Styles
|
||||||
qApp.setPalette(self._guiPalette)
|
QApplication.setPalette(self._guiPalette)
|
||||||
|
|
||||||
# Reset stylesheets so that they are regenerated
|
# Reset stylesheets so that they are regenerated
|
||||||
self._buildStyleSheets(self._guiPalette)
|
self._buildStyleSheets(self._guiPalette)
|
||||||
@@ -408,7 +408,7 @@ class GuiTheme:
|
|||||||
font.setFamily(CONFIG.guiFont)
|
font.setFamily(CONFIG.guiFont)
|
||||||
font.setPointSize(CONFIG.guiFontSize)
|
font.setPointSize(CONFIG.guiFontSize)
|
||||||
|
|
||||||
qApp.setFont(font)
|
QApplication.setFont(font)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
+19
-19
@@ -30,11 +30,11 @@ from time import time
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from PyQt5.QtGui import QCloseEvent, QCursor, QIcon
|
|
||||||
from PyQt5.QtCore import Qt, QTimer, pyqtSlot
|
from PyQt5.QtCore import Qt, QTimer, pyqtSlot
|
||||||
|
from PyQt5.QtGui import QCloseEvent, QCursor, QIcon
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QFileDialog, QHBoxLayout, QMainWindow, QMessageBox, QShortcut, QSplitter,
|
QApplication, QFileDialog, QHBoxLayout, QMainWindow, QMessageBox, QShortcut, QSplitter,
|
||||||
QStackedWidget, QVBoxLayout, QWidget, qApp
|
QStackedWidget, QVBoxLayout, QWidget
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED, __hexversion__, __version__
|
from novelwriter import CONFIG, SHARED, __hexversion__, __version__
|
||||||
@@ -109,7 +109,7 @@ class GuiMain(QMainWindow):
|
|||||||
nwIcon = CONFIG.assetPath("icons") / "novelwriter.svg"
|
nwIcon = CONFIG.assetPath("icons") / "novelwriter.svg"
|
||||||
self.nwIcon = QIcon(str(nwIcon)) if nwIcon.is_file() else QIcon()
|
self.nwIcon = QIcon(str(nwIcon)) if nwIcon.is_file() else QIcon()
|
||||||
self.setWindowIcon(self.nwIcon)
|
self.setWindowIcon(self.nwIcon)
|
||||||
qApp.setWindowIcon(self.nwIcon)
|
QApplication.setWindowIcon(self.nwIcon)
|
||||||
|
|
||||||
# Build the GUI
|
# Build the GUI
|
||||||
# =============
|
# =============
|
||||||
@@ -328,7 +328,7 @@ class GuiMain(QMainWindow):
|
|||||||
def postLaunchTasks(self, cmdOpen: str | None) -> None:
|
def postLaunchTasks(self, cmdOpen: str | None) -> None:
|
||||||
"""Process tasks after the main window has been created."""
|
"""Process tasks after the main window has been created."""
|
||||||
if cmdOpen:
|
if cmdOpen:
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
logger.info("Command line path: %s", cmdOpen)
|
logger.info("Command line path: %s", cmdOpen)
|
||||||
self.openProject(cmdOpen)
|
self.openProject(cmdOpen)
|
||||||
|
|
||||||
@@ -474,12 +474,12 @@ class GuiMain(QMainWindow):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if lastEdited is not None:
|
if lastEdited is not None:
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
self.openDocument(lastEdited, doScroll=True)
|
self.openDocument(lastEdited, doScroll=True)
|
||||||
|
|
||||||
lastViewed = SHARED.project.data.getLastHandle("viewer")
|
lastViewed = SHARED.project.data.getLastHandle("viewer")
|
||||||
if lastViewed is not None:
|
if lastViewed is not None:
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
self.viewDocument(lastViewed)
|
self.viewDocument(lastViewed)
|
||||||
|
|
||||||
# Check if we need to rebuild the index
|
# Check if we need to rebuild the index
|
||||||
@@ -488,7 +488,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.rebuildIndex()
|
self.rebuildIndex()
|
||||||
|
|
||||||
# Make sure the changed status is set to false on things opened
|
# Make sure the changed status is set to false on things opened
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
self.docEditor.setDocumentChanged(False)
|
self.docEditor.setDocumentChanged(False)
|
||||||
SHARED.project.setProjectChanged(False)
|
SHARED.project.setProjectChanged(False)
|
||||||
|
|
||||||
@@ -738,7 +738,7 @@ class GuiMain(QMainWindow):
|
|||||||
"""Rebuild the entire index."""
|
"""Rebuild the entire index."""
|
||||||
if SHARED.hasProject:
|
if SHARED.hasProject:
|
||||||
logger.info("Rebuilding index ...")
|
logger.info("Rebuilding index ...")
|
||||||
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
|
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
|
||||||
tStart = time()
|
tStart = time()
|
||||||
|
|
||||||
self.projView.saveProjectTasks()
|
self.projView.saveProjectTasks()
|
||||||
@@ -752,7 +752,7 @@ class GuiMain(QMainWindow):
|
|||||||
)
|
)
|
||||||
self.docEditor.updateTagHighLighting()
|
self.docEditor.updateTagHighLighting()
|
||||||
self._updateStatusWordCount()
|
self._updateStatusWordCount()
|
||||||
qApp.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
|
|
||||||
if not beQuiet:
|
if not beQuiet:
|
||||||
SHARED.info(self.tr("The project index has been successfully rebuilt."))
|
SHARED.info(self.tr("The project index has been successfully rebuilt."))
|
||||||
@@ -797,7 +797,7 @@ class GuiMain(QMainWindow):
|
|||||||
dialog.setModal(True)
|
dialog.setModal(True)
|
||||||
dialog.show()
|
dialog.show()
|
||||||
dialog.raise_()
|
dialog.raise_()
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
dialog.updateValues()
|
dialog.updateValues()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -810,7 +810,7 @@ class GuiMain(QMainWindow):
|
|||||||
dialog.setModal(False)
|
dialog.setModal(False)
|
||||||
dialog.show()
|
dialog.show()
|
||||||
dialog.raise_()
|
dialog.raise_()
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
dialog.loadContent()
|
dialog.loadContent()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -832,7 +832,7 @@ class GuiMain(QMainWindow):
|
|||||||
dialog.setModal(False)
|
dialog.setModal(False)
|
||||||
dialog.show()
|
dialog.show()
|
||||||
dialog.raise_()
|
dialog.raise_()
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
dialog.populateGUI()
|
dialog.populateGUI()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -843,7 +843,7 @@ class GuiMain(QMainWindow):
|
|||||||
dialog.setModal(True)
|
dialog.setModal(True)
|
||||||
dialog.show()
|
dialog.show()
|
||||||
dialog.raise_()
|
dialog.raise_()
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
dialog.populateGUI()
|
dialog.populateGUI()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -861,7 +861,7 @@ class GuiMain(QMainWindow):
|
|||||||
dialog.setModal(True)
|
dialog.setModal(True)
|
||||||
dialog.show()
|
dialog.show()
|
||||||
dialog.raise_()
|
dialog.raise_()
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
if not dialog.initDialog():
|
if not dialog.initDialog():
|
||||||
dialog.close()
|
dialog.close()
|
||||||
SHARED.error(self.tr("Could not initialise the dialog."))
|
SHARED.error(self.tr("Could not initialise the dialog."))
|
||||||
@@ -909,7 +909,7 @@ class GuiMain(QMainWindow):
|
|||||||
CONFIG.saveConfig()
|
CONFIG.saveConfig()
|
||||||
self.reportConfErr()
|
self.reportConfErr()
|
||||||
|
|
||||||
qApp.quit()
|
QApplication.quit()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -1056,7 +1056,7 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
if theme:
|
if theme:
|
||||||
# We are doing this manually instead of connecting to
|
# We are doing this manually instead of connecting to
|
||||||
# qApp.paletteChanged since the processing order matters
|
# paletteChanged since the processing order matters
|
||||||
SHARED.theme.loadTheme()
|
SHARED.theme.loadTheme()
|
||||||
self.docEditor.updateTheme()
|
self.docEditor.updateTheme()
|
||||||
self.docViewer.updateTheme()
|
self.docViewer.updateTheme()
|
||||||
@@ -1115,7 +1115,7 @@ class GuiMain(QMainWindow):
|
|||||||
@pyqtSlot(Path)
|
@pyqtSlot(Path)
|
||||||
def _openProjectFromWelcome(self, path: Path) -> None:
|
def _openProjectFromWelcome(self, path: Path) -> None:
|
||||||
"""Handle an open project request from the welcome dialog."""
|
"""Handle an open project request from the welcome dialog."""
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
self.openProject(path)
|
self.openProject(path)
|
||||||
if not SHARED.hasProject:
|
if not SHARED.hasProject:
|
||||||
self.showWelcomeDialog()
|
self.showWelcomeDialog()
|
||||||
@@ -1212,7 +1212,7 @@ class GuiMain(QMainWindow):
|
|||||||
if SHARED.hasProject:
|
if SHARED.hasProject:
|
||||||
currTime = time()
|
currTime = time()
|
||||||
editIdle = currTime - self.docEditor.lastActive > CONFIG.userIdleTime
|
editIdle = currTime - self.docEditor.lastActive > CONFIG.userIdleTime
|
||||||
userIdle = qApp.applicationState() != Qt.ApplicationActive
|
userIdle = QApplication.applicationState() != Qt.ApplicationActive
|
||||||
self.mainStatus.setUserIdle(editIdle or userIdle)
|
self.mainStatus.setUserIdle(editIdle or userIdle)
|
||||||
SHARED.updateIdleTime(currTime, editIdle or userIdle)
|
SHARED.updateIdleTime(currTime, editIdle or userIdle)
|
||||||
self.mainStatus.updateTime(idleTime=SHARED.projectIdleTime)
|
self.mainStatus.updateTime(idleTime=SHARED.projectIdleTime)
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ import logging
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
from PyQt5.QtGui import QCloseEvent, QTextCursor
|
|
||||||
from PyQt5.QtCore import pyqtSlot
|
from PyQt5.QtCore import pyqtSlot
|
||||||
|
from PyQt5.QtGui import QCloseEvent, QTextCursor
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QDialog, QDialogButtonBox, QFileDialog, QFrame, QHBoxLayout, QLabel,
|
QApplication, QDialog, QDialogButtonBox, QFileDialog, QFrame, QHBoxLayout,
|
||||||
QLineEdit, QPlainTextEdit, QPushButton, QVBoxLayout, QWidget, qApp
|
QLabel, QLineEdit, QPlainTextEdit, QPushButton, QVBoxLayout, QWidget
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
@@ -158,7 +158,7 @@ class GuiDictionaries(QDialog):
|
|||||||
"Additional dictionaries found: {0}"
|
"Additional dictionaries found: {0}"
|
||||||
).format(len(self._currDicts)))
|
).format(len(self._currDicts)))
|
||||||
|
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
self.adjustSize()
|
self.adjustSize()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -26,19 +26,19 @@ from __future__ import annotations
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from time import time
|
from time import time
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from PyQt5.QtGui import QCloseEvent, QColor, QCursor, QFont, QPalette, QResizeEvent
|
|
||||||
from PyQt5.QtCore import QTimer, QUrl, Qt, pyqtSignal, pyqtSlot
|
from PyQt5.QtCore import QTimer, QUrl, Qt, pyqtSignal, pyqtSlot
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtGui import QCloseEvent, QColor, QCursor, QFont, QPalette, QResizeEvent
|
||||||
QAbstractItemView, QDialog, QFormLayout, QGridLayout, QHBoxLayout, QLabel,
|
|
||||||
QListWidget, QListWidgetItem, QPushButton, QSizePolicy, QSplitter,
|
|
||||||
QStackedWidget, QTabWidget, QTextBrowser, QTreeWidget, QTreeWidgetItem,
|
|
||||||
QVBoxLayout, QWidget, qApp
|
|
||||||
)
|
|
||||||
from PyQt5.QtPrintSupport import QPrintPreviewDialog, QPrinter
|
from PyQt5.QtPrintSupport import QPrintPreviewDialog, QPrinter
|
||||||
|
from PyQt5.QtWidgets import (
|
||||||
|
QAbstractItemView, QApplication, QDialog, QFormLayout, QGridLayout,
|
||||||
|
QHBoxLayout, QLabel, QListWidget, QListWidgetItem, QPushButton,
|
||||||
|
QSizePolicy, QSplitter, QStackedWidget, QTabWidget, QTextBrowser,
|
||||||
|
QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget
|
||||||
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
from novelwriter.common import checkInt, fuzzyTime
|
from novelwriter.common import checkInt, fuzzyTime
|
||||||
@@ -352,7 +352,7 @@ class GuiManuscript(QDialog):
|
|||||||
self.docPreview.beginNewBuild(len(docBuild))
|
self.docPreview.beginNewBuild(len(docBuild))
|
||||||
for step, _ in docBuild.iterBuildHTML(None):
|
for step, _ in docBuild.iterBuildHTML(None):
|
||||||
self.docPreview.buildStep(step + 1)
|
self.docPreview.buildStep(step + 1)
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
|
|
||||||
buildObj = docBuild.lastBuild
|
buildObj = docBuild.lastBuild
|
||||||
assert isinstance(buildObj, ToHtml)
|
assert isinstance(buildObj, ToHtml)
|
||||||
@@ -486,7 +486,7 @@ class GuiManuscript(QDialog):
|
|||||||
dlgSettings.setModal(False)
|
dlgSettings.setModal(False)
|
||||||
dlgSettings.show()
|
dlgSettings.show()
|
||||||
dlgSettings.raise_()
|
dlgSettings.raise_()
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
dlgSettings.loadContent()
|
dlgSettings.loadContent()
|
||||||
dlgSettings.newSettingsReady.connect(self._processNewSettings)
|
dlgSettings.newSettingsReady.connect(self._processNewSettings)
|
||||||
|
|
||||||
@@ -850,16 +850,16 @@ class _PreviewWidget(QTextBrowser):
|
|||||||
def buildStep(self, value: int) -> None:
|
def buildStep(self, value: int) -> None:
|
||||||
"""Update the progress bar value."""
|
"""Update the progress bar value."""
|
||||||
self.buildProgress.setValue(value)
|
self.buildProgress.setValue(value)
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
return
|
return
|
||||||
|
|
||||||
def setContent(self, data: dict) -> None:
|
def setContent(self, data: dict) -> None:
|
||||||
"""Set the content of the preview widget."""
|
"""Set the content of the preview widget."""
|
||||||
sPos = self.verticalScrollBar().value()
|
sPos = self.verticalScrollBar().value()
|
||||||
qApp.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
||||||
|
|
||||||
self.buildProgress.setCentreText(self.tr("Processing ..."))
|
self.buildProgress.setCentreText(self.tr("Processing ..."))
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
|
|
||||||
styles = "\n".join(data.get("styles", []))
|
styles = "\n".join(data.get("styles", []))
|
||||||
self.document().setDefaultStyleSheet(styles)
|
self.document().setDefaultStyleSheet(styles)
|
||||||
@@ -867,7 +867,7 @@ class _PreviewWidget(QTextBrowser):
|
|||||||
html = "".join(data.get("html", []))
|
html = "".join(data.get("html", []))
|
||||||
html = html.replace("\t", "!!tab!!")
|
html = html.replace("\t", "!!tab!!")
|
||||||
self.setHtml(html)
|
self.setHtml(html)
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
while self.find("!!tab!!"):
|
while self.find("!!tab!!"):
|
||||||
cursor = self.textCursor()
|
cursor = self.textCursor()
|
||||||
cursor.insertText("\t")
|
cursor.insertText("\t")
|
||||||
@@ -881,8 +881,8 @@ class _PreviewWidget(QTextBrowser):
|
|||||||
self.document().markContentsDirty(0, self.document().characterCount())
|
self.document().markContentsDirty(0, self.document().characterCount())
|
||||||
|
|
||||||
self.buildProgress.setCentreText(self.tr("Done"))
|
self.buildProgress.setCentreText(self.tr("Done"))
|
||||||
qApp.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
qApp.processEvents()
|
QApplication.processEvents()
|
||||||
QTimer.singleShot(300, self._hideProgress)
|
QTimer.singleShot(300, self._hideProgress)
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -904,10 +904,10 @@ class _PreviewWidget(QTextBrowser):
|
|||||||
@pyqtSlot("QPrinter*")
|
@pyqtSlot("QPrinter*")
|
||||||
def printPreview(self, printer: QPrinter) -> None:
|
def printPreview(self, printer: QPrinter) -> None:
|
||||||
"""Connect the print preview painter to the document viewer."""
|
"""Connect the print preview painter to the document viewer."""
|
||||||
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
|
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
||||||
printer.setOrientation(QPrinter.Portrait)
|
printer.setOrientation(QPrinter.Portrait)
|
||||||
self.document().print(printer)
|
self.document().print(printer)
|
||||||
qApp.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
|
|||||||
@@ -25,19 +25,19 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from PyQt5.QtGui import QCloseEvent, QColor, QFont, QPaintEvent, QPainter, QPen
|
|
||||||
from PyQt5.QtCore import (
|
from PyQt5.QtCore import (
|
||||||
QAbstractListModel, QEvent, QModelIndex, QObject, QPoint, QSize, Qt,
|
QAbstractListModel, QEvent, QModelIndex, QObject, QPoint, QSize, Qt,
|
||||||
pyqtSignal, pyqtSlot
|
pyqtSignal, pyqtSlot
|
||||||
)
|
)
|
||||||
|
from PyQt5.QtGui import QCloseEvent, QColor, QFont, QPaintEvent, QPainter, QPen
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QAction, QDialog, QFileDialog, QFormLayout, QHBoxLayout, QLabel, QLineEdit,
|
QAction, QApplication, QDialog, QFileDialog, QFormLayout, QHBoxLayout,
|
||||||
QListView, QMenu, QPushButton, QScrollArea, QShortcut, QStackedWidget,
|
QLabel, QLineEdit, QListView, QMenu, QPushButton, QScrollArea, QShortcut,
|
||||||
QStyle, QStyleOptionViewItem, QStyledItemDelegate, QVBoxLayout, QWidget,
|
QStackedWidget, QStyle, QStyleOptionViewItem, QStyledItemDelegate,
|
||||||
qApp
|
QVBoxLayout, QWidget
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
@@ -411,11 +411,11 @@ class _ProjectListItem(QStyledItemDelegate):
|
|||||||
self._pPx = (mPx//2, 3*mPx//2, iPx + mPx, mPx, mPx + tPx) # Painter coordinates
|
self._pPx = (mPx//2, 3*mPx//2, iPx + mPx, mPx, mPx + tPx) # Painter coordinates
|
||||||
self._hPx = 2*mPx + tPx + fPx # Fixed height
|
self._hPx = 2*mPx + tPx + fPx # Fixed height
|
||||||
|
|
||||||
self._tFont = qApp.font()
|
self._tFont = QApplication.font()
|
||||||
self._tFont.setPointSizeF(1.2*fPt)
|
self._tFont.setPointSizeF(1.2*fPt)
|
||||||
self._tFont.setWeight(QFont.Weight.Bold)
|
self._tFont.setWeight(QFont.Weight.Bold)
|
||||||
|
|
||||||
self._dFont = qApp.font()
|
self._dFont = QApplication.font()
|
||||||
self._dFont.setPointSizeF(fPt)
|
self._dFont.setPointSizeF(fPt)
|
||||||
self._dPen = QPen(SHARED.theme.helpText)
|
self._dPen = QPen(SHARED.theme.helpText)
|
||||||
|
|
||||||
@@ -433,7 +433,7 @@ class _ProjectListItem(QStyledItemDelegate):
|
|||||||
painter.save()
|
painter.save()
|
||||||
if opt.state & QStyle.StateFlag.State_Selected == QStyle.StateFlag.State_Selected:
|
if opt.state & QStyle.StateFlag.State_Selected == QStyle.StateFlag.State_Selected:
|
||||||
painter.setOpacity(0.25)
|
painter.setOpacity(0.25)
|
||||||
painter.fillRect(rect, qApp.palette().highlight())
|
painter.fillRect(rect, QApplication.palette().highlight())
|
||||||
painter.setOpacity(1.0)
|
painter.setOpacity(1.0)
|
||||||
|
|
||||||
painter.drawPixmap(ix, rect.top() + iy, self._icon)
|
painter.drawPixmap(ix, rect.top() + iy, self._icon)
|
||||||
|
|||||||
@@ -29,11 +29,12 @@ import logging
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from PyQt5.QtGui import QCloseEvent, QPixmap, QCursor
|
|
||||||
from PyQt5.QtCore import Qt, pyqtSlot
|
from PyQt5.QtCore import Qt, pyqtSlot
|
||||||
|
from PyQt5.QtGui import QCloseEvent, QCursor, QPixmap
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
qApp, QDialog, QTreeWidget, QTreeWidgetItem, QDialogButtonBox, QGridLayout,
|
QAction, QApplication, QDialog, QDialogButtonBox, QFileDialog, QGridLayout,
|
||||||
QLabel, QGroupBox, QMenu, QAction, QFileDialog, QSpinBox, QHBoxLayout
|
QGroupBox, QHBoxLayout, QLabel, QMenu, QSpinBox, QTreeWidget,
|
||||||
|
QTreeWidgetItem
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
@@ -301,10 +302,10 @@ class GuiWritingStats(QDialog):
|
|||||||
|
|
||||||
def populateGUI(self) -> None:
|
def populateGUI(self) -> None:
|
||||||
"""Populate list box with data from the log file."""
|
"""Populate list box with data from the log file."""
|
||||||
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
|
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
||||||
self._loadLogFile()
|
self._loadLogFile()
|
||||||
self._updateListBox()
|
self._updateListBox()
|
||||||
qApp.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ def testBaseError_Dialog(qtbot, monkeypatch, nwGUI):
|
|||||||
nwErr.show()
|
nwErr.show()
|
||||||
|
|
||||||
# Invalid Error Message
|
# Invalid Error Message
|
||||||
nwErr.setMessage(Exception, "Faulty Error", 123)
|
nwErr.setMessage(Exception, "Faulty Error", 123) # type: ignore
|
||||||
assert nwErr.msgBody.toPlainText() == "Failed to generate error report ..."
|
assert nwErr.msgBody.toPlainText() == "Failed to generate error report ..."
|
||||||
|
|
||||||
# Valid Error Message
|
# Valid Error Message
|
||||||
with monkeypatch.context() as mp:
|
with monkeypatch.context() as mp:
|
||||||
mp.setattr("PyQt5.QtCore.QSysInfo.kernelVersion", lambda: "1.2.3")
|
mp.setattr("PyQt5.QtCore.QSysInfo.kernelVersion", lambda: "1.2.3")
|
||||||
nwErr.setMessage(Exception, "Fine Error", None)
|
nwErr.setMessage(Exception, "Fine Error", None) # type: ignore
|
||||||
message = nwErr.msgBody.toPlainText()
|
message = nwErr.msgBody.toPlainText()
|
||||||
assert message != ""
|
assert message != ""
|
||||||
assert "Fine Error" in message
|
assert "Fine Error" in message
|
||||||
@@ -52,7 +52,7 @@ def testBaseError_Dialog(qtbot, monkeypatch, nwGUI):
|
|||||||
# No kernel version retrieved
|
# No kernel version retrieved
|
||||||
with monkeypatch.context() as mp:
|
with monkeypatch.context() as mp:
|
||||||
mp.setattr("PyQt5.QtCore.QSysInfo.kernelVersion", causeException)
|
mp.setattr("PyQt5.QtCore.QSysInfo.kernelVersion", causeException)
|
||||||
nwErr.setMessage(Exception, "Almost Fine Error", None)
|
nwErr.setMessage(Exception, "Almost Fine Error", None) # type: ignore
|
||||||
message = nwErr.msgBody.toPlainText()
|
message = nwErr.msgBody.toPlainText()
|
||||||
assert message != ""
|
assert message != ""
|
||||||
assert "(Unknown)" in message
|
assert "(Unknown)" in message
|
||||||
@@ -66,36 +66,36 @@ def testBaseError_Dialog(qtbot, monkeypatch, nwGUI):
|
|||||||
|
|
||||||
@pytest.mark.base
|
@pytest.mark.base
|
||||||
def testBaseError_Handler(qtbot, monkeypatch, nwGUI):
|
def testBaseError_Handler(qtbot, monkeypatch, nwGUI):
|
||||||
"""Test the error handler. This test doesn'thave any asserts, but it
|
"""Test the error handler. This test doesn't have any asserts, but
|
||||||
checks that the error handler handles potential exceptions. The test
|
it checks that the error handler handles potential exceptions. The
|
||||||
will fail if exceptions are not handled.
|
test will fail if exceptions are not handled.
|
||||||
"""
|
"""
|
||||||
# Normal shutdown
|
# Normal shutdown
|
||||||
with monkeypatch.context() as mp:
|
with monkeypatch.context() as mp:
|
||||||
mp.setattr(NWErrorMessage, "exec_", lambda *a: None)
|
mp.setattr(NWErrorMessage, "exec_", lambda *a: None)
|
||||||
mp.setattr("PyQt5.QtWidgets.qApp.exit", lambda *a: None)
|
mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None)
|
||||||
exceptionHandler(Exception, "Error Message", None)
|
exceptionHandler(Exception, "Error Message", None) # type: ignore
|
||||||
|
|
||||||
# Should not crash when no GUI is found
|
# Should not crash when no GUI is found
|
||||||
with monkeypatch.context() as mp:
|
with monkeypatch.context() as mp:
|
||||||
mp.setattr(NWErrorMessage, "exec_", lambda *a: None)
|
mp.setattr(NWErrorMessage, "exec_", lambda *a: None)
|
||||||
mp.setattr("PyQt5.QtWidgets.qApp.exit", lambda *a: None)
|
mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None)
|
||||||
mp.setattr("PyQt5.QtWidgets.qApp.topLevelWidgets", lambda: [])
|
mp.setattr("PyQt5.QtWidgets.QApplication.topLevelWidgets", lambda: [])
|
||||||
exceptionHandler(Exception, "Error Message", None)
|
exceptionHandler(Exception, "Error Message", None) # type: ignore
|
||||||
|
|
||||||
# Should handle qApp failing
|
# Should handle QApplication failing
|
||||||
with monkeypatch.context() as mp:
|
with monkeypatch.context() as mp:
|
||||||
mp.setattr(NWErrorMessage, "exec_", lambda *a: None)
|
mp.setattr(NWErrorMessage, "exec_", lambda *a: None)
|
||||||
mp.setattr("PyQt5.QtWidgets.qApp.exit", lambda *a: None)
|
mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None)
|
||||||
mp.setattr("PyQt5.QtWidgets.qApp.topLevelWidgets", causeException)
|
mp.setattr("PyQt5.QtWidgets.QApplication.topLevelWidgets", causeException)
|
||||||
exceptionHandler(Exception, "Error Message", None)
|
exceptionHandler(Exception, "Error Message", None) # type: ignore
|
||||||
|
|
||||||
# Should handle failing to close main GUI
|
# Should handle failing to close main GUI
|
||||||
with monkeypatch.context() as mp:
|
with monkeypatch.context() as mp:
|
||||||
mp.setattr(NWErrorMessage, "exec_", lambda *a: None)
|
mp.setattr(NWErrorMessage, "exec_", lambda *a: None)
|
||||||
mp.setattr("PyQt5.QtWidgets.qApp.exit", lambda *a: None)
|
mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None)
|
||||||
mp.setattr(nwGUI, "closeMain", causeException)
|
mp.setattr(nwGUI, "closeMain", causeException)
|
||||||
exceptionHandler(Exception, "Error Message", None)
|
exceptionHandler(Exception, "Error Message", None) # type: ignore
|
||||||
|
|
||||||
nwGUI.closeMain()
|
nwGUI.closeMain()
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from tools import C, buildTestProject
|
|
||||||
from mocked import causeOSError
|
from mocked import causeOSError
|
||||||
|
from tools import C, buildTestProject
|
||||||
|
|
||||||
from PyQt5.QtGui import QClipboard, QTextBlock, QTextCursor, QTextOption
|
|
||||||
from PyQt5.QtCore import QThreadPool, Qt
|
from PyQt5.QtCore import QThreadPool, Qt
|
||||||
from PyQt5.QtWidgets import QAction, QMenu, qApp
|
from PyQt5.QtGui import QClipboard, QTextBlock, QTextCursor, QTextOption
|
||||||
|
from PyQt5.QtWidgets import QAction, QApplication, QMenu
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
from novelwriter.constants import nwKeyWords, nwUnicode
|
from novelwriter.constants import nwKeyWords, nwUnicode
|
||||||
@@ -361,14 +361,14 @@ def testGuiEditor_ContextMenu(monkeypatch, qtbot, nwGUI, projPath, mockRnd):
|
|||||||
assert actions == [
|
assert actions == [
|
||||||
"Cut", "Copy", "Paste", "Select All", "Select Word", "Select Paragraph"
|
"Cut", "Copy", "Paste", "Select All", "Select Word", "Select Paragraph"
|
||||||
]
|
]
|
||||||
qApp.clipboard().clear()
|
QApplication.clipboard().clear()
|
||||||
ctxMenu.actions()[1].trigger()
|
ctxMenu.actions()[1].trigger()
|
||||||
assert qApp.clipboard().text(QClipboard.Mode.Clipboard) == "text"
|
assert QApplication.clipboard().text(QClipboard.Mode.Clipboard) == "text"
|
||||||
|
|
||||||
# Cut Text
|
# Cut Text
|
||||||
qApp.clipboard().clear()
|
QApplication.clipboard().clear()
|
||||||
ctxMenu.actions()[0].trigger()
|
ctxMenu.actions()[0].trigger()
|
||||||
assert qApp.clipboard().text(QClipboard.Mode.Clipboard) == "text"
|
assert QApplication.clipboard().text(QClipboard.Mode.Clipboard) == "text"
|
||||||
assert "text" not in docEditor.getText()
|
assert "text" not in docEditor.getText()
|
||||||
|
|
||||||
# Paste Text
|
# Paste Text
|
||||||
@@ -400,7 +400,7 @@ def testGuiEditor_Actions(qtbot, nwGUI, projPath, ipsumText, mockRnd):
|
|||||||
# Select/Cut/Copy/Paste/Undo/Redo
|
# Select/Cut/Copy/Paste/Undo/Redo
|
||||||
# ===============================
|
# ===============================
|
||||||
|
|
||||||
qApp.clipboard().clear()
|
QApplication.clipboard().clear()
|
||||||
|
|
||||||
# Select All
|
# Select All
|
||||||
assert nwGUI.docEditor.docAction(nwDocAction.SEL_ALL) is True
|
assert nwGUI.docEditor.docAction(nwDocAction.SEL_ALL) is True
|
||||||
@@ -452,7 +452,7 @@ def testGuiEditor_Actions(qtbot, nwGUI, projPath, ipsumText, mockRnd):
|
|||||||
assert newPara[5] == ipsumText[4]
|
assert newPara[5] == ipsumText[4]
|
||||||
assert newPara[6] == ipsumText[2]
|
assert newPara[6] == ipsumText[2]
|
||||||
|
|
||||||
qApp.clipboard().clear()
|
QApplication.clipboard().clear()
|
||||||
|
|
||||||
# Emphasis/Undo/Redo
|
# Emphasis/Undo/Redo
|
||||||
# ==================
|
# ==================
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ from mocked import causeException
|
|||||||
|
|
||||||
from PyQt5.QtGui import QMouseEvent, QTextCursor
|
from PyQt5.QtGui import QMouseEvent, QTextCursor
|
||||||
from PyQt5.QtCore import QEvent, QPoint, Qt, QUrl
|
from PyQt5.QtCore import QEvent, QPoint, Qt, QUrl
|
||||||
from PyQt5.QtWidgets import QMenu, qApp, QAction
|
from PyQt5.QtWidgets import QAction, QApplication, QMenu
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
from novelwriter.enum import nwDocAction
|
from novelwriter.enum import nwDocAction
|
||||||
@@ -77,7 +77,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
|
|||||||
docViewer.setTextCursor(cursor)
|
docViewer.setTextCursor(cursor)
|
||||||
docViewer._makeSelection(QTextCursor.WordUnderCursor)
|
docViewer._makeSelection(QTextCursor.WordUnderCursor)
|
||||||
|
|
||||||
qClip = qApp.clipboard()
|
qClip = QApplication.clipboard()
|
||||||
qClip.clear()
|
qClip.clear()
|
||||||
|
|
||||||
# Cut
|
# Cut
|
||||||
|
|||||||
@@ -23,11 +23,9 @@ from __future__ import annotations
|
|||||||
import sys
|
import sys
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from collections.abc import Callable
|
|
||||||
|
|
||||||
from tools import buildTestProject
|
from tools import buildTestProject
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QDialog, qApp, QMessageBox
|
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
from novelwriter.dialogs.about import GuiAbout
|
from novelwriter.dialogs.about import GuiAbout
|
||||||
@@ -55,12 +53,12 @@ def testGuiI18n_Localisation(qtbot, monkeypatch, language, nwGUI, projPath):
|
|||||||
|
|
||||||
# Set the test language
|
# Set the test language
|
||||||
CONFIG.guiLocale = language
|
CONFIG.guiLocale = language
|
||||||
CONFIG.initLocalisation(qApp)
|
CONFIG.initLocalisation(QApplication.instance()) # type: ignore
|
||||||
|
|
||||||
buildTestProject(nwGUI, projPath)
|
buildTestProject(nwGUI, projPath)
|
||||||
nwGUI.show()
|
nwGUI.show()
|
||||||
|
|
||||||
def showDialog(func: Callable, dType: QDialog) -> None:
|
def showDialog(func, dType) -> None:
|
||||||
func()
|
func()
|
||||||
qtbot.waitUntil(lambda: SHARED.findTopLevelWidget(dType) is not None, timeout=1000)
|
qtbot.waitUntil(lambda: SHARED.findTopLevelWidget(dType) is not None, timeout=1000)
|
||||||
dialog = SHARED.findTopLevelWidget(dType)
|
dialog = SHARED.findTopLevelWidget(dType)
|
||||||
|
|||||||
Reference in New Issue
Block a user