Skip to content

Commit

Permalink
Merge pull request #281 from vkbo/outline_details
Browse files Browse the repository at this point in the history
Outline Details Panel
  • Loading branch information
vkbo committed Jun 4, 2020
2 parents 3a22863 + 184d0f6 commit 91fdb71
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 69 deletions.
22 changes: 16 additions & 6 deletions nw/config.py
Expand Up @@ -95,6 +95,7 @@ def __init__(self):
self.projColWidth = [140, 55, 140]
self.mainPanePos = [300, 800]
self.docPanePos = [400, 400]
self.outlnPanePos = [500, 150]
self.isFullScreen = False

## Project
Expand Down Expand Up @@ -342,6 +343,9 @@ def loadConfig(self):
self.docPanePos = self._parseLine(
cnfParse, cnfSec, "docpane", self.CNF_LIST, self.docPanePos
)
self.outlnPanePos = self._parseLine(
cnfParse, cnfSec, "outlinepane", self.CNF_LIST, self.outlnPanePos
)
self.isFullScreen = self._parseLine(
cnfParse, cnfSec, "fullscreen", self.CNF_BOOL, self.isFullScreen
)
Expand Down Expand Up @@ -481,12 +485,13 @@ def saveConfig(self):
## Sizes
cnfSec = "Sizes"
cnfParse.add_section(cnfSec)
cnfParse.set(cnfSec,"geometry", self._packList(self.winGeometry))
cnfParse.set(cnfSec,"treecols", self._packList(self.treeColWidth))
cnfParse.set(cnfSec,"projcols", self._packList(self.projColWidth))
cnfParse.set(cnfSec,"mainpane", self._packList(self.mainPanePos))
cnfParse.set(cnfSec,"docpane", self._packList(self.docPanePos))
cnfParse.set(cnfSec,"fullscreen", str(self.isFullScreen))
cnfParse.set(cnfSec,"geometry", self._packList(self.winGeometry))
cnfParse.set(cnfSec,"treecols", self._packList(self.treeColWidth))
cnfParse.set(cnfSec,"projcols", self._packList(self.projColWidth))
cnfParse.set(cnfSec,"mainpane", self._packList(self.mainPanePos))
cnfParse.set(cnfSec,"docpane", self._packList(self.docPanePos))
cnfParse.set(cnfSec,"outlinepane", self._packList(self.outlnPanePos))
cnfParse.set(cnfSec,"fullscreen", str(self.isFullScreen))

## Project
cnfSec = "Project"
Expand Down Expand Up @@ -700,6 +705,11 @@ def setDocPanePos(self, panePos):
self.confChanged = True
return True

def setOutlinePanePos(self, panePos):
self.outlnPanePos = panePos
self.confChanged = True
return True

def setShowRefPanel(self, checkState):
self.showRefPanel = checkState
self.confChanged = True
Expand Down
6 changes: 4 additions & 2 deletions nw/gui/__init__.py
Expand Up @@ -13,7 +13,8 @@
from nw.gui.itemdetails import GuiItemDetails
from nw.gui.itemeditor import GuiItemEditor
from nw.gui.mainmenu import GuiMainMenu
from nw.gui.outline import GuiProjectOutline
from nw.gui.outline import GuiOutline
from nw.gui.outlinedetails import GuiOutlineDetails
from nw.gui.preferences import GuiPreferences
from nw.gui.projload import GuiProjectLoad
from nw.gui.projsettings import GuiProjectSettings
Expand All @@ -37,7 +38,8 @@
"GuiItemDetails",
"GuiItemEditor",
"GuiMainMenu",
"GuiProjectOutline",
"GuiOutline",
"GuiOutlineDetails",
"GuiPreferences",
"GuiProjectLoad",
"GuiProjectSettings",
Expand Down
4 changes: 2 additions & 2 deletions nw/gui/docdetails.py
Expand Up @@ -37,13 +37,13 @@

class GuiDocViewDetails(QWidget):

def __init__(self, theParent, theProject):
def __init__(self, theParent):
QWidget.__init__(self, theParent)

logger.debug("Initialising DocViewDetails ...")
self.mainConf = nw.CONFIG
self.theParent = theParent
self.theProject = theProject
self.theProject = theParent.theProject
self.currHandle = None

self.outerBox = QGridLayout(self)
Expand Down
6 changes: 3 additions & 3 deletions nw/gui/doceditor.py
Expand Up @@ -50,16 +50,16 @@

class GuiDocEditor(QTextEdit):

def __init__(self, theParent, theProject):
QTextEdit.__init__(self)
def __init__(self, theParent):
QTextEdit.__init__(self, theParent)

logger.debug("Initialising GuiDocEditor ...")

