Added autosave and theme to preferences dialog

This commit is contained in:
Veronica K. B. Olsen
2019-06-10 14:41:32 +02:00
parent c30886732a
commit ca0a756fe5
9 changed files with 177 additions and 28 deletions
+73 -8
View File
@@ -20,8 +20,7 @@ from PyQt5.QtGui import QIcon, QPixmap, QColor, QBrush, QStandardItemModel
from PyQt5.QtSvg import QSvgWidget
from PyQt5.QtWidgets import (
QDialog, QHBoxLayout, QVBoxLayout, QFormLayout, QLineEdit, QPlainTextEdit, QLabel,
QWidget, QTabWidget, QDialogButtonBox, QListWidget, QListWidgetItem, QPushButton,
QColorDialog, QAbstractItemView, QTreeWidget, QTreeWidgetItem
QWidget, QTabWidget, QDialogButtonBox, QSpinBox, QGroupBox, QComboBox, QMessageBox
)
from nw.enum import nwAlert
@@ -40,7 +39,7 @@ class GuiConfigEditor(QDialog):
self.outerBox = QHBoxLayout()
self.innerBox = QVBoxLayout()
self.setWindowTitle("%s Configuration" % nw.__package__)
self.setWindowTitle("Preferences")
self.gradPath = path.abspath(path.join(self.mainConf.appPath,"graphics","block.svg"))
self.svgGradient = QSvgWidget(self.gradPath)
@@ -70,8 +69,21 @@ class GuiConfigEditor(QDialog):
return
def _doSave(self):
logger.verbose("ConfigEditor save button clicked")
self.close()
needsRestart = False
needsRestart |= self.tabMain.saveValues()
if needsRestart:
msgBox = QMessageBox()
msgBox.information(
self, "Preferences",
"Some changes will not be applied until<br>%s has been restarted." % nw.__package__
)
self.accept()
return
def _doClose(self):
@@ -86,12 +98,65 @@ class GuiConfigEditGeneral(QWidget):
def __init__(self, theParent, theProject):
QWidget.__init__(self, theParent)
self.theParent = theParent
self.theProject = theProject
self.mainForm = QFormLayout()
self.mainConf = nw.CONFIG
self.theParent = theParent
self.theProject = theProject
self.outerBox = QVBoxLayout()
self.setLayout(self.mainForm)
# User Interface
self.guiLook = QGroupBox("User Interface", self)
self.guiLookForm = QFormLayout(self)
self.guiLook.setLayout(self.guiLookForm)
self.theThemes = self.theParent.theTheme.listThemes()
self.guiLookTheme = QComboBox()
for themeDir, themeName in self.theThemes:
self.guiLookTheme.addItem(themeName, themeDir)
themeIdx = self.guiLookTheme.findData(self.mainConf.guiTheme)
if themeIdx != -1:
self.guiLookTheme.setCurrentIndex(themeIdx)
self.guiLookForm.addRow("Theme", self.guiLookTheme)
# AutoSave
self.autoSave = QGroupBox("Auto-Save", self)
self.autoSaveForm = QFormLayout(self)
self.autoSave.setLayout(self.autoSaveForm)
self.autoSaveDoc = QSpinBox(self)
self.autoSaveDoc.setMinimum(5)
self.autoSaveDoc.setMaximum(600)
self.autoSaveDoc.setSingleStep(1)
self.autoSaveDoc.setValue(self.mainConf.autoSaveDoc)
self.autoSaveForm.addRow("Save Document (seconds)", self.autoSaveDoc)
self.autoSaveProj = QSpinBox(self)
self.autoSaveProj.setMinimum(5)
self.autoSaveProj.setMaximum(600)
self.autoSaveProj.setSingleStep(1)
self.autoSaveProj.setValue(self.mainConf.autoSaveProj)
self.autoSaveForm.addRow("Save Project (seconds)", self.autoSaveProj)
self.outerBox.addWidget(self.guiLook)
self.outerBox.addWidget(self.autoSave)
self.setLayout(self.outerBox)
return
def saveValues(self):
autoSaveDoc = self.autoSaveDoc.value()
autoSaveProj = self.autoSaveProj.value()
guiTheme = self.guiLookTheme.currentData()
# Check if restart is needed
needsRestart = False
needsRestart |= self.mainConf.guiTheme != guiTheme
self.mainConf.autoSaveDoc = autoSaveDoc
self.mainConf.autoSaveProj = autoSaveProj
self.mainConf.guiTheme = guiTheme
self.mainConf.confChanged = True
return needsRestart
# END Class GuiConfigEditGeneral
+15 -8
View File
@@ -19,7 +19,7 @@ from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtGui import QIcon, QPixmap, QColor
from PyQt5.QtWidgets import (
qApp, QWidget, QMainWindow, QVBoxLayout, QFrame, QSplitter, QFileDialog,
QShortcut, QMessageBox, QProgressDialog
QShortcut, QMessageBox, QProgressDialog, QDialog
)
from nw.gui.doctree import GuiDocTree
@@ -50,7 +50,7 @@ class GuiMain(QMainWindow):
logger.debug("Initialising GUI ...")
self.mainConf = nw.CONFIG
self.theTheme = Theme()
self.theTheme = Theme(self)
self.theProject = NWProject(self)
self.theIndex = NWIndex(self.theProject, self)
self.hasProject = False
@@ -119,15 +119,11 @@ class GuiMain(QMainWindow):
# Set Up Autosaving Project Timer
self.asProjTimer = QTimer()
self.asProjTimer.setInterval(int(self.mainConf.autoSaveProj*1000))
self.asProjTimer.timeout.connect(self._autoSaveProject)
self.asProjTimer.start()
# Set Up Autosaving Document Timer
self.asDocTimer = QTimer()
self.asDocTimer.setInterval(int(self.mainConf.autoSaveDoc*1000))
self.asDocTimer.timeout.connect(self._autoSaveDocument)
self.asDocTimer.start()
# Keyboard Shortcuts
QShortcut(Qt.Key_Return, self.treeView, context=Qt.WidgetShortcut, activated=self._treeKeyPressReturn)
@@ -139,6 +135,10 @@ class GuiMain(QMainWindow):
if self.mainConf.showGUI:
self.show()
self.initMain()
self.asProjTimer.start()
self.asDocTimer.start()
logger.debug("GUI initialisation complete")
return
@@ -150,6 +150,11 @@ class GuiMain(QMainWindow):
self.statusBar.clearStatus()
return True
def initMain(self):
self.asProjTimer.setInterval(int(self.mainConf.autoSaveProj*1000))
self.asDocTimer.setInterval(int(self.mainConf.autoSaveDoc*1000))
return True
##
# Project Actions
##
@@ -456,8 +461,10 @@ class GuiMain(QMainWindow):
return None
def editConfigDialog(self):
dlgProj = GuiConfigEditor(self, self.theProject)
dlgProj.exec_()
dlgConf = GuiConfigEditor(self, self.theProject)
if dlgConf.exec_() == QDialog.Accepted:
logger.debug("Applying new preferences")
self.initMain()
return True
def editProjectDialog(self):