Improved lookup of enums

This commit is contained in:
Veronica K. B. Olsen
2020-05-07 00:59:05 +02:00
parent 8037b3a311
commit d5775a7838
+12 -21
View File
@@ -146,40 +146,31 @@ class NWItem():
def setType(self, theType): def setType(self, theType):
if isinstance(theType, nwItemType): if isinstance(theType, nwItemType):
self.itemType = theType self.itemType = theType
return elif theType in nwItemType.__members__:
self.itemType = nwItemType[theType]
else: else:
for itemType in nwItemType: logger.error("Unrecognised item type '%s'" % theType)
if theType == itemType.name: self.itemType = nwItemType.NO_TYPE
self.itemType = itemType
return
logger.error("Unrecognised item type '%s'" % theType)
self.itemType = nwItemType.NO_TYPE
return return
def setClass(self, theClass): def setClass(self, theClass):
if isinstance(theClass, nwItemClass): if isinstance(theClass, nwItemClass):
self.itemClass = theClass self.itemClass = theClass
return elif theClass in nwItemClass.__members__:
self.itemClass = nwItemClass[theClass]
else: else:
for itemClass in nwItemClass: logger.error("Unrecognised item class '%s'" % theClass)
if theClass == itemClass.name: self.itemClass = nwItemClass.NO_CLASS
self.itemClass = itemClass
return
logger.error("Unrecognised item class '%s'" % theClass)
self.itemClass = nwItemClass.NO_CLASS
return return
def setLayout(self, theLayout): def setLayout(self, theLayout):
if isinstance(theLayout, nwItemLayout): if isinstance(theLayout, nwItemLayout):
self.itemLayout = theLayout self.itemLayout = theLayout
return elif theLayout in nwItemLayout.__members__:
self.itemLayout = nwItemLayout[theLayout]
else: else:
for itemLayout in nwItemLayout: logger.error("Unrecognised item layout '%s'" % theLayout)
if theLayout == itemLayout.name: self.itemLayout = nwItemLayout.NO_LAYOUT
self.itemLayout = itemLayout
return
logger.error("Unrecognised item layout '%s'" % theLayout)
self.itemLayout = nwItemLayout.NO_LAYOUT
return return
def setStatus(self, theStatus): def setStatus(self, theStatus):