From 8e95728e20b769d2095c767925be16a0742e4bee Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 27 Oct 2020 20:30:11 +0100 Subject: [PATCH] Move the keyword maps into the nwKeyWords constants class where the keywords are defined --- nw/constants/constants.py | 18 ++++++++++++++++++ nw/core/index.py | 28 +++------------------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/nw/constants/constants.py b/nw/constants/constants.py index f2e97cf5..0a23e369 100644 --- a/nw/constants/constants.py +++ b/nw/constants/constants.py @@ -80,6 +80,24 @@ class nwKeyWords: ENTITY_KEY = "@entity" CUSTOM_KEY = "@custom" + # Set of Valid Keys + VALID_KEYS = { + TAG_KEY, POV_KEY, CHAR_KEY, PLOT_KEY, TIME_KEY, + WORLD_KEY, OBJECT_KEY, ENTITY_KEY, CUSTOM_KEY + } + + # Map from Keys to Item Class + KEY_CLASS = { + CHAR_KEY : nwItemClass.CHARACTER, + POV_KEY : nwItemClass.CHARACTER, + PLOT_KEY : nwItemClass.PLOT, + TIME_KEY : nwItemClass.TIMELINE, + WORLD_KEY : nwItemClass.WORLD, + OBJECT_KEY : nwItemClass.OBJECT, + ENTITY_KEY : nwItemClass.ENTITY, + CUSTOM_KEY : nwItemClass.CUSTOM, + } + # END Class nwKeyWords class nwLabels(): diff --git a/nw/core/index.py b/nw/core/index.py index 29f80ea9..cb0ac376 100644 --- a/nw/core/index.py +++ b/nw/core/index.py @@ -42,28 +42,6 @@ logger = logging.getLogger(__name__) class NWIndex(): - 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 = { - nwKeyWords.CHAR_KEY : nwItemClass.CHARACTER, - nwKeyWords.POV_KEY : nwItemClass.CHARACTER, - nwKeyWords.PLOT_KEY : nwItemClass.PLOT, - nwKeyWords.TIME_KEY : nwItemClass.TIMELINE, - nwKeyWords.WORLD_KEY : nwItemClass.WORLD, - nwKeyWords.OBJECT_KEY : nwItemClass.OBJECT, - nwKeyWords.ENTITY_KEY : nwItemClass.ENTITY, - nwKeyWords.CUSTOM_KEY : nwItemClass.CUSTOM, - } - def __init__(self, theProject, theParent): # Internal @@ -530,7 +508,7 @@ class NWIndex(): return [] # Check that the key is valid - isGood[0] = theBits[0] in self.VALID_KEYS + isGood[0] = theBits[0] in nwKeyWords.VALID_KEYS if not isGood[0] or nBits == 1: return isGood @@ -550,7 +528,7 @@ class NWIndex(): # If we're still here, we better check that the references exist for n in range(1, nBits): if theBits[n] in self.tagIndex: - isGood[n] = self.TAG_CLASS[theBits[0]].name == self.tagIndex[theBits[n]][2] + isGood[n] = nwKeyWords.KEY_CLASS[theBits[0]].name == self.tagIndex[theBits[n]][2] return isGood @@ -608,7 +586,7 @@ class NWIndex(): section. sTitle must be a string. """ theRefs = {} - for tKey in self.TAG_CLASS: + for tKey in nwKeyWords.KEY_CLASS: theRefs[tKey] = [] if tHandle not in self.refIndex: