Remove the global APP singleton again

This commit is contained in:
Veronica Berglyd Olsen
2023-08-07 20:45:25 +02:00
parent 7756368113
commit 470017cdea
3 changed files with 2 additions and 70 deletions
+1 -4
View File
@@ -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_())
-63
View File
@@ -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):
+1 -3
View File
@@ -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