/GUI/Generic/Enumerations.py

https://bitbucket.org/alsh/pygui-mirror · Python · 16 lines · 10 code · 3 blank · 3 comment · 3 complexity · 7453ef07b596f36fd9cc373f266368ab MD5 · raw file

  1. #
  2. # PyGUI - Enumerated type facilities
  3. #
  4. class EnumMap(dict):
  5. def __init__(self, __name__, *args, **kwds):
  6. self.name = __name__
  7. dict.__init__(self, *args, **kwds)
  8. def __getitem__(self, key):
  9. try:
  10. return dict.__getitem__(self, key)
  11. except KeyError:
  12. raise ValueError("Invalid %s '%s', should be one of %s" %
  13. (self.name, key, ", ".join(["'%s'" % val for val in self.keys()])))