Skip to content

Commit

Permalink
Merge branch 'main' into feature/build_preview
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed May 28, 2024
2 parents cf14f84 + b387150 commit dc6fe77
Show file tree
Hide file tree
Showing 30 changed files with 202 additions and 169 deletions.
21 changes: 8 additions & 13 deletions novelwriter/dialogs/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
from novelwriter import CONFIG, SHARED
from novelwriter.common import cssCol, readTextFile
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.modified import NNonBlockingDialog
from novelwriter.extensions.modified import NDialog
from novelwriter.extensions.versioninfo import VersionInfoWidget
from novelwriter.types import QtAlignRightTop, QtDialogClose

logger = logging.getLogger(__name__)


class GuiAbout(NNonBlockingDialog):
class GuiAbout(NDialog):

def __init__(self, parent: QWidget) -> None:
super().__init__(parent=parent)
Expand Down Expand Up @@ -106,7 +106,9 @@ def __init__(self, parent: QWidget) -> None:

self.setLayout(self.outerBox)
self.setSizeGripEnabled(True)

self._setStyleSheet()
self._fillCreditsPage()

logger.debug("Ready: GuiAbout")

Expand All @@ -116,19 +118,14 @@ def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiAbout")
return

def populateGUI(self) -> None:
"""Populate tabs with text."""
self._fillCreditsPage()
return

##
# Events
##

def closeEvent(self, event: QCloseEvent) -> None:
"""Capture the close event and perform cleanup."""
event.accept()
self.deleteLater()
self.softDelete()
return

##
Expand All @@ -137,16 +134,14 @@ def closeEvent(self, event: QCloseEvent) -> None:

def _fillCreditsPage(self) -> None:
"""Load the content for the Credits page."""
docPath = CONFIG.assetPath("text") / "credits_en.htm"
docText = readTextFile(docPath)
if docText:
self.txtCredits.setHtml(docText)
if html := readTextFile(CONFIG.assetPath("text") / "credits_en.htm"):
self.txtCredits.setHtml(html)
else:
self.txtCredits.setHtml("Error loading credits text ...")
return

