Skip to content

Commit

Permalink
Clean up dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Nov 27, 2023
1 parent 93b3640 commit 4fa2027
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 113 deletions.
55 changes: 27 additions & 28 deletions novelwriter/dialogs/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from datetime import datetime

from PyQt5.QtGui import QCursor
from PyQt5.QtCore import Qt
from PyQt5.QtCore import Qt, pyqtSlot
from PyQt5.QtWidgets import (
qApp, QDialog, QDialogButtonBox, QHBoxLayout, QLabel, QTabWidget,
QTextBrowser, QVBoxLayout, QWidget
Expand All @@ -44,7 +44,7 @@

class GuiAbout(QDialog):

def __init__(self, parent: QWidget):
def __init__(self, parent: QWidget) -> None:
super().__init__(parent=parent)

logger.debug("Create: GuiAbout")
Expand Down Expand Up @@ -111,13 +111,12 @@ def __init__(self, parent: QWidget):

return

def __del__(self): # pragma: no cover
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiAbout")
return

def populateGUI(self):
"""Populate tabs with text.
"""
def populateGUI(self) -> None:
"""Populate tabs with text."""
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
self._setStyleSheet()
self._fillAboutPage()
Expand All @@ -127,19 +126,27 @@ def populateGUI(self):
qApp.restoreOverrideCursor()
return

def showReleaseNotes(self):
"""Show the release notes.
"""
def showReleaseNotes(self) -> None:
"""Show the release notes."""
self.tabBox.setCurrentWidget(self.pageNotes)
return

##
# Private Slots
##

@pyqtSlot()
def _doClose(self) -> None:
"""Close the dialog"""
self.close()
return

##
# Internal Functions
##

def _fillAboutPage(self):
"""Generate the content for the About page.
"""
def _fillAboutPage(self) -> None:
"""Generate the content for the About page."""
aboutMsg = (
"<h2>{title1}</h2>"
"<p>{copy}</p>"
Expand Down Expand Up @@ -181,9 +188,8 @@ def _fillAboutPage(self):

return

def _fillNotesPage(self):
"""Load the content for the Release Notes page.
"""
def _fillNotesPage(self) -> None:
"""Load the content for the Release Notes page."""
docPath = CONFIG.assetPath("text") / "release_notes.htm"
docText = readTextFile(docPath)
if docText:
Expand All @@ -192,9 +198,8 @@ def _fillNotesPage(self):
self.pageNotes.setHtml("Error loading release notes text ...")
return

def _fillCreditsPage(self):
"""Load the content for the Credits page.
"""
def _fillCreditsPage(self) -> None:
"""Load the content for the Credits page."""
docPath = CONFIG.assetPath("text") / "credits_en.htm"
docText = readTextFile(docPath)
if docText:
Expand All @@ -203,9 +208,8 @@ def _fillCreditsPage(self):
self.pageCredits.setHtml("Error loading credits text ...")
return

def _fillLicensePage(self):
"""Load the content for the Licence page.
"""
def _fillLicensePage(self) -> None:
"""Load the content for the Licence page."""
docPath = CONFIG.assetPath("text") / "gplv3_en.htm"
docText = readTextFile(docPath)
if docText:
Expand All @@ -214,9 +218,8 @@ def _fillLicensePage(self):
self.pageLicense.setHtml("Error loading licence text ...")
return

def _setStyleSheet(self):
"""Set stylesheet for all browser tabs
"""
def _setStyleSheet(self) -> None:
"""Set stylesheet for all browser tabs."""
styleSheet = (
"h1, h2, h3, h4 {{"
" color: rgb({hColR},{hColG},{hColB});"
Expand All @@ -242,8 +245,4 @@ def _setStyleSheet(self):

return

def _doClose(self):
self.close()
return

# END Class GuiAbout
19 changes: 8 additions & 11 deletions novelwriter/dialogs/docmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,12 @@ def __init__(self, parent: QWidget, sHandle: str, itemList: list[str]) -> None:

return

def __del__(self): # pragma: no cover
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiDocMerge")
return

def getData(self):
"""Return the user's choices.
"""
def getData(self) -> dict:
"""Return the user's choices."""
finalItems = []
for i in range(self.listBox.count()):
item = self.listBox.item(i)
Expand All @@ -127,12 +126,11 @@ def getData(self):
return self._data

##
# Slots
# Private Slots
##

def _resetList(self):
"""Reset the content of the list box to its original state.
"""
def _resetList(self) -> None:
"""Reset the content of the list box to its original state."""
logger.debug("Resetting list box content")
sHandle = self._data.get("sHandle", None)
itemList = self._data.get("origItems", [])
Expand All @@ -143,9 +141,8 @@ def _resetList(self):
# Internal Functions
##

def _loadContent(self, sHandle, itemList):
"""Load content from a given list of items.
"""
def _loadContent(self, sHandle: str, itemList: list[str]) -> None:
"""Load content from a given list of items."""
self._data = {}
self._data["sHandle"] = sHandle
self._data["origItems"] = itemList
Expand Down
25 changes: 12 additions & 13 deletions novelwriter/dialogs/docsplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

import logging

from PyQt5.QtCore import Qt
from PyQt5.QtCore import Qt, pyqtSlot
from PyQt5.QtWidgets import (
QDialog, QVBoxLayout, QComboBox, QListWidget, QAbstractItemView,
QListWidgetItem, QDialogButtonBox, QLabel, QGridLayout
QAbstractItemView, QComboBox, QDialog, QDialogButtonBox, QGridLayout,
QLabel, QListWidget, QListWidgetItem, QVBoxLayout, QWidget
)

from novelwriter import CONFIG, SHARED
Expand All @@ -45,7 +45,7 @@ class GuiDocSplit(QDialog):
LEVEL_ROLE = Qt.ItemDataRole.UserRole + 1
LABEL_ROLE = Qt.ItemDataRole.UserRole + 2

def __init__(self, parent, sHandle):
def __init__(self, parent: QWidget, sHandle: str) -> None:
super().__init__(parent=parent)

logger.debug("Create: GuiDocSplit")
Expand Down Expand Up @@ -138,11 +138,11 @@ def __init__(self, parent, sHandle):

return

def __del__(self): # pragma: no cover
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiDocSplit")
return

def getData(self):
def getData(self) -> tuple[dict, list]:
"""Return the user's choices. Also save the users options for
the next time the dialog is used.
"""
Expand Down Expand Up @@ -175,12 +175,12 @@ def getData(self):
return self._data, self._text

##
# Slots
# Private Slots
##

def _reloadList(self):
"""Reload the content of the list box.
"""
@pyqtSlot()
def _reloadList(self) -> None:
"""Reload the content of the list box."""
sHandle = self._data.get("sHandle", None)
self._loadContent(sHandle)
return
Expand All @@ -189,9 +189,8 @@ def _reloadList(self):
# Internal Functions
##

def _loadContent(self, sHandle):
"""Load content from a given source item.
"""
def _loadContent(self, sHandle: str) -> None:
"""Load content from a given source item."""
self._data = {}
self._data["sHandle"] = sHandle

Expand Down
16 changes: 12 additions & 4 deletions novelwriter/dialogs/editlabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import logging

from PyQt5.QtWidgets import (
QDialog, QVBoxLayout, QLineEdit, QLabel, QDialogButtonBox, QHBoxLayout
QDialog, QDialogButtonBox, QHBoxLayout, QLabel, QLineEdit, QVBoxLayout,
QWidget
)

from novelwriter import CONFIG
Expand All @@ -36,9 +37,10 @@

class GuiEditLabel(QDialog):

def __init__(self, parent, text=""):
def __init__(self, parent: QWidget, text: str = "") -> None:
super().__init__(parent=parent)

logger.debug("Create: GuiEditLabel")
self.setObjectName("GuiEditLabel")
self.setWindowTitle(self.tr("Item Label"))

Expand Down Expand Up @@ -70,14 +72,20 @@ def __init__(self, parent, text=""):

self.setLayout(self.outerBox)

logger.debug("Ready: GuiEditLabel")

return

def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiEditLabel")
return

@property
def itemLabel(self):
def itemLabel(self) -> str:
return self.labelValue.text()

@classmethod
def getLabel(cls, parent, text):
def getLabel(cls, parent: QWidget, text: str) -> tuple[str, bool]:
cls = GuiEditLabel(parent, text=text)
cls.exec_()
return cls.itemLabel, cls.result() == QDialog.Accepted
Expand Down
2 changes: 1 addition & 1 deletion novelwriter/dialogs/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self, parent: QWidget) -> None:

return

def __del__(self): # pragma: no cover
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiPreferences")
return

Expand Down
Loading

0 comments on commit 4fa2027

Please sign in to comment.