From a39387d40535410eaadb36d4829a7df206ebcda3 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 2 Nov 2019 14:26:27 +0100 Subject: [PATCH] Add entity as another root folder type --- nw/constants.py | 27 +++++++++++++++++++++ nw/convert/text/tohtml.py | 17 +++----------- nw/enum.py | 5 ++-- nw/gui/mainmenu.py | 1 + nw/project/index.py | 49 +++++++++++++++++++-------------------- 5 files changed, 58 insertions(+), 41 deletions(-) diff --git a/nw/constants.py b/nw/constants.py index 51bde4e5..7919ba8c 100644 --- a/nw/constants.py +++ b/nw/constants.py @@ -32,6 +32,20 @@ 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_NAME = { @@ -42,6 +56,7 @@ class nwLabels(): nwItemClass.WORLD : "Locations", nwItemClass.TIMELINE : "Timeline", nwItemClass.OBJECT : "Objects", + nwItemClass.ENTITY : "Entity", nwItemClass.CUSTOM : "Custom", nwItemClass.TRASH : "Trash", } @@ -53,6 +68,7 @@ class nwLabels(): nwItemClass.WORLD : "L", nwItemClass.TIMELINE : "T", nwItemClass.OBJECT : "O", + nwItemClass.ENTITY : "E", nwItemClass.CUSTOM : "X", nwItemClass.TRASH : "R", } @@ -78,6 +94,17 @@ class nwLabels(): nwItemLayout.SCENE : "Sc", 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 diff --git a/nw/convert/text/tohtml.py b/nw/convert/text/tohtml.py index c8615f75..de161146 100644 --- a/nw/convert/text/tohtml.py +++ b/nw/convert/text/tohtml.py @@ -15,7 +15,7 @@ import re import nw from nw.convert.tokenizer import Tokenizer -from nw.constants import nwUnicode +from nw.constants import nwUnicode, nwLabels logger = logging.getLogger(__name__) @@ -134,17 +134,6 @@ class ToHtml(Tokenizer): if not self.forPreview: return "
@%s
\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 isValid, theBits, thePos = self.theParent.theIndex.scanThis(tText) if not isValid or not theBits: @@ -152,8 +141,8 @@ class ToHtml(Tokenizer): retText = "" refTags = [] - if theBits[0] in theLabel: - retText += "%s: " % theLabel[theBits[0]] + if theBits[0] in nwLabels.KEY_NAME: + retText += "%s: " % nwLabels.KEY_NAME[theBits[0]] for tTag in theBits[1:]: refTags.append("%s" % ( theBits[0][1:], tTag, tTag diff --git a/nw/enum.py b/nw/enum.py index f83d9135..738ebce8 100644 --- a/nw/enum.py +++ b/nw/enum.py @@ -31,8 +31,9 @@ class nwItemClass(Enum): WORLD = 4 TIMELINE = 5 OBJECT = 6 - CUSTOM = 7 - TRASH = 8 + ENTITY = 7 + CUSTOM = 8 + TRASH = 9 # END Enum nwItemClass diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index 7a42f6cf..7e4fde17 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -235,6 +235,7 @@ class GuiMainMenu(QMenuBar): self.rootItems[nwItemClass.WORLD] = QAction("Location Root", rootMenu) self.rootItems[nwItemClass.TIMELINE] = QAction("Timeline 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) nCount = 0 for itemClass in self.rootItems.keys(): diff --git a/nw/project/index.py b/nw/project/index.py index 08b872dc..d0e08315 100644 --- a/nw/project/index.py +++ b/nw/project/index.py @@ -18,33 +18,33 @@ from os import path from nw.project.document import NWDoc from nw.enum import nwItemType, nwItemClass, nwItemLayout -from nw.constants import nwFiles +from nw.constants import nwFiles, nwKeyWords from nw.enum import nwAlert logger = logging.getLogger(__name__) class NWIndex(): - TAG_KEY = "@tag" - POV_KEY = "@pov" - CHAR_KEY = "@char" - PLOT_KEY = "@plot" - TIME_KEY = "@time" - WORLD_KEY = "@location" - OBJECT_KEY = "@object" - CUSTOM_KEY = "@custom" - - NOTE_KEYS = [TAG_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] + VALID_KEYS = [ + nwKeyWords.TAG_KEY, + nwKeyWords.PLOT_KEY, + nwKeyWords.POV_KEY, + nwKeyWords.CHAR_KEY, + nwKeyWords.WORLD_KEY, + nwKeyWords.TIME_KEY, + nwKeyWords.OBJECT_KEY, + nwKeyWords.ENTITY_KEY, + nwKeyWords.CUSTOM_KEY + ] TAG_CLASS = { - CHAR_KEY : [nwItemClass.CHARACTER, 1], - POV_KEY : [nwItemClass.CHARACTER, 2], - PLOT_KEY : [nwItemClass.PLOT, 1], - TIME_KEY : [nwItemClass.TIMELINE, 1], - WORLD_KEY : [nwItemClass.WORLD, 1], - OBJECT_KEY : [nwItemClass.OBJECT, 1], - CUSTOM_KEY : [nwItemClass.CUSTOM, 1], + nwKeyWords.CHAR_KEY : [nwItemClass.CHARACTER, 1], + nwKeyWords.POV_KEY : [nwItemClass.CHARACTER, 2], + nwKeyWords.PLOT_KEY : [nwItemClass.PLOT, 1], + nwKeyWords.TIME_KEY : [nwItemClass.TIMELINE, 1], + nwKeyWords.WORLD_KEY : [nwItemClass.WORLD, 1], + nwKeyWords.OBJECT_KEY : [nwItemClass.OBJECT, 1], + nwKeyWords.ENTITY_KEY : [nwItemClass.ENTITY, 1], + nwKeyWords.CUSTOM_KEY : [nwItemClass.CUSTOM, 1], } def __init__(self, theProject, theParent): @@ -275,10 +275,9 @@ class NWIndex(): if not isValid or len(theBits) == 0: return False - theKey = theBits[0] - if theKey in self.NOVEL_KEYS: + if theBits[0] != nwKeyWords.TAG_KEY: for aVal in theBits[1:]: - self.refIndex[tHandle].append([nLine, theKey, aVal, nTitle]) + self.refIndex[tHandle].append([nLine, theBits[0], aVal, nTitle]) return True @@ -290,7 +289,7 @@ class NWIndex(): if not isValid or len(theBits) != 2: return False - if theBits[0] == self.TAG_KEY: + if theBits[0] == nwKeyWords.TAG_KEY: self.tagIndex[theBits[1]] = [nLine, tHandle, itemClass.name] return True @@ -355,7 +354,7 @@ class NWIndex(): return isGood # 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 if theBits[1] in self.tagIndex.keys(): if self.tagIndex[theBits[1]][1] == tItem.itemHandle: