The document title bar is no populated on document open
This commit is contained in:
@@ -234,6 +234,12 @@ class nwUnicode:
|
|||||||
U_NBSP = "\u00a0" # Non-breaking space
|
U_NBSP = "\u00a0" # Non-breaking space
|
||||||
U_PARA = "\u2029" # Paragraph separator
|
U_PARA = "\u2029" # Paragraph separator
|
||||||
|
|
||||||
|
## Arrows
|
||||||
|
U_UTRI = "\u2bc5" # Up-pointing triangle
|
||||||
|
U_DTRI = "\u2bc6" # Down-pointing triangle
|
||||||
|
U_LTRI = "\u2bc7" # Left-pointing triangle
|
||||||
|
U_RTRI = "\u2bc8" # Right-pointing triangle
|
||||||
|
|
||||||
# HTML Equivalents
|
# HTML Equivalents
|
||||||
|
|
||||||
## Quotes
|
## Quotes
|
||||||
@@ -265,4 +271,10 @@ class nwUnicode:
|
|||||||
## Other
|
## Other
|
||||||
H_NBSP = " "
|
H_NBSP = " "
|
||||||
|
|
||||||
|
## Arrows
|
||||||
|
H_UTRI = "⯅"
|
||||||
|
H_DTRI = "⯆"
|
||||||
|
H_LTRI = "⯇"
|
||||||
|
H_RTRI = "⯈"
|
||||||
|
|
||||||
# END Class nwUnicode
|
# END Class nwUnicode
|
||||||
|
|||||||
@@ -32,23 +32,28 @@ from PyQt5.QtCore import Qt
|
|||||||
from PyQt5.QtGui import QPalette, QColor
|
from PyQt5.QtGui import QPalette, QColor
|
||||||
from PyQt5.QtWidgets import QLabel
|
from PyQt5.QtWidgets import QLabel
|
||||||
|
|
||||||
|
from nw.constants import nwUnicode
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class GuiDocTitleBar(QLabel):
|
class GuiDocTitleBar(QLabel):
|
||||||
|
|
||||||
def __init__(self, theParent):
|
def __init__(self, theParent, theProject):
|
||||||
QLabel.__init__(self, theParent)
|
QLabel.__init__(self, theParent)
|
||||||
|
|
||||||
logger.debug("Initialising DocTitleBar ...")
|
logger.debug("Initialising DocTitleBar ...")
|
||||||
|
|
||||||
self.mainConf = nw.CONFIG
|
self.mainConf = nw.CONFIG
|
||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theTheme = theParent.theTheme
|
self.theProject = theProject
|
||||||
|
self.theTheme = theParent.theTheme
|
||||||
|
self.theHandle = None
|
||||||
|
|
||||||
self.setText("A > B > C")
|
self.setText("")
|
||||||
self.setContentsMargins(8,2,8,2)
|
self.setContentsMargins(8,2,8,2)
|
||||||
self.setAutoFillBackground(True)
|
self.setAutoFillBackground(True)
|
||||||
self.setAlignment(Qt.AlignCenter)
|
self.setAlignment(Qt.AlignCenter)
|
||||||
|
self.setWordWrap(True)
|
||||||
docPalette = self.palette()
|
docPalette = self.palette()
|
||||||
docPalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack))
|
docPalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack))
|
||||||
docPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
|
docPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
|
||||||
@@ -58,4 +63,32 @@ class GuiDocTitleBar(QLabel):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def setTitleFromHandle(self, tHandle):
|
||||||
|
"""Sets the document title from the handle, or alternatively,
|
||||||
|
set the whole document path.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.setText("")
|
||||||
|
self.theHandle = tHandle
|
||||||
|
if tHandle is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if True:
|
||||||
|
tTitle = []
|
||||||
|
tTree = self.theProject.getItemPath(tHandle)
|
||||||
|
for aHandle in reversed(tTree):
|
||||||
|
nwItem = self.theProject.getItem(aHandle)
|
||||||
|
if nwItem is not None:
|
||||||
|
tTitle.append(nwItem.itemName)
|
||||||
|
sSep = " %s " % nwUnicode.U_RTRI
|
||||||
|
self.setText(sSep.join(tTitle))
|
||||||
|
else:
|
||||||
|
nwItem = self.theProject.getItem(tHandle)
|
||||||
|
if nwItem is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.setText(nwItem.itemName)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
# END Class GuiDocTitleBar
|
# END Class GuiDocTitleBar
|
||||||
|
|||||||
+9
-2
@@ -93,8 +93,8 @@ 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.viewTitle = GuiDocTitleBar(self, self.theProject)
|
||||||
self.editTitle = GuiDocTitleBar(self)
|
self.editTitle = GuiDocTitleBar(self, self.theProject)
|
||||||
|
|
||||||
# Minor Gui Elements
|
# Minor Gui Elements
|
||||||
self.statusIcons = []
|
self.statusIcons = []
|
||||||
@@ -452,10 +452,13 @@ class GuiMain(QMainWindow):
|
|||||||
##
|
##
|
||||||
|
|
||||||
def closeDocument(self):
|
def closeDocument(self):
|
||||||
|
"""Close the document and clear the editor and title field.
|
||||||
|
"""
|
||||||
if self.hasProject:
|
if self.hasProject:
|
||||||
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):
|
||||||
@@ -467,6 +470,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)
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@@ -477,6 +481,8 @@ class GuiMain(QMainWindow):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def viewDocument(self, tHandle=None):
|
def viewDocument(self, tHandle=None):
|
||||||
|
"""Load a document for viewing in the view panel.
|
||||||
|
"""
|
||||||
|
|
||||||
if tHandle is None:
|
if tHandle is None:
|
||||||
tHandle = self.treeView.getSelectedHandle()
|
tHandle = self.treeView.getSelectedHandle()
|
||||||
@@ -494,6 +500,7 @@ 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]
|
||||||
|
|||||||
@@ -601,6 +601,9 @@ class NWProject():
|
|||||||
##
|
##
|
||||||
|
|
||||||
def getItem(self, tHandle):
|
def getItem(self, tHandle):
|
||||||
|
"""Return a project item based on its handle. Returns None if
|
||||||
|
the handle doesn't exist in the project.
|
||||||
|
"""
|
||||||
if tHandle in self.projTree:
|
if tHandle in self.projTree:
|
||||||
return self.projTree[tHandle]
|
return self.projTree[tHandle]
|
||||||
logger.error("No tree item with handle %s" % str(tHandle))
|
logger.error("No tree item with handle %s" % str(tHandle))
|
||||||
@@ -626,6 +629,28 @@ class NWProject():
|
|||||||
return tHandle
|
return tHandle
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def getItemPath(self, tHandle):
|
||||||
|
"""Iterate upwards in the tree until we find the item with
|
||||||
|
parent None, the root item, and return the list of handles.
|
||||||
|
We do this with a for loop with a maximum depth of 200 to make
|
||||||
|
infinite loops impossible.
|
||||||
|
"""
|
||||||
|
tTree = []
|
||||||
|
tItem = self.getItem(tHandle)
|
||||||
|
if tItem is not None:
|
||||||
|
tTree.append(tHandle)
|
||||||
|
for i in range(200):
|
||||||
|
if tItem.parHandle is None:
|
||||||
|
return tTree
|
||||||
|
else:
|
||||||
|
tHandle = tItem.parHandle
|
||||||
|
tItem = self.getItem(tHandle)
|
||||||
|
if tItem is None:
|
||||||
|
return tTree
|
||||||
|
else:
|
||||||
|
tTree.append(tHandle)
|
||||||
|
return tTree
|
||||||
|
|
||||||
def getProjectItems(self):
|
def getProjectItems(self):
|
||||||
"""This function is called from the tree view when building the
|
"""This function is called from the tree view when building the
|
||||||
tree. Each item in the project is returned in the order saved in
|
tree. Each item in the project is returned in the order saved in
|
||||||
|
|||||||
Reference in New Issue
Block a user