Added project settings GUI

This commit is contained in:
Veronica K. B. Olsen
2018-10-25 23:33:13 +02:00
parent 1104baef22
commit 3b90eea7cb
6 changed files with 191 additions and 44 deletions
+50 -17
View File
@@ -13,20 +13,32 @@
import logging
import nw
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QGroupBox, QFormLayout, QLabel, QLineEdit, QPlainTextEdit, QPushButton, QFileDialog
from os import path
from PyQt5.QtWidgets import QDialog, QHBoxLayout, QVBoxLayout, QGroupBox, QFormLayout, QLabel, QLineEdit, QPlainTextEdit, QPushButton
from PyQt5.QtSvg import QSvgWidget
from PyQt5.QtGui import QIcon
logger = logging.getLogger(__name__)
class GuiProjectEditor(QWidget):
class GuiProjectEditor(QDialog):
def __init__(self):
QWidget.__init__(self)
def __init__(self, guiParent, theProject):
QDialog.__init__(self, guiParent)
logger.debug("Initialising ProjectEditor ...")
self.outerBox = QVBoxLayout()
self.mainConf = nw.CONFIG
self.theProject = theProject
self.outerBox = QHBoxLayout()
self.innerBox = QVBoxLayout()
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("Project Settings")
self.mainForm = QFormLayout()
@@ -34,29 +46,50 @@ class GuiProjectEditor(QWidget):
self.editName = QLineEdit()
self.editTitle = QLineEdit()
self.editAuthors = QPlainTextEdit()
self.saveBox = QHBoxLayout()
self.savePath = QLineEdit()
self.saveButton = QPushButton(QIcon.fromTheme("folder"),"Browse")
self.saveButton.setToolTip("Browse for Save Path")
self.saveButton.clicked.connect(self._browseProjectPath)
self.saveBox.addWidget(self.savePath)
self.saveBox.addWidget(self.saveButton)
self.mainForm.addRow("Working Title", self.editName)
self.mainForm.addRow("Book Title", self.editTitle)
self.mainForm.addRow("Book Authors", self.editAuthors)
self.mainForm.addRow("Save Path", self.saveBox)
self.editName.setText(self.theProject.projName)
self.editTitle.setText(self.theProject.bookTitle)
bookAuthors = ""
for bookAuthor in self.theProject.bookAuthors:
bookAuthors += bookAuthor+"\n"
self.editAuthors.setPlainText(bookAuthors)
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.outerBox.addWidget(self.mainGroup)
self.innerBox.addWidget(self.mainGroup)
self.innerBox.addLayout(self.buttonBox)
self.show()
logger.debug("ProjectEditor initialisation complete")
return
def _browseProjectPath(self):
fileName, _ = QFileDialog.getSaveFileName(self,"Project File Name","","novelWriter File (*.nwf);;All Files (*)")
self.savePath.setText(fileName)
def _doSave(self):
logger.vverbose("ProjectEditor 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.vverbose("ProjectEditor close button clicked")
self.close()
return
# END Class GuiProjectEditor