mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
added iterator for Enum
This commit is contained in:
parent
af10d2d283
commit
0c9ebbc8d1
@ -1862,6 +1862,18 @@ def uniqueName(name):
|
|||||||
global _serialGen
|
global _serialGen
|
||||||
return '%s-%s' % (name, _serialGen.next())
|
return '%s-%s' % (name, _serialGen.next())
|
||||||
|
|
||||||
|
class EnumIter:
|
||||||
|
def __init__(self, enum):
|
||||||
|
self._values = enum._stringTable.keys()
|
||||||
|
self._index = 0
|
||||||
|
def __iter__(self):
|
||||||
|
return self
|
||||||
|
def next(self):
|
||||||
|
if self._index >= len(self._values):
|
||||||
|
raise StopIteration
|
||||||
|
self._index += 1
|
||||||
|
return self._values[self._index-1]
|
||||||
|
|
||||||
class Enum:
|
class Enum:
|
||||||
"""Pass in list of strings or string of comma-separated strings.
|
"""Pass in list of strings or string of comma-separated strings.
|
||||||
Items are accessible as instance.item, and are assigned unique,
|
Items are accessible as instance.item, and are assigned unique,
|
||||||
@ -1923,6 +1935,9 @@ class Enum:
|
|||||||
self._stringTable[i] = item
|
self._stringTable[i] = item
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return EnumIter(self)
|
||||||
|
|
||||||
def getString(self, value):
|
def getString(self, value):
|
||||||
return self._stringTable[value]
|
return self._stringTable[value]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user