From 470017cdea6dc7be15ff9443b0c5d8a395f2ca21 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 7 Aug 2023 20:45:25 +0200 Subject: [PATCH] Remove the global APP singleton again --- novelwriter/__init__.py | 5 +--- novelwriter/config.py | 63 ----------------------------------------- novelwriter/guimain.py | 4 +-- 3 files changed, 2 insertions(+), 70 deletions(-) diff --git a/novelwriter/__init__.py b/novelwriter/__init__.py index d83415f7..bb42ba17 100644 --- a/novelwriter/__init__.py +++ b/novelwriter/__init__.py @@ -30,7 +30,7 @@ import logging from PyQt5.QtWidgets import QApplication, QErrorMessage from novelwriter.error import exceptionHandler, logException -from novelwriter.config import Config, NWApp +from novelwriter.config import Config ## # Version Scheme @@ -74,7 +74,6 @@ logger = logging.getLogger(__name__) # Create the global singleton instances CONFIG = Config() -APP = NWApp() def main(sysArgs: list | None = None): @@ -228,7 +227,6 @@ def main(sysArgs: list | None = None): from novelwriter.guimain import GuiMain if testMode: nwGUI = GuiMain() - APP.setGUI(nwGUI) return nwGUI else: @@ -248,7 +246,6 @@ def main(sysArgs: list | None = None): # Launch main GUI nwGUI = GuiMain() - APP.setGUI(nwGUI) nwGUI.postLaunchTasks(cmdOpen) sys.exit(nwApp.exec_()) diff --git a/novelwriter/config.py b/novelwriter/config.py index 7bbf125e..f7a94c1b 100644 --- a/novelwriter/config.py +++ b/novelwriter/config.py @@ -29,7 +29,6 @@ import json import logging from time import time -from typing import TYPE_CHECKING from pathlib import Path from PyQt5.QtGui import QFontDatabase @@ -42,11 +41,6 @@ from novelwriter.error import logException, formatException from novelwriter.common import checkPath, formatTimeStamp, NWConfigParser from novelwriter.constants import nwFiles, nwUnicode -if TYPE_CHECKING: # pragma: no cover - from novelwriter.guimain import GuiMain - from novelwriter.gui.theme import GuiTheme - from novelwriter.core.project import NWProject - logger = logging.getLogger(__name__) @@ -798,63 +792,6 @@ class Config: # END Class Config -class NWApp: - """Singleton: Global Pointers - - This class holds pointers to the core singletons: - * The GuiMain instance - * The GuiTheme instance - * The NWProject instance - """ - - def __init__(self) -> None: - self._gui: GuiMain | None = None - self._theme: GuiTheme | None = None - self._project: NWProject | None = None - return - - @property - def gui(self) -> GuiMain: - """The main gui instance.""" - if self._gui is None: - raise Exception("GLOBAL not fully initialised") - return self._gui - - @property - def theme(self) -> GuiTheme: - """The main gui theme instance.""" - if self._theme is None: - raise Exception("GLOBAL not fully initialised") - return self._theme - - @property - def project(self) -> NWProject: - """The main project instance.""" - if self._project is None: - raise Exception("GLOBAL not fully initialised") - return self._project - - def setGUI(self, gui: GuiMain) -> None: - """Set the GUI instance. Can only be set once.""" - if self._gui is None: - self._gui = gui - return - - def setTheme(self, theme: GuiTheme) -> None: - """Set the theme instance. Can only be set once.""" - if self._theme is None: - self._theme = theme - return - - def setProject(self, project: NWProject) -> None: - """Set the project instance. Can only be set once.""" - if self._project is None: - self._project = project - return - -# END Class NWApp - - class RecentProjects: def __init__(self, config): diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index 3ffd0768..6076d120 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -37,7 +37,7 @@ from PyQt5.QtWidgets import ( QStackedWidget, QVBoxLayout, QWidget ) -from novelwriter import CONFIG, APP, __hexversion__ +from novelwriter import CONFIG, __hexversion__ from novelwriter.gui.theme import GuiTheme from novelwriter.gui.sidebar import GuiSideBar from novelwriter.gui.outline import GuiOutlineView @@ -115,8 +115,6 @@ class GuiMain(QMainWindow): # Core Classes self.mainTheme = GuiTheme() self.theProject = NWProject(self) - APP.setTheme(self.mainTheme) - APP.setProject(self.theProject) # Core Settings self.hasProject = False