codis 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codis-1.1.1.dist-info/METADATA +194 -0
- codis-1.1.1.dist-info/RECORD +329 -0
- codis-1.1.1.dist-info/WHEEL +5 -0
- codis-1.1.1.dist-info/entry_points.txt +5 -0
- codis-1.1.1.dist-info/licenses/LICENSE +21 -0
- codis-1.1.1.dist-info/top_level.txt +2 -0
- run.py +190 -0
- src/__init__.py +1 -0
- src/__main__.py +81 -0
- src/_app_build.py +1507 -0
- src/_app_editor.py +1274 -0
- src/_app_kui.py +825 -0
- src/_app_lsp.py +625 -0
- src/_app_recovery.py +189 -0
- src/_app_settings.py +1385 -0
- src/_app_tools.py +2471 -0
- src/_app_webpreview.py +126 -0
- src/_font_safety.py +127 -0
- src/_shells.py +172 -0
- src/app.py +1488 -0
- src/chat/__init__.py +1 -0
- src/chat/adapters/__init__.py +33 -0
- src/chat/adapters/base.py +209 -0
- src/chat/adapters/discord.py +190 -0
- src/chat/adapters/http.py +78 -0
- src/chat/adapters/irc.py +360 -0
- src/chat/adapters/matrix.py +219 -0
- src/chat/adapters/mattermost.py +178 -0
- src/chat/adapters/mqtt.py +165 -0
- src/chat/adapters/slack.py +204 -0
- src/chat/adapters/telegram.py +117 -0
- src/chat/adapters/ws.py +154 -0
- src/chat/adapters/xmpp.py +337 -0
- src/chat/history.py +76 -0
- src/chat/models.py +207 -0
- src/chat/probe.py +79 -0
- src/chat/session.py +446 -0
- src/chat/util.py +125 -0
- src/collab/__init__.py +1 -0
- src/collab/net.py +411 -0
- src/collab/ot.py +311 -0
- src/collab/session.py +141 -0
- src/collab/tk_adapter.py +134 -0
- src/config.py +335 -0
- src/constants.py +2552 -0
- src/dep_catalog.py +446 -0
- src/diff/__init__.py +1 -0
- src/diff/engine.py +247 -0
- src/dpi.py +30 -0
- src/editor/__init__.py +1 -0
- src/editor/_pane_lsp.py +2937 -0
- src/editor/_pane_utils.py +171 -0
- src/editor/autocomplete.py +607 -0
- src/editor/code_folding.py +836 -0
- src/editor/color_preview.py +382 -0
- src/editor/complexity_lens.py +281 -0
- src/editor/diff_pane.py +623 -0
- src/editor/file_watcher.py +144 -0
- src/editor/focus_block.py +236 -0
- src/editor/heatmap.py +141 -0
- src/editor/inlay_hints.py +366 -0
- src/editor/inline_blame.py +429 -0
- src/editor/kdocs.py +3376 -0
- src/editor/large_file.py +488 -0
- src/editor/ligatures.py +180 -0
- src/editor/line_numbers.py +598 -0
- src/editor/minimap.py +691 -0
- src/editor/multi_cursor.py +269 -0
- src/editor/pane.py +2082 -0
- src/editor/rhythm.py +206 -0
- src/editor/save_hooks.py +43 -0
- src/editor/smart_selection.py +425 -0
- src/editor/smart_tips.py +719 -0
- src/editor/snippets.py +411 -0
- src/editor/sticky_note_gutter.py +410 -0
- src/editor/sticky_scroll.py +385 -0
- src/editor/suggest.py +464 -0
- src/editor/text_transforms.py +310 -0
- src/editor/vim_mode.py +1074 -0
- src/events/__init__.py +84 -0
- src/events/bus.py +427 -0
- src/events/correlator.py +244 -0
- src/events/kinds.py +125 -0
- src/events/pipeline.py +264 -0
- src/events/stream.py +416 -0
- src/events/window.py +204 -0
- src/extcompat/__init__.py +19 -0
- src/extcompat/code/__init__.py +13 -0
- src/extcompat/code/consent.py +162 -0
- src/extcompat/code/host.py +353 -0
- src/extcompat/code/hosts/py_host.py +763 -0
- src/extcompat/code/locate.py +105 -0
- src/extcompat/code/manager.py +325 -0
- src/extcompat/code/permissions.py +154 -0
- src/extcompat/code/sandbox.py +60 -0
- src/extcompat/colors.py +131 -0
- src/extcompat/common.py +184 -0
- src/extcompat/cson.py +269 -0
- src/extcompat/formats/__init__.py +22 -0
- src/extcompat/formats/_tm.py +189 -0
- src/extcompat/formats/_util.py +31 -0
- src/extcompat/formats/base16.py +66 -0
- src/extcompat/formats/brackets.py +172 -0
- src/extcompat/formats/eclipse.py +193 -0
- src/extcompat/formats/emacs.py +361 -0
- src/extcompat/formats/geany.py +147 -0
- src/extcompat/formats/generic.py +184 -0
- src/extcompat/formats/gtksource.py +117 -0
- src/extcompat/formats/helix.py +91 -0
- src/extcompat/formats/jetbrains.py +343 -0
- src/extcompat/formats/kate.py +130 -0
- src/extcompat/formats/micro.py +131 -0
- src/extcompat/formats/nano.py +111 -0
- src/extcompat/formats/notepadpp.py +140 -0
- src/extcompat/formats/pulsar.py +165 -0
- src/extcompat/formats/pyides.py +163 -0
- src/extcompat/formats/sublime.py +340 -0
- src/extcompat/jsonc.py +65 -0
- src/extcompat/lessish.py +128 -0
- src/extcompat/manager.py +122 -0
- src/extcompat/market/__init__.py +63 -0
- src/extcompat/market/sources.py +211 -0
- src/extcompat/model.py +88 -0
- src/extcompat/net.py +228 -0
- src/extcompat/openvsx.py +63 -0
- src/extcompat/readers.py +362 -0
- src/extcompat/registry.py +73 -0
- src/extcompat/safexml.py +63 -0
- src/extcompat/sexp.py +187 -0
- src/extcompat/sources.py +105 -0
- src/extcompat/store.py +276 -0
- src/extcompat/textmate.py +214 -0
- src/extcompat/themes.py +487 -0
- src/extcompat/yamlite.py +294 -0
- src/fileio.py +94 -0
- src/fs_ops.py +106 -0
- src/i18n.py +233 -0
- src/ia/__init__.py +1 -0
- src/ia/actions.py +295 -0
- src/ia/approval_gate.py +672 -0
- src/ia/checkpoints.py +308 -0
- src/ia/context_builder.py +921 -0
- src/ia/dialdiff.py +408 -0
- src/ia/iaspace.py +2078 -0
- src/ia/pair.py +296 -0
- src/ia/providers.py +954 -0
- src/ia/session.py +335 -0
- src/ia/toolbox.py +2524 -0
- src/launcher_actions.py +204 -0
- src/lint/__init__.py +1 -0
- src/lint/manager.py +1058 -0
- src/locales/.translate_manifest.json +64170 -0
- src/locales/de.json +4936 -0
- src/locales/en.json +4936 -0
- src/locales/es.json +4936 -0
- src/locales/fr.json +4936 -0
- src/locales/it.json +4936 -0
- src/locales/ja.json +4936 -0
- src/locales/ko.json +4936 -0
- src/locales/nl.json +4936 -0
- src/locales/pl.json +4936 -0
- src/locales/pt-BR.json +4936 -0
- src/locales/ru.json +4936 -0
- src/locales/tr.json +4936 -0
- src/locales/uk.json +4936 -0
- src/locales/zh-CN.json +4936 -0
- src/lsp/__init__.py +26 -0
- src/lsp/client.py +2300 -0
- src/lsp/dap_client.py +480 -0
- src/lsp/edits.py +84 -0
- src/lsp/framing.py +73 -0
- src/lsp/protocol.py +931 -0
- src/main.py +260 -0
- src/memtrim.py +91 -0
- src/plugins/__init__.py +1 -0
- src/plugins/api.py +1761 -0
- src/plugins/loader.py +571 -0
- src/plugins/process_runner.py +519 -0
- src/plugins/registry.py +342 -0
- src/plugins/safety.py +367 -0
- src/plugins/startup.py +195 -0
- src/plugins/store.py +1178 -0
- src/proc_registry.py +278 -0
- src/pyexec.py +394 -0
- src/recovery.py +259 -0
- src/stall_trace.py +92 -0
- src/standalone.py +1070 -0
- src/startup_profile.py +35 -0
- src/syntax/__init__.py +1 -0
- src/syntax/highlighter.py +776 -0
- src/syntax/patterns.py +584 -0
- src/system_profile.py +430 -0
- src/terminal/backends.py +658 -0
- src/terminal/internal.py +346 -0
- src/terminal/keys.py +138 -0
- src/terminal/palette.py +67 -0
- src/terminal/session.py +283 -0
- src/terminal/shells.py +79 -0
- src/terminal/view.py +489 -0
- src/terminal/vt.py +870 -0
- src/textfmt.py +22 -0
- src/theme/__init__.py +1 -0
- src/theme/base.py +1281 -0
- src/theme/colors.py +49 -0
- src/theme/manager.py +602 -0
- src/theme/utils.py +312 -0
- src/toolbox.py +329 -0
- src/trash_core.py +531 -0
- src/ui/__init__.py +1 -0
- src/ui/_perf_utils.py +285 -0
- src/ui/_persistence_utils.py +93 -0
- src/ui/accessibility.py +843 -0
- src/ui/activity_bar.py +860 -0
- src/ui/app_embed.py +434 -0
- src/ui/archive_panel.py +608 -0
- src/ui/bookmarks.py +314 -0
- src/ui/breadcrumb.py +383 -0
- src/ui/calculator_panel.py +982 -0
- src/ui/calendar_panel.py +1218 -0
- src/ui/chat_panel.py +1271 -0
- src/ui/chat_profile_dialog.py +278 -0
- src/ui/chat_render.py +128 -0
- src/ui/clock_panel.py +810 -0
- src/ui/code_outline.py +364 -0
- src/ui/code_runner.py +729 -0
- src/ui/code_stats.py +546 -0
- src/ui/collab_panel.py +1009 -0
- src/ui/color_picker.py +547 -0
- src/ui/command_palette.py +452 -0
- src/ui/cursor_manager.py +750 -0
- src/ui/custom_keywords_panel.py +413 -0
- src/ui/debug_panel.py +1037 -0
- src/ui/dependency_graph.py +692 -0
- src/ui/diff_panel.py +381 -0
- src/ui/docs_panel.py +514 -0
- src/ui/doom_embed.py +349 -0
- src/ui/dropdown.py +321 -0
- src/ui/easter_eggs.py +979 -0
- src/ui/env_manager.py +666 -0
- src/ui/extcode_bridge.py +215 -0
- src/ui/extcode_dialogs.py +412 -0
- src/ui/extcompat_dialog.py +583 -0
- src/ui/file_timeline.py +319 -0
- src/ui/file_tree.py +1208 -0
- src/ui/find_in_files.py +1355 -0
- src/ui/flowchart_panel.py +727 -0
- src/ui/formatter_panel.py +490 -0
- src/ui/git_auth.py +763 -0
- src/ui/git_clone_dialog.py +487 -0
- src/ui/git_panel.py +1483 -0
- src/ui/grab_safe.py +84 -0
- src/ui/internal_python_dialog.py +98 -0
- src/ui/k_ui/__init__.py +1305 -0
- src/ui/k_ui/_bgrenderer.py +317 -0
- src/ui/k_ui/_colors.py +213 -0
- src/ui/k_ui/_dock.py +545 -0
- src/ui/k_ui/_easter.py +290 -0
- src/ui/k_ui/_engine.py +5448 -0
- src/ui/k_ui/_perf.py +333 -0
- src/ui/k_ui/_tkutil.py +7 -0
- src/ui/k_ui/_tooltip.py +365 -0
- src/ui/k_ui/_widgets.py +1204 -0
- src/ui/k_ui/_world.py +837 -0
- src/ui/key_remapper.py +856 -0
- src/ui/launcher.py +1252 -0
- src/ui/lazy_panel.py +73 -0
- src/ui/macro_recorder.py +610 -0
- src/ui/menu_bar.py +898 -0
- src/ui/output_panel.py +321 -0
- src/ui/paint_canvas.py +1000 -0
- src/ui/paint_engine.py +535 -0
- src/ui/paint_panel.py +888 -0
- src/ui/panel_detach.py +112 -0
- src/ui/performance_panel.py +861 -0
- src/ui/pip_manager.py +1758 -0
- src/ui/plugin_panel.py +1586 -0
- src/ui/pomodoro_panel.py +447 -0
- src/ui/problems.py +566 -0
- src/ui/process_manager.py +1657 -0
- src/ui/project_templates.py +775 -0
- src/ui/recovery_dialog.py +122 -0
- src/ui/regex_playground.py +304 -0
- src/ui/remote_adapters.py +1398 -0
- src/ui/remote_browser.py +1224 -0
- src/ui/remote_profile_dialog.py +342 -0
- src/ui/render_panel.py +1293 -0
- src/ui/rest_client.py +549 -0
- src/ui/scratchpad.py +548 -0
- src/ui/search_bar.py +1274 -0
- src/ui/settings_editor.py +3349 -0
- src/ui/settings_window.py +1554 -0
- src/ui/snippets_panel.py +597 -0
- src/ui/sql_studio.py +1815 -0
- src/ui/status_bar.py +438 -0
- src/ui/tab_bar.py +654 -0
- src/ui/task_manager.py +1773 -0
- src/ui/terminal.py +525 -0
- src/ui/theme_preview_panel.py +851 -0
- src/ui/thread_safe_tk.py +152 -0
- src/ui/time_tracker.py +574 -0
- src/ui/tkbind.py +43 -0
- src/ui/todo_panel.py +358 -0
- src/ui/toolbox_panels.py +658 -0
- src/ui/trash_manager.py +657 -0
- src/ui/ui_scale.py +294 -0
- src/ui/ux_enhancements.py +41 -0
- src/ui/web_preview.py +397 -0
- src/ui/webdev.py +630 -0
- src/ui/welcome.py +567 -0
- src/ui/window_embed.py +1500 -0
- src/ui/wizard.py +1550 -0
- src/ui/workspace_switcher.py +418 -0
- src/ui/workspace_trust.py +370 -0
- src/ui/zen_audio.py +354 -0
- src/ui/zen_media.py +2271 -0
- src/ui/zen_media_client.py +303 -0
- src/ui/zen_media_host.py +329 -0
- src/ui/zen_player.py +907 -0
- src/ui/zen_player_widgets.py +700 -0
- src/updater/__init__.py +11 -0
- src/updater/assets.py +145 -0
- src/updater/backup.py +101 -0
- src/updater/channel.py +221 -0
- src/updater/dialog.py +492 -0
- src/updater/integrity.py +111 -0
- src/updater/manager.py +727 -0
- src/updater/result.py +114 -0
- src/venv_runtime.py +531 -0
- src/workspace_state.py +25 -0
src/ui/accessibility.py
ADDED
|
@@ -0,0 +1,843 @@
|
|
|
1
|
+
"""Codis - Módulo de Acessibilidade.
|
|
2
|
+
|
|
3
|
+
Funcionalidades:
|
|
4
|
+
- Suporte a leitores de tela via anotações ARIA-like e texto alternativo
|
|
5
|
+
- Navegação completa por teclado (Tab, Shift+Tab, setas, Enter, Escape)
|
|
6
|
+
- Modo de alto contraste (WCAG AA/AAA)
|
|
7
|
+
- Modos para daltonismo: protanopia, deuteranopia, tritanopia
|
|
8
|
+
- Todos os modos são opcionais e ativáveis individualmente via config
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import contextlib
|
|
14
|
+
import logging
|
|
15
|
+
import os
|
|
16
|
+
import platform
|
|
17
|
+
import subprocess
|
|
18
|
+
import threading
|
|
19
|
+
import tkinter as tk
|
|
20
|
+
from collections.abc import Callable
|
|
21
|
+
from dataclasses import dataclass
|
|
22
|
+
from tkinter import ttk
|
|
23
|
+
from typing import Any
|
|
24
|
+
|
|
25
|
+
from src.i18n import _t
|
|
26
|
+
from src.ui.grab_safe import safe_grab_set
|
|
27
|
+
|
|
28
|
+
logger = logging.getLogger("Codis.A11y")
|
|
29
|
+
|
|
30
|
+
_COLORBLIND_PALETTES: dict[str, dict[str, str]] = {
|
|
31
|
+
"protanopia": {
|
|
32
|
+
"error": "#0077BB",
|
|
33
|
+
"warning": "#EE7733",
|
|
34
|
+
"success": "#009988",
|
|
35
|
+
"info": "#BBBBBB",
|
|
36
|
+
"accent": "#0077BB",
|
|
37
|
+
},
|
|
38
|
+
"deuteranopia": {
|
|
39
|
+
"error": "#D55E00",
|
|
40
|
+
"warning": "#E69F00",
|
|
41
|
+
"success": "#0072B2",
|
|
42
|
+
"info": "#BBBBBB",
|
|
43
|
+
"accent": "#0072B2",
|
|
44
|
+
},
|
|
45
|
+
"tritanopia": {
|
|
46
|
+
"error": "#CC3311",
|
|
47
|
+
"warning": "#EE7733",
|
|
48
|
+
"success": "#009988",
|
|
49
|
+
"info": "#AAAAAA",
|
|
50
|
+
"accent": "#CC3311",
|
|
51
|
+
},
|
|
52
|
+
"achromatopsia": {
|
|
53
|
+
"error": "#111111",
|
|
54
|
+
"warning": "#555555",
|
|
55
|
+
"success": "#888888",
|
|
56
|
+
"info": "#BBBBBB",
|
|
57
|
+
"accent": "#333333",
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
_HIGH_CONTRAST_OVERRIDES: dict[str, str] = {
|
|
62
|
+
"bg": "#000000",
|
|
63
|
+
"fg": "#FFFFFF",
|
|
64
|
+
"editor_bg": "#000000",
|
|
65
|
+
"editor_fg": "#FFFFFF",
|
|
66
|
+
"sidebar_bg": "#0A0A0A",
|
|
67
|
+
"panel_bg": "#0A0A0A",
|
|
68
|
+
"border": "#FFFFFF",
|
|
69
|
+
"accent": "#FFFF00",
|
|
70
|
+
"selection": "#0000FF",
|
|
71
|
+
"cursor": "#FFFFFF",
|
|
72
|
+
"fg_muted": "#CCCCCC",
|
|
73
|
+
"line_hl": "#1A1A1A",
|
|
74
|
+
"floating_bg": "#0A0A0A",
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@dataclass
|
|
79
|
+
class _A11yAnnotation:
|
|
80
|
+
"""Anotação de acessibilidade para um widget."""
|
|
81
|
+
|
|
82
|
+
role: str = ""
|
|
83
|
+
label: str = ""
|
|
84
|
+
description: str = ""
|
|
85
|
+
live: str = ""
|
|
86
|
+
expanded: bool | None = None
|
|
87
|
+
checked: bool | None = None
|
|
88
|
+
disabled: bool = False
|
|
89
|
+
keyshortcut: str = ""
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class ScreenReaderBridge:
|
|
93
|
+
"""Envia texto para o leitor de tela do sistema de forma não-bloqueante.
|
|
94
|
+
|
|
95
|
+
Suporta:
|
|
96
|
+
- Windows: NVDA (via nvda_controller_client) e SAPI (via COM/ctypes)
|
|
97
|
+
- Linux: Speech-dispatcher (spd-say) e Orca (via AT-SPI2)
|
|
98
|
+
- macOS: say (nativo)
|
|
99
|
+
|
|
100
|
+
Fallback: log de debug quando nenhum sistema está disponível.
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
def __init__(self) -> None:
|
|
104
|
+
self._platform = platform.system()
|
|
105
|
+
self._available = self._detect()
|
|
106
|
+
self._lock = threading.Lock()
|
|
107
|
+
self._queue: list[str] = []
|
|
108
|
+
|
|
109
|
+
def _detect(self) -> bool:
|
|
110
|
+
"""Detecta disponibilidade de TTS/leitor de tela."""
|
|
111
|
+
if self._platform == "Windows":
|
|
112
|
+
return True
|
|
113
|
+
if self._platform == "Linux":
|
|
114
|
+
return bool(_which("spd-say") or _which("espeak") or _which("festival"))
|
|
115
|
+
if self._platform == "Darwin":
|
|
116
|
+
return bool(_which("say"))
|
|
117
|
+
return False
|
|
118
|
+
|
|
119
|
+
def speak(self, text: str, interrupt: bool = False) -> None:
|
|
120
|
+
"""Anuncia *text* pelo leitor de tela/TTS de forma assíncrona."""
|
|
121
|
+
if not text:
|
|
122
|
+
return
|
|
123
|
+
threading.Thread(
|
|
124
|
+
target=self._speak_worker,
|
|
125
|
+
args=(text, interrupt),
|
|
126
|
+
daemon=True,
|
|
127
|
+
name="Codis-A11y-TTS",
|
|
128
|
+
).start()
|
|
129
|
+
|
|
130
|
+
def _speak_worker(self, text: str, interrupt: bool) -> None:
|
|
131
|
+
"""Worker assíncrono que chama o TTS do sistema."""
|
|
132
|
+
with self._lock:
|
|
133
|
+
if self._platform == "Linux":
|
|
134
|
+
self._speak_linux(text, interrupt)
|
|
135
|
+
elif self._platform == "Darwin":
|
|
136
|
+
self._speak_macos(text, interrupt)
|
|
137
|
+
elif self._platform == "Windows":
|
|
138
|
+
self._speak_windows(text, interrupt)
|
|
139
|
+
else:
|
|
140
|
+
logger.debug("A11y TTS: %s", text)
|
|
141
|
+
|
|
142
|
+
def _speak_linux(self, text: str, interrupt: bool) -> None:
|
|
143
|
+
cmd: list[str] = []
|
|
144
|
+
if _which("spd-say"):
|
|
145
|
+
cmd = ["spd-say", "-e" if interrupt else "", "--", text]
|
|
146
|
+
cmd = [c for c in cmd if c]
|
|
147
|
+
elif _which("espeak"):
|
|
148
|
+
cmd = ["espeak", "--", text]
|
|
149
|
+
if cmd:
|
|
150
|
+
with contextlib.suppress(OSError, subprocess.SubprocessError):
|
|
151
|
+
subprocess.run(cmd, timeout=10, check=False,
|
|
152
|
+
capture_output=True)
|
|
153
|
+
|
|
154
|
+
def _speak_macos(self, text: str, interrupt: bool) -> None:
|
|
155
|
+
with contextlib.suppress(OSError, subprocess.SubprocessError):
|
|
156
|
+
subprocess.run(["say", "--", text], timeout=15,
|
|
157
|
+
check=False, capture_output=True)
|
|
158
|
+
|
|
159
|
+
def _speak_windows(self, text: str, interrupt: bool) -> None:
|
|
160
|
+
ps_cmd = (
|
|
161
|
+
"Add-Type -AssemblyName System.Speech; "
|
|
162
|
+
"$s = New-Object System.Speech.Synthesis.SpeechSynthesizer; "
|
|
163
|
+
"$s.Speak($env:CODIS_TTS_TEXT);"
|
|
164
|
+
)
|
|
165
|
+
env = {**os.environ, "CODIS_TTS_TEXT": text}
|
|
166
|
+
with contextlib.suppress(OSError, subprocess.SubprocessError):
|
|
167
|
+
subprocess.run(
|
|
168
|
+
["powershell", "-NoProfile", "-Command", ps_cmd],
|
|
169
|
+
timeout=15,
|
|
170
|
+
check=False,
|
|
171
|
+
capture_output=True,
|
|
172
|
+
env=env,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
@property
|
|
176
|
+
def available(self) -> bool:
|
|
177
|
+
"""True se um motor TTS foi detectado no sistema."""
|
|
178
|
+
return self._available
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _which(cmd: str) -> str | None:
|
|
182
|
+
"""Retorna o caminho completo de *cmd* ou None se não encontrado."""
|
|
183
|
+
import shutil
|
|
184
|
+
|
|
185
|
+
return shutil.which(cmd)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
class KeyboardNavigationManager:
|
|
189
|
+
"""Gerencia navegação por teclado em uma janela Tkinter.
|
|
190
|
+
|
|
191
|
+
- Tab / Shift+Tab: foco sequencial entre widgets registrados
|
|
192
|
+
- Setas: movimento contextual (listas, menus, árvores)
|
|
193
|
+
- Enter / Space: ativação do widget focado
|
|
194
|
+
- Escape: fecha modais ou retorna ao contexto anterior
|
|
195
|
+
"""
|
|
196
|
+
|
|
197
|
+
def __init__(self, root: tk.Tk | tk.Toplevel) -> None:
|
|
198
|
+
self._root = root
|
|
199
|
+
self._groups: dict[str, list[tk.Widget]] = {}
|
|
200
|
+
self._active_group: str | None = None
|
|
201
|
+
self._focus_index: dict[str, int] = {}
|
|
202
|
+
|
|
203
|
+
root.bind_all("<Tab>", self._on_tab, add="+")
|
|
204
|
+
root.bind_all("<Shift-Tab>", self._on_shift_tab, add="+")
|
|
205
|
+
root.bind_all("<Escape>", self._on_escape, add="+")
|
|
206
|
+
|
|
207
|
+
def _focus_current(self) -> None:
|
|
208
|
+
if self._active_group is None:
|
|
209
|
+
return
|
|
210
|
+
grp = self._groups.get(self._active_group, [])
|
|
211
|
+
idx = self._focus_index.get(self._active_group, 0)
|
|
212
|
+
if grp and 0 <= idx < len(grp):
|
|
213
|
+
with contextlib.suppress(tk.TclError):
|
|
214
|
+
grp[idx].focus_set()
|
|
215
|
+
|
|
216
|
+
def _on_tab(self, event: tk.Event) -> str | None:
|
|
217
|
+
if self._active_group is None:
|
|
218
|
+
return None
|
|
219
|
+
grp = self._groups.get(self._active_group, [])
|
|
220
|
+
if not grp:
|
|
221
|
+
return None
|
|
222
|
+
idx = self._focus_index[self._active_group]
|
|
223
|
+
self._focus_index[self._active_group] = (idx + 1) % len(grp)
|
|
224
|
+
self._focus_current()
|
|
225
|
+
return "break"
|
|
226
|
+
|
|
227
|
+
def _on_shift_tab(self, event: tk.Event) -> str | None:
|
|
228
|
+
if self._active_group is None:
|
|
229
|
+
return None
|
|
230
|
+
grp = self._groups.get(self._active_group, [])
|
|
231
|
+
if not grp:
|
|
232
|
+
return None
|
|
233
|
+
idx = self._focus_index[self._active_group]
|
|
234
|
+
self._focus_index[self._active_group] = (idx - 1) % len(grp)
|
|
235
|
+
self._focus_current()
|
|
236
|
+
return "break"
|
|
237
|
+
|
|
238
|
+
def _on_escape(self, _event: tk.Event) -> None:
|
|
239
|
+
self._active_group = None
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
class AccessibilityManager:
|
|
243
|
+
"""Gerenciador central de acessibilidade do Codis.
|
|
244
|
+
|
|
245
|
+
Controla:
|
|
246
|
+
- Modo de alto contraste
|
|
247
|
+
- Modo para daltonismo
|
|
248
|
+
- Suporte a leitor de tela
|
|
249
|
+
- Navegação por teclado
|
|
250
|
+
- Tamanho mínimo de fonte acessível
|
|
251
|
+
|
|
252
|
+
Todos os modos são opcionais. Nenhum afeta o comportamento padrão
|
|
253
|
+
enquanto não for explicitamente ativado pelo usuário nas configurações.
|
|
254
|
+
"""
|
|
255
|
+
|
|
256
|
+
def __init__(self, app: Any, cfg: Any, theme_mgr: Any) -> None:
|
|
257
|
+
"""
|
|
258
|
+
Args:
|
|
259
|
+
app: Instância de CodisApp.
|
|
260
|
+
cfg: ConfigManager com preferências do usuário.
|
|
261
|
+
theme_mgr: ThemeManager para aplicar sobreposições de cor.
|
|
262
|
+
"""
|
|
263
|
+
self._app = app
|
|
264
|
+
self._cfg = cfg
|
|
265
|
+
self._tmgr = theme_mgr
|
|
266
|
+
self._annotations: dict[str, _A11yAnnotation] = {}
|
|
267
|
+
self._sr = ScreenReaderBridge()
|
|
268
|
+
self._nav: KeyboardNavigationManager | None = None
|
|
269
|
+
self._active_modes: set[str] = set()
|
|
270
|
+
|
|
271
|
+
self._high_contrast = False
|
|
272
|
+
self._colorblind_mode: str | None = None
|
|
273
|
+
self._screen_reader_enabled: bool = False
|
|
274
|
+
self._keyboard_nav_enabled: bool = True
|
|
275
|
+
self._large_ui_font: bool = False
|
|
276
|
+
self._reduce_motion: bool = False
|
|
277
|
+
self._prev_theme_name: str | None = None
|
|
278
|
+
|
|
279
|
+
self._load_prefs()
|
|
280
|
+
|
|
281
|
+
def _load_prefs(self) -> None:
|
|
282
|
+
"""Carrega preferências de acessibilidade do ConfigManager."""
|
|
283
|
+
hc = self._cfg.get("a11y_high_contrast", False)
|
|
284
|
+
cb = self._cfg.get("a11y_colorblind_mode", "")
|
|
285
|
+
self._screen_reader_enabled = self._cfg.get("a11y_screen_reader", False)
|
|
286
|
+
self._keyboard_nav_enabled = self._cfg.get("a11y_keyboard_nav", True)
|
|
287
|
+
self._large_ui_font = self._cfg.get("a11y_large_ui_font", False)
|
|
288
|
+
self._reduce_motion = self._cfg.get("a11y_reduce_motion", False)
|
|
289
|
+
if hc:
|
|
290
|
+
self.enable_high_contrast(save=False)
|
|
291
|
+
if cb and cb in _COLORBLIND_PALETTES:
|
|
292
|
+
self.enable_colorblind_mode(cb, save=False)
|
|
293
|
+
if self._keyboard_nav_enabled:
|
|
294
|
+
with contextlib.suppress(Exception):
|
|
295
|
+
root = getattr(self._app, "_root", None)
|
|
296
|
+
if root:
|
|
297
|
+
self.setup_keyboard_navigation(root)
|
|
298
|
+
|
|
299
|
+
def _save_prefs(self) -> None:
|
|
300
|
+
self._cfg.set("a11y_high_contrast", self._high_contrast)
|
|
301
|
+
self._cfg.set("a11y_colorblind_mode", self._colorblind_mode or "")
|
|
302
|
+
self._cfg.set("a11y_screen_reader", self._screen_reader_enabled)
|
|
303
|
+
self._cfg.set("a11y_keyboard_nav", self._keyboard_nav_enabled)
|
|
304
|
+
self._cfg.set("a11y_large_ui_font", self._large_ui_font)
|
|
305
|
+
self._cfg.set("a11y_reduce_motion", self._reduce_motion)
|
|
306
|
+
|
|
307
|
+
def enable_high_contrast(self, save: bool = True) -> None:
|
|
308
|
+
"""Ativa o modo de alto contraste trocando o tema para 'high_contrast'."""
|
|
309
|
+
|
|
310
|
+
from src.theme.base import THEMES
|
|
311
|
+
|
|
312
|
+
self._high_contrast = True
|
|
313
|
+
self._active_modes.add("high_contrast")
|
|
314
|
+
|
|
315
|
+
if self._prev_theme_name is None:
|
|
316
|
+
current_name = getattr(self._tmgr, "_name", None) or getattr(
|
|
317
|
+
self._tmgr.theme, "name", "fluent_dark"
|
|
318
|
+
)
|
|
319
|
+
if current_name != "high_contrast":
|
|
320
|
+
self._prev_theme_name = current_name
|
|
321
|
+
|
|
322
|
+
if "high_contrast" in THEMES:
|
|
323
|
+
with contextlib.suppress(Exception):
|
|
324
|
+
self._tmgr.set("high_contrast")
|
|
325
|
+
else:
|
|
326
|
+
self._reapply_active_overrides()
|
|
327
|
+
|
|
328
|
+
logger.info("Acessibilidade: alto contraste ativado.")
|
|
329
|
+
if save:
|
|
330
|
+
self._save_prefs()
|
|
331
|
+
self._announce(_t("a11y.high_contrast_on",
|
|
332
|
+
"Modo de alto contraste ativado."))
|
|
333
|
+
|
|
334
|
+
def disable_high_contrast(self, save: bool = True) -> None:
|
|
335
|
+
"""Desativa o modo de alto contraste restaurando o tema anterior."""
|
|
336
|
+
|
|
337
|
+
self._high_contrast = False
|
|
338
|
+
self._active_modes.discard("high_contrast")
|
|
339
|
+
|
|
340
|
+
prev = self._prev_theme_name
|
|
341
|
+
self._prev_theme_name = None
|
|
342
|
+
if prev:
|
|
343
|
+
with contextlib.suppress(Exception):
|
|
344
|
+
self._tmgr.set(prev)
|
|
345
|
+
else:
|
|
346
|
+
self._restore_theme()
|
|
347
|
+
|
|
348
|
+
if save:
|
|
349
|
+
self._save_prefs()
|
|
350
|
+
self._announce(
|
|
351
|
+
_t("a11y.high_contrast_off", "Modo de alto contraste desativado.")
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
def toggle_high_contrast(self) -> bool:
|
|
355
|
+
"""Alterna alto contraste. Retorna o novo estado."""
|
|
356
|
+
if self._high_contrast:
|
|
357
|
+
self.disable_high_contrast()
|
|
358
|
+
else:
|
|
359
|
+
self.enable_high_contrast()
|
|
360
|
+
return self._high_contrast
|
|
361
|
+
|
|
362
|
+
def enable_colorblind_mode(self, mode: str, save: bool = True) -> None:
|
|
363
|
+
"""Ativa paleta otimizada para o tipo de daltonismo especificado.
|
|
364
|
+
|
|
365
|
+
Args:
|
|
366
|
+
mode: "protanopia" | "deuteranopia" | "tritanopia" | "achromatopsia"
|
|
367
|
+
"""
|
|
368
|
+
if mode not in _COLORBLIND_PALETTES:
|
|
369
|
+
logger.warning("Modo de daltonismo desconhecido: %s", mode)
|
|
370
|
+
return
|
|
371
|
+
if self._colorblind_mode:
|
|
372
|
+
self._active_modes.discard(f"colorblind_{self._colorblind_mode}")
|
|
373
|
+
self._colorblind_mode = mode
|
|
374
|
+
self._active_modes.add(f"colorblind_{mode}")
|
|
375
|
+
self._reapply_active_overrides()
|
|
376
|
+
logger.info("Acessibilidade: modo daltonismo '%s' ativado.", mode)
|
|
377
|
+
if save:
|
|
378
|
+
self._save_prefs()
|
|
379
|
+
label = _t(f"a11y.colorblind_{mode}",
|
|
380
|
+
mode.replace("_", " ").capitalize())
|
|
381
|
+
self._announce(
|
|
382
|
+
_t("a11y.colorblind_on", f"Modo para daltonismo ativado: {label}")
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
def disable_colorblind_mode(self, save: bool = True) -> None:
|
|
386
|
+
"""Desativa o modo de daltonismo atual."""
|
|
387
|
+
if self._colorblind_mode:
|
|
388
|
+
self._active_modes.discard(f"colorblind_{self._colorblind_mode}")
|
|
389
|
+
self._colorblind_mode = None
|
|
390
|
+
self._restore_theme()
|
|
391
|
+
if save:
|
|
392
|
+
self._save_prefs()
|
|
393
|
+
self._announce(
|
|
394
|
+
_t("a11y.colorblind_off", "Modo para daltonismo desativado."))
|
|
395
|
+
|
|
396
|
+
@property
|
|
397
|
+
def available_colorblind_modes(self) -> list[str]:
|
|
398
|
+
"""Lista de modos de daltonismo disponíveis."""
|
|
399
|
+
return list(_COLORBLIND_PALETTES.keys())
|
|
400
|
+
|
|
401
|
+
def annotate(self, widget: tk.Widget, **kwargs: Any) -> None:
|
|
402
|
+
"""Associa metadados de acessibilidade a um widget.
|
|
403
|
+
|
|
404
|
+
Exemplo::
|
|
405
|
+
|
|
406
|
+
mgr.annotate(btn_save,
|
|
407
|
+
role="button",
|
|
408
|
+
label=_t("file.save", "Salvar"),
|
|
409
|
+
keyshortcut="Ctrl+S")
|
|
410
|
+
|
|
411
|
+
Args:
|
|
412
|
+
widget: Widget Tkinter a anotar.
|
|
413
|
+
**kwargs: Campos de :class:`_A11yAnnotation`.
|
|
414
|
+
"""
|
|
415
|
+
widget_id = str(id(widget))
|
|
416
|
+
self._annotations[widget_id] = _A11yAnnotation(**kwargs)
|
|
417
|
+
|
|
418
|
+
def _on_focus(_ev: tk.Event) -> None:
|
|
419
|
+
ann = self._annotations.get(widget_id)
|
|
420
|
+
if ann:
|
|
421
|
+
parts = [ann.label or ann.role]
|
|
422
|
+
if ann.keyshortcut:
|
|
423
|
+
parts.append(f"({ann.keyshortcut})")
|
|
424
|
+
if ann.description:
|
|
425
|
+
parts.append(f"- {ann.description}")
|
|
426
|
+
self._announce(" ".join(parts))
|
|
427
|
+
|
|
428
|
+
with contextlib.suppress(tk.TclError):
|
|
429
|
+
widget.bind("<FocusIn>", _on_focus, add="+")
|
|
430
|
+
|
|
431
|
+
def setup_widget_reading(self, root: tk.Widget) -> None:
|
|
432
|
+
"""Lê automaticamente rótulos de qualquer widget que ganhe foco.
|
|
433
|
+
|
|
434
|
+
Funciona como o TalkBack do Android: lê o texto ou aria-label
|
|
435
|
+
de todo widget focalizável, mesmo sem anotação explícita.
|
|
436
|
+
"""
|
|
437
|
+
if not self._screen_reader_enabled:
|
|
438
|
+
return
|
|
439
|
+
|
|
440
|
+
def _on_any_focus(ev: tk.Event) -> None:
|
|
441
|
+
widget = ev.widget
|
|
442
|
+
ann = self._annotations.get(str(id(widget)))
|
|
443
|
+
if ann and ann.label:
|
|
444
|
+
parts = [ann.label]
|
|
445
|
+
if ann.role:
|
|
446
|
+
parts.append(f"({ann.role})")
|
|
447
|
+
if ann.keyshortcut:
|
|
448
|
+
parts.append(ann.keyshortcut)
|
|
449
|
+
self._announce(" ".join(parts), interrupt=True)
|
|
450
|
+
return
|
|
451
|
+
text_parts: list[str] = []
|
|
452
|
+
try:
|
|
453
|
+
cls = type(widget).__name__
|
|
454
|
+
if cls in ("Button", "Label"):
|
|
455
|
+
text_parts.append(str(widget.cget("text")))
|
|
456
|
+
elif cls == "Entry":
|
|
457
|
+
text_parts.append(_t("a11y.input_field", "Campo de texto"))
|
|
458
|
+
val = widget.get()
|
|
459
|
+
if val:
|
|
460
|
+
text_parts.append(val[:40])
|
|
461
|
+
elif cls == "Checkbutton":
|
|
462
|
+
text_parts.append(str(widget.cget("text")))
|
|
463
|
+
elif cls == "Combobox":
|
|
464
|
+
text_parts.append(_t("a11y.combobox", "Lista"))
|
|
465
|
+
text_parts.append(widget.get())
|
|
466
|
+
elif cls == "Scale":
|
|
467
|
+
text_parts.append(_t("a11y.slider", "Deslizador"))
|
|
468
|
+
text_parts.append(str(widget.get()))
|
|
469
|
+
elif cls == "Text":
|
|
470
|
+
text_parts.append(
|
|
471
|
+
_t("a11y.text_editor", "Editor de texto"))
|
|
472
|
+
except Exception:
|
|
473
|
+
logger.debug(
|
|
474
|
+
"Falha ao descrever widget para leitor de tela.", exc_info=True
|
|
475
|
+
)
|
|
476
|
+
if text_parts:
|
|
477
|
+
self._announce(
|
|
478
|
+
" - ".join(p for p in text_parts if p), interrupt=True)
|
|
479
|
+
|
|
480
|
+
_hover_job: list[str] = [None] # type: ignore[list-item]
|
|
481
|
+
|
|
482
|
+
def _on_hover(ev: tk.Event) -> None:
|
|
483
|
+
"""Anuncia o widget sob o mouse com debounce de 400ms."""
|
|
484
|
+
widget = ev.widget
|
|
485
|
+
cls = type(widget).__name__
|
|
486
|
+
if cls in (
|
|
487
|
+
"Frame",
|
|
488
|
+
"LabelFrame",
|
|
489
|
+
"PanedWindow",
|
|
490
|
+
"Canvas",
|
|
491
|
+
"Scrollbar",
|
|
492
|
+
"Tk",
|
|
493
|
+
"Toplevel",
|
|
494
|
+
):
|
|
495
|
+
return
|
|
496
|
+
try:
|
|
497
|
+
if not widget.winfo_exists():
|
|
498
|
+
return
|
|
499
|
+
except tk.TclError:
|
|
500
|
+
return
|
|
501
|
+
if _hover_job[0]:
|
|
502
|
+
with contextlib.suppress(tk.TclError):
|
|
503
|
+
root.after_cancel(_hover_job[0])
|
|
504
|
+
_hover_job[0] = None
|
|
505
|
+
|
|
506
|
+
def _safe_announce() -> None:
|
|
507
|
+
with contextlib.suppress(tk.TclError):
|
|
508
|
+
if widget.winfo_exists():
|
|
509
|
+
_on_any_focus(ev)
|
|
510
|
+
|
|
511
|
+
_hover_job[0] = root.after(400, _safe_announce)
|
|
512
|
+
|
|
513
|
+
with contextlib.suppress(tk.TclError):
|
|
514
|
+
root.bind_all("<FocusIn>", _on_any_focus, add="+")
|
|
515
|
+
root.bind_all("<Enter>", _on_hover, add="+")
|
|
516
|
+
|
|
517
|
+
def announce(self, text: str, interrupt: bool = False) -> None:
|
|
518
|
+
"""Anuncia texto via leitor de tela de forma pública.
|
|
519
|
+
|
|
520
|
+
Args:
|
|
521
|
+
text: Mensagem a ser lida.
|
|
522
|
+
interrupt: Se True, interrompe a fala atual.
|
|
523
|
+
"""
|
|
524
|
+
self._announce(text, interrupt)
|
|
525
|
+
|
|
526
|
+
def _announce(self, text: str, interrupt: bool = False) -> None:
|
|
527
|
+
if self._sr.available:
|
|
528
|
+
self._sr.speak(text, interrupt)
|
|
529
|
+
else:
|
|
530
|
+
logger.debug("A11y announce: %s", text)
|
|
531
|
+
|
|
532
|
+
@property
|
|
533
|
+
def screen_reader_available(self) -> bool:
|
|
534
|
+
"""True se um motor TTS/leitor de tela foi detectado."""
|
|
535
|
+
return self._sr.available
|
|
536
|
+
|
|
537
|
+
def setup_keyboard_navigation(
|
|
538
|
+
self, root: tk.Tk | tk.Toplevel
|
|
539
|
+
) -> KeyboardNavigationManager:
|
|
540
|
+
"""Configura navegação global por teclado para a janela *root*."""
|
|
541
|
+
self._nav = KeyboardNavigationManager(root)
|
|
542
|
+
return self._nav
|
|
543
|
+
|
|
544
|
+
def _reapply_active_overrides(self) -> None:
|
|
545
|
+
"""Restaura o tema base e reaplicar todos os modos ativos em sequência.
|
|
546
|
+
|
|
547
|
+
Garante consistência quando múltiplos modos (alto contraste + daltonismo)
|
|
548
|
+
estão ativos ao mesmo tempo e um deles é desativado.
|
|
549
|
+
"""
|
|
550
|
+
from src.theme.base import THEMES
|
|
551
|
+
|
|
552
|
+
hc_uses_full_theme = self._high_contrast and "high_contrast" in THEMES
|
|
553
|
+
|
|
554
|
+
if not hc_uses_full_theme:
|
|
555
|
+
with contextlib.suppress(Exception):
|
|
556
|
+
from src.theme.manager import _patch_theme
|
|
557
|
+
|
|
558
|
+
theme_name = getattr(
|
|
559
|
+
self._tmgr, "_name", getattr(
|
|
560
|
+
self._tmgr, "name", "fluent_dark")
|
|
561
|
+
)
|
|
562
|
+
if theme_name in THEMES:
|
|
563
|
+
self._tmgr.theme = THEMES[theme_name]
|
|
564
|
+
_patch_theme(self._tmgr.theme)
|
|
565
|
+
|
|
566
|
+
if self._high_contrast:
|
|
567
|
+
theme = self._tmgr.theme
|
|
568
|
+
for attr, color in _HIGH_CONTRAST_OVERRIDES.items():
|
|
569
|
+
if hasattr(theme, attr):
|
|
570
|
+
with contextlib.suppress(AttributeError):
|
|
571
|
+
object.__setattr__(theme, attr, color)
|
|
572
|
+
|
|
573
|
+
if self._colorblind_mode and self._colorblind_mode in _COLORBLIND_PALETTES:
|
|
574
|
+
theme = self._tmgr.theme
|
|
575
|
+
for attr, color in _COLORBLIND_PALETTES[self._colorblind_mode].items():
|
|
576
|
+
if hasattr(theme, attr):
|
|
577
|
+
with contextlib.suppress(AttributeError):
|
|
578
|
+
object.__setattr__(theme, attr, color)
|
|
579
|
+
|
|
580
|
+
with contextlib.suppress(Exception):
|
|
581
|
+
self._tmgr.apply_ttk()
|
|
582
|
+
self._request_ui_refresh()
|
|
583
|
+
|
|
584
|
+
def _restore_theme(self) -> None:
|
|
585
|
+
"""Restaura o tema original e reaplicar modos ainda ativos."""
|
|
586
|
+
self._reapply_active_overrides()
|
|
587
|
+
|
|
588
|
+
def _request_ui_refresh(self) -> None:
|
|
589
|
+
"""Solicita redesenho da UI ao thread principal."""
|
|
590
|
+
with contextlib.suppress(Exception):
|
|
591
|
+
root = getattr(self._app, "_root", None) or getattr(
|
|
592
|
+
self._app, "root", None)
|
|
593
|
+
if root:
|
|
594
|
+
root.after(50, root.update_idletasks)
|
|
595
|
+
|
|
596
|
+
@property
|
|
597
|
+
def high_contrast(self) -> bool:
|
|
598
|
+
"""True se o modo de alto contraste estiver ativo."""
|
|
599
|
+
return self._high_contrast
|
|
600
|
+
|
|
601
|
+
@property
|
|
602
|
+
def colorblind_mode(self) -> str | None:
|
|
603
|
+
"""Nome do modo de daltonismo ativo, ou None."""
|
|
604
|
+
return self._colorblind_mode
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
class AccessibilityPanel(tk.Toplevel):
|
|
608
|
+
"""Janela de configuração dos modos de acessibilidade.
|
|
609
|
+
|
|
610
|
+
Abre como modal. Permite ativar/desativar individualmente cada modo
|
|
611
|
+
sem precisar reabrir o editor.
|
|
612
|
+
"""
|
|
613
|
+
|
|
614
|
+
def __init__(self, parent: tk.Widget, mgr: AccessibilityManager, tmgr: Any) -> None:
|
|
615
|
+
super().__init__(parent)
|
|
616
|
+
self._mgr = mgr
|
|
617
|
+
self._tmgr = tmgr
|
|
618
|
+
t = tmgr.theme
|
|
619
|
+
|
|
620
|
+
self.title(_t("a11y.panel_title", "Acessibilidade"))
|
|
621
|
+
self.resizable(False, False)
|
|
622
|
+
self.config(bg=t.panel_bg)
|
|
623
|
+
safe_grab_set(self)
|
|
624
|
+
|
|
625
|
+
self._build_ui(t)
|
|
626
|
+
self.update_idletasks()
|
|
627
|
+
self._center()
|
|
628
|
+
|
|
629
|
+
def _build_ui(self, t: Any) -> None:
|
|
630
|
+
from src.constants import FONT_UI
|
|
631
|
+
|
|
632
|
+
pad = {"padx": 16, "pady": 6}
|
|
633
|
+
|
|
634
|
+
hdr = tk.Frame(self, bg=t.sidebar_bg)
|
|
635
|
+
hdr.pack(fill="x")
|
|
636
|
+
tk.Label(
|
|
637
|
+
hdr,
|
|
638
|
+
text=_t("a11y.panel_header", "♿ Acessibilidade"),
|
|
639
|
+
bg=t.sidebar_bg,
|
|
640
|
+
fg=t.fg,
|
|
641
|
+
font=(FONT_UI, 13, "bold"),
|
|
642
|
+
anchor="w",
|
|
643
|
+
).pack(side="left", **pad)
|
|
644
|
+
|
|
645
|
+
body = tk.Frame(self, bg=t.panel_bg)
|
|
646
|
+
body.pack(fill="both", expand=True, padx=8, pady=8)
|
|
647
|
+
|
|
648
|
+
def _section(label: str) -> None:
|
|
649
|
+
tk.Label(
|
|
650
|
+
body,
|
|
651
|
+
text=label,
|
|
652
|
+
bg=t.panel_bg,
|
|
653
|
+
fg=t.fg_muted,
|
|
654
|
+
font=(FONT_UI, 9, "bold"),
|
|
655
|
+
anchor="w",
|
|
656
|
+
).pack(fill="x", padx=8, pady=(10, 2))
|
|
657
|
+
ttk.Separator(body, orient="horizontal").pack(fill="x", padx=8)
|
|
658
|
+
|
|
659
|
+
def _toggle_row(
|
|
660
|
+
label: str, desc: str, var: tk.BooleanVar, command: Callable
|
|
661
|
+
) -> None:
|
|
662
|
+
row = tk.Frame(body, bg=t.panel_bg)
|
|
663
|
+
row.pack(fill="x", padx=8, pady=3)
|
|
664
|
+
cb = tk.Checkbutton(
|
|
665
|
+
row,
|
|
666
|
+
variable=var,
|
|
667
|
+
command=command,
|
|
668
|
+
bg=t.panel_bg,
|
|
669
|
+
fg=t.fg,
|
|
670
|
+
activebackground=t.panel_bg,
|
|
671
|
+
selectcolor=t.sidebar_bg,
|
|
672
|
+
font=(FONT_UI, 10),
|
|
673
|
+
text=label,
|
|
674
|
+
anchor="w",
|
|
675
|
+
)
|
|
676
|
+
cb.pack(side="left")
|
|
677
|
+
if desc:
|
|
678
|
+
tk.Label(
|
|
679
|
+
row, text=desc, bg=t.panel_bg, fg=t.fg_muted, font=(
|
|
680
|
+
FONT_UI, 8)
|
|
681
|
+
).pack(side="left", padx=(4, 0))
|
|
682
|
+
|
|
683
|
+
_section(_t("a11y.section_vision", "Visão"))
|
|
684
|
+
|
|
685
|
+
self._hc_var = tk.BooleanVar(value=self._mgr.high_contrast)
|
|
686
|
+
_toggle_row(
|
|
687
|
+
_t("a11y.hc_label", "Alto contraste (WCAG AA)"),
|
|
688
|
+
_t("a11y.hc_desc", "Fundo preto, texto branco, bordas nítidas"),
|
|
689
|
+
self._hc_var,
|
|
690
|
+
self._on_hc_toggle,
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
tk.Label(
|
|
694
|
+
body,
|
|
695
|
+
text=_t("a11y.cb_label", "Modo daltonismo:"),
|
|
696
|
+
bg=t.panel_bg,
|
|
697
|
+
fg=t.fg,
|
|
698
|
+
font=(FONT_UI, 10),
|
|
699
|
+
anchor="w",
|
|
700
|
+
).pack(fill="x", padx=8, pady=(8, 2))
|
|
701
|
+
|
|
702
|
+
cb_modes = [""] + self._mgr.available_colorblind_modes
|
|
703
|
+
cb_labels = [_t("a11y.cb_none", "Nenhum")] + [
|
|
704
|
+
_t(f"a11y.colorblind_{m}", m.replace("_", " ").capitalize())
|
|
705
|
+
for m in self._mgr.available_colorblind_modes
|
|
706
|
+
]
|
|
707
|
+
self._cb_var = tk.StringVar(value=self._mgr.colorblind_mode or "")
|
|
708
|
+
cb_combo = ttk.Combobox(
|
|
709
|
+
body,
|
|
710
|
+
textvariable=self._cb_var,
|
|
711
|
+
values=cb_labels,
|
|
712
|
+
state="readonly",
|
|
713
|
+
width=28,
|
|
714
|
+
)
|
|
715
|
+
cb_combo.pack(padx=16, pady=(0, 4), anchor="w")
|
|
716
|
+
cb_combo.bind("<<ComboboxSelected>>", self._on_cb_change)
|
|
717
|
+
|
|
718
|
+
self._cb_label_map = dict(zip(cb_labels, cb_modes, strict=False))
|
|
719
|
+
if self._mgr.colorblind_mode:
|
|
720
|
+
idx = cb_modes.index(self._mgr.colorblind_mode)
|
|
721
|
+
cb_combo.current(idx)
|
|
722
|
+
else:
|
|
723
|
+
cb_combo.current(0)
|
|
724
|
+
|
|
725
|
+
_section(_t("a11y.section_nav", "Navegação e Interação"))
|
|
726
|
+
|
|
727
|
+
self._nav_var = tk.BooleanVar(value=self._mgr._keyboard_nav_enabled)
|
|
728
|
+
_toggle_row(
|
|
729
|
+
_t("a11y.nav_label", "Navegação aprimorada por teclado (Tab/Setas)"),
|
|
730
|
+
_t("a11y.nav_desc", "Tab e setas se movem por áreas registradas"),
|
|
731
|
+
self._nav_var,
|
|
732
|
+
lambda: self._on_toggle(
|
|
733
|
+
"_keyboard_nav_enabled", "a11y_keyboard_nav", self._nav_var
|
|
734
|
+
),
|
|
735
|
+
)
|
|
736
|
+
|
|
737
|
+
self._font_var = tk.BooleanVar(value=self._mgr._large_ui_font)
|
|
738
|
+
_toggle_row(
|
|
739
|
+
_t("a11y.font_label", "Fonte de UI grande (mín. 13pt)"),
|
|
740
|
+
_t("a11y.font_desc", "Aumenta legibilidade em telas de baixa resolução"),
|
|
741
|
+
self._font_var,
|
|
742
|
+
lambda: self._on_toggle(
|
|
743
|
+
"_large_ui_font", "a11y_large_ui_font", self._font_var
|
|
744
|
+
),
|
|
745
|
+
)
|
|
746
|
+
|
|
747
|
+
self._motion_var = tk.BooleanVar(value=self._mgr._reduce_motion)
|
|
748
|
+
_toggle_row(
|
|
749
|
+
_t("a11y.motion_label", "Reduzir animações e movimento"),
|
|
750
|
+
_t("a11y.motion_desc", "Desativa transições, piscar e efeitos visuais"),
|
|
751
|
+
self._motion_var,
|
|
752
|
+
lambda: self._on_toggle(
|
|
753
|
+
"_reduce_motion", "a11y_reduce_motion", self._motion_var
|
|
754
|
+
),
|
|
755
|
+
)
|
|
756
|
+
|
|
757
|
+
_section(_t("a11y.section_sr", "Leitor de Tela / TTS"))
|
|
758
|
+
|
|
759
|
+
self._sr_var = tk.BooleanVar(value=self._mgr._screen_reader_enabled)
|
|
760
|
+
_toggle_row(
|
|
761
|
+
_t("a11y.sr_enable_label", "Habilitar anúncios por TTS"),
|
|
762
|
+
_t("a11y.sr_enable_desc", "Anuncia ações e foco para leitor de tela"),
|
|
763
|
+
self._sr_var,
|
|
764
|
+
lambda: self._on_toggle(
|
|
765
|
+
"_screen_reader_enabled", "a11y_screen_reader", self._sr_var
|
|
766
|
+
),
|
|
767
|
+
)
|
|
768
|
+
|
|
769
|
+
status_color = t.fg if self._mgr.screen_reader_available else t.fg_muted
|
|
770
|
+
status_text = (
|
|
771
|
+
_t("a11y.sr_available", "TTS detectado no sistema.")
|
|
772
|
+
if self._mgr.screen_reader_available
|
|
773
|
+
else _t(
|
|
774
|
+
"a11y.sr_unavailable",
|
|
775
|
+
"Nenhum TTS detectado (spd-say, espeak, say, SAPI).",
|
|
776
|
+
)
|
|
777
|
+
)
|
|
778
|
+
tk.Label(
|
|
779
|
+
body,
|
|
780
|
+
text=status_text,
|
|
781
|
+
bg=t.panel_bg,
|
|
782
|
+
fg=status_color,
|
|
783
|
+
font=(FONT_UI, 9),
|
|
784
|
+
wraplength=340,
|
|
785
|
+
justify="left",
|
|
786
|
+
anchor="w",
|
|
787
|
+
).pack(fill="x", padx=8, pady=4)
|
|
788
|
+
|
|
789
|
+
tk.Button(
|
|
790
|
+
body,
|
|
791
|
+
text=_t("a11y.sr_test", "🔊 Testar leitor de tela"),
|
|
792
|
+
bg=t.sidebar_bg,
|
|
793
|
+
fg=t.fg,
|
|
794
|
+
activebackground=t.accent,
|
|
795
|
+
relief="flat",
|
|
796
|
+
font=(FONT_UI, 9),
|
|
797
|
+
command=self._on_sr_test,
|
|
798
|
+
).pack(padx=16, pady=4, anchor="w")
|
|
799
|
+
|
|
800
|
+
tk.Button(
|
|
801
|
+
self,
|
|
802
|
+
text=_t("a11y.close", "Fechar"),
|
|
803
|
+
bg=t.accent,
|
|
804
|
+
fg="#FFFFFF",
|
|
805
|
+
activebackground=t.accent,
|
|
806
|
+
relief="flat",
|
|
807
|
+
font=(FONT_UI, 10),
|
|
808
|
+
command=self.destroy,
|
|
809
|
+
).pack(pady=(4, 12))
|
|
810
|
+
|
|
811
|
+
def _on_toggle(self, attr: str, cfg_key: str, var: tk.BooleanVar) -> None:
|
|
812
|
+
"""Persiste uma preferência booleana simples no manager e no ConfigManager."""
|
|
813
|
+
val = var.get()
|
|
814
|
+
setattr(self._mgr, attr, val)
|
|
815
|
+
self._mgr._cfg.set(cfg_key, val)
|
|
816
|
+
self._mgr._save_prefs()
|
|
817
|
+
|
|
818
|
+
def _on_hc_toggle(self) -> None:
|
|
819
|
+
self._mgr.toggle_high_contrast()
|
|
820
|
+
|
|
821
|
+
def _on_cb_change(self, _event: tk.Event) -> None:
|
|
822
|
+
label = self._cb_var.get()
|
|
823
|
+
mode = self._cb_label_map.get(label, "")
|
|
824
|
+
if mode:
|
|
825
|
+
self._mgr.enable_colorblind_mode(mode)
|
|
826
|
+
else:
|
|
827
|
+
self._mgr.disable_colorblind_mode()
|
|
828
|
+
|
|
829
|
+
def _on_sr_test(self) -> None:
|
|
830
|
+
self._mgr.announce(
|
|
831
|
+
_t("a11y.sr_test_msg", "Leitor de tela do Codis funcionando corretamente."),
|
|
832
|
+
interrupt=True,
|
|
833
|
+
)
|
|
834
|
+
|
|
835
|
+
def _center(self) -> None:
|
|
836
|
+
"""Centraliza a janela na tela."""
|
|
837
|
+
self.update_idletasks()
|
|
838
|
+
w, h = self.winfo_reqwidth(), self.winfo_reqheight()
|
|
839
|
+
sw = self.winfo_screenwidth()
|
|
840
|
+
sh = self.winfo_screenheight()
|
|
841
|
+
x = (sw - w) // 2
|
|
842
|
+
y = (sh - h) // 2
|
|
843
|
+
self.geometry(f"{w}x{h}+{x}+{y}")
|