Finished the edit item dialog and now updating tree and project settings.

This commit is contained in:
Veronica K. B. Olsen
2019-04-28 13:17:24 +02:00
parent e00b3b4c20
commit af9aa08fe6
8 changed files with 146 additions and 79 deletions
+61
View File
@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
"""novelWriter Constants
novelWriter Constants
=========================
Constants for translating flags and enums to text
File History:
Created: 2019-04-28 [0.0.1]
"""
from nw.enum import nwItemClass, nwItemLayout
class nwLabels():
CLASS_NAME = {
nwItemClass.NO_CLASS : "None",
nwItemClass.NOVEL : "Novel",
nwItemClass.PLOT : "Plot",
nwItemClass.CHARACTER : "Characters",
nwItemClass.WORLD : "Locations",
nwItemClass.TIMELINE : "Timeline",
nwItemClass.OBJECT : "Objects",
nwItemClass.CUSTOM : "Custom",
}
CLASS_FLAG = {
nwItemClass.NO_CLASS : "0",
nwItemClass.NOVEL : "N",
nwItemClass.PLOT : "P",
nwItemClass.CHARACTER : "C",
nwItemClass.WORLD : "L",
nwItemClass.TIMELINE : "T",
nwItemClass.OBJECT : "O",
nwItemClass.CUSTOM : "X",
}
LAYOUT_NAME = {
nwItemLayout.NO_LAYOUT : "None",
nwItemLayout.TITLE : "Title Page",
nwItemLayout.BOOK : "Book",
nwItemLayout.PAGE : "Plain Page",
nwItemLayout.PARTITION : "Partition",
nwItemLayout.UNNUMBERED : "Un-Numbered",
nwItemLayout.CHAPTER : "Chapter",
nwItemLayout.SCENE : "Scene",
nwItemLayout.NOTE : "Note",
}
LAYOUT_FLAG = {
nwItemLayout.NO_LAYOUT : "Xo",
nwItemLayout.TITLE : "Tt",
nwItemLayout.BOOK : "Bk",
nwItemLayout.PAGE : "Pg",
nwItemLayout.PARTITION : "Pt",
nwItemLayout.UNNUMBERED : "Un",
nwItemLayout.CHAPTER : "Ch",
nwItemLayout.SCENE : "Sc",
nwItemLayout.NOTE : "Nt",
}
# END nwLabels
+3 -3
View File
@@ -18,7 +18,7 @@ from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QFrame, QGridLayout, QLabel
from nw.enum import nwItemType, nwItemClass, nwItemLayout
from nw.project.item import NWItem
from nw.constants import nwLabels
logger = logging.getLogger(__name__)
@@ -72,8 +72,8 @@ class GuiDocDetails(QFrame):
colTwo = [
nwItem.itemName,
self.theProject.statusLabels[itemStatus],
NWItem.CLASS_NAME[nwItem.itemClass],
NWItem.LAYOUT_NAME[nwItem.itemLayout],
nwLabels.CLASS_NAME[nwItem.itemClass],
nwLabels.LAYOUT_NAME[nwItem.itemLayout],
]
for nRow in range(4):
+29 -18
View File
@@ -18,8 +18,9 @@ from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QIcon, QFont, QColor
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QAbstractItemView, QInputDialog, QLineEdit, QApplication
from nw.enum import nwItemType, nwItemClass
from nw.project.item import NWItem
from nw.enum import nwItemType, nwItemClass
from nw.constants import nwLabels
logger = logging.getLogger(__name__)
@@ -76,7 +77,7 @@ class GuiDocTree(QTreeWidget):
)
if itemType == nwItemType.ROOT:
tHandle = self.theProject.newRoot(NWItem.CLASS_NAME[itemClass], itemClass)
tHandle = self.theProject.newRoot(nwLabels.CLASS_NAME[itemClass], itemClass)
else:
# If no parent has been selected, make the new file under the root NOVEL item.
@@ -184,31 +185,19 @@ class GuiDocTree(QTreeWidget):
def _addTreeItem(self, nwItem):
tName = nwItem.itemName
tHandle = nwItem.itemHandle
pHandle = nwItem.parHandle
tStatus = NWItem.CLASS_FLAG[nwItem.itemClass]
if nwItem.itemType == nwItemType.FILE:
tStatus += "."+NWItem.LAYOUT_FLAG[nwItem.itemLayout]
nStatus = nwItem.itemStatus
if nStatus < 0 or nStatus >= len(self.theProject.statusIcons):
nStatus = 0
newItem = QTreeWidgetItem([""]*4)
newItem.setText(self.C_NAME,tName)
newItem.setText(self.C_NAME, "")
newItem.setText(self.C_COUNT, "0")
newItem.setText(self.C_FLAGS, "")
newItem.setText(self.C_HANDLE, tHandle)
newItem.setText(self.C_COUNT,"0")
# newItem.setFont(self.C_COUNT,self.fontCount)
newItem.setForeground(self.C_COUNT,QColor(0,105,135))
newItem.setTextAlignment(self.C_COUNT,Qt.AlignRight)
newItem.setText(self.C_FLAGS,tStatus)
newItem.setIcon(self.C_FLAGS,self.theProject.statusIcons[nStatus])
newItem.setFont(self.C_FLAGS,self.fontFlags)
newItem.setText(self.C_HANDLE, tHandle)
self.theMap[tHandle] = newItem
if pHandle is None:
self.addTopLevelItem(newItem)
@@ -216,6 +205,7 @@ class GuiDocTree(QTreeWidget):
self.theMap[pHandle].addChild(newItem)
self.propagateCount(tHandle, nwItem.wordCount)
self.setTreeItemValues(tHandle)
newItem.setExpanded(nwItem.isExpanded)
if nwItem.itemType == nwItemType.ROOT:
@@ -228,6 +218,27 @@ class GuiDocTree(QTreeWidget):
return newItem
def setTreeItemValues(self, tHandle):
trItem = self.theMap[tHandle]
nwItem = self.theProject.getItem(tHandle)
tName = nwItem.itemName
tHandle = nwItem.itemHandle
pHandle = nwItem.parHandle
tStatus = nwLabels.CLASS_FLAG[nwItem.itemClass]
if nwItem.itemType == nwItemType.FILE:
tStatus += "."+nwLabels.LAYOUT_FLAG[nwItem.itemLayout]
nStatus = nwItem.itemStatus
if nStatus < 0 or nStatus >= len(self.theProject.statusIcons):
nStatus = 0
trItem.setText(self.C_NAME,tName)
trItem.setText(self.C_FLAGS,tStatus)
trItem.setIcon(self.C_FLAGS,self.theProject.statusIcons[nStatus])
return
def propagateCount(self, tHandle, theCount, nDepth=0):
tItem = self.theMap[tHandle]
tItem.setText(self.C_COUNT,"{:n}".format(theCount))
+2 -2
View File
@@ -17,8 +17,8 @@ from copy import copy
from PyQt5.QtWidgets import QMenu, QAction
from nw.project.item import NWItem
from nw.enum import nwItemType, nwItemClass, nwItemAction
from nw.constants import nwLabels
logger = logging.getLogger(__name__)
@@ -192,7 +192,7 @@ class GuiDocTreeCtx(QMenu):
return
def _buildSubMenuAddRoot(self, itemClass):
mnuSub = QAction("Add %s Root" % NWItem.CLASS_NAME[itemClass], self)
mnuSub = QAction("Add %s Root" % nwLabels.CLASS_NAME[itemClass], self)
mnuSub.triggered.connect(lambda: self._ctxSignal(
nwItemAction.ADD_ROOT,
itemClass,
+47 -11
View File
@@ -15,9 +15,12 @@ import nw
from os import path
from PyQt5.QtWidgets import QDialog, QHBoxLayout, QVBoxLayout, QGroupBox, QFormLayout, QLineEdit, QPushButton
from PyQt5.QtWidgets import QDialog, QHBoxLayout, QVBoxLayout, QGroupBox, QFormLayout, QLineEdit, QPushButton, QComboBox
from PyQt5.QtSvg import QSvgWidget
from nw.enum import nwItemLayout, nwItemClass, nwItemType
from nw.constants import nwLabels
logger = logging.getLogger(__name__)
class GuiItemEditor(QDialog):
@@ -47,16 +50,46 @@ class GuiItemEditor(QDialog):
self.mainForm = QFormLayout()
self.editName = QLineEdit()
self.editStatus = QLineEdit()
self.editLayout = QLineEdit()
self.editStatus = QComboBox()
self.editLayout = QComboBox()
for n in range(len(self.theProject.statusLabels)):
self.editStatus.addItem(
self.theProject.statusIcons[n], self.theProject.statusLabels[n], n
)
self.validLayouts = []
if self.theItem.itemType == nwItemType.FILE:
if self.theItem.itemClass == nwItemClass.NOVEL:
self.validLayouts.append(nwItemLayout.TITLE)
self.validLayouts.append(nwItemLayout.BOOK)
self.validLayouts.append(nwItemLayout.PAGE)
self.validLayouts.append(nwItemLayout.PARTITION)
self.validLayouts.append(nwItemLayout.UNNUMBERED)
self.validLayouts.append(nwItemLayout.CHAPTER)
self.validLayouts.append(nwItemLayout.SCENE)
else:
self.validLayouts.append(nwItemLayout.NOTE)
else:
self.validLayouts.append(nwItemLayout.NO_LAYOUT)
for itemLayout in nwItemLayout:
if itemLayout in self.validLayouts:
self.editLayout.addItem(nwLabels.LAYOUT_NAME[itemLayout],itemLayout)
self.mainForm.addRow("Name", self.editName)
self.mainForm.addRow("Status", self.editStatus)
self.mainForm.addRow("Layout", self.editLayout)
self.editName.setMinimumWidth(200)
self.editName.setText(self.theItem.itemName)
self.editStatus.setText(str(self.theItem.itemStatus))
self.editLayout.setText(str(self.theItem.itemLayout))
statusIdx = self.editStatus.findData(self.theItem.itemStatus)
if statusIdx != -1:
self.editStatus.setCurrentIndex(statusIdx)
layoutIdx = self.editLayout.findData(self.theItem.itemLayout)
if layoutIdx != -1:
self.editLayout.setCurrentIndex(layoutIdx)
self.buttonBox = QHBoxLayout()
self.closeButton = QPushButton("Close")
@@ -79,16 +112,19 @@ class GuiItemEditor(QDialog):
def _doSave(self):
logger.verbose("ItemEditor save button clicked")
# projName = self.editName.text()
# bookTitle = self.editTitle.text()
# bookAuthors = self.editAuthors.toPlainText()
# self.theProject.setProjectName(projName)
# self.theProject.setBookTitle(bookTitle)
# self.theProject.setBookAuthors(bookAuthors)
itemName = self.editName.text()
itemStatus = self.editStatus.currentData()
itemLayout = self.editLayout.currentData()
self.theItem.setName(itemName)
self.theItem.setStatus(itemStatus)
self.theItem.setLayout(itemLayout)
self.accept()
self.close()
return
def _doClose(self):
logger.verbose("ItemEditor close button clicked")
self.reject()
self.close()
return
+3 -2
View File
@@ -171,8 +171,9 @@ class GuiMain(QMainWindow):
logger.verbose("Requesting change to item %s" % tHandle)
dlgProj = GuiItemEditor(self, self.theProject, tHandle)
dlgProj.exec_()
if dlgProj.exec_():
self.treeView.setTreeItemValues(tHandle)
return
##
-42
View File
@@ -24,48 +24,6 @@ logger = logging.getLogger(__name__)
class NWItem():
MAX_DEPTH = 8
CLASS_NAME = {
nwItemClass.NO_CLASS : "None",
nwItemClass.NOVEL : "Novel",
nwItemClass.PLOT : "Plot",
nwItemClass.CHARACTER : "Characters",
nwItemClass.WORLD : "Locations",
nwItemClass.TIMELINE : "Timeline",
nwItemClass.OBJECT : "Objects",
nwItemClass.CUSTOM : "Custom",
}
CLASS_FLAG = {
nwItemClass.NO_CLASS : "0",
nwItemClass.NOVEL : "N",
nwItemClass.PLOT : "P",
nwItemClass.CHARACTER : "C",
nwItemClass.WORLD : "L",
nwItemClass.TIMELINE : "T",
nwItemClass.OBJECT : "O",
nwItemClass.CUSTOM : "X",
}
LAYOUT_NAME = {
nwItemLayout.NO_LAYOUT : "None",
nwItemLayout.TITLE : "Title Page",
nwItemLayout.BOOK : "Book",
nwItemLayout.PAGE : "Plain Page",
nwItemLayout.PARTITION : "Partition",
nwItemLayout.UNNUMBERED : "Un-Numbered",
nwItemLayout.CHAPTER : "Chapter",
nwItemLayout.SCENE : "Scene",
nwItemLayout.NOTE : "Note",
}
LAYOUT_FLAG = {
nwItemLayout.NO_LAYOUT : "Xo",
nwItemLayout.TITLE : "Tt",
nwItemLayout.BOOK : "Bk",
nwItemLayout.PAGE : "Pg",
nwItemLayout.PARTITION : "Pt",
nwItemLayout.UNNUMBERED : "Un",
nwItemLayout.CHAPTER : "Ch",
nwItemLayout.SCENE : "Sc",
nwItemLayout.NOTE : "Nt",
}
def __init__(self):
+1 -1
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.0.1" fileVersion="1.0" timeStamp="2019-04-27 16:47:59">
<novelWriterXML appVersion="0.0.1" fileVersion="1.0" timeStamp="2019-04-28 13:15:28">
<project>
<name>Sample Project</name>
<title>Sample Project</title>