| 1 |
import sys |
| 2 |
from unittest import mock |
| 3 |
from pprint import PrettyPrinter |
| 4 |
|
| 5 |
sys.modules["evdev.ecodes"] = mock.Mock() |
| 6 |
from evdev import ecodes_runtime as ecodes |
| 7 |
|
| 8 |
pprint = PrettyPrinter(indent=2, sort_dicts=True, width=120).pprint |
| 9 |
|
| 10 |
|
| 11 |
print("# Automatically generated by evdev.genecodes_py") |
| 12 |
print() |
| 13 |
print('"""') |
| 14 |
print(ecodes.__doc__.strip()) |
| 15 |
print('"""') |
| 16 |
|
| 17 |
print() |
| 18 |
print("from typing import Final") |
| 19 |
print() |
| 20 |
|
| 21 |
for name, value in ecodes.ecodes.items(): |
| 22 |
print(f"{name}: Final[int] = {value}") |
| 23 |
print() |
| 24 |
|
| 25 |
entries = [ |
| 26 |
("ecodes", "dict[str, int]", "#: Mapping of names to values."), |
| 27 |
("bytype", "dict[int, dict[int, str | tuple[str]]]", "#: Mapping of event types to other value/name mappings."), |
| 28 |
("keys", "dict[int, str | tuple[str]]", "#: Keys are a combination of all BTN and KEY codes."), |
| 29 |
("KEY", "dict[int, str | tuple[str]]", None), |
| 30 |
("ABS", "dict[int, str | tuple[str]]", None), |
| 31 |
("REL", "dict[int, str | tuple[str]]", None), |
| 32 |
("SW", "dict[int, str | tuple[str]]", None), |
| 33 |
("MSC", "dict[int, str | tuple[str]]", None), |
| 34 |
("LED", "dict[int, str | tuple[str]]", None), |
| 35 |
("BTN", "dict[int, str | tuple[str]]", None), |
| 36 |
("REP", "dict[int, str | tuple[str]]", None), |
| 37 |
("SND", "dict[int, str | tuple[str]]", None), |
| 38 |
("ID", "dict[int, str | tuple[str]]", None), |
| 39 |
("EV", "dict[int, str | tuple[str]]", None), |
| 40 |
("BUS", "dict[int, str | tuple[str]]", None), |
| 41 |
("SYN", "dict[int, str | tuple[str]]", None), |
| 42 |
("FF", "dict[int, str | tuple[str]]", None), |
| 43 |
("UI_FF", "dict[int, str | tuple[str]]", None), |
| 44 |
("FF_STATUS", "dict[int, str | tuple[str]]", None), |
| 45 |
("INPUT_PROP", "dict[int, str | tuple[str]]", None) |
| 46 |
] |
| 47 |
|
| 48 |
for key, annotation, doc in entries: |
| 49 |
if doc: |
| 50 |
print(doc) |
| 51 |
|
| 52 |
print(f"{key}: {annotation} = ", end="") |
| 53 |
pprint(getattr(ecodes, key)) |
| 54 |
print() |