Tie things together to ensure title is always updated, and add some needed comments here and there
This commit is contained in:
@@ -150,6 +150,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
|
|
||||||
self.setDocumentChanged(False)
|
self.setDocumentChanged(False)
|
||||||
self.theParent.noticeBar.hideNote()
|
self.theParent.noticeBar.hideNote()
|
||||||
|
self.theParent.updateEditTitle()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -264,6 +265,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
else:
|
else:
|
||||||
self.theParent.noticeBar.showNote("This document is read only.")
|
self.theParent.noticeBar.showNote("This document is read only.")
|
||||||
|
|
||||||
|
self.theParent.updateEditTitle()
|
||||||
self.hLight.spellCheck = spTemp
|
self.hLight.spellCheck = spTemp
|
||||||
qApp.restoreOverrideCursor()
|
qApp.restoreOverrideCursor()
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ class GuiDocTitleBar(QLabel):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
##
|
||||||
|
# Setters
|
||||||
|
##
|
||||||
|
|
||||||
def setTitleFromHandle(self, tHandle):
|
def setTitleFromHandle(self, tHandle):
|
||||||
"""Sets the document title from the handle, or alternatively,
|
"""Sets the document title from the handle, or alternatively,
|
||||||
set the whole document path.
|
set the whole document path.
|
||||||
@@ -91,4 +95,15 @@ class GuiDocTitleBar(QLabel):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
##
|
||||||
|
# Events
|
||||||
|
##
|
||||||
|
|
||||||
|
def mousePressEvent(self, theEvent):
|
||||||
|
"""Capture a click on the title and ensure that the item is
|
||||||
|
selected in the project tree.
|
||||||
|
"""
|
||||||
|
self.theParent.treeView.setSelectedHandle(self.theHandle)
|
||||||
|
return
|
||||||
|
|
||||||
# END Class GuiDocTitleBar
|
# END Class GuiDocTitleBar
|
||||||
|
|||||||
@@ -457,6 +457,9 @@ class GuiDocTree(QTreeWidget):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def getSelectedHandle(self):
|
def getSelectedHandle(self):
|
||||||
|
"""Get the currently selected handle. If multiple items are
|
||||||
|
selected, return the first.
|
||||||
|
"""
|
||||||
selItem = self.selectedItems()
|
selItem = self.selectedItems()
|
||||||
if len(selItem) == 0:
|
if len(selItem) == 0:
|
||||||
return None
|
return None
|
||||||
@@ -465,6 +468,8 @@ class GuiDocTree(QTreeWidget):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def getSelectedHandles(self):
|
def getSelectedHandles(self):
|
||||||
|
"""Return a list of all currently selected item handles.
|
||||||
|
"""
|
||||||
selItems = self.selectedItems()
|
selItems = self.selectedItems()
|
||||||
selHandles = []
|
selHandles = []
|
||||||
for n in range(len(selItems)):
|
for n in range(len(selItems)):
|
||||||
@@ -472,6 +477,15 @@ class GuiDocTree(QTreeWidget):
|
|||||||
selHandles.append(selItems[n].text(self.C_HANDLE))
|
selHandles.append(selItems[n].text(self.C_HANDLE))
|
||||||
return selHandles
|
return selHandles
|
||||||
|
|
||||||
|
def setSelectedHandle(self, tHandle):
|
||||||
|
"""Set a specific handle as the selected item.
|
||||||
|
"""
|
||||||
|
if tHandle in self.theMap:
|
||||||
|
self.clearSelection()
|
||||||
|
self.theMap[tHandle].setSelected(True)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
##
|
##
|
||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -69,8 +69,12 @@ class GuiDocViewer(QTextBrowser):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def clearViewer(self):
|
def clearViewer(self):
|
||||||
|
"""Clear the content of the document and reset key variables.
|
||||||
|
"""
|
||||||
self.clear()
|
self.clear()
|
||||||
self.setSearchPaths([""])
|
self.setSearchPaths([""])
|
||||||
|
self.theHandle = None
|
||||||
|
self.theParent.updateViewTitle()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def initViewer(self):
|
def initViewer(self):
|
||||||
@@ -108,6 +112,8 @@ class GuiDocViewer(QTextBrowser):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def loadText(self, tHandle):
|
def loadText(self, tHandle):
|
||||||
|
"""Load text into the viewer from an item handle.
|
||||||
|
"""
|
||||||
|
|
||||||
tItem = self.theProject.getItem(tHandle)
|
tItem = self.theProject.getItem(tHandle)
|
||||||
if tItem is None:
|
if tItem is None:
|
||||||
@@ -132,7 +138,9 @@ class GuiDocViewer(QTextBrowser):
|
|||||||
self.theHandle = tHandle
|
self.theHandle = tHandle
|
||||||
self.theProject.setLastViewed(tHandle)
|
self.theProject.setLastViewed(tHandle)
|
||||||
|
|
||||||
|
# Make sure the main GUI knows we changed the content
|
||||||
self.theParent.viewMeta.refreshReferences(tHandle)
|
self.theParent.viewMeta.refreshReferences(tHandle)
|
||||||
|
self.theParent.updateViewTitle()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
+43
-6
@@ -65,6 +65,11 @@ class GuiMain(QMainWindow):
|
|||||||
self.hasProject = False
|
self.hasProject = False
|
||||||
self.isZenMode = False
|
self.isZenMode = False
|
||||||
|
|
||||||
|
# Init early to avoid circular dependencies
|
||||||
|
self.docEditor = None
|
||||||
|
self.docViewer = None
|
||||||
|
|
||||||
|
# Some runtime info useful for debugging
|
||||||
logger.info("OS: %s" % self.mainConf.osType)
|
logger.info("OS: %s" % self.mainConf.osType)
|
||||||
logger.info("Kernel: %s" % self.mainConf.kernelVer)
|
logger.info("Kernel: %s" % self.mainConf.kernelVer)
|
||||||
logger.info("Host: %s" % self.mainConf.hostName)
|
logger.info("Host: %s" % self.mainConf.hostName)
|
||||||
@@ -78,13 +83,19 @@ class GuiMain(QMainWindow):
|
|||||||
self.mainConf.verPyString, self.mainConf.verPyHexVal)
|
self.mainConf.verPyString, self.mainConf.verPyHexVal)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Prepare main window
|
||||||
self.resize(*self.mainConf.winGeometry)
|
self.resize(*self.mainConf.winGeometry)
|
||||||
self._setWindowTitle()
|
self._setWindowTitle()
|
||||||
self.setWindowIcon(QIcon(self.mainConf.appIcon))
|
self.setWindowIcon(QIcon(self.mainConf.appIcon))
|
||||||
|
|
||||||
|
# Build the GUI
|
||||||
|
################
|
||||||
|
|
||||||
# Main GUI Elements
|
# Main GUI Elements
|
||||||
self.statusBar = GuiMainStatus(self)
|
self.statusBar = GuiMainStatus(self)
|
||||||
self.noticeBar = GuiNoticeBar(self)
|
self.noticeBar = GuiNoticeBar(self)
|
||||||
|
self.viewTitle = GuiDocTitleBar(self, self.theProject)
|
||||||
|
self.editTitle = GuiDocTitleBar(self, self.theProject)
|
||||||
self.docEditor = GuiDocEditor(self, self.theProject)
|
self.docEditor = GuiDocEditor(self, self.theProject)
|
||||||
self.docViewer = GuiDocViewer(self, self.theProject)
|
self.docViewer = GuiDocViewer(self, self.theProject)
|
||||||
self.viewMeta = GuiDocViewDetails(self, self.theProject)
|
self.viewMeta = GuiDocViewDetails(self, self.theProject)
|
||||||
@@ -93,8 +104,6 @@ class GuiMain(QMainWindow):
|
|||||||
self.treeView = GuiDocTree(self, self.theProject)
|
self.treeView = GuiDocTree(self, self.theProject)
|
||||||
self.projView = GuiProjectOutline(self, self.theProject)
|
self.projView = GuiProjectOutline(self, self.theProject)
|
||||||
self.mainMenu = GuiMainMenu(self, self.theProject)
|
self.mainMenu = GuiMainMenu(self, self.theProject)
|
||||||
self.viewTitle = GuiDocTitleBar(self, self.theProject)
|
|
||||||
self.editTitle = GuiDocTitleBar(self, self.theProject)
|
|
||||||
|
|
||||||
# Minor Gui Elements
|
# Minor Gui Elements
|
||||||
self.statusIcons = []
|
self.statusIcons = []
|
||||||
@@ -168,7 +177,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.viewPane.setVisible(False)
|
self.viewPane.setVisible(False)
|
||||||
self.searchBar.setVisible(False)
|
self.searchBar.setVisible(False)
|
||||||
|
|
||||||
# Build The Tree View
|
# Build the Tree View
|
||||||
self.treeView.itemSelectionChanged.connect(self._treeSingleClick)
|
self.treeView.itemSelectionChanged.connect(self._treeSingleClick)
|
||||||
self.treeView.itemDoubleClicked.connect(self._treeDoubleClick)
|
self.treeView.itemDoubleClicked.connect(self._treeDoubleClick)
|
||||||
self.rebuildTree()
|
self.rebuildTree()
|
||||||
@@ -178,6 +187,9 @@ class GuiMain(QMainWindow):
|
|||||||
self.setStatusBar(self.statusBar)
|
self.setStatusBar(self.statusBar)
|
||||||
self.statusBar.setStatus("Ready")
|
self.statusBar.setStatus("Ready")
|
||||||
|
|
||||||
|
# Finalise Initialisation
|
||||||
|
##########################
|
||||||
|
|
||||||
# Set Up Autosaving Project Timer
|
# Set Up Autosaving Project Timer
|
||||||
self.asProjTimer = QTimer()
|
self.asProjTimer = QTimer()
|
||||||
self.asProjTimer.timeout.connect(self._autoSaveProject)
|
self.asProjTimer.timeout.connect(self._autoSaveProject)
|
||||||
@@ -216,6 +228,8 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
logger.debug("GUI initialisation complete")
|
logger.debug("GUI initialisation complete")
|
||||||
|
|
||||||
|
# Check if a project path was provided at command line, and if
|
||||||
|
# not, open the project manager instead.
|
||||||
if self.mainConf.cmdOpen is not None:
|
if self.mainConf.cmdOpen is not None:
|
||||||
logger.debug("Opening project from additional command line option")
|
logger.debug("Opening project from additional command line option")
|
||||||
self.openProject(self.mainConf.cmdOpen)
|
self.openProject(self.mainConf.cmdOpen)
|
||||||
@@ -234,6 +248,8 @@ class GuiMain(QMainWindow):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def initMain(self):
|
def initMain(self):
|
||||||
|
"""Initialise elements that depend on user settings.
|
||||||
|
"""
|
||||||
self.asProjTimer.setInterval(int(self.mainConf.autoSaveProj*1000))
|
self.asProjTimer.setInterval(int(self.mainConf.autoSaveProj*1000))
|
||||||
self.asDocTimer.setInterval(int(self.mainConf.autoSaveDoc*1000))
|
self.asDocTimer.setInterval(int(self.mainConf.autoSaveDoc*1000))
|
||||||
return True
|
return True
|
||||||
@@ -443,6 +459,8 @@ class GuiMain(QMainWindow):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def backupProject(self):
|
def backupProject(self):
|
||||||
|
"""Trigger the project backup process.
|
||||||
|
"""
|
||||||
theBackup = NWBackup(self, self.theProject)
|
theBackup = NWBackup(self, self.theProject)
|
||||||
theBackup.zipIt()
|
theBackup.zipIt()
|
||||||
return True
|
return True
|
||||||
@@ -458,7 +476,6 @@ class GuiMain(QMainWindow):
|
|||||||
if self.docEditor.docChanged:
|
if self.docEditor.docChanged:
|
||||||
self.saveDocument()
|
self.saveDocument()
|
||||||
self.docEditor.clearEditor()
|
self.docEditor.clearEditor()
|
||||||
self.editTitle.setTitleFromHandle(None)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def openDocument(self, tHandle, tLine=None):
|
def openDocument(self, tHandle, tLine=None):
|
||||||
@@ -470,7 +487,7 @@ class GuiMain(QMainWindow):
|
|||||||
if self.docEditor.loadText(tHandle, tLine):
|
if self.docEditor.loadText(tHandle, tLine):
|
||||||
self.docEditor.setFocus()
|
self.docEditor.setFocus()
|
||||||
self.theProject.setLastEdited(tHandle)
|
self.theProject.setLastEdited(tHandle)
|
||||||
self.editTitle.setTitleFromHandle(tHandle)
|
self.treeView.setSelectedHandle(tHandle)
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@@ -500,7 +517,6 @@ class GuiMain(QMainWindow):
|
|||||||
self.tabWidget.setCurrentWidget(self.splitView)
|
self.tabWidget.setCurrentWidget(self.splitView)
|
||||||
|
|
||||||
if self.docViewer.loadText(tHandle) and not self.viewPane.isVisible():
|
if self.docViewer.loadText(tHandle) and not self.viewPane.isVisible():
|
||||||
self.viewTitle.setTitleFromHandle(tHandle)
|
|
||||||
bPos = self.splitMain.sizes()
|
bPos = self.splitMain.sizes()
|
||||||
self.viewPane.setVisible(True)
|
self.viewPane.setVisible(True)
|
||||||
vPos = [0,0]
|
vPos = [0,0]
|
||||||
@@ -511,6 +527,9 @@ class GuiMain(QMainWindow):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def importDocument(self):
|
def importDocument(self):
|
||||||
|
"""Import the text contained in an out-of-project text file, and
|
||||||
|
insert the text into the currently open document.
|
||||||
|
"""
|
||||||
|
|
||||||
lastPath = self.mainConf.lastPath
|
lastPath = self.mainConf.lastPath
|
||||||
|
|
||||||
@@ -595,6 +614,24 @@ class GuiMain(QMainWindow):
|
|||||||
logger.debug("Document action requested, but no document has focus")
|
logger.debug("Document action requested, but no document has focus")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def updateEditTitle(self):
|
||||||
|
"""Ensure the editor title is up to date with the editor text.
|
||||||
|
This should only be called by loadText and clearEditor in the
|
||||||
|
editor class.
|
||||||
|
"""
|
||||||
|
if self.docEditor is not None:
|
||||||
|
self.editTitle.setTitleFromHandle(self.docEditor.theHandle)
|
||||||
|
return
|
||||||
|
|
||||||
|
def updateViewTitle(self):
|
||||||
|
"""Ensure the viewer title is up to date with the viewer text.
|
||||||
|
This should only be called by loadText and clearViewer in the
|
||||||
|
viewer class.
|
||||||
|
"""
|
||||||
|
if self.docViewer is not None:
|
||||||
|
self.viewTitle.setTitleFromHandle(self.docViewer.theHandle)
|
||||||
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Tree Item Actions
|
# Tree Item Actions
|
||||||
##
|
##
|
||||||
|
|||||||
Reference in New Issue
Block a user