Drop the qApp macro

This commit is contained in:
Veronica Berglyd Olsen
2024-04-03 18:36:37 +02:00
parent 2744fb2fd4
commit c8fe5e6620
19 changed files with 152 additions and 153 deletions
+16 -16
View File
@@ -47,8 +47,8 @@ from PyQt5.QtGui import (
QPixmap, QResizeEvent, QTextBlock, QTextCursor, QTextDocument, QTextOption
)
from PyQt5.QtWidgets import (
QAction, QFrame, QGridLayout, QHBoxLayout, QLabel, QLineEdit, QMenu,
QPlainTextEdit, QShortcut, QToolBar, QVBoxLayout, QWidget, qApp
QAction, QApplication, QFrame, QGridLayout, QHBoxLayout, QLabel, QLineEdit,
QMenu, QPlainTextEdit, QShortcut, QToolBar, QVBoxLayout, QWidget
)
from novelwriter import CONFIG, SHARED
@@ -393,13 +393,13 @@ class GuiDocEditor(QPlainTextEdit):
self.clearEditor()
return False
qApp.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
self._docHandle = tHandle
self._allowAutoReplace(False)
self._qDocument.setTextContent(docText, tHandle)
self._allowAutoReplace(True)
qApp.processEvents()
QApplication.processEvents()
self._lastEdit = time()
self._lastActive = time()
@@ -423,12 +423,12 @@ class GuiDocEditor(QPlainTextEdit):
self.setPlainText("")
self.setCursorPosition(0)
qApp.processEvents()
QApplication.processEvents()
self.setDocumentChanged(False)
self._qDocument.clearUndoRedoStacks()
self.docToolBar.setVisible(CONFIG.showEditToolBar)
qApp.restoreOverrideCursor()
QApplication.restoreOverrideCursor()
# Update the status bar
if self._nwItem is not None:
@@ -445,11 +445,11 @@ class GuiDocEditor(QPlainTextEdit):
"""Replace the text of the current document with the provided
text. This also clears undo history.
"""
qApp.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
self.setPlainText(text)
self.updateDocMargins()
self.setDocumentChanged(True)
qApp.restoreOverrideCursor()
QApplication.restoreOverrideCursor()
return
def saveText(self) -> bool:
@@ -536,7 +536,7 @@ class GuiDocEditor(QPlainTextEdit):
while self.cursorRect().bottom() > vH and count < 100000:
vBar.setValue(vBar.value() + 1)
count += 1
qApp.processEvents()
QApplication.processEvents()
return
def updateDocMargins(self) -> None:
@@ -699,9 +699,9 @@ class GuiDocEditor(QPlainTextEdit):
"""
logger.debug("Running spell checker")
start = time()
qApp.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
self._qDocument.syntaxHighlighter.rehighlight()
qApp.restoreOverrideCursor()
QApplication.restoreOverrideCursor()
logger.debug("Document highlighted in %.3f ms", 1000*(time() - start))
self.statusMessage.emit(self.tr("Spell check complete"))
return
@@ -814,7 +814,7 @@ class GuiDocEditor(QPlainTextEdit):
def anyFocus(self) -> bool:
"""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:
"""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
follow tag function.
"""
if qApp.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier:
if QApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier:
self._processTag(self.cursorForPosition(event.pos()))
super().mouseReleaseEvent(event)
return
@@ -1912,7 +1912,7 @@ class GuiDocEditor(QPlainTextEdit):
).format(tag)):
itemClass = nwKeyWords.KEY_CLASS.get(tBits[0], nwItemClass.NO_CLASS)
self.requestNewNoteCreation.emit(tag, itemClass)
qApp.processEvents()
QApplication.processEvents()
self._qDocument.syntaxHighlighter.rehighlightBlock(block)
return nwTrinary.POSITIVE if exist else nwTrinary.NEGATIVE
@@ -2627,7 +2627,7 @@ class GuiDocEditSearch(QFrame):
def updateTheme(self) -> None:
"""Update theme elements."""
qPalette = qApp.palette()
qPalette = QApplication.palette()
self.setPalette(qPalette)
self.searchBox.setPalette(qPalette)
self.replaceBox.setPalette(qPalette)
@@ -2714,7 +2714,7 @@ class GuiDocEditSearch(QFrame):
def _doSearch(self) -> None:
"""Call the search action function for the document editor."""
self.docEditor.findNext(goBack=(
qApp.keyboardModifiers() == Qt.KeyboardModifier.ShiftModifier)
QApplication.keyboardModifiers() == Qt.KeyboardModifier.ShiftModifier)
)
return
+5 -5
View File
@@ -36,8 +36,8 @@ from PyQt5.QtGui import (
QTextOption
)
from PyQt5.QtWidgets import (
QAction, QFrame, QHBoxLayout, QLabel, QMenu, QTextBrowser, QToolButton,
QWidget, qApp
QAction, QApplication, QFrame, QHBoxLayout, QLabel, QMenu, QTextBrowser,
QToolButton, QWidget
)
from novelwriter import CONFIG, SHARED
@@ -195,7 +195,7 @@ class GuiDocViewer(QTextBrowser):
return False
logger.debug("Generating preview for item '%s'", tHandle)
qApp.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
sPos = self.verticalScrollBar().value()
aDoc = ToHtml(SHARED.project)
@@ -217,7 +217,7 @@ class GuiDocViewer(QTextBrowser):
logger.error("Failed to generate preview for document with handle '%s'", tHandle)
logException()
self.setText(self.tr("An error occurred while generating the preview."))
qApp.restoreOverrideCursor()
QApplication.restoreOverrideCursor()
return False
# Refresh the tab stops
@@ -250,7 +250,7 @@ class GuiDocViewer(QTextBrowser):
# 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.
self.redrawText()
qApp.restoreOverrideCursor()
QApplication.restoreOverrideCursor()
self.documentLoaded.emit(tHandle)
return True
+4 -4
View File
@@ -25,14 +25,14 @@ from __future__ import annotations
import logging
from time import time
from collections.abc import Iterable
from time import time
from PyQt5.QtGui import QTextBlock, QTextCursor, QTextDocument
from PyQt5.QtCore import QObject, pyqtSlot
from PyQt5.QtWidgets import QPlainTextDocumentLayout, qApp
from novelwriter import SHARED
from PyQt5.QtWidgets import QApplication, QPlainTextDocumentLayout
from novelwriter import SHARED
from novelwriter.gui.dochighlight import GuiDocHighlighter, TextBlockData
logger = logging.getLogger(__name__)
@@ -86,7 +86,7 @@ class GuiTextDocument(QTextDocument):
self.setUndoRedoEnabled(True)
self.blockSignals(False)
self._syntax.rehighlight()
qApp.processEvents()
QApplication.processEvents()
tEnd = time()
+5 -5
View File
@@ -30,8 +30,8 @@ from time import time
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
from PyQt5.QtGui import QCursor, QKeyEvent
from PyQt5.QtWidgets import (
QFrame, QHBoxLayout, QHeaderView, QLabel, QLineEdit, QToolBar, QTreeWidget,
QTreeWidgetItem, QVBoxLayout, QWidget, qApp
QApplication, QFrame, QHBoxLayout, QHeaderView, QLabel, QLineEdit,
QToolBar, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget
)
from novelwriter import CONFIG, SHARED
@@ -257,7 +257,7 @@ class GuiProjectSearch(QWidget):
def _processSearch(self) -> None:
"""Perform a search."""
if not self._blocked:
qApp.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
start = time()
SHARED.mainGui.saveDocument()
self._blocked = True
@@ -271,7 +271,7 @@ class GuiProjectSearch(QWidget):
self._displayResultSet(item, results, capped)
logger.debug("Search took %.3f ms", 1000*(time() - start))
self._time = time()
qApp.restoreOverrideCursor()
QApplication.restoreOverrideCursor()
self._blocked = False
return
@@ -355,7 +355,7 @@ class GuiProjectSearch(QWidget):
for i in range(tItem.childCount()):
self.searchResult.setFirstColumnSpanned(i, parent, True)
qApp.processEvents()
QApplication.processEvents()
return
+4 -4
View File
@@ -25,12 +25,12 @@ from __future__ import annotations
import logging
from datetime import datetime
from time import time
from typing import TYPE_CHECKING, Literal
from datetime import datetime
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.common import formatTime
@@ -198,7 +198,7 @@ class GuiMainStatus(QStatusBar):
def setStatusMessage(self, message: str) -> None:
"""Set the status bar message to display."""
self.showMessage(message, nwConst.STATUS_MSG_TIMEOUT)
qApp.processEvents()
QApplication.processEvents()
return
@pyqtSlot(str, str)
@@ -240,7 +240,7 @@ class GuiMainStatus(QStatusBar):
import tracemalloc
from collections import Counter
widgets = qApp.allWidgets()
widgets = QApplication.allWidgets()
if not self._debugInfo:
if tracemalloc.is_tracing():
self._traceMallocRef = "Total"
+10 -10
View File
@@ -30,16 +30,16 @@ from math import ceil
from pathlib import Path
from PyQt5.QtCore import QSize, Qt
from PyQt5.QtWidgets import qApp
from PyQt5.QtGui import (
QPalette, QColor, QIcon, QFont, QFontMetrics, QFontDatabase, QPixmap
)
from PyQt5.QtWidgets import QApplication
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.constants import nwLabels
from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType
from novelwriter.error import logException
logger = logging.getLogger(__name__)
@@ -144,15 +144,15 @@ class GuiTheme:
self.getHeaderDecorationNarrow = self.iconCache.getHeaderDecorationNarrow
# Extract Other Info
self.guiDPI = qApp.primaryScreen().logicalDotsPerInchX()
self.guiScale = qApp.primaryScreen().logicalDotsPerInchX()/96.0
self.guiDPI = QApplication.primaryScreen().logicalDotsPerInchX()
self.guiScale = QApplication.primaryScreen().logicalDotsPerInchX()/96.0
CONFIG.guiScale = self.guiScale
logger.debug("GUI DPI: %.1f", self.guiDPI)
logger.debug("GUI Scale: %.2f", self.guiScale)
# Fonts
self.guiFont = qApp.font()
self.guiFontB = qApp.font()
self.guiFont = QApplication.font()
self.guiFontB = QApplication.font()
self.guiFontB.setBold(True)
qMetric = QFontMetrics(self.guiFont)
@@ -255,7 +255,7 @@ class GuiTheme:
self._setPalette(parser, sec, "link", QPalette.ColorRole.Link)
self._setPalette(parser, sec, "linkvisited", QPalette.ColorRole.LinkVisited)
else:
self._guiPalette = qApp.style().standardPalette()
self._guiPalette = QApplication.style().standardPalette()
# GUI
sec = "GUI"
@@ -284,7 +284,7 @@ class GuiTheme:
self.iconCache.loadTheme(self.themeIcons or defaultIcons)
# Apply Styles
qApp.setPalette(self._guiPalette)
QApplication.setPalette(self._guiPalette)
# Reset stylesheets so that they are regenerated
self._buildStyleSheets(self._guiPalette)
@@ -408,7 +408,7 @@ class GuiTheme:
font.setFamily(CONFIG.guiFont)
font.setPointSize(CONFIG.guiFontSize)
qApp.setFont(font)
QApplication.setFont(font)
return