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.theParent.noticeBar.hideNote()
|
||||
self.theParent.updateEditTitle()
|
||||
|
||||
return True
|
||||
|
||||
@@ -264,6 +265,7 @@ class GuiDocEditor(QTextEdit):
|
||||
else:
|
||||
self.theParent.noticeBar.showNote("This document is read only.")
|
||||
|
||||
self.theParent.updateEditTitle()
|
||||
self.hLight.spellCheck = spTemp
|
||||
qApp.restoreOverrideCursor()
|
||||
|
||||
|
||||
@@ -63,6 +63,10 @@ class GuiDocTitleBar(QLabel):
|
||||
|
||||
return
|
||||
|
||||
##
|
||||
# Setters
|
||||
##
|
||||
|
||||
def setTitleFromHandle(self, tHandle):
|
||||
"""Sets the document title from the handle, or alternatively,
|
||||
set the whole document path.
|
||||
@@ -91,4 +95,15 @@ class GuiDocTitleBar(QLabel):
|
||||
|
||||
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
|
||||
|
||||
@@ -457,6 +457,9 @@ class GuiDocTree(QTreeWidget):
|
||||
return True
|
||||
|
||||
def getSelectedHandle(self):
|
||||
"""Get the currently selected handle. If multiple items are
|
||||
selected, return the first.
|
||||
"""
|
||||
selItem = self.selectedItems()
|
||||
if len(selItem) == 0:
|
||||
return None
|
||||
@@ -465,6 +468,8 @@ class GuiDocTree(QTreeWidget):
|
||||
return None
|
||||
|
||||
def getSelectedHandles(self):
|
||||
"""Return a list of all currently selected item handles.
|
||||
"""
|
||||
selItems = self.selectedItems()
|
||||
selHandles = []
|
||||
for n in range(len(selItems)):
|
||||
@@ -472,6 +477,15 @@ class GuiDocTree(QTreeWidget):
|
||||
selHandles.append(selItems[n].text(self.C_HANDLE))
|
||||
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
|
||||
##
|
||||
|
||||
@@ -69,8 +69,12 @@ class GuiDocViewer(QTextBrowser):
|
||||
return
|
||||
|
||||
def clearViewer(self):
|
||||
"""Clear the content of the document and reset key variables.
|
||||
"""
|
||||
self.clear()
|
||||
self.setSearchPaths([""])
|
||||
self.theHandle = None
|
||||
self.theParent.updateViewTitle()
|
||||
return True
|
||||
|
||||
def initViewer(self):
|
||||
@@ -108,6 +112,8 @@ class GuiDocViewer(QTextBrowser):
|
||||
return True
|
||||
|
||||
def loadText(self, tHandle):
|
||||
"""Load text into the viewer from an item handle.
|
||||
"""
|
||||
|
||||
tItem = self.theProject.getItem(tHandle)
|
||||
if tItem is None:
|
||||
@@ -132,7 +138,9 @@ class GuiDocViewer(QTextBrowser):
|
||||
self.theHandle = tHandle
|
||||
self.theProject.setLastViewed(tHandle)
|
||||
|
||||
# Make sure the main GUI knows we changed the content
|
||||
self.theParent.viewMeta.refreshReferences(tHandle)
|
||||
self.theParent.updateViewTitle()
|
||||
|
||||
return True
|
||||
|
||||
|
||||
+43
-6
@@ -65,6 +65,11 @@ class GuiMain(QMainWindow):
|
||||
self.hasProject = 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("Kernel: %s" % self.mainConf.kernelVer)
|
||||
logger.info("Host: %s" % self.mainConf.hostName)
|
||||
@@ -78,13 +83,19 @@ class GuiMain(QMainWindow):
|
||||
self.mainConf.verPyString, self.mainConf.verPyHexVal)
|
||||
)
|
||||
|
||||
# Prepare main window
|
||||
self.resize(*self.mainConf.winGeometry)
|
||||
self._setWindowTitle()
|
||||
self.setWindowIcon(QIcon(self.mainConf.appIcon))
|
||||
|
||||
# Build the GUI
|
||||
################
|
||||
|
||||
# Main GUI Elements
|
||||
self.statusBar = GuiMainStatus(self)
|
||||
self.noticeBar = GuiNoticeBar(self)
|
||||
self.viewTitle = GuiDocTitleBar(self, self.theProject)
|
||||
self.editTitle = GuiDocTitleBar(self, self.theProject)
|
||||
self.docEditor = GuiDocEditor(self, self.theProject)
|
||||
self.docViewer = GuiDocViewer(self, self.theProject)
|
||||
self.viewMeta = GuiDocViewDetails(self, self.theProject)
|
||||
@@ -93,8 +104,6 @@ class GuiMain(QMainWindow):
|
||||
self.treeView = GuiDocTree(self, self.theProject)
|
||||
self.projView = GuiProjectOutline(self, self.theProject)
|
||||
self.mainMenu = GuiMainMenu(self, self.theProject)
|
||||
self.viewTitle = GuiDocTitleBar(self, self.theProject)
|
||||
self.editTitle = GuiDocTitleBar(self, self.theProject)
|
||||
|
||||
# Minor Gui Elements
|
||||
self.statusIcons = []
|
||||
@@ -168,7 +177,7 @@ class GuiMain(QMainWindow):
|
||||
self.viewPane.setVisible(False)
|
||||
self.searchBar.setVisible(False)
|
||||
|
||||
# Build The Tree View
|
||||
# Build the Tree View
|
||||
self.treeView.itemSelectionChanged.connect(self._treeSingleClick)
|
||||
self.treeView.itemDoubleClicked.connect(self._treeDoubleClick)
|
||||
self.rebuildTree()
|
||||
@@ -178,6 +187,9 @@ class GuiMain(QMainWindow):
|
||||
self.setStatusBar(self.statusBar)
|
||||
self.statusBar.setStatus("Ready")
|
||||
|
||||
# Finalise Initialisation
|
||||
##########################
|
||||
|
||||
# Set Up Autosaving Project Timer
|
||||
self.asProjTimer = QTimer()
|
||||
self.asProjTimer.timeout.connect(self._autoSaveProject)
|
||||
@@ -216,6 +228,8 @@ class GuiMain(QMainWindow):
|
||||
|
||||
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:
|
||||
logger.debug("Opening project from additional command line option")
|
||||
self.openProject(self.mainConf.cmdOpen)
|
||||
@@ -234,6 +248,8 @@ class GuiMain(QMainWindow):
|
||||
return True
|
||||
|
||||
def initMain(self):
|
||||
"""Initialise elements that depend on user settings.
|
||||
"""
|
||||
self.asProjTimer.setInterval(int(self.mainConf.autoSaveProj*1000))
|
||||
self.asDocTimer.setInterval(int(self.mainConf.autoSaveDoc*1000))
|
||||
return True
|
||||
@@ -443,6 +459,8 @@ class GuiMain(QMainWindow):
|
||||
return True
|
||||
|
||||
def backupProject(self):
|
||||
"""Trigger the project backup process.
|
||||
"""
|
||||
theBackup = NWBackup(self, self.theProject)
|
||||
theBackup.zipIt()
|
||||
return True
|
||||
@@ -458,7 +476,6 @@ class GuiMain(QMainWindow):
|
||||
if self.docEditor.docChanged:
|
||||
self.saveDocument()
|
||||
self.docEditor.clearEditor()
|
||||
self.editTitle.setTitleFromHandle(None)
|
||||
return True
|
||||
|
||||
def openDocument(self, tHandle, tLine=None):
|
||||
@@ -470,7 +487,7 @@ class GuiMain(QMainWindow):
|
||||
if self.docEditor.loadText(tHandle, tLine):
|
||||
self.docEditor.setFocus()
|
||||
self.theProject.setLastEdited(tHandle)
|
||||
self.editTitle.setTitleFromHandle(tHandle)
|
||||
self.treeView.setSelectedHandle(tHandle)
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
@@ -500,7 +517,6 @@ class GuiMain(QMainWindow):
|
||||
self.tabWidget.setCurrentWidget(self.splitView)
|
||||
|
||||
if self.docViewer.loadText(tHandle) and not self.viewPane.isVisible():
|
||||
self.viewTitle.setTitleFromHandle(tHandle)
|
||||
bPos = self.splitMain.sizes()
|
||||
self.viewPane.setVisible(True)
|
||||
vPos = [0,0]
|
||||
@@ -511,6 +527,9 @@ class GuiMain(QMainWindow):
|
||||
return True
|
||||
|
||||
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
|
||||
|
||||
@@ -595,6 +614,24 @@ class GuiMain(QMainWindow):
|
||||
logger.debug("Document action requested, but no document has focus")
|
||||
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
|
||||
##
|
||||
|
||||
Reference in New Issue
Block a user