pymel.util.enum.EnumDict

digraph inheritanceb695497f03 {
rankdir=TB;
ranksep=0.15;
nodesep=0.15;
size="8.0, 12.0";
  "EnumDict" [fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,URL="#pymel.util.enum.EnumDict",style="setlinewidth(0.5)",height=0.25,shape=box,fontsize=8];
  "EquivalencePairs" -> "EnumDict" [arrowsize=0.5,style="setlinewidth(0.5)"];
  "EquivalencePairs" [fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,URL="../pymel.util.utilitytypes/pymel.util.utilitytypes.EquivalencePairs.html#pymel.util.utilitytypes.EquivalencePairs",style="setlinewidth(0.5)",height=0.25,shape=box,fontsize=8];
  "TwoWayDict" -> "EquivalencePairs" [arrowsize=0.5,style="setlinewidth(0.5)"];
  "TwoWayDict" [fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,URL="../pymel.util.utilitytypes/pymel.util.utilitytypes.TwoWayDict.html#pymel.util.utilitytypes.TwoWayDict",style="setlinewidth(0.5)",height=0.25,shape=box,fontsize=8];
}

class EnumDict(keys, **kwargs)

This class provides a dictionary type for storing enumerations. Keys are string labels, while values are enumerated integers.

To instantiate, pass a sequence of string arguments to the EnumDict() constructor:

>>> from enum import EnumDict
>>> Colours = EnumDict(['red', 'blue', 'green'])
>>> Weekdays = EnumDict(['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'])
>>> Weekdays
{'fri': 4, 'mon': 0, 'sat': 5, 'sun': 6, 'thu': 3, 'tue': 1, 'wed': 2}

Alternately, a dictionary of label-value pairs can be provided:

>>> Numbers = EnumDict({'one': 1, 'two': 2, 'hundred' : 100, 'thousand' : 1000 } )

To convert from one representation to another, just use normal dictionary retrieval, it works in either direction:

>>> Weekdays[4]
'fri'
>>> Weekdays['fri']
4

If you need a particular representation, but don’t know what you’re starting from ( for example, a value that was passed as an argument ) you can use EnumDict.key or EnumDict.value:

>>> Weekdays.value(3)
3
>>> Weekdays.value('thu')
3
>>> Weekdays.key(2)
'wed'
>>> Weekdays.key('wed')
'wed'
key(index)

get a key value from an index. this method always returns a key. if a valid key is passed instead of an index, the key will be returned unchanged. this is useful when you need a key, but are not certain whether you are starting with a key or an index.

>>> units = EnumDict('units', ['invalid', 'inches', 'feet', 'yards', 'miles', 'millimeters', 'centimeters', 'kilometers', 'meters'])
>>> units.key(2)
'feet'
>>> units.key('inches')
'inches'
>>> units.key(10)
Traceback (most recent call last):
  ...
ValueError: invalid enumerator index: 10
>>> units.key('hectares')
Traceback (most recent call last):
  ...
ValueError: invalid enumerator key: 'hectares'
keys()
return a list of keys as strings ordered by their enumerator value
value(key)

get an index value from a key. this method always returns an index. if a valid index is passed instead of a key, the index will be returned unchanged. this is useful when you need an index, but are not certain whether you are starting with a key or an index.

>>> units = EnumDict('units', ['invalid', 'inches', 'feet', 'yards', 'miles', 'millimeters', 'centimeters', 'kilometers', 'meters'])
>>> units.value('inches')
1
>>> units.value(3)
3
>>> units.value('hectares')
Traceback (most recent call last):
  ...
ValueError: invalid enumerator key: 'hectares'
>>> units.value(10)
Traceback (most recent call last):
  ...
ValueError: invalid enumerator index: 10
values()
return a list of ordered integer values

Previous topic

pymel.util.enum.Enum

Next topic

pymel.util.enum.EnumValue

Core

Core Modules

Other Modules

This Page