Merge branch 'dev' into feature/build_gui

This commit is contained in:
Veronica Berglyd Olsen
2023-05-16 23:45:22 +02:00
69 changed files with 960 additions and 1037 deletions
+2 -6
View File
@@ -27,13 +27,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import shutil
import logging
import novelwriter
from time import time
from functools import partial
from PyQt5.QtCore import QCoreApplication
from novelwriter import CONFIG
from novelwriter.enum import nwAlert
from novelwriter.common import minmax, simplified
from novelwriter.constants import nwItemClass
@@ -268,12 +268,8 @@ class ProjectBuilder:
"""
def __init__(self, mainGui):
self.mainGui = mainGui
self.mainConf = novelwriter.CONFIG
self.tr = partial(QCoreApplication.translate, "NWProject")
return
##
@@ -431,7 +427,7 @@ class ProjectBuilder:
logger.error("No project path set for the example project")
return False
pkgSample = self.mainConf.assetPath("sample.zip")
pkgSample = CONFIG.assetPath("sample.zip")
if pkgSample.is_file():
try:
shutil.unpack_archive(pkgSample, projPath)
+3 -4
View File
@@ -24,10 +24,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import logging
import novelwriter
from PyQt5.QtGui import QFont, QFontInfo
from novelwriter import CONFIG
from novelwriter.error import formatException
from novelwriter.core.tomd import ToMarkdown
from novelwriter.core.toodt import ToOdt
@@ -40,7 +40,6 @@ class NWBuildDocument:
def __init__(self, project):
self._conf = novelwriter.CONFIG
self._project = project
self._build = {}
self._documents = []
@@ -164,8 +163,8 @@ class NWBuildDocument:
buildLang = self._build.get("format.buildLang", "en_GB")
hideScene = self._build.get("format.hideScene", False)
hideSection = self._build.get("format.hideSection", False)
textFont = self._build.get("format.textFont", self._conf.textFont)
textSize = self._build.get("format.textSize", self._conf.textSize)
textFont = self._build.get("format.textFont", CONFIG.textFont)
textSize = self._build.get("format.textSize", CONFIG.textSize)
lineHeight = self._build.get("format.lineHeight", 1.15)
justifyText = self._build.get("format.justifyText", False)
noStyling = self._build.get("format.noStyling", False)
+10 -11
View File
@@ -25,7 +25,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import json
import logging
import novelwriter
from time import time
from pathlib import Path
@@ -33,6 +32,7 @@ from functools import partial
from PyQt5.QtCore import QCoreApplication, QObject, pyqtSignal
from novelwriter import CONFIG, __version__, __hexversion__
from novelwriter.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert
from novelwriter.error import logException
from novelwriter.constants import trConst, nwFiles, nwLabels
@@ -58,8 +58,7 @@ class NWProject(QObject):
super().__init__(parent=mainGui)
# Internal
self.mainConf = novelwriter.CONFIG
self.mainGui = mainGui
self.mainGui = mainGui
# Core Elements
self._options = OptionState(self) # Project-specific GUI options
@@ -328,7 +327,7 @@ class NWProject(QObject):
# Check novelWriter Version
# =========================
if xmlReader.hexVersion > hexToInt(novelwriter.__hexversion__):
if xmlReader.hexVersion > hexToInt(__hexversion__):
msgYes = self.mainGui.askQuestion(
self.tr("Version Conflict"),
self.tr(
@@ -337,7 +336,7 @@ class NWProject(QObject):
"continue to open the project, some attributes and "
"settings may not be preserved, but the overall project "
"should be fine. Continue opening the project?"
).format(appVersion, novelwriter.__version__)
).format(appVersion, __version__)
)
if not msgYes:
self.clearProject()
@@ -351,7 +350,7 @@ class NWProject(QObject):
self._loadProjectLocalisation()
# Update recent projects
self.mainConf.recentProjects.update(
CONFIG.recentProjects.update(
self._storage.storagePath, self._data.name, sum(self._data.initCounts), time()
)
@@ -422,7 +421,7 @@ class NWProject(QObject):
self._storage.runPostSaveTasks(autoSave=autoSave)
# Update recent projects
self.mainConf.recentProjects.update(
CONFIG.recentProjects.update(
self._storage.storagePath, self._data.name, sum(self._data.currCounts), saveTime
)
@@ -455,7 +454,7 @@ class NWProject(QObject):
logger.info("Backing up project")
self.mainGui.setStatus(self.tr("Backing up project ..."))
backupPath = self.mainConf.backupPath()
backupPath = CONFIG.backupPath()
if not isinstance(backupPath, Path):
self.mainGui.makeAlert(self.tr(
"Cannot backup project because no valid backup path is set. "
@@ -677,13 +676,13 @@ class NWProject(QObject):
def _loadProjectLocalisation(self):
"""Load the language data for the current project language.
"""
if self._data.language is None or self.mainConf._nwLangPath is None:
if self._data.language is None or CONFIG._nwLangPath is None:
self._langData = {}
return False
langFile = Path(self.mainConf._nwLangPath) / f"project_{self._data.language}.json"
langFile = Path(CONFIG._nwLangPath) / f"project_{self._data.language}.json"
if not langFile.is_file():
langFile = Path(self.mainConf._nwLangPath) / "project_en_GB.json"
langFile = Path(CONFIG._nwLangPath) / "project_en_GB.json"
try:
with open(langFile, mode="r", encoding="utf-8") as inFile:
+3 -3
View File
@@ -26,13 +26,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import logging
import novelwriter
from enum import Enum
from lxml import etree
from time import time
from pathlib import Path
from novelwriter import __version__, __hexversion__
from novelwriter.common import (
checkBool, checkInt, checkString, checkStringNone, formatTimeStamp,
hexToInt, simplified, yesNo
@@ -501,8 +501,8 @@ class ProjectXMLWriter:
logger.debug("Writing project XML")
xRoot = etree.Element("novelWriterXML", attrib={
"appVersion": str(novelwriter.__version__),
"hexVersion": str(novelwriter.__hexversion__),
"appVersion": str(__version__),
"hexVersion": str(__hexversion__),
"fileVersion": FILE_VERSION,
"timeStamp": formatTimeStamp(saveTime),
})
+5 -5
View File
@@ -26,11 +26,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import random
import logging
import novelwriter
from PyQt5.QtGui import QIcon, QPainter, QPainterPath, QPixmap, QColor
from PyQt5.QtCore import QRectF, Qt
from novelwriter import CONFIG
from novelwriter.common import minmax, simplified
logger = logging.getLogger(__name__)
@@ -47,11 +47,11 @@ class NWStatus:
self._store = {}
self._default = None
self._iPX = novelwriter.CONFIG.pxInt(24)
self._iPX = CONFIG.pxInt(24)
pA = novelwriter.CONFIG.pxInt(2)
pB = novelwriter.CONFIG.pxInt(20)
pR = float(novelwriter.CONFIG.pxInt(4))
pA = CONFIG.pxInt(2)
pB = CONFIG.pxInt(20)
pR = float(CONFIG.pxInt(4))
self._iconPath = QPainterPath()
self._iconPath.addRoundedRect(QRectF(pA, pA, pB, pB), pR, pR)
+3 -4
View File
@@ -24,12 +24,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import logging
import novelwriter
from time import time
from pathlib import Path
from zipfile import ZIP_DEFLATED, ZIP_STORED, ZipFile
from novelwriter import CONFIG
from novelwriter.error import logException
from novelwriter.common import minmax
from novelwriter.constants import nwFiles
@@ -47,7 +47,6 @@ class NWStorage:
def __init__(self, theProject):
self.mainConf = novelwriter.CONFIG
self.theProject = theProject
self._storagePath = None
@@ -220,8 +219,8 @@ class NWStorage:
return False
data = [
self.mainConf.hostName, self.mainConf.osType,
self.mainConf.kernelVer, str(int(time()))
CONFIG.hostName, CONFIG.osType,
CONFIG.kernelVer, str(int(time()))
]
try:
self._lockFilePath.write_text(";".join(data), encoding="utf-8")
+3 -2
View File
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import logging
from novelwriter import CONFIG
from novelwriter.constants import nwKeyWords, nwLabels, nwHtmlUnicode
from novelwriter.core.tokenizer import Tokenizer, stripEscape
@@ -204,9 +205,9 @@ class ToHtml(Tokenizer):
aStyle.append("margin-top: 0;")
if tStyle & self.A_IND_L:
aStyle.append(f"margin-left: {self.mainConf.tabWidth:d}px;")
aStyle.append(f"margin-left: {CONFIG.tabWidth:d}px;")
if tStyle & self.A_IND_R:
aStyle.append(f"margin-right: {self.mainConf.tabWidth:d}px;")
aStyle.append(f"margin-right: {CONFIG.tabWidth:d}px;")
if len(aStyle) > 0:
stVals = " ".join(aStyle)
-2
View File
@@ -25,7 +25,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import re
import logging
import novelwriter
from abc import ABC, abstractmethod
from operator import itemgetter
@@ -92,7 +91,6 @@ class Tokenizer(ABC):
def __init__(self, theProject):
self.theProject = theProject
self.mainConf = novelwriter.CONFIG
# Data Variables
self._theText = "" # The raw text to be tokenized
+2 -2
View File
@@ -24,13 +24,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import logging
import novelwriter
from lxml import etree
from hashlib import sha256
from zipfile import ZipFile
from datetime import datetime
from novelwriter import __version__
from novelwriter.constants import nwKeyWords, nwLabels
from novelwriter.core.tokenizer import Tokenizer, stripEscape
@@ -336,7 +336,7 @@ class ToOdt(Tokenizer):
xMeta.text = timeStamp
xMeta = etree.SubElement(self._xMeta, _mkTag("meta", "generator"))
xMeta.text = f"novelWriter/{novelwriter.__version__}"
xMeta.text = f"novelWriter/{__version__}"
xMeta = etree.SubElement(self._xMeta, _mkTag("meta", "initial-creator"))
xMeta.text = self.theProject.data.author