Added an item editor

This commit is contained in:
Veronica K. B. Olsen
2019-04-27 16:29:00 +02:00
parent 7c6393302a
commit bd24b58926
3 changed files with 113 additions and 0 deletions
+95
View File
@@ -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
+1
View File
@@ -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
+17
View File
@@ -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
##