Alexandre B A Villares 🐍 on Nostr: If your #Python application has user interface "modes", how do you keep track of ...
If your #Python application has user interface "modes", how do you keep track of different modes and the "active mode"?
I always think about trying to use Enums, but end up using a tuple of strings and a global variable with an int for the active mode :((
It feels pretty clumsy to write
```if modes[active_mode] == 'MODE_NAME':
...
and
def toggle_mode():
global active_mode
active_mode = (active_mode + 1) % len(modes)
Published at
2024-07-31 15:55:08Event JSON
{
"id": "df392aeedbe3f042d6e478ea2c44d49d025ac9420a7b646aac57085baba79aad",
"pubkey": "883b5e42e69fa4eb2bee76e555c217028b48dc7676f61453c7f506fd1a33ab62",
"created_at": 1722441308,
"kind": 1,
"tags": [
[
"t",
"python"
],
[
"proxy",
"https://ciberlandia.pt/users/villares/statuses/112881913579554755",
"activitypub"
]
],
"content": "If your #Python application has user interface \"modes\", how do you keep track of different modes and the \"active mode\"?\n\nI always think about trying to use Enums, but end up using a tuple of strings and a global variable with an int for the active mode :((\n\nIt feels pretty clumsy to write \n```if modes[active_mode] == 'MODE_NAME':\n ...\n\nand\n\n\ndef toggle_mode():\n global active_mode\n active_mode = (active_mode + 1) % len(modes)\n\n",
"sig": "24c112579d09aead2a1b879cc10a39aa32e57d64b3056ddf5a624cddbe9e77d841328738692167e76c3bb70e639e7b83bf3003a2b452653f0e667036e548b15a"
}