# Class Variables
self.mainConf = nw.CONFIG
self.theProject = theProject
self.theParent = theParent
self.theTheme = theParent.theTheme
self.theProject = theParent.theProject
self.docChanged = False
self.spellCheck = False
self.nwDocument = NWDoc(self.theProject, self.theParent)
Expand Down
36 changes: 20 additions & 16 deletions nw/gui/docviewer.py
Expand Up @@ -40,16 +40,16 @@

class GuiDocViewer(QTextBrowser):

def __init__(self, theParent, theProject):
QTextBrowser.__init__(self)
def __init__(self, theParent):
QTextBrowser.__init__(self, theParent)

logger.debug("Initialising DocViewer ...")
logger.debug("Initialising GuiDocViewer ...")

# Class Variables
self.mainConf = nw.CONFIG
self.theProject = theProject
self.theParent = theParent
self.theTheme = theParent.theTheme
self.theProject = theParent.theProject
self.theHandle = None

self.qDocument = self.document()
Expand All @@ -70,7 +70,7 @@ def __init__(self, theParent, theProject):
self.anchorClicked.connect(self._linkClicked)
self.setFocusPolicy(Qt.StrongFocus)

logger.debug("DocViewer initialisation complete")
logger.debug("GuiDocViewer initialisation complete")

# Connect Functions
self.setSelectedHandle = self.theParent.treeView.setSelectedHandle
Expand Down Expand Up @@ -268,6 +268,21 @@ def setCursorLine(self, theLine):
logger.verbose("Cursor moved to line %d" % theLine)
return True

##
# Slots
##

def _linkClicked(self, theURL):
"""Slot for a link in the document being clicked.
"""
theLink = theURL.url()
logger.verbose("Clicked link: '%s'" % theLink)
if len(theLink) > 0:
theBits = theLink.split("=")
if len(theBits) == 2:
self.loadFromTag(theBits[1])
return

##
# Events
##
Expand All @@ -293,17 +308,6 @@ def _makeSelection(self, selMode):
self.setTextCursor(theCursor)
return

def _linkClicked(self, theURL):
"""Slot for a link in the document being clicked.
"""
theLink = theURL.url()
logger.verbose("Clicked link: '%s'" % theLink)
if len(theLink) > 0:
theBits = theLink.split("=")
if len(theBits) == 2:
self.loadFromTag(theBits[1])
return

