Add entity as another root folder type

This commit is contained in:
Veronica K. B. Olsen
2019-11-02 14:26:27 +01:00
parent c0aca6a069
commit a39387d405
5 changed files with 58 additions and 41 deletions
+27
View File
@@ -32,6 +32,20 @@ class nwFiles():
# END Class nwFiles # END Class nwFiles
class nwKeyWords:
TAG_KEY = "@tag"
POV_KEY = "@pov"
CHAR_KEY = "@char"
PLOT_KEY = "@plot"
TIME_KEY = "@time"
WORLD_KEY = "@location"
OBJECT_KEY = "@object"
ENTITY_KEY = "@entity"
CUSTOM_KEY = "@custom"
# END Class nwKeyWords
class nwLabels(): class nwLabels():
CLASS_NAME = { CLASS_NAME = {
@@ -42,6 +56,7 @@ class nwLabels():
nwItemClass.WORLD : "Locations", nwItemClass.WORLD : "Locations",
nwItemClass.TIMELINE : "Timeline", nwItemClass.TIMELINE : "Timeline",
nwItemClass.OBJECT : "Objects", nwItemClass.OBJECT : "Objects",
nwItemClass.ENTITY : "Entity",
nwItemClass.CUSTOM : "Custom", nwItemClass.CUSTOM : "Custom",
nwItemClass.TRASH : "Trash", nwItemClass.TRASH : "Trash",
} }
@@ -53,6 +68,7 @@ class nwLabels():
nwItemClass.WORLD : "L", nwItemClass.WORLD : "L",
nwItemClass.TIMELINE : "T", nwItemClass.TIMELINE : "T",
nwItemClass.OBJECT : "O", nwItemClass.OBJECT : "O",
nwItemClass.ENTITY : "E",
nwItemClass.CUSTOM : "X", nwItemClass.CUSTOM : "X",
nwItemClass.TRASH : "R", nwItemClass.TRASH : "R",
} }
@@ -78,6 +94,17 @@ class nwLabels():
nwItemLayout.SCENE : "Sc", nwItemLayout.SCENE : "Sc",
nwItemLayout.NOTE : "Nt", nwItemLayout.NOTE : "Nt",
} }
KEY_NAME = {
nwKeyWords.TAG_KEY : "Tag",
nwKeyWords.POV_KEY : "Point of View",
nwKeyWords.CHAR_KEY : "Characters",
nwKeyWords.PLOT_KEY : "Plot",
nwKeyWords.TIME_KEY : "Time",
nwKeyWords.WORLD_KEY : "Locations",
nwKeyWords.OBJECT_KEY : "Objects",
nwKeyWords.ENTITY_KEY : "Entities",
nwKeyWords.CUSTOM_KEY : "Custom",
}
# END Class nwLabels # END Class nwLabels
+3 -14
View File
@@ -15,7 +15,7 @@ import re
import nw import nw
from nw.convert.tokenizer import Tokenizer from nw.convert.tokenizer import Tokenizer
from nw.constants import nwUnicode from nw.constants import nwUnicode, nwLabels
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -134,17 +134,6 @@ class ToHtml(Tokenizer):
if not self.forPreview: if not self.forPreview:
return "<pre>@%s</pre>\n" % tText return "<pre>@%s</pre>\n" % tText
theLabel = {
"@tag" : "Tag",
"@pov" : "Point of View",
"@char" : "Character(s)",
"@plot" : "Plot",
"@time" : "Time",
"@location" : "Location(s)",
"@object" : "Object(s)",
"@custom" : "Custom",
}
tText = "@"+tText tText = "@"+tText
isValid, theBits, thePos = self.theParent.theIndex.scanThis(tText) isValid, theBits, thePos = self.theParent.theIndex.scanThis(tText)
if not isValid or not theBits: if not isValid or not theBits:
@@ -152,8 +141,8 @@ class ToHtml(Tokenizer):
retText = "" retText = ""
refTags = [] refTags = []
if theBits[0] in theLabel: if theBits[0] in nwLabels.KEY_NAME:
retText += "<span class='tags'>%s:</span>&nbsp;" % theLabel[theBits[0]] retText += "<span class='tags'>%s:</span>&nbsp;" % nwLabels.KEY_NAME[theBits[0]]
for tTag in theBits[1:]: for tTag in theBits[1:]:
refTags.append("<a href='#%s=%s'>%s</a>" % ( refTags.append("<a href='#%s=%s'>%s</a>" % (
theBits[0][1:], tTag, tTag theBits[0][1:], tTag, tTag
+3 -2
View File
@@ -31,8 +31,9 @@ class nwItemClass(Enum):
WORLD = 4 WORLD = 4
TIMELINE = 5 TIMELINE = 5
OBJECT = 6 OBJECT = 6
CUSTOM = 7 ENTITY = 7
TRASH = 8 CUSTOM = 8
TRASH = 9
# END Enum nwItemClass # END Enum nwItemClass
+1
View File
@@ -235,6 +235,7 @@ class GuiMainMenu(QMenuBar):
self.rootItems[nwItemClass.WORLD] = QAction("Location Root", rootMenu) self.rootItems[nwItemClass.WORLD] = QAction("Location Root", rootMenu)
self.rootItems[nwItemClass.TIMELINE] = QAction("Timeline Root", rootMenu) self.rootItems[nwItemClass.TIMELINE] = QAction("Timeline Root", rootMenu)
self.rootItems[nwItemClass.OBJECT] = QAction("Object Root", rootMenu) self.rootItems[nwItemClass.OBJECT] = QAction("Object Root", rootMenu)
self.rootItems[nwItemClass.ENTITY] = QAction("Entity Root", rootMenu)
self.rootItems[nwItemClass.CUSTOM] = QAction("Custom Root", rootMenu) self.rootItems[nwItemClass.CUSTOM] = QAction("Custom Root", rootMenu)
nCount = 0 nCount = 0
for itemClass in self.rootItems.keys(): for itemClass in self.rootItems.keys():
+24 -25
View File
@@ -18,33 +18,33 @@ from os import path
from nw.project.document import NWDoc from nw.project.document import NWDoc
from nw.enum import nwItemType, nwItemClass, nwItemLayout from nw.enum import nwItemType, nwItemClass, nwItemLayout
from nw.constants import nwFiles from nw.constants import nwFiles, nwKeyWords
from nw.enum import nwAlert from nw.enum import nwAlert
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class NWIndex(): class NWIndex():
TAG_KEY = "@tag" VALID_KEYS = [
POV_KEY = "@pov" nwKeyWords.TAG_KEY,
CHAR_KEY = "@char" nwKeyWords.PLOT_KEY,
PLOT_KEY = "@plot" nwKeyWords.POV_KEY,
TIME_KEY = "@time" nwKeyWords.CHAR_KEY,
WORLD_KEY = "@location" nwKeyWords.WORLD_KEY,
OBJECT_KEY = "@object" nwKeyWords.TIME_KEY,
CUSTOM_KEY = "@custom" nwKeyWords.OBJECT_KEY,
nwKeyWords.ENTITY_KEY,
NOTE_KEYS = [TAG_KEY] nwKeyWords.CUSTOM_KEY
NOVEL_KEYS = [PLOT_KEY, POV_KEY, CHAR_KEY, WORLD_KEY, TIME_KEY, OBJECT_KEY, CUSTOM_KEY] ]
VALID_KEYS = [TAG_KEY, PLOT_KEY, POV_KEY, CHAR_KEY, WORLD_KEY, TIME_KEY, OBJECT_KEY, CUSTOM_KEY]
TAG_CLASS = { TAG_CLASS = {
CHAR_KEY : [nwItemClass.CHARACTER, 1], nwKeyWords.CHAR_KEY : [nwItemClass.CHARACTER, 1],
POV_KEY : [nwItemClass.CHARACTER, 2], nwKeyWords.POV_KEY : [nwItemClass.CHARACTER, 2],
PLOT_KEY : [nwItemClass.PLOT, 1], nwKeyWords.PLOT_KEY : [nwItemClass.PLOT, 1],
TIME_KEY : [nwItemClass.TIMELINE, 1], nwKeyWords.TIME_KEY : [nwItemClass.TIMELINE, 1],
WORLD_KEY : [nwItemClass.WORLD, 1], nwKeyWords.WORLD_KEY : [nwItemClass.WORLD, 1],
OBJECT_KEY : [nwItemClass.OBJECT, 1], nwKeyWords.OBJECT_KEY : [nwItemClass.OBJECT, 1],
CUSTOM_KEY : [nwItemClass.CUSTOM, 1], nwKeyWords.ENTITY_KEY : [nwItemClass.ENTITY, 1],
nwKeyWords.CUSTOM_KEY : [nwItemClass.CUSTOM, 1],
} }
def __init__(self, theProject, theParent): def __init__(self, theProject, theParent):
@@ -275,10 +275,9 @@ class NWIndex():
if not isValid or len(theBits) == 0: if not isValid or len(theBits) == 0:
return False return False
theKey = theBits[0] if theBits[0] != nwKeyWords.TAG_KEY:
if theKey in self.NOVEL_KEYS:
for aVal in theBits[1:]: for aVal in theBits[1:]:
self.refIndex[tHandle].append([nLine, theKey, aVal, nTitle]) self.refIndex[tHandle].append([nLine, theBits[0], aVal, nTitle])
return True return True
@@ -290,7 +289,7 @@ class NWIndex():
if not isValid or len(theBits) != 2: if not isValid or len(theBits) != 2:
return False return False
if theBits[0] == self.TAG_KEY: if theBits[0] == nwKeyWords.TAG_KEY:
self.tagIndex[theBits[1]] = [nLine, tHandle, itemClass.name] self.tagIndex[theBits[1]] = [nLine, tHandle, itemClass.name]
return True return True
@@ -355,7 +354,7 @@ class NWIndex():
return isGood return isGood
# If we have a tag, only the first value is accepted, the rest is ignored # If we have a tag, only the first value is accepted, the rest is ignored
if theBits[0] == self.TAG_KEY and nBits > 1: if theBits[0] == nwKeyWords.TAG_KEY and nBits > 1:
isGood[0] = True isGood[0] = True
if theBits[1] in self.tagIndex.keys(): if theBits[1] in self.tagIndex.keys():
if self.tagIndex[theBits[1]][1] == tItem.itemHandle: if self.tagIndex[theBits[1]][1] == tItem.itemHandle: