| 16 | |
| 17 | == listener |
| 18 | This is a translation of the [wiki:Listener java Listener] |
| 19 | |
| 20 | == Tools |
| 21 | Tools contains a set of small tools for python. |
| 22 | === enum |
| 23 | enum is a tool to support 'classic enums' in python. The classic way was to just put enumeration values inside a class. For example, math.pi equals the number 3.1415 etc. We refer to pi in math.pi as an **enum item** in the math class. |
| 24 | We call this the "classic" enumeration, to distinguish it from the more complex Enum type in python. |
| 25 | |
| 26 | This tool assumes that all enum items in the class are actual instances of that class. So for example, this SimpleEnum class contains enum items P and Q: |
| 27 | |
| 28 | {{{ |
| 29 | class SimpleEnum: |
| 30 | def val(self) -> str: |
| 31 | return "$" |
| 32 | @staticmethod |
| 33 | def _static_init_(): |
| 34 | SimpleEnum.P = SimpleEnum() |
| 35 | SimpleEnum.Q = SimpleEnum() |
| 36 | SimpleEnum._static_init_() |
| 37 | }}} |
| 38 | |
| 39 | the enum method enumValues(claz) returns all the enum items contained in that claz. So in the above example, {{{enumValues(SimpleEnum) -> [SimpleEnum.P, SimpleEnum.Q]}}}. |
| 40 | |
| 41 | The enum method enumToString(item) returns the string representation. So in the above example, enumToString(SimpleEnum.P) returns "P". |