JSON encode/decode GTK enums
问题 I have to save various properties of custom GTK elements to a file for future use and decided to use JSON because of the simple format and nesting of dicts. Many properties are GTK enums, like gtk.PAGE_ORIENTATION_PORTRAIT , gtk.ANCHOR_CENTER and pango.ALIGN_LEFT . They have a unique name which can be retrieved with obj.value_name to get a valid JSON type. Currently I have 2 methods for each of my elements: to_str() to get the value_name and from_str() which maps the str to the enum again. I