Make build settings dialog work with single settings object
This commit is contained in:
@@ -31,7 +31,6 @@ from PyQt5.QtWidgets import (
|
|||||||
QWidget, qApp
|
QWidget, qApp
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter.common import getGuiItem
|
|
||||||
from novelwriter.tools.manussettings import GuiBuildSettings
|
from novelwriter.tools.manussettings import GuiBuildSettings
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -115,17 +114,14 @@ class GuiBuildManuscript(QDialog):
|
|||||||
def _createNewBuild(self):
|
def _createNewBuild(self):
|
||||||
"""Open the build settings dialog for a new build.
|
"""Open the build settings dialog for a new build.
|
||||||
"""
|
"""
|
||||||
dlgSettings = getGuiItem("GuiBuildSettings")
|
data = {"name": self.tr("My Manuscript")}
|
||||||
if dlgSettings is None:
|
|
||||||
dlgSettings = GuiBuildSettings(self)
|
|
||||||
assert isinstance(dlgSettings, GuiBuildSettings)
|
|
||||||
|
|
||||||
|
dlgSettings = GuiBuildSettings(self.mainGui, data)
|
||||||
dlgSettings.setModal(False)
|
dlgSettings.setModal(False)
|
||||||
dlgSettings.show()
|
dlgSettings.show()
|
||||||
dlgSettings.raise_()
|
dlgSettings.raise_()
|
||||||
qApp.processEvents()
|
qApp.processEvents()
|
||||||
|
dlgSettings.loadContent()
|
||||||
dlgSettings.loadContent({"name": self.tr("My Manuscript")})
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,15 @@ General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import novelwriter
|
import novelwriter
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from PyQt5.QtGui import QIcon
|
from PyQt5.QtGui import QIcon
|
||||||
from PyQt5.QtCore import QSize, Qt, pyqtSlot
|
from PyQt5.QtCore import QEvent, QSize, Qt, pyqtSlot
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QAbstractItemView, QDialog, QGridLayout, QHBoxLayout, QHeaderView, QLabel,
|
QAbstractItemView, QDialog, QGridLayout, QHBoxLayout, QHeaderView, QLabel,
|
||||||
QLineEdit, QPushButton, QSplitter, QStackedWidget, QToolButton,
|
QLineEdit, QPushButton, QSplitter, QStackedWidget, QToolButton,
|
||||||
@@ -39,6 +42,9 @@ from novelwriter.extensions.switch import NSwitch
|
|||||||
from novelwriter.extensions.switchbox import NSwitchBox
|
from novelwriter.extensions.switchbox import NSwitchBox
|
||||||
from novelwriter.extensions.pagedsidebar import NPagedSideBar
|
from novelwriter.extensions.pagedsidebar import NPagedSideBar
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from novelwriter.guimain import GuiMain
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -52,15 +58,19 @@ class GuiBuildSettings(QDialog):
|
|||||||
BLD_MARKDOWN = 6
|
BLD_MARKDOWN = 6
|
||||||
BLD_ODT = 7
|
BLD_ODT = 7
|
||||||
|
|
||||||
def __init__(self, mainGui):
|
def __init__(self, mainGui: GuiMain, buildData: dict):
|
||||||
super().__init__(parent=mainGui)
|
super().__init__(parent=mainGui)
|
||||||
|
|
||||||
|
logger.debug("Initialising GuiBuildSettings ...")
|
||||||
|
self.setObjectName("GuiBuildSettings")
|
||||||
|
|
||||||
self.mainConf = novelwriter.CONFIG
|
self.mainConf = novelwriter.CONFIG
|
||||||
self.mainGui = mainGui
|
self.mainGui = mainGui
|
||||||
self.mainTheme = mainGui.mainTheme
|
self.mainTheme = mainGui.mainTheme
|
||||||
self.theProject = mainGui.theProject
|
self.theProject = mainGui.theProject
|
||||||
|
|
||||||
self._build = None
|
self._build = BuildSettings()
|
||||||
|
self._build.unpack(buildData)
|
||||||
|
|
||||||
self.setWindowTitle(self.tr("Manuscript Build Settings"))
|
self.setWindowTitle(self.tr("Manuscript Build Settings"))
|
||||||
self.setMinimumWidth(self.mainConf.pxInt(700))
|
self.setMinimumWidth(self.mainConf.pxInt(700))
|
||||||
@@ -102,13 +112,13 @@ class GuiBuildSettings(QDialog):
|
|||||||
# ============
|
# ============
|
||||||
|
|
||||||
# Create Tabs
|
# Create Tabs
|
||||||
self.optTabSelect = GuiBuildFilterTab(self)
|
self.optTabSelect = GuiBuildFilterTab(self, self._build)
|
||||||
self.optTabHeadings = GuiBuildHeadingsTab(self)
|
self.optTabHeadings = GuiBuildHeadingsTab(self, self._build)
|
||||||
self.optTabFormat = GuiBuildFormatTab(self)
|
self.optTabFormat = GuiBuildFormatTab(self, self._build)
|
||||||
self.optTabContent = GuiBuildContentTab(self)
|
self.optTabContent = GuiBuildContentTab(self, self._build)
|
||||||
self.buildTabHTML = GuiBuildHTMLTab(self)
|
self.buildTabHTML = GuiBuildHTMLTab(self, self._build)
|
||||||
self.buildTabMarkdown = GuiBuildMarkdownTab(self)
|
self.buildTabMarkdown = GuiBuildMarkdownTab(self, self._build)
|
||||||
self.buildTabODT = GuiBuildODTTab(self)
|
self.buildTabODT = GuiBuildODTTab(self, self._build)
|
||||||
|
|
||||||
# Add Tabs
|
# Add Tabs
|
||||||
self.toolStack = QStackedWidget(self)
|
self.toolStack = QStackedWidget(self)
|
||||||
@@ -120,29 +130,34 @@ class GuiBuildSettings(QDialog):
|
|||||||
self.toolStack.addWidget(self.buildTabMarkdown)
|
self.toolStack.addWidget(self.buildTabMarkdown)
|
||||||
self.toolStack.addWidget(self.buildTabODT)
|
self.toolStack.addWidget(self.buildTabODT)
|
||||||
|
|
||||||
# Assemble
|
# Main Settings
|
||||||
self.outerBox = QHBoxLayout()
|
# =============
|
||||||
self.outerBox.addWidget(self.optSideBar)
|
|
||||||
self.outerBox.addWidget(self.toolStack)
|
self.lblTitle = QLabel()
|
||||||
|
|
||||||
|
# Assemble GUI
|
||||||
|
# ============
|
||||||
|
|
||||||
|
self.mainBox = QHBoxLayout()
|
||||||
|
self.mainBox.addWidget(self.optSideBar)
|
||||||
|
self.mainBox.addWidget(self.toolStack)
|
||||||
|
|
||||||
|
self.outerBox = QVBoxLayout()
|
||||||
|
self.outerBox.addLayout(self.mainBox)
|
||||||
|
|
||||||
self.setLayout(self.outerBox)
|
self.setLayout(self.outerBox)
|
||||||
|
|
||||||
# Set Default Tab
|
# Set Default Tab
|
||||||
self.optSideBar.setSelected(self.OPT_FILTERS)
|
self.optSideBar.setSelected(self.OPT_FILTERS)
|
||||||
|
|
||||||
|
logger.debug("GuiBuildSettings initialisation complete")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def loadContent(self, data):
|
def loadContent(self):
|
||||||
"""Populate the child widgets.
|
"""Populate the child widgets.
|
||||||
"""
|
"""
|
||||||
if isinstance(self._build, BuildSettings) and self._build.changed:
|
|
||||||
logger.error("There are unsaved changes in this GUI")
|
|
||||||
return
|
|
||||||
|
|
||||||
self._build = BuildSettings()
|
|
||||||
self._build.unpack(data)
|
|
||||||
self.optTabSelect.loadContent(self._build)
|
self.optTabSelect.loadContent(self._build)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -150,7 +165,7 @@ class GuiBuildSettings(QDialog):
|
|||||||
##
|
##
|
||||||
|
|
||||||
@pyqtSlot(int)
|
@pyqtSlot(int)
|
||||||
def _stackPageSelected(self, pageId):
|
def _stackPageSelected(self, pageId: int):
|
||||||
"""Process a user request to switch page.
|
"""Process a user request to switch page.
|
||||||
"""
|
"""
|
||||||
if pageId == self.OPT_FILTERS:
|
if pageId == self.OPT_FILTERS:
|
||||||
@@ -173,7 +188,7 @@ class GuiBuildSettings(QDialog):
|
|||||||
# Events
|
# Events
|
||||||
##
|
##
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event: QEvent):
|
||||||
"""Capture the user closing the window so we can save settings.
|
"""Capture the user closing the window so we can save settings.
|
||||||
"""
|
"""
|
||||||
self._saveSettings()
|
self._saveSettings()
|
||||||
@@ -221,7 +236,7 @@ class GuiBuildFilterTab(QWidget):
|
|||||||
F_INCLUDED = 2
|
F_INCLUDED = 2
|
||||||
F_EXCLUDED = 3
|
F_EXCLUDED = 3
|
||||||
|
|
||||||
def __init__(self, buildMain):
|
def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings):
|
||||||
super().__init__(parent=buildMain)
|
super().__init__(parent=buildMain)
|
||||||
|
|
||||||
self.mainConf = novelwriter.CONFIG
|
self.mainConf = novelwriter.CONFIG
|
||||||
@@ -230,7 +245,7 @@ class GuiBuildFilterTab(QWidget):
|
|||||||
self.theProject = buildMain.mainGui.theProject
|
self.theProject = buildMain.mainGui.theProject
|
||||||
|
|
||||||
self._treeMap = {}
|
self._treeMap = {}
|
||||||
self._build = None
|
self._build = build
|
||||||
|
|
||||||
self._statusFlags = {
|
self._statusFlags = {
|
||||||
self.F_NONE: ("", QIcon()),
|
self.F_NONE: ("", QIcon()),
|
||||||
@@ -321,7 +336,7 @@ class GuiBuildFilterTab(QWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def loadContent(self, build):
|
def loadContent(self, build: BuildSettings):
|
||||||
"""Populate the widgets.
|
"""Populate the widgets.
|
||||||
"""
|
"""
|
||||||
self._build = build
|
self._build = build
|
||||||
@@ -329,7 +344,7 @@ class GuiBuildFilterTab(QWidget):
|
|||||||
self._populateFilters()
|
self._populateFilters()
|
||||||
return
|
return
|
||||||
|
|
||||||
def mainSplitSizes(self):
|
def mainSplitSizes(self) -> tuple[int, int]:
|
||||||
"""Extract the sizes of the main splitter.
|
"""Extract the sizes of the main splitter.
|
||||||
"""
|
"""
|
||||||
sizes = self.mainSplit.sizes()
|
sizes = self.mainSplit.sizes()
|
||||||
@@ -342,11 +357,9 @@ class GuiBuildFilterTab(QWidget):
|
|||||||
##
|
##
|
||||||
|
|
||||||
@pyqtSlot(str, bool)
|
@pyqtSlot(str, bool)
|
||||||
def _applyFilterSwitch(self, key, state):
|
def _applyFilterSwitch(self, key: str, state: bool):
|
||||||
"""A filter switch has been toggled, so update the settings.
|
"""A filter switch has been toggled, so update the settings.
|
||||||
"""
|
"""
|
||||||
if not isinstance(self._build, BuildSettings):
|
|
||||||
return
|
|
||||||
if key.startswith("doc:"):
|
if key.startswith("doc:"):
|
||||||
self._build.setValue(key[4:], state)
|
self._build.setValue(key[4:], state)
|
||||||
self._setTreeItemMode()
|
self._setTreeItemMode()
|
||||||
@@ -362,9 +375,6 @@ class GuiBuildFilterTab(QWidget):
|
|||||||
def _populateTree(self):
|
def _populateTree(self):
|
||||||
"""Build the tree of project items.
|
"""Build the tree of project items.
|
||||||
"""
|
"""
|
||||||
if not isinstance(self._build, BuildSettings):
|
|
||||||
return
|
|
||||||
|
|
||||||
logger.debug("Building project tree")
|
logger.debug("Building project tree")
|
||||||
self._treeMap = {}
|
self._treeMap = {}
|
||||||
self.optTree.clear()
|
self.optTree.clear()
|
||||||
@@ -423,9 +433,6 @@ class GuiBuildFilterTab(QWidget):
|
|||||||
"""Populate the filter options switches.
|
"""Populate the filter options switches.
|
||||||
"""
|
"""
|
||||||
self.filterOpt.clear()
|
self.filterOpt.clear()
|
||||||
if not isinstance(self._build, BuildSettings):
|
|
||||||
return
|
|
||||||
|
|
||||||
self.filterOpt.addLabel(self._build.getLabel("filter"))
|
self.filterOpt.addLabel(self._build.getLabel("filter"))
|
||||||
self.filterOpt.addItem(
|
self.filterOpt.addItem(
|
||||||
self.mainTheme.getIcon("proj_scene"),
|
self.mainTheme.getIcon("proj_scene"),
|
||||||
@@ -459,12 +466,9 @@ class GuiBuildFilterTab(QWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def _setSelectedMode(self, mode):
|
def _setSelectedMode(self, mode: int):
|
||||||
"""Set the mode for the selected items.
|
"""Set the mode for the selected items.
|
||||||
"""
|
"""
|
||||||
if not isinstance(self._build, BuildSettings):
|
|
||||||
return
|
|
||||||
|
|
||||||
for item in self.optTree.selectedItems():
|
for item in self.optTree.selectedItems():
|
||||||
if not isinstance(item, QTreeWidgetItem):
|
if not isinstance(item, QTreeWidgetItem):
|
||||||
continue
|
continue
|
||||||
@@ -486,9 +490,6 @@ class GuiBuildFilterTab(QWidget):
|
|||||||
def _setTreeItemMode(self):
|
def _setTreeItemMode(self):
|
||||||
"""Update the filtered mode icon on all items.
|
"""Update the filtered mode icon on all items.
|
||||||
"""
|
"""
|
||||||
if not isinstance(self._build, BuildSettings):
|
|
||||||
return
|
|
||||||
|
|
||||||
filtered = self._build.buildItemFilter(self.theProject)
|
filtered = self._build.buildItemFilter(self.theProject)
|
||||||
for tHandle, item in self._treeMap.items():
|
for tHandle, item in self._treeMap.items():
|
||||||
allow, mode = filtered.get(tHandle, (False, FilterMode.UNKNOWN))
|
allow, mode = filtered.get(tHandle, (False, FilterMode.UNKNOWN))
|
||||||
@@ -507,7 +508,7 @@ class GuiBuildFilterTab(QWidget):
|
|||||||
|
|
||||||
class GuiBuildHeadingsTab(QWidget):
|
class GuiBuildHeadingsTab(QWidget):
|
||||||
|
|
||||||
def __init__(self, buildMain):
|
def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings):
|
||||||
super().__init__(parent=buildMain)
|
super().__init__(parent=buildMain)
|
||||||
|
|
||||||
self.mainConf = novelwriter.CONFIG
|
self.mainConf = novelwriter.CONFIG
|
||||||
@@ -515,6 +516,8 @@ class GuiBuildHeadingsTab(QWidget):
|
|||||||
self.mainTheme = buildMain.mainGui.mainTheme
|
self.mainTheme = buildMain.mainGui.mainTheme
|
||||||
self.theProject = buildMain.mainGui.theProject
|
self.theProject = buildMain.mainGui.theProject
|
||||||
|
|
||||||
|
self._build = build
|
||||||
|
|
||||||
iPx = self.mainTheme.baseIconSize
|
iPx = self.mainTheme.baseIconSize
|
||||||
vSp = self.mainConf.pxInt(12)
|
vSp = self.mainConf.pxInt(12)
|
||||||
bSp = self.mainConf.pxInt(6)
|
bSp = self.mainConf.pxInt(6)
|
||||||
@@ -629,9 +632,11 @@ class GuiBuildHeadingsTab(QWidget):
|
|||||||
|
|
||||||
class GuiBuildFormatTab(QWidget):
|
class GuiBuildFormatTab(QWidget):
|
||||||
|
|
||||||
def __init__(self, buildMain):
|
def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings):
|
||||||
super().__init__(parent=buildMain)
|
super().__init__(parent=buildMain)
|
||||||
|
|
||||||
|
self._build = build
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# END Class GuiBuildFormatTab
|
# END Class GuiBuildFormatTab
|
||||||
@@ -639,9 +644,11 @@ class GuiBuildFormatTab(QWidget):
|
|||||||
|
|
||||||
class GuiBuildContentTab(QWidget):
|
class GuiBuildContentTab(QWidget):
|
||||||
|
|
||||||
def __init__(self, buildMain):
|
def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings):
|
||||||
super().__init__(parent=buildMain)
|
super().__init__(parent=buildMain)
|
||||||
|
|
||||||
|
self._build = build
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# END Class GuiBuildContentTab
|
# END Class GuiBuildContentTab
|
||||||
@@ -649,9 +656,11 @@ class GuiBuildContentTab(QWidget):
|
|||||||
|
|
||||||
class GuiBuildHTMLTab(QWidget):
|
class GuiBuildHTMLTab(QWidget):
|
||||||
|
|
||||||
def __init__(self, buildMain):
|
def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings):
|
||||||
super().__init__(parent=buildMain)
|
super().__init__(parent=buildMain)
|
||||||
|
|
||||||
|
self._build = build
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# END Class GuiBuildHTMLTab
|
# END Class GuiBuildHTMLTab
|
||||||
@@ -659,9 +668,11 @@ class GuiBuildHTMLTab(QWidget):
|
|||||||
|
|
||||||
class GuiBuildMarkdownTab(QWidget):
|
class GuiBuildMarkdownTab(QWidget):
|
||||||
|
|
||||||
def __init__(self, buildMain):
|
def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings):
|
||||||
super().__init__(parent=buildMain)
|
super().__init__(parent=buildMain)
|
||||||
|
|
||||||
|
self._build = build
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# END Class GuiBuildMarkdownTab
|
# END Class GuiBuildMarkdownTab
|
||||||
@@ -669,9 +680,11 @@ class GuiBuildMarkdownTab(QWidget):
|
|||||||
|
|
||||||
class GuiBuildODTTab(QWidget):
|
class GuiBuildODTTab(QWidget):
|
||||||
|
|
||||||
def __init__(self, buildMain):
|
def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings):
|
||||||
super().__init__(parent=buildMain)
|
super().__init__(parent=buildMain)
|
||||||
|
|
||||||
|
self._build = build
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# END Class GuiBuildODTTab
|
# END Class GuiBuildODTTab
|
||||||
|
|||||||
Reference in New Issue
Block a user