|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from dataclasses import dataclass |
| 4 | + |
| 5 | + |
| 6 | +@dataclass(frozen=True, slots=True) |
| 7 | +class SettingsPageRegistration: |
| 8 | + route_name: str |
| 9 | + interface_attr: str |
| 10 | + item_attr: str |
| 11 | + page_method: str |
| 12 | + is_pivot: bool |
| 13 | + icon_name: str |
| 14 | + language_module: str |
| 15 | + sidebar_setting_key: str |
| 16 | + title_key: str = "title" |
| 17 | + url_alias: str | None = None |
| 18 | + |
| 19 | + |
| 20 | +SETTINGS_PAGE_REGISTRY: tuple[SettingsPageRegistration, ...] = ( |
| 21 | + SettingsPageRegistration( |
| 22 | + route_name="settings_basic", |
| 23 | + interface_attr="basicSettingsInterface", |
| 24 | + item_attr="basic_settings_item", |
| 25 | + page_method="basic_settings_page", |
| 26 | + is_pivot=False, |
| 27 | + icon_name="ic_fluent_wrench_settings_20_filled", |
| 28 | + language_module="basic_settings", |
| 29 | + sidebar_setting_key="base_settings", |
| 30 | + url_alias="basic", |
| 31 | + ), |
| 32 | + SettingsPageRegistration( |
| 33 | + route_name="settings_list", |
| 34 | + interface_attr="listManagementInterface", |
| 35 | + item_attr="list_management_item", |
| 36 | + page_method="list_management_page", |
| 37 | + is_pivot=True, |
| 38 | + icon_name="ic_fluent_list_20_filled", |
| 39 | + language_module="list_management", |
| 40 | + sidebar_setting_key="name_management", |
| 41 | + url_alias="list", |
| 42 | + ), |
| 43 | + SettingsPageRegistration( |
| 44 | + route_name="settings_extraction", |
| 45 | + interface_attr="extractionSettingsInterface", |
| 46 | + item_attr="extraction_settings_item", |
| 47 | + page_method="extraction_settings_page", |
| 48 | + is_pivot=True, |
| 49 | + icon_name="ic_fluent_archive_20_filled", |
| 50 | + language_module="extraction_settings", |
| 51 | + sidebar_setting_key="draw_settings", |
| 52 | + url_alias="extraction", |
| 53 | + ), |
| 54 | + SettingsPageRegistration( |
| 55 | + route_name="settings_floating", |
| 56 | + interface_attr="floatingWindowManagementInterface", |
| 57 | + item_attr="floating_window_management_item", |
| 58 | + page_method="floating_window_management_page", |
| 59 | + is_pivot=True, |
| 60 | + icon_name="ic_fluent_window_apps_20_filled", |
| 61 | + language_module="floating_window_management", |
| 62 | + sidebar_setting_key="floating_window_management", |
| 63 | + url_alias="floating", |
| 64 | + ), |
| 65 | + SettingsPageRegistration( |
| 66 | + route_name="settings_notification", |
| 67 | + interface_attr="notificationSettingsInterface", |
| 68 | + item_attr="notification_settings_item", |
| 69 | + page_method="notification_settings_page", |
| 70 | + is_pivot=True, |
| 71 | + icon_name="ic_fluent_comment_note_20_filled", |
| 72 | + language_module="notification_settings", |
| 73 | + sidebar_setting_key="notification_service", |
| 74 | + url_alias="notification", |
| 75 | + ), |
| 76 | + SettingsPageRegistration( |
| 77 | + route_name="settings_safety", |
| 78 | + interface_attr="safetySettingsInterface", |
| 79 | + item_attr="safety_settings_item", |
| 80 | + page_method="safety_settings_page", |
| 81 | + is_pivot=True, |
| 82 | + icon_name="ic_fluent_shield_20_filled", |
| 83 | + language_module="safety_settings", |
| 84 | + sidebar_setting_key="security_settings", |
| 85 | + url_alias="safety", |
| 86 | + ), |
| 87 | + SettingsPageRegistration( |
| 88 | + route_name="settings_linkage", |
| 89 | + interface_attr="courseSettingsInterface", |
| 90 | + item_attr="course_settings_item", |
| 91 | + page_method="linkage_settings_page", |
| 92 | + is_pivot=False, |
| 93 | + icon_name="ic_fluent_calendar_ltr_20_filled", |
| 94 | + language_module="linkage_settings", |
| 95 | + sidebar_setting_key="linkage_settings", |
| 96 | + ), |
| 97 | + SettingsPageRegistration( |
| 98 | + route_name="settings_voice", |
| 99 | + interface_attr="voiceSettingsInterface", |
| 100 | + item_attr="voice_settings_item", |
| 101 | + page_method="voice_settings_page", |
| 102 | + is_pivot=True, |
| 103 | + icon_name="ic_fluent_person_voice_20_filled", |
| 104 | + language_module="voice_settings", |
| 105 | + sidebar_setting_key="voice_settings", |
| 106 | + url_alias="voice", |
| 107 | + ), |
| 108 | + SettingsPageRegistration( |
| 109 | + route_name="settings_theme", |
| 110 | + interface_attr="themeManagementInterface", |
| 111 | + item_attr="theme_management_item", |
| 112 | + page_method="theme_management_page", |
| 113 | + is_pivot=False, |
| 114 | + icon_name="ic_fluent_paint_brush_20_filled", |
| 115 | + language_module="theme_management", |
| 116 | + sidebar_setting_key="theme_management", |
| 117 | + ), |
| 118 | + SettingsPageRegistration( |
| 119 | + route_name="settings_history", |
| 120 | + interface_attr="historyInterface", |
| 121 | + item_attr="history_item", |
| 122 | + page_method="history_page", |
| 123 | + is_pivot=True, |
| 124 | + icon_name="ic_fluent_history_20_filled", |
| 125 | + language_module="history", |
| 126 | + sidebar_setting_key="settings_history", |
| 127 | + url_alias="history", |
| 128 | + ), |
| 129 | + SettingsPageRegistration( |
| 130 | + route_name="settings_more", |
| 131 | + interface_attr="moreSettingsInterface", |
| 132 | + item_attr="more_settings_item", |
| 133 | + page_method="more_settings_page", |
| 134 | + is_pivot=True, |
| 135 | + icon_name="ic_fluent_more_horizontal_20_filled", |
| 136 | + language_module="more_settings", |
| 137 | + sidebar_setting_key="more_settings", |
| 138 | + url_alias="more", |
| 139 | + ), |
| 140 | + SettingsPageRegistration( |
| 141 | + route_name="settings_update", |
| 142 | + interface_attr="updateInterface", |
| 143 | + item_attr="update_item", |
| 144 | + page_method="update_page", |
| 145 | + is_pivot=False, |
| 146 | + icon_name="ic_fluent_arrow_sync_20_filled", |
| 147 | + language_module="update", |
| 148 | + sidebar_setting_key="updateInterface", |
| 149 | + url_alias="update", |
| 150 | + ), |
| 151 | + SettingsPageRegistration( |
| 152 | + route_name="settings_about", |
| 153 | + interface_attr="aboutInterface", |
| 154 | + item_attr="about_item", |
| 155 | + page_method="about_page", |
| 156 | + is_pivot=False, |
| 157 | + icon_name="ic_fluent_info_20_filled", |
| 158 | + language_module="about", |
| 159 | + sidebar_setting_key="aboutInterface", |
| 160 | + url_alias="about", |
| 161 | + ), |
| 162 | +) |
| 163 | + |
| 164 | + |
| 165 | +MAIN_PAGE_ALIAS_MAP: dict[str, str] = { |
| 166 | + "roll": "roll_call_page", |
| 167 | + "lottery": "lottery_page", |
| 168 | + "history": "history_page", |
| 169 | +} |
| 170 | + |
| 171 | + |
| 172 | +SETTINGS_PAGE_BY_ROUTE: dict[str, SettingsPageRegistration] = { |
| 173 | + page.route_name: page for page in SETTINGS_PAGE_REGISTRY |
| 174 | +} |
| 175 | +SETTINGS_PAGE_BY_INTERFACE: dict[str, SettingsPageRegistration] = { |
| 176 | + page.interface_attr: page for page in SETTINGS_PAGE_REGISTRY |
| 177 | +} |
| 178 | +SETTINGS_PAGE_BY_ALIAS: dict[str, SettingsPageRegistration] = { |
| 179 | + page.url_alias: page for page in SETTINGS_PAGE_REGISTRY if page.url_alias |
| 180 | +} |
| 181 | + |
| 182 | + |
| 183 | +def iter_settings_pages() -> tuple[SettingsPageRegistration, ...]: |
| 184 | + return SETTINGS_PAGE_REGISTRY |
| 185 | + |
| 186 | + |
| 187 | +def iter_navigable_settings_pages() -> tuple[SettingsPageRegistration, ...]: |
| 188 | + return SETTINGS_PAGE_REGISTRY |
| 189 | + |
| 190 | + |
| 191 | +def iter_settings_page_container_names() -> tuple[str, ...]: |
| 192 | + return tuple(page.interface_attr for page in SETTINGS_PAGE_REGISTRY) |
| 193 | + |
| 194 | + |
| 195 | +def get_settings_page_by_route(route_name: str) -> SettingsPageRegistration | None: |
| 196 | + return SETTINGS_PAGE_BY_ROUTE.get(route_name) |
| 197 | + |
| 198 | + |
| 199 | +def get_settings_page_by_interface( |
| 200 | + interface_attr: str, |
| 201 | +) -> SettingsPageRegistration | None: |
| 202 | + return SETTINGS_PAGE_BY_INTERFACE.get(interface_attr) |
| 203 | + |
| 204 | + |
| 205 | +def get_settings_page_by_alias(alias: str) -> SettingsPageRegistration | None: |
| 206 | + return SETTINGS_PAGE_BY_ALIAS.get(alias) |
| 207 | + |
| 208 | + |
| 209 | +def resolve_main_page_alias(alias: str) -> str | None: |
| 210 | + return MAIN_PAGE_ALIAS_MAP.get(alias) |
0 commit comments