From 32d75567e3ff4da58e7194fc87130d06fabe7e9b Mon Sep 17 00:00:00 2001
From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com>
Date: Mon, 28 Nov 2022 18:23:36 +0100
Subject: [PATCH] Use direct imports everywhere
---
novelwriter/core/__init__.py | 40 ------------------
novelwriter/core/index.py | 4 +-
novelwriter/core/storage.py | 2 +-
novelwriter/core/tohtml.py | 2 +-
novelwriter/dialogs/__init__.py | 46 ---------------------
novelwriter/gui/__init__.py | 45 --------------------
novelwriter/gui/doceditor.py | 3 +-
novelwriter/gui/dochighlight.py | 2 +-
novelwriter/gui/docviewer.py | 2 +-
novelwriter/gui/projtree.py | 7 +++-
novelwriter/guimain.py | 37 +++++++++++------
novelwriter/tools/__init__.py | 32 --------------
novelwriter/tools/build.py | 4 +-
tests/test_core/test_core_item.py | 2 +-
tests/test_gui/test_gui_guimain.py | 6 ++-
tests/test_gui/test_gui_theme.py | 4 +-
tests/test_tools/test_tools_build.py | 2 +-
tests/test_tools/test_tools_lipsum.py | 2 +-
tests/test_tools/test_tools_writingstats.py | 2 +-
tests/tools.py | 2 +-
20 files changed, 50 insertions(+), 196 deletions(-)
delete mode 100644 novelwriter/core/__init__.py
delete mode 100644 novelwriter/dialogs/__init__.py
delete mode 100644 novelwriter/gui/__init__.py
delete mode 100644 novelwriter/tools/__init__.py
diff --git a/novelwriter/core/__init__.py b/novelwriter/core/__init__.py
deleted file mode 100644
index 07d6cc94..00000000
--- a/novelwriter/core/__init__.py
+++ /dev/null
@@ -1,40 +0,0 @@
-"""
-novelWriter – Core Init
-=======================
-
-This file is a part of novelWriter
-Copyright 2018–2022, Veronica Berglyd Olsen
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-"""
-
-from novelwriter.core.coretools import DocMerger, DocSplitter, ProjectBuilder
-from novelwriter.core.index import countWords
-from novelwriter.core.project import NWProject
-from novelwriter.core.spellcheck import NWSpellEnchant
-from novelwriter.core.tohtml import ToHtml
-from novelwriter.core.toodt import ToOdt
-from novelwriter.core.tomd import ToMarkdown
-
-__all__ = [
- "DocMerger",
- "DocSplitter",
- "ProjectBuilder",
- "countWords",
- "NWProject",
- "NWSpellEnchant",
- "ToHtml",
- "ToOdt",
- "ToMarkdown",
-]
diff --git a/novelwriter/core/index.py b/novelwriter/core/index.py
index 7d292af4..15bc4e8d 100644
--- a/novelwriter/core/index.py
+++ b/novelwriter/core/index.py
@@ -36,10 +36,8 @@ from pathlib import Path
from novelwriter.enum import nwItemType, nwItemLayout
from novelwriter.error import logException
+from novelwriter.common import checkInt, isHandle, isItemClass, isTitleTag, jsonEncode
from novelwriter.constants import nwFiles, nwKeyWords, nwUnicode, nwHeaders
-from novelwriter.common import (
- checkInt, isHandle, isItemClass, isTitleTag, jsonEncode
-)
logger = logging.getLogger(__name__)
diff --git a/novelwriter/core/storage.py b/novelwriter/core/storage.py
index c9580522..9d0746c4 100644
--- a/novelwriter/core/storage.py
+++ b/novelwriter/core/storage.py
@@ -30,11 +30,11 @@ from time import time
from pathlib import Path
from zipfile import ZIP_DEFLATED, ZIP_STORED, ZipFile
+from novelwriter.error import logException
from novelwriter.common import minmax
from novelwriter.constants import nwFiles
from novelwriter.core.document import NWDocument
from novelwriter.core.projectxml import ProjectXMLReader, ProjectXMLWriter
-from novelwriter.error import logException
logger = logging.getLogger(__name__)
diff --git a/novelwriter/core/tohtml.py b/novelwriter/core/tohtml.py
index 88647d63..db458a07 100644
--- a/novelwriter/core/tohtml.py
+++ b/novelwriter/core/tohtml.py
@@ -25,8 +25,8 @@ along with this program. If not, see .
import logging
-from novelwriter.core.tokenizer import Tokenizer
from novelwriter.constants import nwKeyWords, nwLabels, nwHtmlUnicode
+from novelwriter.core.tokenizer import Tokenizer
logger = logging.getLogger(__name__)
diff --git a/novelwriter/dialogs/__init__.py b/novelwriter/dialogs/__init__.py
deleted file mode 100644
index 03efef5c..00000000
--- a/novelwriter/dialogs/__init__.py
+++ /dev/null
@@ -1,46 +0,0 @@
-"""
-novelWriter – Dialogs Init
-==========================
-
-This file is a part of novelWriter
-Copyright 2018–2022, Veronica Berglyd Olsen
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-"""
-
-from novelwriter.dialogs.about import GuiAbout
-from novelwriter.dialogs.docmerge import GuiDocMerge
-from novelwriter.dialogs.docsplit import GuiDocSplit
-from novelwriter.dialogs.editlabel import GuiEditLabel
-from novelwriter.dialogs.preferences import GuiPreferences
-from novelwriter.dialogs.projdetails import GuiProjectDetails
-from novelwriter.dialogs.projload import GuiProjectLoad
-from novelwriter.dialogs.projsettings import GuiProjectSettings
-from novelwriter.dialogs.quotes import GuiQuoteSelect
-from novelwriter.dialogs.updates import GuiUpdates
-from novelwriter.dialogs.wordlist import GuiWordList
-
-__all__ = [
- "GuiAbout",
- "GuiDocMerge",
- "GuiDocSplit",
- "GuiEditLabel",
- "GuiPreferences",
- "GuiProjectDetails",
- "GuiProjectLoad",
- "GuiProjectSettings",
- "GuiQuoteSelect",
- "GuiUpdates",
- "GuiWordList",
-]
diff --git a/novelwriter/gui/__init__.py b/novelwriter/gui/__init__.py
deleted file mode 100644
index bbe814d2..00000000
--- a/novelwriter/gui/__init__.py
+++ /dev/null
@@ -1,45 +0,0 @@
-"""
-novelWriter – GUI Init
-======================
-
-This file is a part of novelWriter
-Copyright 2018–2022, Veronica Berglyd Olsen
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-"""
-
-from novelwriter.gui.doceditor import GuiDocEditor
-from novelwriter.gui.docviewer import GuiDocViewer, GuiDocViewDetails
-from novelwriter.gui.itemdetails import GuiItemDetails
-from novelwriter.gui.mainmenu import GuiMainMenu
-from novelwriter.gui.noveltree import GuiNovelView
-from novelwriter.gui.outline import GuiOutlineView
-from novelwriter.gui.projtree import GuiProjectView
-from novelwriter.gui.statusbar import GuiMainStatus
-from novelwriter.gui.theme import GuiTheme
-from novelwriter.gui.sidebar import GuiSideBar
-
-__all__ = [
- "GuiDocEditor",
- "GuiDocViewDetails",
- "GuiDocViewer",
- "GuiItemDetails",
- "GuiMainMenu",
- "GuiMainStatus",
- "GuiNovelView",
- "GuiOutlineView",
- "GuiProjectView",
- "GuiTheme",
- "GuiSideBar",
-]
diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py
index e5d87502..bc1421af 100644
--- a/novelwriter/gui/doceditor.py
+++ b/novelwriter/gui/doceditor.py
@@ -50,10 +50,11 @@ from PyQt5.QtWidgets import (
QFrame
)
-from novelwriter.core import NWSpellEnchant, countWords
from novelwriter.enum import nwAlert, nwDocAction, nwDocInsert, nwDocMode, nwItemClass
from novelwriter.common import minmax, transferCase
from novelwriter.constants import nwConst, nwFiles, nwKeyWords, nwUnicode
+from novelwriter.core.index import countWords
+from novelwriter.core.spellcheck import NWSpellEnchant
from novelwriter.gui.dochighlight import GuiDocHighlighter
logger = logging.getLogger(__name__)
diff --git a/novelwriter/gui/dochighlight.py b/novelwriter/gui/dochighlight.py
index baea34bb..1b06d25f 100644
--- a/novelwriter/gui/dochighlight.py
+++ b/novelwriter/gui/dochighlight.py
@@ -33,8 +33,8 @@ from PyQt5.QtGui import (
QColor, QTextCharFormat, QFont, QSyntaxHighlighter, QBrush
)
-from novelwriter.constants import nwRegEx, nwUnicode
from novelwriter.common import checkInt
+from novelwriter.constants import nwRegEx, nwUnicode
logger = logging.getLogger(__name__)
diff --git a/novelwriter/gui/docviewer.py b/novelwriter/gui/docviewer.py
index a25fad6d..f0ac6345 100644
--- a/novelwriter/gui/docviewer.py
+++ b/novelwriter/gui/docviewer.py
@@ -41,10 +41,10 @@ from PyQt5.QtWidgets import (
QAction, QMenu, QFrame
)
-from novelwriter.core import ToHtml
from novelwriter.enum import nwItemType, nwDocAction, nwDocMode
from novelwriter.error import logException
from novelwriter.constants import nwUnicode
+from novelwriter.core.tohtml import ToHtml
logger = logging.getLogger(__name__)
diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py
index b5ddc926..434c5852 100644
--- a/novelwriter/gui/projtree.py
+++ b/novelwriter/gui/projtree.py
@@ -39,10 +39,13 @@ from PyQt5.QtWidgets import (
QVBoxLayout, QWidget
)
-from novelwriter.core import DocMerger, DocSplitter
from novelwriter.enum import nwDocMode, nwItemType, nwItemClass, nwItemLayout, nwAlert
-from novelwriter.dialogs import GuiDocMerge, GuiDocSplit, GuiEditLabel, GuiProjectSettings
from novelwriter.constants import nwHeaders, nwUnicode, trConst, nwLabels
+from novelwriter.core.coretools import DocMerger, DocSplitter
+from novelwriter.dialogs.docmerge import GuiDocMerge
+from novelwriter.dialogs.docsplit import GuiDocSplit
+from novelwriter.dialogs.editlabel import GuiEditLabel
+from novelwriter.dialogs.projsettings import GuiProjectSettings
logger = logging.getLogger(__name__)
diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py
index 55511bfe..019539bb 100644
--- a/novelwriter/guimain.py
+++ b/novelwriter/guimain.py
@@ -38,19 +38,30 @@ from PyQt5.QtWidgets import (
QMessageBox, QDialog, QStackedWidget
)
-from novelwriter.gui import (
- GuiDocEditor, GuiDocViewDetails, GuiDocViewer, GuiItemDetails, GuiMainMenu,
- GuiMainStatus, GuiNovelView, GuiOutlineView, GuiProjectView, GuiTheme,
- GuiSideBar
-)
-from novelwriter.dialogs import (
- GuiAbout, GuiPreferences, GuiProjectDetails, GuiProjectLoad,
- GuiProjectSettings, GuiUpdates, GuiWordList
-)
-from novelwriter.tools import (
- GuiBuildNovel, GuiLipsum, GuiProjectWizard, GuiWritingStats
-)
-from novelwriter.core import NWProject, ProjectBuilder
+from novelwriter.gui.theme import GuiTheme
+from novelwriter.gui.sidebar import GuiSideBar
+from novelwriter.gui.outline import GuiOutlineView
+from novelwriter.gui.mainmenu import GuiMainMenu
+from novelwriter.gui.projtree import GuiProjectView
+from novelwriter.gui.doceditor import GuiDocEditor
+from novelwriter.gui.docviewer import GuiDocViewDetails, GuiDocViewer
+from novelwriter.gui.noveltree import GuiNovelView
+from novelwriter.gui.statusbar import GuiMainStatus
+from novelwriter.gui.itemdetails import GuiItemDetails
+from novelwriter.dialogs.about import GuiAbout
+from novelwriter.dialogs.updates import GuiUpdates
+from novelwriter.dialogs.projload import GuiProjectLoad
+from novelwriter.dialogs.wordlist import GuiWordList
+from novelwriter.dialogs.preferences import GuiPreferences
+from novelwriter.dialogs.projdetails import GuiProjectDetails
+from novelwriter.dialogs.projsettings import GuiProjectSettings
+from novelwriter.tools.build import GuiBuildNovel
+from novelwriter.tools.lipsum import GuiLipsum
+from novelwriter.tools.projwizard import GuiProjectWizard
+from novelwriter.tools.writingstats import GuiWritingStats
+from novelwriter.core.project import NWProject
+from novelwriter.core.coretools import ProjectBuilder
+
from novelwriter.enum import (
nwDocMode, nwItemType, nwItemClass, nwAlert, nwWidget, nwView
)
diff --git a/novelwriter/tools/__init__.py b/novelwriter/tools/__init__.py
deleted file mode 100644
index 024ae3fd..00000000
--- a/novelwriter/tools/__init__.py
+++ /dev/null
@@ -1,32 +0,0 @@
-"""
-novelWriter – Tools Init
-========================
-
-This file is a part of novelWriter
-Copyright 2018–2022, Veronica Berglyd Olsen
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-"""
-
-from novelwriter.tools.build import GuiBuildNovel
-from novelwriter.tools.lipsum import GuiLipsum
-from novelwriter.tools.projwizard import GuiProjectWizard
-from novelwriter.tools.writingstats import GuiWritingStats
-
-__all__ = [
- "GuiBuildNovel",
- "GuiLipsum",
- "GuiProjectWizard",
- "GuiWritingStats",
-]
diff --git a/novelwriter/tools/build.py b/novelwriter/tools/build.py
index dbdbe16a..4b2a940c 100644
--- a/novelwriter/tools/build.py
+++ b/novelwriter/tools/build.py
@@ -43,12 +43,14 @@ from PyQt5.QtWidgets import (
)
from PyQt5.QtPrintSupport import QPrinter, QPrintPreviewDialog
-from novelwriter.core import ToHtml, ToOdt, ToMarkdown
from novelwriter.enum import nwAlert, nwItemType, nwItemLayout, nwItemClass
from novelwriter.error import formatException, logException
from novelwriter.common import fuzzyTime, makeFileNameSafe
from novelwriter.custom import QSwitch
from novelwriter.constants import nwConst, nwFiles
+from novelwriter.core.tomd import ToMarkdown
+from novelwriter.core.toodt import ToOdt
+from novelwriter.core.tohtml import ToHtml
logger = logging.getLogger(__name__)
diff --git a/tests/test_core/test_core_item.py b/tests/test_core/test_core_item.py
index 034240e1..2633ed7e 100644
--- a/tests/test_core/test_core_item.py
+++ b/tests/test_core/test_core_item.py
@@ -25,9 +25,9 @@ from PyQt5.QtGui import QIcon
from tools import C, buildTestProject
+from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
from novelwriter.core.item import NWItem
from novelwriter.core.project import NWProject
-from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
@pytest.mark.core
diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py
index 80745c6e..ec17114c 100644
--- a/tests/test_gui/test_gui_guimain.py
+++ b/tests/test_gui/test_gui_guimain.py
@@ -31,13 +31,15 @@ from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QDialog, QMessageBox, QInputDialog
from novelwriter.enum import nwItemType, nwView, nwWidget
-from novelwriter.tools import GuiProjectWizard
-from novelwriter.dialogs import GuiEditLabel, GuiAbout, GuiProjectLoad
from novelwriter.constants import nwFiles
from novelwriter.gui.outline import GuiOutlineView
from novelwriter.gui.projtree import GuiProjectTree
from novelwriter.gui.doceditor import GuiDocEditor
from novelwriter.gui.noveltree import GuiNovelView
+from novelwriter.dialogs.about import GuiAbout
+from novelwriter.dialogs.projload import GuiProjectLoad
+from novelwriter.dialogs.editlabel import GuiEditLabel
+from novelwriter.tools.projwizard import GuiProjectWizard
KEY_DELAY = 1
diff --git a/tests/test_gui/test_gui_theme.py b/tests/test_gui/test_gui_theme.py
index 5ec03c30..f5751e7b 100644
--- a/tests/test_gui/test_gui_theme.py
+++ b/tests/test_gui/test_gui_theme.py
@@ -26,14 +26,14 @@ from pathlib import Path
from configparser import ConfigParser
from mock import causeOSError
-from novelwriter.constants import nwLabels
-from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType
from tools import writeFile
from PyQt5.QtGui import QIcon, QPalette, QPixmap
from PyQt5.QtWidgets import QApplication
+from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType
from novelwriter.config import Config
+from novelwriter.constants import nwLabels
from novelwriter.gui.theme import GuiIcons, GuiTheme
diff --git a/tests/test_tools/test_tools_build.py b/tests/test_tools/test_tools_build.py
index d07ce1b0..44d5330f 100644
--- a/tests/test_tools/test_tools_build.py
+++ b/tests/test_tools/test_tools_build.py
@@ -28,7 +28,7 @@ from tools import cmpFiles, getGuiItem
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QAction, QFileDialog
-from novelwriter.tools import GuiBuildNovel
+from novelwriter.tools.build import GuiBuildNovel
@pytest.mark.gui
diff --git a/tests/test_tools/test_tools_lipsum.py b/tests/test_tools/test_tools_lipsum.py
index 409a168b..e0cf85f1 100644
--- a/tests/test_tools/test_tools_lipsum.py
+++ b/tests/test_tools/test_tools_lipsum.py
@@ -25,7 +25,7 @@ from tools import C, getGuiItem, buildTestProject
from PyQt5.QtWidgets import QAction
-from novelwriter.tools import GuiLipsum
+from novelwriter.tools.lipsum import GuiLipsum
@pytest.mark.gui
diff --git a/tests/test_tools/test_tools_writingstats.py b/tests/test_tools/test_tools_writingstats.py
index a02d386a..c071cf43 100644
--- a/tests/test_tools/test_tools_writingstats.py
+++ b/tests/test_tools/test_tools_writingstats.py
@@ -28,8 +28,8 @@ from tools import getGuiItem, writeFile, buildTestProject
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QAction, QFileDialog
-from novelwriter.tools import GuiWritingStats
from novelwriter.constants import nwFiles
+from novelwriter.tools.writingstats import GuiWritingStats
@pytest.mark.gui
diff --git a/tests/tools.py b/tests/tools.py
index 1e446912..5b77af92 100644
--- a/tests/tools.py
+++ b/tests/tools.py
@@ -158,7 +158,7 @@ def buildTestProject(theObject, projPath):
object as the parent.
"""
from novelwriter.enum import nwItemClass
- from novelwriter.core import NWProject
+ from novelwriter.core.project import NWProject
if isinstance(theObject, NWProject):
theGUI = None