def _makeStyleSheet(self):
"""Generate an appropriate style sheet for the document viewer,
based on the current syntax highlighter theme,
Expand Down
10 changes: 5 additions & 5 deletions nw/gui/itemdetails.py
Expand Up @@ -30,23 +30,23 @@

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont, QIcon, QPixmap
from PyQt5.QtWidgets import QFrame, QGridLayout, QLabel
from PyQt5.QtWidgets import QWidget, QGridLayout, QLabel

from nw.constants import (
nwLabels, nwItemClass, nwItemType, nwItemLayout, nwUnicode
)

logger = logging.getLogger(__name__)

class GuiItemDetails(QFrame):
class GuiItemDetails(QWidget):

def __init__(self, theParent, theProject):
QFrame.__init__(self, theParent)
def __init__(self, theParent):
QWidget.__init__(self, theParent)

logger.debug("Initialising GuiItemDetails ...")
self.mainConf = nw.CONFIG
self.theParent = theParent
self.theProject = theProject
self.theProject = theParent.theProject
self.theTheme = theParent.theTheme
self.theHandle = None

Expand Down
8 changes: 4 additions & 4 deletions nw/gui/mainmenu.py
Expand Up @@ -39,13 +39,13 @@

class GuiMainMenu(QMenuBar):

def __init__(self, theParent, theProject):
def __init__(self, theParent):
QMenuBar.__init__(self, theParent)

logger.debug("Initialising Main Menu ...")
logger.debug("Initialising GuiMainMenu ...")
self.mainConf = nw.CONFIG
self.theParent = theParent
self.theProject = theProject
self.theProject = theParent.theProject

self._buildProjectMenu()
self._buildDocumentMenu()
Expand All @@ -60,7 +60,7 @@ def __init__(self, theParent, theProject):
self._moveTreeItem = self.theParent.treeView.moveTreeItem
self._newTreeItem = self.theParent.treeView.newTreeItem

logger.debug("Main Menu initialisation complete")
logger.debug("GuiMainMenu initialisation complete")

return

Expand Down
40 changes: 27 additions & 13 deletions nw/gui/outline.py
Expand Up @@ -39,7 +39,7 @@

logger = logging.getLogger(__name__)

class GuiProjectOutline(QTreeWidget):
class GuiOutline(QTreeWidget):

DEF_WIDTH = {
nwOutline.TITLE : 200,
Expand Down Expand Up @@ -79,17 +79,17 @@ class GuiProjectOutline(QTreeWidget):
nwOutline.SYNOP : False,
}

def __init__(self, theParent, theProject):
def __init__(self, theParent):
QTreeWidget.__init__(self, theParent)

logger.debug("Initialising ProjectOutline ...")
logger.debug("Initialising GuiOutline ...")

self.mainConf = nw.CONFIG
self.theParent = theParent
self.theProject = theProject
self.theProject = theParent.theProject
self.theTheme = theParent.theTheme
self.theIndex = theParent.theIndex
self.optState = theProject.optState
self.optState = theParent.theProject.optState
self.headerMenu = GuiOutlineHeaderMenu(self)

self.firstView = True
Expand All @@ -100,6 +100,7 @@ def __init__(self, theParent, theProject):
self.setExpandsOnDoubleClick(False)
self.setDragEnabled(False)
self.itemDoubleClicked.connect(self._treeDoubleClick)
self.itemSelectionChanged.connect(self._itemSelected)

iPx = self.theTheme.textIconSize
self.setIconSize(QSize(iPx, iPx))
Expand All @@ -120,7 +121,7 @@ def __init__(self, theParent, theProject):
self.clearOutline()
self.headerMenu.setHiddenState(self.colHidden)

logger.debug("ProjectOutline initialisation complete")
logger.debug("GuiOutline initialisation complete")

return

Expand Down Expand Up @@ -198,6 +199,18 @@ def _treeDoubleClick(self, tItem, tCol):
self.theParent.openDocument(tHandle, tLine - 1)
return

def _itemSelected(self):
"""Extract the handle and line number of the currently selected
title, and send it to the details panel.
"""
selItems = self.selectedItems()
if selItems:
tHandle = selItems[0].data(self.colIndex[nwOutline.TITLE], Qt.UserRole)
sTitle = selItems[0].data(self.colIndex[nwOutline.LINE], Qt.UserRole)
logger.verbose("User selected entry %s:%s" % (tHandle, sTitle))
self.theParent.projMeta.showItem(tHandle, sTitle)
return

def _headerRightClick(self, clickPos):
"""Show the header column menu.
"""
Expand Down Expand Up @@ -233,7 +246,7 @@ def _loadHeaderState(self):
# Load whatever we saved last time, regardless of wether it
# contains the correct names or number of columns. The names
# must be valid though.
tempOrder = self.optState.getValue("GuiProjectOutline", "headerOrder", [])
tempOrder = self.optState.getValue("GuiOutline", "headerOrder", [])
treeOrder = []
for hName in tempOrder:
try:
Expand All @@ -256,14 +269,14 @@ def _loadHeaderState(self):

# We load whatever column widths and hidden states we find in
# the file, and leave the rest in their default state.
tmpWidth = self.optState.getValue("GuiProjectOutline", "columnWidth", {})
tmpWidth = self.optState.getValue("GuiOutline", "columnWidth", {})
for hName in tmpWidth:
try:
self.colWidth[nwOutline[hName]] = tmpWidth[hName]
except:
logger.warning("Ignored unknown outline column '%s'" % str(hName))

tmpHidden = self.optState.getValue("GuiProjectOutline", "columnHidden", {})
tmpHidden = self.optState.getValue("GuiOutline", "columnHidden", {})
for hName in tmpHidden:
try:
self.colHidden[nwOutline[hName]] = tmpHidden[hName]
Expand Down Expand Up @@ -304,9 +317,9 @@ def _saveHeaderState(self):
if not logHidden and logWidth > 0:
colWidth[hName] = logWidth

self.optState.setValue("GuiProjectOutline", "headerOrder", treeOrder)
self.optState.setValue("GuiProjectOutline", "columnWidth", colWidth)
self.optState.setValue("GuiProjectOutline", "columnHidden", colHidden)
self.optState.setValue("GuiOutline", "headerOrder", treeOrder)
self.optState.setValue("GuiOutline", "columnWidth", colWidth)
self.optState.setValue("GuiOutline", "columnHidden", colHidden)
self.optState.saveSettings()

return
Expand Down Expand Up @@ -415,6 +428,7 @@ def _createTreeItem(self, tHandle, sTitle):
newItem.setText(self.colIndex[nwOutline.LABEL], nwItem.itemName)
newItem.setIcon(self.colIndex[nwOutline.LABEL], self.theTheme.getIcon("proj_document"))
newItem.setText(self.colIndex[nwOutline.LINE], sTitle[1:].lstrip("0"))
newItem.setData(self.colIndex[nwOutline.LINE], Qt.UserRole, sTitle)
newItem.setText(self.colIndex[nwOutline.SYNOP], novIdx["synopsis"])
newItem.setText(self.colIndex[nwOutline.CCOUNT], str(novIdx["cCount"]))
newItem.setText(self.colIndex[nwOutline.WCOUNT], str(novIdx["wCount"]))
Expand All @@ -438,7 +452,7 @@ def _createTreeItem(self, tHandle, sTitle):

return newItem

# END Class GuiProjectOutline
# END Class GuiOutline

class GuiOutlineHeaderMenu(QMenu):

Expand Down

0 comments on commit 91fdb71

Please sign in to comment.