Browse Source

added Enum.hasString and Enum.fromString

Darren Ranalli 16 years ago
parent
commit
85fc649f2c
1 changed files with 9 additions and 0 deletions
  1. 9 0
      direct/src/showbase/PythonUtil.py

+ 9 - 0
direct/src/showbase/PythonUtil.py

@@ -2360,6 +2360,15 @@ class Enum:
     def __iter__(self):
         return EnumIter(self)
 
+    def hasString(self, string):
+        return string in set(self._stringTable.values())
+
+    def fromString(self, string):
+        if self.hasString(string):
+            return self.__dict__[string]
+        # throw an error
+        {}[string]
+
     def getString(self, value):
         return self._stringTable[value]