Remove the global APP singleton again
This commit is contained in:
@@ -30,7 +30,7 @@ import logging
|
|||||||
from PyQt5.QtWidgets import QApplication, QErrorMessage
|
from PyQt5.QtWidgets import QApplication, QErrorMessage
|
||||||
|
|
||||||
from novelwriter.error import exceptionHandler, logException
|
from novelwriter.error import exceptionHandler, logException
|
||||||
from novelwriter.config import Config, NWApp
|
from novelwriter.config import Config
|
||||||
|
|
||||||
##
|
##
|
||||||
# Version Scheme
|
# Version Scheme
|
||||||
@@ -74,7 +74,6 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
# Create the global singleton instances
|
# Create the global singleton instances
|
||||||
CONFIG = Config()
|
CONFIG = Config()
|
||||||
APP = NWApp()
|
|
||||||
|
|
||||||
|
|
||||||
def main(sysArgs: list | None = None):
|
def main(sysArgs: list | None = None):
|
||||||
@@ -228,7 +227,6 @@ def main(sysArgs: list | None = None):
|
|||||||
from novelwriter.guimain import GuiMain
|
from novelwriter.guimain import GuiMain
|
||||||
if testMode:
|
if testMode:
|
||||||
nwGUI = GuiMain()
|
nwGUI = GuiMain()
|
||||||
APP.setGUI(nwGUI)
|
|
||||||
return nwGUI
|
return nwGUI
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -248,7 +246,6 @@ def main(sysArgs: list | None = None):
|
|||||||
|
|
||||||
# Launch main GUI
|
# Launch main GUI
|
||||||
nwGUI = GuiMain()
|
nwGUI = GuiMain()
|
||||||
APP.setGUI(nwGUI)
|
|
||||||
nwGUI.postLaunchTasks(cmdOpen)
|
nwGUI.postLaunchTasks(cmdOpen)
|
||||||
|
|
||||||
sys.exit(nwApp.exec_())
|
sys.exit(nwApp.exec_())
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from time import time
|
from time import time
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from PyQt5.QtGui import QFontDatabase
|
from PyQt5.QtGui import QFontDatabase
|
||||||
@@ -42,11 +41,6 @@ from novelwriter.error import logException, formatException
|
|||||||
from novelwriter.common import checkPath, formatTimeStamp, NWConfigParser
|
from novelwriter.common import checkPath, formatTimeStamp, NWConfigParser
|
||||||
from novelwriter.constants import nwFiles, nwUnicode
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -798,63 +792,6 @@ class Config:
|
|||||||
# END 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:
|
class RecentProjects:
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ from PyQt5.QtWidgets import (
|
|||||||
QStackedWidget, QVBoxLayout, QWidget
|
QStackedWidget, QVBoxLayout, QWidget
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, APP, __hexversion__
|
from novelwriter import CONFIG, __hexversion__
|
||||||
from novelwriter.gui.theme import GuiTheme
|
from novelwriter.gui.theme import GuiTheme
|
||||||
from novelwriter.gui.sidebar import GuiSideBar
|
from novelwriter.gui.sidebar import GuiSideBar
|
||||||
from novelwriter.gui.outline import GuiOutlineView
|
from novelwriter.gui.outline import GuiOutlineView
|
||||||
@@ -115,8 +115,6 @@ class GuiMain(QMainWindow):
|
|||||||
# Core Classes
|
# Core Classes
|
||||||
self.mainTheme = GuiTheme()
|
self.mainTheme = GuiTheme()
|
||||||
self.theProject = NWProject(self)
|
self.theProject = NWProject(self)
|
||||||
APP.setTheme(self.mainTheme)
|
|
||||||
APP.setProject(self.theProject)
|
|
||||||
|
|
||||||
# Core Settings
|
# Core Settings
|
||||||
self.hasProject = False
|
self.hasProject = False
|
||||||
|
|||||||
Reference in New Issue
Block a user