def _setStyleSheet(self) -> None:
"""Set stylesheet for all browser tabs."""
"""Set stylesheet text document."""
baseCol = cssCol(self.palette().window().color())
self.txtCredits.setStyleSheet(
f"QTextBrowser {{border: none; background: {baseCol};}} "
Expand Down
30 changes: 15 additions & 15 deletions novelwriter/dialogs/docmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
import logging

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

from novelwriter import CONFIG, SHARED
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.modified import NDialog
from novelwriter.extensions.switch import NSwitch
from novelwriter.types import QtDialogCancel, QtDialogOk, QtDialogReset, QtUserRole
from novelwriter.types import QtAccepted, QtDialogCancel, QtDialogOk, QtDialogReset, QtUserRole

logger = logging.getLogger(__name__)


class GuiDocMerge(QDialog):
class GuiDocMerge(NDialog):

D_HANDLE = QtUserRole

Expand Down Expand Up @@ -117,7 +117,7 @@ def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiDocMerge")
return

def getData(self) -> dict:
def data(self) -> dict:
"""Return the user's choices."""
finalItems = []
for i in range(self.listBox.count()):
Expand All @@ -130,15 +130,15 @@ def getData(self) -> dict:

return self._data

##
# Events
##

def closeEvent(self, event: QCloseEvent) -> None:
"""Capture the close event and perform cleanup."""
event.accept()
self.deleteLater()
return
@classmethod
def getData(cls, parent: QWidget, handle: str, items: list[str]) -> tuple[dict, bool]:
"""Pop the dialog and return the result."""
cls = GuiDocMerge(parent, handle, items)
cls.exec()
data = cls.data()
accepted = cls.result() == QtAccepted
cls.softDelete()
return data, accepted

##
# Private Slots
Expand Down
30 changes: 15 additions & 15 deletions novelwriter/dialogs/docsplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
import logging

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

from novelwriter import CONFIG, SHARED
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.modified import NDialog
from novelwriter.extensions.switch import NSwitch
from novelwriter.types import QtDialogCancel, QtDialogOk, QtUserRole
from novelwriter.types import QtAccepted, QtDialogCancel, QtDialogOk, QtUserRole

logger = logging.getLogger(__name__)


class GuiDocSplit(QDialog):
class GuiDocSplit(NDialog):

LINE_ROLE = QtUserRole
LEVEL_ROLE = QtUserRole + 1
Expand Down Expand Up @@ -145,7 +145,7 @@ def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiDocSplit")
return

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

return self._data, self._text

##
# Events
##

def closeEvent(self, event: QCloseEvent) -> None:
"""Capture the close event and perform cleanup."""
event.accept()
self.deleteLater()
return
@classmethod
def getData(cls, parent: QWidget, handle: str) -> tuple[dict, list[str], bool]:
"""Pop the dialog and return the result."""
cls = GuiDocSplit(parent, handle)
cls.exec()
data, text = cls.data()
accepted = cls.result() == QtAccepted
cls.softDelete()
return data, text, accepted

##
# Private Slots
Expand Down
14 changes: 6 additions & 8 deletions novelwriter/dialogs/editlabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@

import logging

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

from novelwriter import CONFIG
from novelwriter.types import QtDialogCancel, QtDialogOk
from novelwriter.extensions.modified import NDialog
from novelwriter.types import QtAccepted, QtDialogCancel, QtDialogOk

logger = logging.getLogger(__name__)


class GuiEditLabel(QDialog):
class GuiEditLabel(NDialog):

def __init__(self, parent: QWidget, text: str = "") -> None:
super().__init__(parent=parent)
Expand Down Expand Up @@ -91,6 +89,6 @@ def getLabel(cls, parent: QWidget, text: str) -> tuple[str, bool]:
cls = GuiEditLabel(parent, text=text)
cls.exec()
label = cls.itemLabel
accepted = cls.result() == QDialog.DialogCode.Accepted
cls.deleteLater()
accepted = cls.result() == QtAccepted
cls.softDelete()
return label, accepted
21 changes: 8 additions & 13 deletions novelwriter/dialogs/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@
import logging

from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
from PyQt5.QtGui import QCloseEvent, QKeyEvent, QKeySequence
from PyQt5.QtGui import QCloseEvent
from PyQt5.QtWidgets import (
QAbstractButton, QApplication, QCompleter, QDialog, QDialogButtonBox,
QFileDialog, QHBoxLayout, QLineEdit, QPushButton, QVBoxLayout, QWidget
QAbstractButton, QApplication, QCompleter, QDialogButtonBox, QFileDialog,
QHBoxLayout, QLineEdit, QPushButton, QVBoxLayout, QWidget
)

from novelwriter import CONFIG, SHARED
from novelwriter.common import describeFont
from novelwriter.constants import nwConst, nwUnicode
from novelwriter.dialogs.quotes import GuiQuoteSelect
from novelwriter.extensions.configlayout import NColourLabel, NScrollableForm
from novelwriter.extensions.modified import NComboBox, NDoubleSpinBox, NIconToolButton, NSpinBox
from novelwriter.extensions.modified import (
NComboBox, NDialog, NDoubleSpinBox, NIconToolButton, NSpinBox
)
from novelwriter.extensions.pagedsidebar import NPagedSideBar
from novelwriter.extensions.switch import NSwitch
from novelwriter.types import (
Expand All @@ -49,7 +51,7 @@
logger = logging.getLogger(__name__)


class GuiPreferences(QDialog):
class GuiPreferences(NDialog):

newPreferencesReady = pyqtSignal(bool, bool, bool, bool)

Expand Down Expand Up @@ -769,14 +771,7 @@ def closeEvent(self, event: QCloseEvent) -> None:
event.accept()
QApplication.processEvents()
self.done(nwConst.DLG_FINISHED)
self.deleteLater()
return

def keyPressEvent(self, event: QKeyEvent) -> None:
"""Overload keyPressEvent to block enter key to save."""
if event.matches(QKeySequence.StandardKey.Cancel):
self.close()
event.ignore()
self.softDelete()
return

##
Expand Down
8 changes: 4 additions & 4 deletions novelwriter/dialogs/projectsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
from PyQt5.QtGui import QCloseEvent, QColor
from PyQt5.QtWidgets import (
QAbstractItemView, QApplication, QColorDialog, QDialog, QDialogButtonBox,
QAbstractItemView, QApplication, QColorDialog, QDialogButtonBox,
QHBoxLayout, QLineEdit, QMenu, QStackedWidget, QToolButton, QTreeWidget,
QTreeWidgetItem, QVBoxLayout, QWidget
)
Expand All @@ -40,7 +40,7 @@
from novelwriter.core.status import NWStatus, StatusEntry
from novelwriter.enum import nwStatusShape
from novelwriter.extensions.configlayout import NColourLabel, NFixedPage, NScrollableForm
from novelwriter.extensions.modified import NComboBox, NIconToolButton
from novelwriter.extensions.modified import NComboBox, NDialog, NIconToolButton
from novelwriter.extensions.pagedsidebar import NPagedSideBar
from novelwriter.extensions.switch import NSwitch
from novelwriter.types import (
Expand All @@ -51,7 +51,7 @@
logger = logging.getLogger(__name__)


class GuiProjectSettings(QDialog):
class GuiProjectSettings(NDialog):

PAGE_SETTINGS = 0
PAGE_STATUS = 1
Expand Down Expand Up @@ -147,7 +147,7 @@ def closeEvent(self, event: QCloseEvent) -> None:
"""Capture the user closing the window and save settings."""
self._saveSettings()
event.accept()
self.deleteLater()
self.softDelete()
return

##
Expand Down
14 changes: 9 additions & 5 deletions novelwriter/dialogs/quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@
from PyQt5.QtCore import QSize, pyqtSlot
from PyQt5.QtGui import QFontMetrics
from PyQt5.QtWidgets import (
QDialog, QDialogButtonBox, QFrame, QHBoxLayout, QLabel, QListWidget,
QDialogButtonBox, QFrame, QHBoxLayout, QLabel, QListWidget,
QListWidgetItem, QVBoxLayout, QWidget
)

from novelwriter import CONFIG
from novelwriter.constants import nwQuotes, trConst
from novelwriter.types import QtAlignCenter, QtAlignTop, QtDialogCancel, QtDialogOk, QtUserRole
from novelwriter.extensions.modified import NDialog
from novelwriter.types import (
QtAccepted, QtAlignCenter, QtAlignTop, QtDialogCancel, QtDialogOk,
QtUserRole
)

logger = logging.getLogger(__name__)


class GuiQuoteSelect(QDialog):
class GuiQuoteSelect(NDialog):

_selected = ""

Expand Down Expand Up @@ -126,8 +130,8 @@ def getQuote(cls, parent: QWidget, current: str = "") -> tuple[str, bool]:
cls = GuiQuoteSelect(parent, current=current)
cls.exec()
quote = cls._selected
accepted = cls.result() == QDialog.DialogCode.Accepted
cls.deleteLater()
accepted = cls.result() == QtAccepted
cls.softDelete()
return quote, accepted

##
Expand Down
8 changes: 4 additions & 4 deletions novelwriter/dialogs/wordlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
from PyQt5.QtGui import QCloseEvent
from PyQt5.QtWidgets import (
QAbstractItemView, QApplication, QDialog, QDialogButtonBox, QFileDialog,
QAbstractItemView, QApplication, QDialogButtonBox, QFileDialog,
QHBoxLayout, QLineEdit, QListWidget, QVBoxLayout, QWidget
)

from novelwriter import CONFIG, SHARED
from novelwriter.common import formatFileFilter
from novelwriter.core.spellcheck import UserDictionary
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.modified import NIconToolButton
from novelwriter.extensions.modified import NDialog, NIconToolButton
from novelwriter.types import QtDialogClose, QtDialogSave

logger = logging.getLogger(__name__)


class GuiWordList(QDialog):
class GuiWordList(NDialog):

newWordListReady = pyqtSignal()

Expand Down Expand Up @@ -140,7 +140,7 @@ def closeEvent(self, event: QCloseEvent) -> None:
"""Capture the close event and perform cleanup."""
self._saveGuiSettings()
event.accept()
self.deleteLater()
self.softDelete()
return

##
Expand Down
Loading

0 comments on commit dc6fe77

Please sign in to comment.