From bd24b589267b88a8fa551705dbc85f8305339bfb Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Sat, 27 Apr 2019 16:29:00 +0200 Subject: [PATCH] Added an item editor --- nw/gui/itemeditor.py | 95 ++++++++++++++++++++++++++++++++++++++++++++ nw/gui/mainmenu.py | 1 + nw/gui/winmain.py | 17 ++++++++ 3 files changed, 113 insertions(+) create mode 100644 nw/gui/itemeditor.py diff --git a/nw/gui/itemeditor.py b/nw/gui/itemeditor.py new file mode 100644 index 00000000..6a93c627 --- /dev/null +++ b/nw/gui/itemeditor.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- +"""novelWriter GUI Item Editor + + novelWriter – GUI Item Editor +=============================== + Class holding the item editor + + File History: + Created: 2019-04-27 [0.0.1] + +""" + +import logging +import nw + +from os import path + +from PyQt5.QtWidgets import QDialog, QHBoxLayout, QVBoxLayout, QGroupBox, QFormLayout, QLineEdit, QPushButton +from PyQt5.QtSvg import QSvgWidget + +logger = logging.getLogger(__name__) + +class GuiItemEditor(QDialog): + + def __init__(self, guiParent, theProject, tHandle): + QDialog.__init__(self, guiParent) + + logger.debug("Initialising ItemEditor ...") + + self.mainConf = nw.CONFIG + self.theProject = theProject + self.theItem = self.theProject.getItem(tHandle) + + self.outerBox = QHBoxLayout() + self.innerBox = QVBoxLayout() + + self.setWindowTitle("Item Settings") + + self.gradPath = path.abspath(path.join(self.mainConf.appPath,"graphics","block.svg")) + self.svgGradient = QSvgWidget(self.gradPath) + self.svgGradient.setFixedWidth(80) + self.setLayout(self.outerBox) + self.outerBox.addWidget(self.svgGradient) + self.outerBox.addLayout(self.innerBox) + + self.mainGroup = QGroupBox("Item Settings") + self.mainForm = QFormLayout() + + self.editName = QLineEdit() + self.editStatus = QLineEdit() + self.editLayout = QLineEdit() + + self.mainForm.addRow("Name", self.editName) + self.mainForm.addRow("Status", self.editStatus) + self.mainForm.addRow("Layout", self.editLayout) + + self.editName.setText(self.theItem.itemName) + self.editStatus.setText(str(self.theItem.itemStatus)) + self.editLayout.setText(str(self.theItem.itemLayout)) + + self.buttonBox = QHBoxLayout() + self.closeButton = QPushButton("Close") + self.closeButton.clicked.connect(self._doClose) + self.saveButton = QPushButton("Save") + self.saveButton.clicked.connect(self._doSave) + self.buttonBox.addStretch(1) + self.buttonBox.addWidget(self.closeButton) + self.buttonBox.addWidget(self.saveButton) + + self.mainGroup.setLayout(self.mainForm) + self.innerBox.addWidget(self.mainGroup) + self.innerBox.addLayout(self.buttonBox) + + self.show() + + logger.debug("ItemEditor initialisation complete") + + return + + def _doSave(self): + logger.verbose("ItemEditor save button clicked") + # projName = self.editName.text() + # bookTitle = self.editTitle.text() + # bookAuthors = self.editAuthors.toPlainText() + # self.theProject.setProjectName(projName) + # self.theProject.setBookTitle(bookTitle) + # self.theProject.setBookAuthors(bookAuthors) + return + + def _doClose(self): + logger.verbose("ItemEditor close button clicked") + self.close() + return + +# END Class GuiItemEditor diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index 7e0ee462..c34fd2af 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -205,6 +205,7 @@ class GuiMainMenu(QMenuBar): menuItem = QAction(QIcon.fromTheme("document-properties"), "&Edit Document", self) menuItem.setStatusTip("Change Document Settings") menuItem.setShortcut("Ctrl+E") + menuItem.triggered.connect(self.theParent.editItem) self.docuMenu.addAction(menuItem) # Document > Delete diff --git a/nw/gui/winmain.py b/nw/gui/winmain.py index d1e9be29..d7f15298 100644 --- a/nw/gui/winmain.py +++ b/nw/gui/winmain.py @@ -24,6 +24,7 @@ from nw.gui.doceditor import GuiDocEditor from nw.gui.docdetails import GuiDocDetails from nw.gui.mainmenu import GuiMainMenu from nw.gui.projecteditor import GuiProjectEditor +from nw.gui.itemeditor import GuiItemEditor from nw.gui.statusbar import GuiMainStatus from nw.project.project import NWProject from nw.project.document import NWDoc @@ -144,6 +145,22 @@ class GuiMain(QMainWindow): self.theDocument.saveDocument(docHtml) return + ## + # Tree Item Actions + ## + + def editItem(self): + tHandle = self.treeView.getSelectedHandle() + logger.verbose("Requesting change to item %s" % tHandle) + if tHandle is None: + logger.warning("No item selected") + return + + dlgProj = GuiItemEditor(self, self.theProject, tHandle) + dlgProj.exec_() + + return + ## # Main Dialogs ##