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/wizard.py
ADDED
|
@@ -0,0 +1,1550 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Assistente de primeira execução do Codis.
|
|
3
|
+
|
|
4
|
+
Implementa ``FirstRunWizard``, o wizard de configuração inicial exibido
|
|
5
|
+
na primeira vez que o usuário abre o aplicativo, guiando a escolha de
|
|
6
|
+
tema, fonte, linguagem e configurações de IA. Os valores já marcados vêm da
|
|
7
|
+
detecção do sistema (``src.system_profile``): tela, DPI, tema claro/escuro,
|
|
8
|
+
idioma, fontes instaladas, acessibilidade e capacidade da máquina.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import contextlib
|
|
14
|
+
import logging
|
|
15
|
+
import sys
|
|
16
|
+
import tkinter as tk
|
|
17
|
+
from collections.abc import Callable, Mapping
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
from tkinter import ttk
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
from src._shells import SHELL_OPTIONS, get_default_shell
|
|
23
|
+
from src.config import ConfigManager
|
|
24
|
+
from src.constants import (
|
|
25
|
+
APP_NAME,
|
|
26
|
+
FONT_MONO,
|
|
27
|
+
FONT_UI,
|
|
28
|
+
TAB_SIZE,
|
|
29
|
+
)
|
|
30
|
+
from src.i18n import I18n, _t
|
|
31
|
+
from src.system_profile import SystemProfile, auto_ui_percent, describe, detect_profile, recommend
|
|
32
|
+
from src.theme.base import THEME_ORDER, THEMES
|
|
33
|
+
from src.theme.manager import ThemeManager, _patch_theme
|
|
34
|
+
from src.ui.dropdown import DropDown
|
|
35
|
+
from src.ui.grab_safe import safe_grab_set
|
|
36
|
+
|
|
37
|
+
logger = logging.getLogger("Codis.Wizard")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _luminance(color: str) -> float:
|
|
41
|
+
try:
|
|
42
|
+
raw = color.lstrip("#")
|
|
43
|
+
channels = [int(raw[i : i + 2], 16) / 255 for i in (0, 2, 4)]
|
|
44
|
+
except (ValueError, IndexError):
|
|
45
|
+
return 0.0
|
|
46
|
+
lin = [c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4 for c in channels]
|
|
47
|
+
return 0.2126 * lin[0] + 0.7152 * lin[1] + 0.0722 * lin[2]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _contrast(a: str, b: str) -> float:
|
|
51
|
+
hi, lo = sorted((_luminance(a), _luminance(b)), reverse=True)
|
|
52
|
+
return (hi + 0.05) / (lo + 0.05)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def readable_surface(theme: Any) -> str:
|
|
56
|
+
"""Fundo de cartões em que ``fg`` e ``fg_muted`` do tema continuam legíveis.
|
|
57
|
+
|
|
58
|
+
Em alguns temas (ex.: ``fluent_light``) a barra de atividades é escura e o texto também,
|
|
59
|
+
então ela não serve de fundo para os textos do assistente.
|
|
60
|
+
"""
|
|
61
|
+
candidates = [getattr(theme, name, "") for name in ("activity_bg", "sidebar_bg", "editor_bg", "floating_bg")]
|
|
62
|
+
|
|
63
|
+
def score(bg: str) -> float:
|
|
64
|
+
return min(_contrast(bg, theme.fg) / 4.5, _contrast(bg, theme.fg_muted) / 3.0)
|
|
65
|
+
|
|
66
|
+
valid = [c for c in candidates if isinstance(c, str) and c.startswith("#") and len(c) >= 7]
|
|
67
|
+
return max(valid, key=score) if valid else theme.floating_bg
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class _WizardPalette:
|
|
71
|
+
"""Tema do assistente: o tema ativo, com ``activity_bg`` trocado por um fundo legível."""
|
|
72
|
+
|
|
73
|
+
def __init__(self, theme: Any) -> None:
|
|
74
|
+
self._theme = theme
|
|
75
|
+
self.activity_bg = readable_surface(theme)
|
|
76
|
+
|
|
77
|
+
def __getattr__(self, name: str) -> Any:
|
|
78
|
+
return getattr(self._theme, name)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@dataclass(frozen=True)
|
|
82
|
+
class WizardToggle:
|
|
83
|
+
"""Opção liga/desliga exibida no wizard e gravada na configuração.
|
|
84
|
+
|
|
85
|
+
Attributes:
|
|
86
|
+
key: chave na configuração do Codis.
|
|
87
|
+
default: valor usado quando a chave ainda não existe.
|
|
88
|
+
icon: ícone do cartão.
|
|
89
|
+
label_key: chave de tradução do título (``label`` é o texto padrão).
|
|
90
|
+
desc_key: chave de tradução da descrição (vazia se não houver).
|
|
91
|
+
sum_key: chave de tradução do rótulo no resumo (usa ``label`` se vazia).
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
key: str
|
|
95
|
+
default: bool
|
|
96
|
+
icon: str
|
|
97
|
+
label_key: str
|
|
98
|
+
label: str
|
|
99
|
+
desc_key: str = ""
|
|
100
|
+
desc: str = ""
|
|
101
|
+
sum_key: str = ""
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
FEATURE_TOGGLES: tuple[WizardToggle, ...] = (
|
|
105
|
+
WizardToggle("lint_enabled", True, "\U0001f50d", "wiz.feat_lint", "Lint", "wiz.feat_lint_desc", "", "wiz.sum_lint"),
|
|
106
|
+
WizardToggle("autocomplete", True, "\u2702", "wiz.feat_ac", "Autocomplete", "wiz.feat_ac_desc", "", "wiz.sum_ac"),
|
|
107
|
+
WizardToggle("minimap", True, "\U0001f5fa", "wiz.feat_mm", "Minimap", "wiz.feat_mm_desc", "", "wiz.sum_mm"),
|
|
108
|
+
WizardToggle("format_on_save", False, "\u2728", "wiz.feat_fmt", "Format on save", "wiz.feat_fmt_desc", "", "wiz.sum_fmt"),
|
|
109
|
+
WizardToggle(
|
|
110
|
+
"lsp_enabled", True, "\U0001f9e0", "wiz.feat_lsp", "Inteligência de código (LSP)",
|
|
111
|
+
"wiz.feat_lsp_desc", "Autocompletar, ir para definição e diagnósticos usando servidores de linguagem.",
|
|
112
|
+
),
|
|
113
|
+
WizardToggle(
|
|
114
|
+
"line_numbers", True, "\U0001f522", "wiz.feat_linenum", "Números de linha",
|
|
115
|
+
"wiz.feat_linenum_desc", "Mostra a numeração na margem do editor.",
|
|
116
|
+
),
|
|
117
|
+
WizardToggle(
|
|
118
|
+
"word_wrap", True, "\u21a9", "wiz.feat_wrap", "Quebra automática de linha",
|
|
119
|
+
"wiz.feat_wrap_desc", "Quebra linhas longas na largura do editor em vez de rolar na horizontal.",
|
|
120
|
+
),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
EXTRA_TOGGLES: tuple[WizardToggle, ...] = (
|
|
124
|
+
WizardToggle("timeline_enabled", True, "\U0001f552", "wiz.timeline", "Timeline", "", "", "wiz.sum_timeline"),
|
|
125
|
+
WizardToggle("autosave", False, "\U0001f4be", "wiz.autosave", "Salvamento automático", "", "", "wiz.sum_autosave"),
|
|
126
|
+
WizardToggle(
|
|
127
|
+
"session_restore", False, "\U0001f4c2", "wiz.session_restore", "Restaurar sessão",
|
|
128
|
+
"wiz.session_restore_desc", "Reabre os arquivos e o workspace da última vez ao iniciar.",
|
|
129
|
+
),
|
|
130
|
+
WizardToggle(
|
|
131
|
+
"auto_check_updates", True, "\U0001f504", "wiz.auto_updates", "Verificar atualizações",
|
|
132
|
+
"wiz.auto_updates_desc", "Procura novas versões do Codis ao iniciar.",
|
|
133
|
+
),
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
A11Y_TOGGLES: tuple[WizardToggle, ...] = (
|
|
137
|
+
WizardToggle(
|
|
138
|
+
"a11y_screen_reader", False, "\U0001f50a", "wiz.a11y_tts", "Leitura em voz alta (TTS)",
|
|
139
|
+
"wiz.a11y_tts_desc", "Anuncia em voz alta o que recebe foco ou fica sob o mouse. Desligado por padrão.",
|
|
140
|
+
),
|
|
141
|
+
WizardToggle(
|
|
142
|
+
"a11y_high_contrast", False, "\u25d0", "wiz.a11y_contrast", "Alto contraste",
|
|
143
|
+
"wiz.a11y_contrast_desc", "Troca para um tema de alto contraste.",
|
|
144
|
+
),
|
|
145
|
+
WizardToggle(
|
|
146
|
+
"a11y_reduce_motion", False, "\U0001f3ac", "wiz.a11y_motion", "Reduzir animações",
|
|
147
|
+
"wiz.a11y_motion_desc", "Remove transições e deixa a interface mais leve em máquinas lentas.",
|
|
148
|
+
),
|
|
149
|
+
WizardToggle(
|
|
150
|
+
"a11y_large_ui_font", False, "\U0001f524", "wiz.a11y_large", "Fonte grande na interface",
|
|
151
|
+
"wiz.a11y_large_desc", "Aumenta o texto de menus, painéis e botões.",
|
|
152
|
+
),
|
|
153
|
+
WizardToggle(
|
|
154
|
+
"a11y_keyboard_nav", True, "\u2328", "wiz.a11y_keys", "Navegação por teclado",
|
|
155
|
+
"wiz.a11y_keys_desc", "Permite percorrer painéis e botões com Tab e atalhos.",
|
|
156
|
+
),
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
ALL_TOGGLES: tuple[WizardToggle, ...] = FEATURE_TOGGLES + EXTRA_TOGGLES + A11Y_TOGGLES
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def initial_toggle_values(
|
|
163
|
+
cfg_get: Callable[[str, Any], Any], overrides: Mapping[str, bool] | None = None
|
|
164
|
+
) -> dict[str, bool]:
|
|
165
|
+
"""Valores iniciais das opções.
|
|
166
|
+
|
|
167
|
+
Vale o que já está salvo ou o padrão da opção; ``overrides`` (as recomendações
|
|
168
|
+
para o sistema) substitui esses valores.
|
|
169
|
+
"""
|
|
170
|
+
values = {tg.key: bool(cfg_get(tg.key, tg.default)) for tg in ALL_TOGGLES}
|
|
171
|
+
if overrides:
|
|
172
|
+
values.update({key: bool(val) for key, val in overrides.items() if key in values})
|
|
173
|
+
return values
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def apply_toggles(cfg: Any, values: Mapping[str, bool]) -> None:
|
|
177
|
+
"""Grava na configuração os valores das opções do wizard (sem salvar em disco)."""
|
|
178
|
+
for tg in ALL_TOGGLES:
|
|
179
|
+
if tg.key in values:
|
|
180
|
+
cfg.set(tg.key, bool(values[tg.key]))
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
class FirstRunWizard(tk.Toplevel):
|
|
184
|
+
"""Assistente de configuracao inicial exibido na primeira execucao do Codis."""
|
|
185
|
+
|
|
186
|
+
STEPS = 10
|
|
187
|
+
|
|
188
|
+
_STEP_LANG = 1
|
|
189
|
+
_STEP_DISPLAY = 2
|
|
190
|
+
|
|
191
|
+
_NAV_KEYS = [
|
|
192
|
+
"wiz.nav_welcome",
|
|
193
|
+
"wiz.nav_lang",
|
|
194
|
+
"wiz.nav_display",
|
|
195
|
+
"wiz.nav_theme",
|
|
196
|
+
"wiz.nav_font",
|
|
197
|
+
"wiz.nav_indent",
|
|
198
|
+
"wiz.nav_features",
|
|
199
|
+
"wiz.nav_extra",
|
|
200
|
+
"wiz.nav_voice",
|
|
201
|
+
"wiz.nav_summary",
|
|
202
|
+
]
|
|
203
|
+
_NAV_ICONS = [
|
|
204
|
+
"\u2736",
|
|
205
|
+
"\U0001f310",
|
|
206
|
+
"\U0001f5a5",
|
|
207
|
+
"\U0001f3a8",
|
|
208
|
+
"\u2712",
|
|
209
|
+
"\u21e5",
|
|
210
|
+
"\u2699",
|
|
211
|
+
"\U0001f195",
|
|
212
|
+
"\U0001f50a",
|
|
213
|
+
"\u2705",
|
|
214
|
+
]
|
|
215
|
+
|
|
216
|
+
def __init__(
|
|
217
|
+
self,
|
|
218
|
+
parent: tk.Tk,
|
|
219
|
+
cfg: ConfigManager,
|
|
220
|
+
tmgr: ThemeManager,
|
|
221
|
+
on_finish: Callable,
|
|
222
|
+
) -> None:
|
|
223
|
+
super().__init__(parent)
|
|
224
|
+
self.title(f"{APP_NAME} \u2014 Setup")
|
|
225
|
+
|
|
226
|
+
self._cfg = cfg
|
|
227
|
+
self._tmgr = tmgr
|
|
228
|
+
self._on_finish = on_finish
|
|
229
|
+
self._step = 0
|
|
230
|
+
self._nav_labels: list[tuple] = []
|
|
231
|
+
|
|
232
|
+
self._profile: SystemProfile = detect_profile(parent)
|
|
233
|
+
self._rec = recommend(self._profile, FONT_MONO, TAB_SIZE)
|
|
234
|
+
self._auto_pct = auto_ui_percent(self._profile)
|
|
235
|
+
|
|
236
|
+
self._locale_var = tk.StringVar(value=self._rec.language)
|
|
237
|
+
self._theme_var = tk.StringVar(value=self._rec.theme)
|
|
238
|
+
self._font_var = tk.StringVar(value=self._rec.font_family)
|
|
239
|
+
self._size_var = tk.IntVar(value=self._rec.font_size)
|
|
240
|
+
self._tab_var = tk.IntVar(value=self._rec.tab_size)
|
|
241
|
+
self._scale_auto = tk.BooleanVar(value=True)
|
|
242
|
+
self._scale_manual = tk.IntVar(value=self._auto_pct)
|
|
243
|
+
initial = initial_toggle_values(cfg.get, self._rec.toggles)
|
|
244
|
+
self._opts: dict[str, tk.BooleanVar] = {
|
|
245
|
+
key: tk.BooleanVar(value=value) for key, value in initial.items()
|
|
246
|
+
}
|
|
247
|
+
self._fmt_var = self._opts["format_on_save"]
|
|
248
|
+
self._autosave_var = self._opts["autosave"]
|
|
249
|
+
self._tts_bridge: Any = None
|
|
250
|
+
self._tts_status: tk.Label | None = None
|
|
251
|
+
self._shell_var2 = tk.StringVar(
|
|
252
|
+
value=cfg.get("default_shell") or get_default_shell())
|
|
253
|
+
|
|
254
|
+
# O wizard já abre no idioma e no tema do sistema.
|
|
255
|
+
with contextlib.suppress(Exception):
|
|
256
|
+
I18n.get_instance().set_locale(self._rec.language)
|
|
257
|
+
if self._rec.theme in THEMES and self._tmgr.theme.name != self._rec.theme:
|
|
258
|
+
with contextlib.suppress(Exception):
|
|
259
|
+
self._tmgr.set(self._rec.theme)
|
|
260
|
+
_patch_theme(self._tmgr.theme)
|
|
261
|
+
t = self._palette()
|
|
262
|
+
self.config(bg=t.floating_bg)
|
|
263
|
+
self.wm_attributes("-topmost", True)
|
|
264
|
+
safe_grab_set(self)
|
|
265
|
+
|
|
266
|
+
I18n.get_instance().on_change(self._on_locale_changed)
|
|
267
|
+
|
|
268
|
+
self._build_layout()
|
|
269
|
+
self._show_step(0)
|
|
270
|
+
self._bind_keys()
|
|
271
|
+
|
|
272
|
+
self.update_idletasks()
|
|
273
|
+
sw = self.winfo_screenwidth()
|
|
274
|
+
sh = self.winfo_screenheight()
|
|
275
|
+
zoom = min(2.0, self._profile.os_scale)
|
|
276
|
+
w = min(int(sw * 0.94), int(min(1100, max(820, sw * 0.78 / zoom)) * zoom))
|
|
277
|
+
h = min(int(sh * 0.92), int(min(720, max(540, sh * 0.82 / zoom)) * zoom))
|
|
278
|
+
self.geometry(f"{w}x{h}+{(sw - w) // 2}+{(sh - h) // 2}")
|
|
279
|
+
self._lock_window()
|
|
280
|
+
|
|
281
|
+
def _lock_window(self) -> None:
|
|
282
|
+
"""Mantém o assistente com tamanho fixo e sempre visível até ser concluído.
|
|
283
|
+
|
|
284
|
+
A janela principal fica oculta durante a configuração inicial, então um
|
|
285
|
+
assistente minimizado ficaria sem nenhum ponto de acesso na tela.
|
|
286
|
+
"""
|
|
287
|
+
self.resizable(False, False)
|
|
288
|
+
with contextlib.suppress(tk.TclError):
|
|
289
|
+
self.wm_attributes("-type", "dialog") # sem minimizar/maximizar em WMs X11
|
|
290
|
+
self.bind("<Unmap>", self._restore_if_minimized, add="+")
|
|
291
|
+
if sys.platform == "win32":
|
|
292
|
+
self.after(0, self._strip_caption_buttons)
|
|
293
|
+
|
|
294
|
+
def _restore_if_minimized(self, event: tk.Event) -> None:
|
|
295
|
+
if event.widget is not self:
|
|
296
|
+
return
|
|
297
|
+
with contextlib.suppress(tk.TclError):
|
|
298
|
+
if self.state() == "iconic":
|
|
299
|
+
self.after_idle(self.deiconify)
|
|
300
|
+
|
|
301
|
+
def _strip_caption_buttons(self) -> None:
|
|
302
|
+
"""Remove os botões de minimizar e maximizar da barra de título (Windows)."""
|
|
303
|
+
try:
|
|
304
|
+
import ctypes
|
|
305
|
+
|
|
306
|
+
user32 = ctypes.windll.user32 # type: ignore[attr-defined]
|
|
307
|
+
hwnd = user32.GetParent(self.winfo_id())
|
|
308
|
+
gwl_style, ws_minimizebox, ws_maximizebox = -16, 0x20000, 0x10000
|
|
309
|
+
style = user32.GetWindowLongW(hwnd, gwl_style)
|
|
310
|
+
user32.SetWindowLongW(hwnd, gwl_style, style & ~(ws_minimizebox | ws_maximizebox))
|
|
311
|
+
# SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED
|
|
312
|
+
user32.SetWindowPos(hwnd, 0, 0, 0, 0, 0, 0x0001 | 0x0002 | 0x0004 | 0x0020)
|
|
313
|
+
except (AttributeError, OSError, tk.TclError):
|
|
314
|
+
pass
|
|
315
|
+
|
|
316
|
+
def _bind_keys(self) -> None:
|
|
317
|
+
"""Rolagem (Windows, macOS e Linux) e atalhos de teclado do assistente."""
|
|
318
|
+
for sequence in ("<MouseWheel>", "<Button-4>", "<Button-5>"):
|
|
319
|
+
self.bind(sequence, self._on_scroll)
|
|
320
|
+
self.bind("<Return>", lambda _e: self._next())
|
|
321
|
+
self.bind("<Alt-Right>", lambda _e: self._next())
|
|
322
|
+
self.bind("<Alt-Left>", lambda _e: self._prev())
|
|
323
|
+
|
|
324
|
+
def _palette(self) -> _WizardPalette:
|
|
325
|
+
return _WizardPalette(self._tmgr.theme)
|
|
326
|
+
|
|
327
|
+
def _rebuild_all(self) -> None:
|
|
328
|
+
"""Reconstrói a janela inteira (barra lateral, topo e rodapé) com o tema atual."""
|
|
329
|
+
self.config(bg=self._tmgr.theme.floating_bg)
|
|
330
|
+
self._root_frame.destroy()
|
|
331
|
+
self._build_layout()
|
|
332
|
+
self._show_step(self._step)
|
|
333
|
+
|
|
334
|
+
def _on_locale_changed(self) -> None:
|
|
335
|
+
with contextlib.suppress(tk.TclError):
|
|
336
|
+
self._rebuild_nav_text()
|
|
337
|
+
self._rebuild_footer_text()
|
|
338
|
+
self._show_step(self._step)
|
|
339
|
+
|
|
340
|
+
def _build_layout(self) -> None:
|
|
341
|
+
t = self._palette()
|
|
342
|
+
root_frame = tk.Frame(self, bg=t.floating_bg, highlightthickness=0)
|
|
343
|
+
root_frame.pack(fill="both", expand=True)
|
|
344
|
+
self._root_frame = root_frame
|
|
345
|
+
|
|
346
|
+
self._sidebar = tk.Frame(
|
|
347
|
+
root_frame, bg=t.activity_bg, width=190, highlightthickness=0, bd=0
|
|
348
|
+
)
|
|
349
|
+
self._sidebar.pack(side="left", fill="y")
|
|
350
|
+
self._sidebar.pack_propagate(False)
|
|
351
|
+
|
|
352
|
+
right = tk.Frame(root_frame, bg=t.floating_bg, highlightthickness=0)
|
|
353
|
+
right.pack(side="left", fill="both", expand=True)
|
|
354
|
+
|
|
355
|
+
self._top_bar = tk.Frame(
|
|
356
|
+
right, bg=t.activity_bg, height=50, highlightthickness=0, bd=0
|
|
357
|
+
)
|
|
358
|
+
self._top_bar.pack(fill="x")
|
|
359
|
+
self._top_bar.pack_propagate(False)
|
|
360
|
+
|
|
361
|
+
prog_track = tk.Frame(right, bg=t.border, height=3,
|
|
362
|
+
highlightthickness=0, bd=0)
|
|
363
|
+
prog_track.pack(fill="x")
|
|
364
|
+
self._prog_bar = tk.Frame(
|
|
365
|
+
prog_track, bg=t.btn_primary, height=3, highlightthickness=0, bd=0
|
|
366
|
+
)
|
|
367
|
+
self._prog_bar.place(x=0, y=0, relwidth=1 / self.STEPS, relheight=1)
|
|
368
|
+
|
|
369
|
+
canvas_wrap = tk.Frame(right, bg=t.floating_bg, highlightthickness=0)
|
|
370
|
+
canvas_wrap.pack(fill="both", expand=True)
|
|
371
|
+
|
|
372
|
+
self._canvas = tk.Canvas(
|
|
373
|
+
canvas_wrap, bg=t.floating_bg, highlightthickness=0, bd=0
|
|
374
|
+
)
|
|
375
|
+
self._vbar = tk.Scrollbar(
|
|
376
|
+
canvas_wrap, orient="vertical", command=self._canvas.yview
|
|
377
|
+
)
|
|
378
|
+
self._canvas.configure(yscrollcommand=self._vbar.set)
|
|
379
|
+
self._vbar.pack(side="right", fill="y")
|
|
380
|
+
self._canvas.pack(side="left", fill="both", expand=True)
|
|
381
|
+
|
|
382
|
+
self._content = tk.Frame(
|
|
383
|
+
self._canvas, bg=t.floating_bg, highlightthickness=0)
|
|
384
|
+
self._canvas_win = self._canvas.create_window(
|
|
385
|
+
(0, 0), window=self._content, anchor="nw"
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
self._content.bind(
|
|
389
|
+
"<Configure>",
|
|
390
|
+
lambda _: self._canvas.configure(
|
|
391
|
+
scrollregion=self._canvas.bbox("all")),
|
|
392
|
+
)
|
|
393
|
+
self._canvas.bind(
|
|
394
|
+
"<Configure>",
|
|
395
|
+
lambda e: self._canvas.itemconfig(self._canvas_win, width=e.width),
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
self._footer = tk.Frame(
|
|
399
|
+
right, bg=t.floating_bg, height=56, highlightthickness=0, bd=0
|
|
400
|
+
)
|
|
401
|
+
self._footer.pack(fill="x")
|
|
402
|
+
self._footer.pack_propagate(False)
|
|
403
|
+
|
|
404
|
+
self._build_sidebar()
|
|
405
|
+
self._build_topbar()
|
|
406
|
+
self._build_footer()
|
|
407
|
+
|
|
408
|
+
def _on_scroll(self, evt: Any) -> None:
|
|
409
|
+
if getattr(evt, "num", 0) == 4:
|
|
410
|
+
units = -1
|
|
411
|
+
elif getattr(evt, "num", 0) == 5:
|
|
412
|
+
units = 1
|
|
413
|
+
else:
|
|
414
|
+
delta = getattr(evt, "delta", 0)
|
|
415
|
+
units = 0 if not delta else -1 * (int(delta / 120) or (1 if delta > 0 else -1))
|
|
416
|
+
with contextlib.suppress(tk.TclError):
|
|
417
|
+
self._canvas.yview_scroll(units, "units")
|
|
418
|
+
|
|
419
|
+
def _build_sidebar(self) -> None:
|
|
420
|
+
t = self._palette()
|
|
421
|
+
for w in self._sidebar.winfo_children():
|
|
422
|
+
w.destroy()
|
|
423
|
+
self._nav_labels.clear()
|
|
424
|
+
|
|
425
|
+
logo_frame = tk.Frame(
|
|
426
|
+
self._sidebar, bg=t.activity_bg, highlightthickness=0)
|
|
427
|
+
logo_frame.pack(fill="x", pady=(18, 4))
|
|
428
|
+
tk.Label(
|
|
429
|
+
logo_frame,
|
|
430
|
+
text="\u2b21",
|
|
431
|
+
bg=t.activity_bg,
|
|
432
|
+
fg=t.btn_primary,
|
|
433
|
+
font=(FONT_UI, 26),
|
|
434
|
+
).pack()
|
|
435
|
+
tk.Label(
|
|
436
|
+
logo_frame,
|
|
437
|
+
text=APP_NAME,
|
|
438
|
+
bg=t.activity_bg,
|
|
439
|
+
fg=t.fg,
|
|
440
|
+
font=(FONT_UI, 12, "bold"),
|
|
441
|
+
).pack()
|
|
442
|
+
|
|
443
|
+
tk.Frame(self._sidebar, bg=t.border, height=1).pack(
|
|
444
|
+
fill="x", padx=14, pady=(8, 10)
|
|
445
|
+
)
|
|
446
|
+
|
|
447
|
+
for i, (icon, key) in enumerate(
|
|
448
|
+
zip(self._NAV_ICONS, self._NAV_KEYS, strict=False)
|
|
449
|
+
):
|
|
450
|
+
row = tk.Frame(
|
|
451
|
+
self._sidebar, bg=t.activity_bg, highlightthickness=0, cursor="hand2"
|
|
452
|
+
)
|
|
453
|
+
row.pack(fill="x")
|
|
454
|
+
accent = tk.Frame(row, width=3, bg=t.activity_bg,
|
|
455
|
+
highlightthickness=0)
|
|
456
|
+
accent.pack(side="left", fill="y")
|
|
457
|
+
inner = tk.Frame(row, bg=t.activity_bg, highlightthickness=0)
|
|
458
|
+
inner.pack(side="left", fill="x",
|
|
459
|
+
expand=True, padx=(6, 10), pady=5)
|
|
460
|
+
icon_lbl = tk.Label(
|
|
461
|
+
inner,
|
|
462
|
+
text=icon,
|
|
463
|
+
bg=t.activity_bg,
|
|
464
|
+
fg=t.fg_muted,
|
|
465
|
+
font=(FONT_UI, 12),
|
|
466
|
+
width=2,
|
|
467
|
+
)
|
|
468
|
+
icon_lbl.pack(side="left")
|
|
469
|
+
text_lbl = tk.Label(
|
|
470
|
+
inner,
|
|
471
|
+
text=_t(key),
|
|
472
|
+
bg=t.activity_bg,
|
|
473
|
+
fg=t.fg_muted,
|
|
474
|
+
font=(FONT_UI, 9),
|
|
475
|
+
anchor="w",
|
|
476
|
+
)
|
|
477
|
+
text_lbl.pack(side="left", fill="x", expand=True)
|
|
478
|
+
|
|
479
|
+
self._nav_labels.append((row, accent, icon_lbl, text_lbl))
|
|
480
|
+
|
|
481
|
+
def _go(step: int = i) -> None:
|
|
482
|
+
if step <= self._step:
|
|
483
|
+
self._show_step(step)
|
|
484
|
+
|
|
485
|
+
for widget in (row, inner, icon_lbl, text_lbl):
|
|
486
|
+
widget.bind("<Button-1>", lambda _, s=i: _go(s), add="+")
|
|
487
|
+
|
|
488
|
+
tk.Frame(self._sidebar, bg=t.activity_bg).pack(
|
|
489
|
+
fill="both", expand=True)
|
|
490
|
+
from src.constants import APP_VERSION as _av
|
|
491
|
+
|
|
492
|
+
tk.Label(
|
|
493
|
+
self._sidebar,
|
|
494
|
+
text=f"v{_av}",
|
|
495
|
+
bg=t.activity_bg,
|
|
496
|
+
fg=t.border,
|
|
497
|
+
font=(FONT_UI, 8),
|
|
498
|
+
).pack(pady=(0, 10))
|
|
499
|
+
|
|
500
|
+
def _build_topbar(self) -> None:
|
|
501
|
+
t = self._palette()
|
|
502
|
+
for w in self._top_bar.winfo_children():
|
|
503
|
+
w.destroy()
|
|
504
|
+
self._top_title = tk.Label(
|
|
505
|
+
self._top_bar,
|
|
506
|
+
text="",
|
|
507
|
+
bg=t.activity_bg,
|
|
508
|
+
fg=t.fg,
|
|
509
|
+
font=(FONT_UI, 11, "bold"),
|
|
510
|
+
)
|
|
511
|
+
self._top_title.pack(side="left", padx=20, pady=12)
|
|
512
|
+
self._step_lbl = tk.Label(
|
|
513
|
+
self._top_bar, text="", bg=t.activity_bg, fg=t.fg_muted, font=(FONT_UI, 9)
|
|
514
|
+
)
|
|
515
|
+
self._step_lbl.pack(side="right", padx=20)
|
|
516
|
+
|
|
517
|
+
def _build_footer(self) -> None:
|
|
518
|
+
t = self._palette()
|
|
519
|
+
for w in self._footer.winfo_children():
|
|
520
|
+
w.destroy()
|
|
521
|
+
tk.Frame(self._footer, bg=t.border, height=1).pack(fill="x")
|
|
522
|
+
btn_row = tk.Frame(self._footer, bg=t.floating_bg)
|
|
523
|
+
btn_row.pack(fill="x", padx=20, pady=8)
|
|
524
|
+
|
|
525
|
+
self._back_btn = tk.Label(
|
|
526
|
+
btn_row,
|
|
527
|
+
text=_t("wiz.back"),
|
|
528
|
+
bg=t.btn_bg,
|
|
529
|
+
fg=t.fg,
|
|
530
|
+
font=(FONT_UI, 9),
|
|
531
|
+
padx=18,
|
|
532
|
+
pady=6,
|
|
533
|
+
cursor="hand2",
|
|
534
|
+
relief="flat",
|
|
535
|
+
)
|
|
536
|
+
self._back_btn.pack(side="left")
|
|
537
|
+
self._back_btn.bind("<Button-1>", lambda _: self._prev())
|
|
538
|
+
|
|
539
|
+
self._skip_btn = tk.Label(
|
|
540
|
+
btn_row,
|
|
541
|
+
text=_t("wiz.skip"),
|
|
542
|
+
bg=t.floating_bg,
|
|
543
|
+
fg=t.fg_muted,
|
|
544
|
+
font=(FONT_UI, 8),
|
|
545
|
+
cursor="hand2",
|
|
546
|
+
)
|
|
547
|
+
self._skip_btn.pack(side="right", padx=12)
|
|
548
|
+
self._skip_btn.bind("<Button-1>", lambda _: self._finish())
|
|
549
|
+
|
|
550
|
+
self._next_btn = tk.Label(
|
|
551
|
+
btn_row,
|
|
552
|
+
text=_t("wiz.next"),
|
|
553
|
+
bg=t.btn_primary,
|
|
554
|
+
fg="#000",
|
|
555
|
+
font=(FONT_UI, 9, "bold"),
|
|
556
|
+
padx=22,
|
|
557
|
+
pady=6,
|
|
558
|
+
cursor="hand2",
|
|
559
|
+
relief="flat",
|
|
560
|
+
)
|
|
561
|
+
self._next_btn.pack(side="right")
|
|
562
|
+
self._next_btn.bind("<Button-1>", lambda _: self._next())
|
|
563
|
+
|
|
564
|
+
def _rebuild_nav_text(self) -> None:
|
|
565
|
+
with contextlib.suppress(tk.TclError):
|
|
566
|
+
for i, (_, _, _, text_lbl) in enumerate(self._nav_labels):
|
|
567
|
+
text_lbl.config(text=_t(self._NAV_KEYS[i]))
|
|
568
|
+
|
|
569
|
+
def _rebuild_footer_text(self) -> None:
|
|
570
|
+
with contextlib.suppress(tk.TclError):
|
|
571
|
+
is_last = self._step == self.STEPS - 1
|
|
572
|
+
self._next_btn.config(text=_t("wiz.finish")
|
|
573
|
+
if is_last else _t("wiz.next"))
|
|
574
|
+
self._back_btn.config(text=_t("wiz.back"))
|
|
575
|
+
self._skip_btn.config(text=_t("wiz.skip"))
|
|
576
|
+
self._step_lbl.config(
|
|
577
|
+
text=_t("wiz.step", n=self._step + 1, total=self.STEPS)
|
|
578
|
+
)
|
|
579
|
+
|
|
580
|
+
def _update_nav_highlight(self, step: int) -> None:
|
|
581
|
+
if not self._nav_labels:
|
|
582
|
+
return
|
|
583
|
+
t = self._palette()
|
|
584
|
+
with contextlib.suppress(tk.TclError):
|
|
585
|
+
for i, (row, accent, icon_lbl, text_lbl) in enumerate(self._nav_labels):
|
|
586
|
+
if i == step:
|
|
587
|
+
for w in [row, accent, icon_lbl, text_lbl, *row.winfo_children()]:
|
|
588
|
+
with contextlib.suppress(tk.TclError):
|
|
589
|
+
if w is accent:
|
|
590
|
+
w.config(bg=t.btn_primary)
|
|
591
|
+
else:
|
|
592
|
+
w.config(bg=t.activity_bg)
|
|
593
|
+
icon_lbl.config(fg=t.btn_primary)
|
|
594
|
+
text_lbl.config(fg=t.fg, font=(FONT_UI, 9, "bold"))
|
|
595
|
+
elif i < step:
|
|
596
|
+
for w in [row, accent, icon_lbl, text_lbl, *row.winfo_children()]:
|
|
597
|
+
with contextlib.suppress(tk.TclError):
|
|
598
|
+
if w is accent:
|
|
599
|
+
w.config(bg=t.ok_fg)
|
|
600
|
+
else:
|
|
601
|
+
w.config(bg=t.activity_bg)
|
|
602
|
+
icon_lbl.config(fg=t.ok_fg)
|
|
603
|
+
text_lbl.config(fg=t.fg_muted, font=(FONT_UI, 9))
|
|
604
|
+
else:
|
|
605
|
+
for w in [row, accent, icon_lbl, text_lbl, *row.winfo_children()]:
|
|
606
|
+
with contextlib.suppress(tk.TclError):
|
|
607
|
+
w.config(bg=t.activity_bg)
|
|
608
|
+
icon_lbl.config(fg=t.fg_muted)
|
|
609
|
+
text_lbl.config(fg=t.fg_muted, font=(FONT_UI, 9))
|
|
610
|
+
|
|
611
|
+
def _clear(self) -> None:
|
|
612
|
+
for w in self._content.winfo_children():
|
|
613
|
+
w.destroy()
|
|
614
|
+
self._canvas.yview_moveto(0)
|
|
615
|
+
|
|
616
|
+
def _show_step(self, step: int) -> None:
|
|
617
|
+
self._step = step
|
|
618
|
+
self._clear()
|
|
619
|
+
t = self._palette()
|
|
620
|
+
|
|
621
|
+
self._prog_bar.place(relwidth=(step + 1) / self.STEPS)
|
|
622
|
+
self._update_nav_highlight(step)
|
|
623
|
+
|
|
624
|
+
is_last = step == self.STEPS - 1
|
|
625
|
+
nav_key = (
|
|
626
|
+
self._NAV_KEYS[step] if step < len(
|
|
627
|
+
self._NAV_KEYS) else self._NAV_KEYS[-1]
|
|
628
|
+
)
|
|
629
|
+
with contextlib.suppress(tk.TclError):
|
|
630
|
+
self._top_title.config(text=_t(nav_key))
|
|
631
|
+
self._step_lbl.config(
|
|
632
|
+
text=_t("wiz.step", n=step + 1, total=self.STEPS))
|
|
633
|
+
self._next_btn.config(
|
|
634
|
+
text=_t("wiz.finish") if is_last else _t("wiz.next"),
|
|
635
|
+
bg=t.ok_fg if is_last else t.btn_primary,
|
|
636
|
+
)
|
|
637
|
+
self._back_btn.config(
|
|
638
|
+
fg=t.fg if step > 0 else t.fg_muted,
|
|
639
|
+
cursor="hand2" if step > 0 else "arrow",
|
|
640
|
+
)
|
|
641
|
+
|
|
642
|
+
dispatch = {
|
|
643
|
+
0: self._step_welcome,
|
|
644
|
+
1: self._step_lang,
|
|
645
|
+
2: self._step_display,
|
|
646
|
+
3: self._step_theme,
|
|
647
|
+
4: self._step_font,
|
|
648
|
+
5: self._step_indent,
|
|
649
|
+
6: self._step_features,
|
|
650
|
+
7: self._step_extra,
|
|
651
|
+
8: self._step_voice,
|
|
652
|
+
9: self._step_summary,
|
|
653
|
+
}
|
|
654
|
+
dispatch.get(step, lambda _: None)(t)
|
|
655
|
+
|
|
656
|
+
def _section_title(self, text: str, t: Any) -> None:
|
|
657
|
+
tk.Label(
|
|
658
|
+
self._content,
|
|
659
|
+
text=text,
|
|
660
|
+
bg=t.floating_bg,
|
|
661
|
+
fg=t.fg,
|
|
662
|
+
font=(FONT_UI, 15, "bold"),
|
|
663
|
+
anchor="w",
|
|
664
|
+
).pack(fill="x", padx=28, pady=(24, 4))
|
|
665
|
+
|
|
666
|
+
def _section_desc(self, text: str, t: Any) -> None:
|
|
667
|
+
tk.Label(
|
|
668
|
+
self._content,
|
|
669
|
+
text=text,
|
|
670
|
+
bg=t.floating_bg,
|
|
671
|
+
fg=t.fg_muted,
|
|
672
|
+
font=(FONT_UI, 9),
|
|
673
|
+
anchor="w",
|
|
674
|
+
justify="left",
|
|
675
|
+
wraplength=680,
|
|
676
|
+
).pack(fill="x", padx=28, pady=(0, 14))
|
|
677
|
+
|
|
678
|
+
def _divider(self, t: Any) -> None:
|
|
679
|
+
tk.Frame(self._content, bg=t.border, height=1).pack(
|
|
680
|
+
fill="x", padx=28, pady=8)
|
|
681
|
+
|
|
682
|
+
def _step_welcome(self, t: Any) -> None:
|
|
683
|
+
outer = tk.Frame(self._content, bg=t.floating_bg)
|
|
684
|
+
outer.pack(fill="both", expand=True, padx=28, pady=(20, 16))
|
|
685
|
+
|
|
686
|
+
hero = tk.Frame(
|
|
687
|
+
outer, bg=t.activity_bg, highlightthickness=1, highlightbackground=t.border
|
|
688
|
+
)
|
|
689
|
+
hero.pack(fill="x", pady=(0, 20))
|
|
690
|
+
|
|
691
|
+
inner_hero = tk.Frame(hero, bg=t.activity_bg)
|
|
692
|
+
inner_hero.pack(padx=36, pady=26)
|
|
693
|
+
tk.Label(
|
|
694
|
+
inner_hero,
|
|
695
|
+
text="\u2b21",
|
|
696
|
+
bg=t.activity_bg,
|
|
697
|
+
fg=t.btn_primary,
|
|
698
|
+
font=(FONT_UI, 36),
|
|
699
|
+
).pack()
|
|
700
|
+
tk.Label(
|
|
701
|
+
inner_hero,
|
|
702
|
+
text=_t("wiz.welcome_title"),
|
|
703
|
+
bg=t.activity_bg,
|
|
704
|
+
fg=t.fg,
|
|
705
|
+
font=(FONT_UI, 19, "bold"),
|
|
706
|
+
).pack(pady=(4, 0))
|
|
707
|
+
tk.Label(
|
|
708
|
+
inner_hero,
|
|
709
|
+
text=_t("wiz.welcome_sub"),
|
|
710
|
+
bg=t.activity_bg,
|
|
711
|
+
fg=t.fg_muted,
|
|
712
|
+
font=(FONT_UI, 10),
|
|
713
|
+
).pack(pady=(4, 0))
|
|
714
|
+
|
|
715
|
+
feat_frame = tk.Frame(outer, bg=t.floating_bg)
|
|
716
|
+
feat_frame.pack(fill="x")
|
|
717
|
+
feat_frame.columnconfigure(0, weight=1)
|
|
718
|
+
feat_frame.columnconfigure(1, weight=1)
|
|
719
|
+
|
|
720
|
+
feats = [_t(f"wiz.welcome_feat{i}") for i in range(1, 6)]
|
|
721
|
+
for i, feat in enumerate(feats):
|
|
722
|
+
r, c = divmod(i, 2)
|
|
723
|
+
card = tk.Frame(
|
|
724
|
+
feat_frame,
|
|
725
|
+
bg=t.activity_bg,
|
|
726
|
+
highlightthickness=1,
|
|
727
|
+
highlightbackground=t.border,
|
|
728
|
+
)
|
|
729
|
+
card.grid(row=r, column=c, padx=5, pady=5, sticky="ew")
|
|
730
|
+
tk.Label(
|
|
731
|
+
card,
|
|
732
|
+
text=feat,
|
|
733
|
+
bg=t.activity_bg,
|
|
734
|
+
fg=t.fg,
|
|
735
|
+
font=(FONT_UI, 9),
|
|
736
|
+
anchor="w",
|
|
737
|
+
padx=14,
|
|
738
|
+
pady=10,
|
|
739
|
+
).pack(fill="x")
|
|
740
|
+
|
|
741
|
+
def _step_lang(self, t: Any) -> None:
|
|
742
|
+
self._section_title(_t("wiz.lang_title"), t)
|
|
743
|
+
self._section_desc(_t("wiz.lang_desc"), t)
|
|
744
|
+
|
|
745
|
+
sf = tk.Frame(self._content, bg=t.floating_bg)
|
|
746
|
+
sf.pack(fill="both", expand=True, padx=28)
|
|
747
|
+
canvas = tk.Canvas(sf, bg=t.floating_bg, highlightthickness=0)
|
|
748
|
+
vsb = tk.Scrollbar(sf, orient="vertical", command=canvas.yview)
|
|
749
|
+
canvas.configure(yscrollcommand=vsb.set)
|
|
750
|
+
vsb.pack(side="right", fill="y")
|
|
751
|
+
canvas.pack(side="left", fill="both", expand=True)
|
|
752
|
+
|
|
753
|
+
inner = tk.Frame(canvas, bg=t.floating_bg)
|
|
754
|
+
canvas.create_window((0, 0), window=inner, anchor="nw")
|
|
755
|
+
inner.columnconfigure(0, weight=1)
|
|
756
|
+
inner.columnconfigure(1, weight=1)
|
|
757
|
+
|
|
758
|
+
for idx, (code, name) in enumerate(I18n.AVAILABLE_LOCALES):
|
|
759
|
+
r, c = divmod(idx, 2)
|
|
760
|
+
selected = code == self._locale_var.get()
|
|
761
|
+
card = tk.Frame(
|
|
762
|
+
inner,
|
|
763
|
+
bg=t.activity_bg if selected else t.floating_bg,
|
|
764
|
+
highlightthickness=1,
|
|
765
|
+
highlightbackground=t.btn_primary if selected else t.border,
|
|
766
|
+
cursor="hand2",
|
|
767
|
+
)
|
|
768
|
+
card.grid(row=r, column=c, padx=4, pady=3, sticky="ew")
|
|
769
|
+
inner_card = tk.Frame(card, bg=card.cget("bg"))
|
|
770
|
+
inner_card.pack(fill="x", padx=12, pady=8)
|
|
771
|
+
tk.Label(
|
|
772
|
+
inner_card,
|
|
773
|
+
text=name,
|
|
774
|
+
bg=inner_card.cget("bg"),
|
|
775
|
+
fg=t.btn_primary if selected else t.fg,
|
|
776
|
+
font=(FONT_UI, 10, "bold" if selected else "normal"),
|
|
777
|
+
anchor="w",
|
|
778
|
+
).pack(side="left")
|
|
779
|
+
tk.Label(
|
|
780
|
+
inner_card,
|
|
781
|
+
text=f" ({code})",
|
|
782
|
+
bg=inner_card.cget("bg"),
|
|
783
|
+
fg=t.fg_muted,
|
|
784
|
+
font=(FONT_UI, 8),
|
|
785
|
+
anchor="w",
|
|
786
|
+
).pack(side="left")
|
|
787
|
+
if selected:
|
|
788
|
+
tk.Label(
|
|
789
|
+
inner_card,
|
|
790
|
+
text="\u2713",
|
|
791
|
+
bg=inner_card.cget("bg"),
|
|
792
|
+
fg=t.btn_primary,
|
|
793
|
+
font=(FONT_UI, 12, "bold"),
|
|
794
|
+
).pack(side="right")
|
|
795
|
+
|
|
796
|
+
def _pick(c2=code):
|
|
797
|
+
self._apply_locale(c2)
|
|
798
|
+
self._show_step(self._step)
|
|
799
|
+
|
|
800
|
+
for w in [card, inner_card] + list(inner_card.winfo_children()):
|
|
801
|
+
w.bind("<Button-1>", lambda _, fn=_pick: fn(), add="+")
|
|
802
|
+
|
|
803
|
+
inner.bind(
|
|
804
|
+
"<Configure>", lambda e: canvas.configure(
|
|
805
|
+
scrollregion=canvas.bbox("all"))
|
|
806
|
+
)
|
|
807
|
+
canvas.bind(
|
|
808
|
+
"<MouseWheel>",
|
|
809
|
+
lambda e: canvas.yview_scroll(int(-1 * e.delta / 120), "units"),
|
|
810
|
+
)
|
|
811
|
+
|
|
812
|
+
def _step_theme(self, t: Any) -> None:
|
|
813
|
+
self._section_title(_t("wiz.theme_title"), t)
|
|
814
|
+
self._section_desc(_t("wiz.theme_desc"), t)
|
|
815
|
+
|
|
816
|
+
grid = tk.Frame(self._content, bg=t.floating_bg)
|
|
817
|
+
grid.pack(fill="both", expand=True, padx=28, pady=(0, 16))
|
|
818
|
+
grid.columnconfigure(0, weight=1)
|
|
819
|
+
grid.columnconfigure(1, weight=1)
|
|
820
|
+
grid.columnconfigure(2, weight=1)
|
|
821
|
+
|
|
822
|
+
for i, name in enumerate(THEME_ORDER):
|
|
823
|
+
th = THEMES.get(name)
|
|
824
|
+
if not th:
|
|
825
|
+
continue
|
|
826
|
+
_patch_theme(th)
|
|
827
|
+
r, c = divmod(i, 3)
|
|
828
|
+
selected = name == self._theme_var.get()
|
|
829
|
+
|
|
830
|
+
card = tk.Frame(
|
|
831
|
+
grid,
|
|
832
|
+
bg=th.editor_bg,
|
|
833
|
+
highlightthickness=2,
|
|
834
|
+
highlightbackground=t.btn_primary if selected else th.border,
|
|
835
|
+
cursor="hand2",
|
|
836
|
+
)
|
|
837
|
+
card.grid(row=r, column=c, padx=5, pady=5, sticky="nsew")
|
|
838
|
+
|
|
839
|
+
hdr = tk.Frame(card, bg=th.activity_bg)
|
|
840
|
+
hdr.pack(fill="x")
|
|
841
|
+
tk.Label(
|
|
842
|
+
hdr,
|
|
843
|
+
text=name,
|
|
844
|
+
bg=th.activity_bg,
|
|
845
|
+
fg=th.fg,
|
|
846
|
+
font=(FONT_UI, 8, "bold"),
|
|
847
|
+
padx=8,
|
|
848
|
+
pady=5,
|
|
849
|
+
anchor="w",
|
|
850
|
+
).pack(side="left", fill="x", expand=True)
|
|
851
|
+
if selected:
|
|
852
|
+
tk.Label(
|
|
853
|
+
hdr,
|
|
854
|
+
text="\u2713",
|
|
855
|
+
bg=th.activity_bg,
|
|
856
|
+
fg=t.btn_primary,
|
|
857
|
+
font=(FONT_UI, 9, "bold"),
|
|
858
|
+
padx=6,
|
|
859
|
+
).pack(side="right")
|
|
860
|
+
|
|
861
|
+
code_f = tk.Frame(card, bg=th.editor_bg, pady=5, padx=8)
|
|
862
|
+
code_f.pack(fill="x")
|
|
863
|
+
row_f = tk.Frame(code_f, bg=th.editor_bg)
|
|
864
|
+
row_f.pack(anchor="w")
|
|
865
|
+
for color, txt in [
|
|
866
|
+
(th.t_keyword, "def "),
|
|
867
|
+
(th.t_func, "hello"),
|
|
868
|
+
(th.fg, "():"),
|
|
869
|
+
]:
|
|
870
|
+
tk.Label(
|
|
871
|
+
row_f, text=txt, bg=th.editor_bg, fg=color, font=(
|
|
872
|
+
FONT_MONO, 8)
|
|
873
|
+
).pack(side="left")
|
|
874
|
+
tk.Label(
|
|
875
|
+
code_f,
|
|
876
|
+
text=' print("Hi!")',
|
|
877
|
+
bg=th.editor_bg,
|
|
878
|
+
fg=th.t_string,
|
|
879
|
+
font=(FONT_MONO, 8),
|
|
880
|
+
anchor="w",
|
|
881
|
+
).pack(anchor="w")
|
|
882
|
+
|
|
883
|
+
strip = tk.Frame(card, bg=th.editor_bg, pady=3)
|
|
884
|
+
strip.pack(fill="x", padx=8)
|
|
885
|
+
for colour in (
|
|
886
|
+
th.t_keyword,
|
|
887
|
+
th.t_func,
|
|
888
|
+
th.t_string,
|
|
889
|
+
th.t_comment,
|
|
890
|
+
th.t_number,
|
|
891
|
+
):
|
|
892
|
+
tk.Frame(strip, bg=colour, width=10, height=10).pack(
|
|
893
|
+
side="left", padx=2
|
|
894
|
+
)
|
|
895
|
+
|
|
896
|
+
def _pick(n=name):
|
|
897
|
+
self._theme_var.set(n)
|
|
898
|
+
self._tmgr.set(n)
|
|
899
|
+
_patch_theme(self._tmgr.theme)
|
|
900
|
+
self._rebuild_all()
|
|
901
|
+
|
|
902
|
+
for w in [card, hdr, code_f, strip, row_f]:
|
|
903
|
+
w.bind("<Button-1>", lambda _, fn=_pick: fn(), add="+")
|
|
904
|
+
for child in getattr(w, "winfo_children", list)():
|
|
905
|
+
child.bind("<Button-1>", lambda _, fn=_pick: fn(), add="+")
|
|
906
|
+
|
|
907
|
+
def _step_font(self, t: Any) -> None:
|
|
908
|
+
self._section_title(_t("wiz.font_title"), t)
|
|
909
|
+
self._section_desc(_t("wiz.font_desc"), t)
|
|
910
|
+
|
|
911
|
+
body = tk.Frame(self._content, bg=t.floating_bg)
|
|
912
|
+
body.pack(fill="x", padx=28)
|
|
913
|
+
|
|
914
|
+
tk.Label(
|
|
915
|
+
body,
|
|
916
|
+
text=_t("wiz.font_family"),
|
|
917
|
+
bg=t.floating_bg,
|
|
918
|
+
fg=t.fg,
|
|
919
|
+
font=(FONT_UI, 9),
|
|
920
|
+
anchor="w",
|
|
921
|
+
).pack(anchor="w")
|
|
922
|
+
fonts = [
|
|
923
|
+
FONT_MONO,
|
|
924
|
+
"Courier New",
|
|
925
|
+
"Fira Code",
|
|
926
|
+
"JetBrains Mono",
|
|
927
|
+
"Source Code Pro",
|
|
928
|
+
"Cascadia Code",
|
|
929
|
+
"Inconsolata",
|
|
930
|
+
"Consolas",
|
|
931
|
+
"Liberation Mono",
|
|
932
|
+
"DejaVu Sans Mono",
|
|
933
|
+
]
|
|
934
|
+
installed = {name.lower() for name in self._profile.fonts}
|
|
935
|
+
fonts = [f for f in fonts if not installed or f.lower() in installed]
|
|
936
|
+
for name in (self._rec.font_family, self._font_var.get()):
|
|
937
|
+
if name not in fonts:
|
|
938
|
+
fonts.insert(0, name)
|
|
939
|
+
DropDown(
|
|
940
|
+
body,
|
|
941
|
+
textvariable=self._font_var,
|
|
942
|
+
values=fonts,
|
|
943
|
+
width=30,
|
|
944
|
+
font=(FONT_UI, 10),
|
|
945
|
+
state="readonly",
|
|
946
|
+
).pack(anchor="w", pady=(4, 16))
|
|
947
|
+
|
|
948
|
+
tk.Label(
|
|
949
|
+
body,
|
|
950
|
+
text=_t("wiz.font_size"),
|
|
951
|
+
bg=t.floating_bg,
|
|
952
|
+
fg=t.fg,
|
|
953
|
+
font=(FONT_UI, 9),
|
|
954
|
+
anchor="w",
|
|
955
|
+
).pack(anchor="w")
|
|
956
|
+
sz_row = tk.Frame(body, bg=t.floating_bg)
|
|
957
|
+
sz_row.pack(anchor="w", pady=(4, 0))
|
|
958
|
+
sz_val = tk.Label(
|
|
959
|
+
sz_row,
|
|
960
|
+
text=str(self._size_var.get()),
|
|
961
|
+
bg=t.activity_bg,
|
|
962
|
+
fg=t.fg,
|
|
963
|
+
font=(FONT_MONO, 10),
|
|
964
|
+
width=4,
|
|
965
|
+
pady=3,
|
|
966
|
+
)
|
|
967
|
+
sz_val.pack(side="right", padx=(8, 0))
|
|
968
|
+
ttk.Scale(
|
|
969
|
+
sz_row,
|
|
970
|
+
from_=8,
|
|
971
|
+
to=28,
|
|
972
|
+
orient="horizontal",
|
|
973
|
+
variable=self._size_var,
|
|
974
|
+
length=260,
|
|
975
|
+
command=lambda v: sz_val.config(text=str(int(float(v)))),
|
|
976
|
+
).pack(side="left")
|
|
977
|
+
|
|
978
|
+
self._divider(t)
|
|
979
|
+
|
|
980
|
+
pf = tk.Frame(
|
|
981
|
+
self._content,
|
|
982
|
+
bg=t.editor_bg,
|
|
983
|
+
highlightthickness=1,
|
|
984
|
+
highlightbackground=t.border,
|
|
985
|
+
)
|
|
986
|
+
pf.pack(fill="x", padx=28, pady=(0, 20))
|
|
987
|
+
ph = tk.Frame(pf, bg=t.activity_bg)
|
|
988
|
+
ph.pack(fill="x")
|
|
989
|
+
tk.Label(
|
|
990
|
+
ph,
|
|
991
|
+
text=" preview.py",
|
|
992
|
+
bg=t.activity_bg,
|
|
993
|
+
fg=t.fg_muted,
|
|
994
|
+
font=(FONT_UI, 8),
|
|
995
|
+
pady=4,
|
|
996
|
+
).pack(side="left")
|
|
997
|
+
pv = tk.Label(
|
|
998
|
+
pf,
|
|
999
|
+
text='def hello_world():\n msg = "Hello, Codis!"\n print(msg)',
|
|
1000
|
+
bg=t.editor_bg,
|
|
1001
|
+
fg=t.t_func,
|
|
1002
|
+
font=(self._font_var.get(), self._size_var.get()),
|
|
1003
|
+
justify="left",
|
|
1004
|
+
anchor="w",
|
|
1005
|
+
padx=16,
|
|
1006
|
+
pady=12,
|
|
1007
|
+
)
|
|
1008
|
+
pv.pack(fill="x")
|
|
1009
|
+
|
|
1010
|
+
def _refresh(*_: Any) -> None:
|
|
1011
|
+
with contextlib.suppress(tk.TclError):
|
|
1012
|
+
pv.config(
|
|
1013
|
+
font=(self._font_var.get(), max(
|
|
1014
|
+
8, int(self._size_var.get())))
|
|
1015
|
+
)
|
|
1016
|
+
|
|
1017
|
+
self._font_var.trace_add("write", _refresh)
|
|
1018
|
+
self._size_var.trace_add("write", _refresh)
|
|
1019
|
+
|
|
1020
|
+
def _step_indent(self, t: Any) -> None:
|
|
1021
|
+
self._section_title(_t("wiz.indent_title"), t)
|
|
1022
|
+
self._section_desc(_t("wiz.indent_desc"), t)
|
|
1023
|
+
|
|
1024
|
+
body = tk.Frame(self._content, bg=t.floating_bg)
|
|
1025
|
+
body.pack(fill="x", padx=28)
|
|
1026
|
+
|
|
1027
|
+
for size, key in [
|
|
1028
|
+
(2, "wiz.indent_2"),
|
|
1029
|
+
(4, "wiz.indent_4"),
|
|
1030
|
+
(8, "wiz.indent_8"),
|
|
1031
|
+
]:
|
|
1032
|
+
selected = self._tab_var.get() == size
|
|
1033
|
+
card = tk.Frame(
|
|
1034
|
+
body,
|
|
1035
|
+
bg=t.activity_bg if selected else t.floating_bg,
|
|
1036
|
+
highlightthickness=1,
|
|
1037
|
+
highlightbackground=t.btn_primary if selected else t.border,
|
|
1038
|
+
cursor="hand2",
|
|
1039
|
+
)
|
|
1040
|
+
card.pack(fill="x", pady=5)
|
|
1041
|
+
inner = tk.Frame(card, bg=card.cget("bg"), pady=10, padx=16)
|
|
1042
|
+
inner.pack(fill="x")
|
|
1043
|
+
left_f = tk.Frame(inner, bg=inner.cget("bg"))
|
|
1044
|
+
left_f.pack(side="left", fill="x", expand=True)
|
|
1045
|
+
tk.Label(
|
|
1046
|
+
left_f,
|
|
1047
|
+
text=_t("wiz.spaces", n=size),
|
|
1048
|
+
bg=left_f.cget("bg"),
|
|
1049
|
+
fg=t.btn_primary if selected else t.fg,
|
|
1050
|
+
font=(FONT_UI, 11, "bold"),
|
|
1051
|
+
).pack(anchor="w")
|
|
1052
|
+
tk.Label(
|
|
1053
|
+
left_f,
|
|
1054
|
+
text=_t(key),
|
|
1055
|
+
bg=left_f.cget("bg"),
|
|
1056
|
+
fg=t.fg_muted,
|
|
1057
|
+
font=(FONT_UI, 8),
|
|
1058
|
+
).pack(anchor="w")
|
|
1059
|
+
preview = "\u00b7" * size + " code here"
|
|
1060
|
+
tk.Label(
|
|
1061
|
+
inner,
|
|
1062
|
+
text=preview,
|
|
1063
|
+
bg=inner.cget("bg"),
|
|
1064
|
+
fg=t.fg_muted,
|
|
1065
|
+
font=(FONT_MONO, 9),
|
|
1066
|
+
).pack(side="right", padx=12)
|
|
1067
|
+
if selected:
|
|
1068
|
+
tk.Label(
|
|
1069
|
+
inner,
|
|
1070
|
+
text="\u2713",
|
|
1071
|
+
bg=inner.cget("bg"),
|
|
1072
|
+
fg=t.btn_primary,
|
|
1073
|
+
font=(FONT_UI, 14, "bold"),
|
|
1074
|
+
).pack(side="right")
|
|
1075
|
+
|
|
1076
|
+
def _pick(s=size):
|
|
1077
|
+
self._tab_var.set(s)
|
|
1078
|
+
self._show_step(4)
|
|
1079
|
+
|
|
1080
|
+
for w in (
|
|
1081
|
+
[card, inner, left_f]
|
|
1082
|
+
+ list(left_f.winfo_children())
|
|
1083
|
+
+ list(inner.winfo_children())
|
|
1084
|
+
):
|
|
1085
|
+
w.bind("<Button-1>", lambda _, fn=_pick: fn(), add="+")
|
|
1086
|
+
|
|
1087
|
+
def _step_features(self, t: Any) -> None:
|
|
1088
|
+
self._section_title(_t("wiz.features_title"), t)
|
|
1089
|
+
self._section_desc(_t("wiz.features_desc"), t)
|
|
1090
|
+
body = tk.Frame(self._content, bg=t.floating_bg)
|
|
1091
|
+
body.pack(fill="x", padx=28)
|
|
1092
|
+
self._toggle_cards(body, t, FEATURE_TOGGLES)
|
|
1093
|
+
|
|
1094
|
+
def _toggle_cards(
|
|
1095
|
+
self, body: tk.Frame, t: Any, toggles: tuple[WizardToggle, ...]
|
|
1096
|
+
) -> None:
|
|
1097
|
+
"""Cria um cartão liga/desliga para cada opção de ``toggles``."""
|
|
1098
|
+
for tg in toggles:
|
|
1099
|
+
desc = _t(tg.desc_key, tg.desc) if tg.desc_key else ""
|
|
1100
|
+
self._feature_card(
|
|
1101
|
+
body, t, self._opts[tg.key], tg.icon, _t(tg.label_key, tg.label), desc
|
|
1102
|
+
)
|
|
1103
|
+
|
|
1104
|
+
def _feature_card(
|
|
1105
|
+
self,
|
|
1106
|
+
parent: tk.Frame,
|
|
1107
|
+
t: Any,
|
|
1108
|
+
var: tk.BooleanVar,
|
|
1109
|
+
icon: str,
|
|
1110
|
+
label: str,
|
|
1111
|
+
desc: str,
|
|
1112
|
+
) -> None:
|
|
1113
|
+
card = tk.Frame(
|
|
1114
|
+
parent,
|
|
1115
|
+
bg=t.activity_bg,
|
|
1116
|
+
highlightthickness=1,
|
|
1117
|
+
highlightbackground=t.border,
|
|
1118
|
+
cursor="hand2",
|
|
1119
|
+
)
|
|
1120
|
+
card.pack(fill="x", pady=5)
|
|
1121
|
+
inner = tk.Frame(card, bg=t.activity_bg, padx=16, pady=10)
|
|
1122
|
+
inner.pack(fill="x")
|
|
1123
|
+
|
|
1124
|
+
icon_lbl = tk.Label(
|
|
1125
|
+
inner, text=icon, bg=t.activity_bg, fg=t.fg, font=(FONT_UI, 16), width=2
|
|
1126
|
+
)
|
|
1127
|
+
icon_lbl.pack(side="left")
|
|
1128
|
+
|
|
1129
|
+
text_f = tk.Frame(inner, bg=t.activity_bg)
|
|
1130
|
+
text_f.pack(side="left", fill="x", expand=True, padx=10)
|
|
1131
|
+
tk.Label(
|
|
1132
|
+
text_f,
|
|
1133
|
+
text=label,
|
|
1134
|
+
bg=t.activity_bg,
|
|
1135
|
+
fg=t.fg,
|
|
1136
|
+
font=(FONT_UI, 10, "bold"),
|
|
1137
|
+
anchor="w",
|
|
1138
|
+
).pack(fill="x")
|
|
1139
|
+
if desc:
|
|
1140
|
+
tk.Label(
|
|
1141
|
+
text_f,
|
|
1142
|
+
text=desc,
|
|
1143
|
+
bg=t.activity_bg,
|
|
1144
|
+
fg=t.fg_muted,
|
|
1145
|
+
font=(FONT_UI, 8),
|
|
1146
|
+
anchor="w",
|
|
1147
|
+
).pack(fill="x")
|
|
1148
|
+
|
|
1149
|
+
toggle_outer = tk.Frame(inner, bg=t.activity_bg)
|
|
1150
|
+
toggle_outer.pack(side="right")
|
|
1151
|
+
toggle_bg = tk.Frame(
|
|
1152
|
+
toggle_outer, bg=t.border, width=40, height=20, cursor="hand2"
|
|
1153
|
+
)
|
|
1154
|
+
toggle_bg.pack_propagate(False)
|
|
1155
|
+
toggle_bg.pack()
|
|
1156
|
+
toggle_dot = tk.Frame(toggle_bg, bg=t.fg_muted, width=14, height=14)
|
|
1157
|
+
|
|
1158
|
+
def _draw(*_: Any) -> None:
|
|
1159
|
+
on = var.get()
|
|
1160
|
+
toggle_bg.config(bg=t.btn_primary if on else t.border)
|
|
1161
|
+
toggle_dot.config(bg="#fff" if on else t.fg_muted)
|
|
1162
|
+
toggle_dot.place(x=22 if on else 2, rely=0.5, anchor="w")
|
|
1163
|
+
|
|
1164
|
+
_draw()
|
|
1165
|
+
|
|
1166
|
+
def _toggle(_evt: Any = None) -> None:
|
|
1167
|
+
var.set(not var.get())
|
|
1168
|
+
_draw()
|
|
1169
|
+
|
|
1170
|
+
var.trace_add("write", _draw)
|
|
1171
|
+
for w in [card, inner, icon_lbl, text_f, toggle_outer, toggle_bg, toggle_dot]:
|
|
1172
|
+
w.bind("<Button-1>", _toggle, add="+")
|
|
1173
|
+
for child in text_f.winfo_children():
|
|
1174
|
+
child.bind("<Button-1>", _toggle, add="+")
|
|
1175
|
+
|
|
1176
|
+
def _step_extra(self, t: Any) -> None:
|
|
1177
|
+
self._section_title(_t("wiz.extra_title"), t)
|
|
1178
|
+
self._section_desc(_t("wiz.extra_desc"), t)
|
|
1179
|
+
|
|
1180
|
+
body = tk.Frame(self._content, bg=t.floating_bg)
|
|
1181
|
+
body.pack(fill="x", padx=28)
|
|
1182
|
+
|
|
1183
|
+
shell_card = tk.Frame(
|
|
1184
|
+
body, bg=t.activity_bg, highlightthickness=1, highlightbackground=t.border
|
|
1185
|
+
)
|
|
1186
|
+
shell_card.pack(fill="x", pady=5)
|
|
1187
|
+
shell_inner = tk.Frame(shell_card, bg=t.activity_bg, padx=16, pady=12)
|
|
1188
|
+
shell_inner.pack(fill="x")
|
|
1189
|
+
tk.Label(
|
|
1190
|
+
shell_inner,
|
|
1191
|
+
text="\U0001f4bb",
|
|
1192
|
+
bg=t.activity_bg,
|
|
1193
|
+
fg=t.fg,
|
|
1194
|
+
font=(FONT_UI, 16),
|
|
1195
|
+
width=2,
|
|
1196
|
+
).pack(side="left")
|
|
1197
|
+
tk.Label(
|
|
1198
|
+
shell_inner,
|
|
1199
|
+
text=_t("wiz.shell"),
|
|
1200
|
+
bg=t.activity_bg,
|
|
1201
|
+
fg=t.fg,
|
|
1202
|
+
font=(FONT_UI, 10, "bold"),
|
|
1203
|
+
padx=10,
|
|
1204
|
+
).pack(side="left")
|
|
1205
|
+
DropDown(
|
|
1206
|
+
shell_inner,
|
|
1207
|
+
textvariable=self._shell_var2,
|
|
1208
|
+
values=list(SHELL_OPTIONS.keys()),
|
|
1209
|
+
width=18,
|
|
1210
|
+
font=(FONT_UI, 9),
|
|
1211
|
+
state="readonly",
|
|
1212
|
+
).pack(side="right")
|
|
1213
|
+
|
|
1214
|
+
self._toggle_cards(body, t, EXTRA_TOGGLES)
|
|
1215
|
+
|
|
1216
|
+
self._divider(t)
|
|
1217
|
+
tk.Label(
|
|
1218
|
+
self._content,
|
|
1219
|
+
text=_t("wiz.extra_note"),
|
|
1220
|
+
bg=t.floating_bg,
|
|
1221
|
+
fg=t.fg_muted,
|
|
1222
|
+
font=(FONT_UI, 9),
|
|
1223
|
+
justify="left",
|
|
1224
|
+
anchor="w",
|
|
1225
|
+
wraplength=680,
|
|
1226
|
+
).pack(fill="x", padx=28, pady=(0, 20))
|
|
1227
|
+
|
|
1228
|
+
def _step_voice(self, t: Any) -> None:
|
|
1229
|
+
self._section_title(_t("wiz.voice_title", "Voz e acessibilidade"), t)
|
|
1230
|
+
self._section_desc(
|
|
1231
|
+
_t(
|
|
1232
|
+
"wiz.voice_desc",
|
|
1233
|
+
"Ajuste a leitura em voz alta e as opções de acessibilidade. "
|
|
1234
|
+
"Tudo pode ser mudado depois em Configurações.",
|
|
1235
|
+
),
|
|
1236
|
+
t,
|
|
1237
|
+
)
|
|
1238
|
+
body = tk.Frame(self._content, bg=t.floating_bg)
|
|
1239
|
+
body.pack(fill="x", padx=28)
|
|
1240
|
+
self._toggle_cards(body, t, A11Y_TOGGLES)
|
|
1241
|
+
|
|
1242
|
+
self._divider(t)
|
|
1243
|
+
card = tk.Frame(
|
|
1244
|
+
body, bg=t.activity_bg, highlightthickness=1, highlightbackground=t.border
|
|
1245
|
+
)
|
|
1246
|
+
card.pack(fill="x", pady=5)
|
|
1247
|
+
inner = tk.Frame(card, bg=t.activity_bg, padx=16, pady=12)
|
|
1248
|
+
inner.pack(fill="x")
|
|
1249
|
+
self._tts_status = tk.Label(
|
|
1250
|
+
inner,
|
|
1251
|
+
text=self._tts_status_text(),
|
|
1252
|
+
bg=t.activity_bg,
|
|
1253
|
+
fg=t.fg_muted,
|
|
1254
|
+
font=(FONT_UI, 9),
|
|
1255
|
+
anchor="w",
|
|
1256
|
+
justify="left",
|
|
1257
|
+
wraplength=480,
|
|
1258
|
+
)
|
|
1259
|
+
self._tts_status.pack(side="left", fill="x", expand=True)
|
|
1260
|
+
tk.Button(
|
|
1261
|
+
inner,
|
|
1262
|
+
text=_t("wiz.tts_test", "Testar voz"),
|
|
1263
|
+
bg=t.btn_bg,
|
|
1264
|
+
fg=t.btn_fg,
|
|
1265
|
+
activebackground=t.btn_hover,
|
|
1266
|
+
activeforeground=t.fg,
|
|
1267
|
+
relief="flat",
|
|
1268
|
+
bd=0,
|
|
1269
|
+
padx=14,
|
|
1270
|
+
pady=6,
|
|
1271
|
+
cursor="hand2",
|
|
1272
|
+
font=(FONT_UI, 9),
|
|
1273
|
+
command=self._test_voice,
|
|
1274
|
+
).pack(side="right")
|
|
1275
|
+
|
|
1276
|
+
def _speech_bridge(self) -> Any:
|
|
1277
|
+
"""Cria (uma vez) a ponte de fala do sistema; ``None`` se indisponível."""
|
|
1278
|
+
if self._tts_bridge is None:
|
|
1279
|
+
try:
|
|
1280
|
+
from src.ui.accessibility import ScreenReaderBridge
|
|
1281
|
+
|
|
1282
|
+
self._tts_bridge = ScreenReaderBridge()
|
|
1283
|
+
except Exception:
|
|
1284
|
+
logger.debug("Ponte de TTS indisponível.", exc_info=True)
|
|
1285
|
+
return None
|
|
1286
|
+
return self._tts_bridge
|
|
1287
|
+
|
|
1288
|
+
def _tts_status_text(self) -> str:
|
|
1289
|
+
bridge = self._speech_bridge()
|
|
1290
|
+
if bridge is not None and bridge.available:
|
|
1291
|
+
return _t("wiz.tts_detected", "Motor de voz do sistema detectado.")
|
|
1292
|
+
return _t(
|
|
1293
|
+
"wiz.tts_missing",
|
|
1294
|
+
"Nenhum motor de voz detectado (Windows: SAPI, Linux: spd-say ou espeak, macOS: say). "
|
|
1295
|
+
"A opção fica salva e passa a valer quando houver um.",
|
|
1296
|
+
)
|
|
1297
|
+
|
|
1298
|
+
def _test_voice(self) -> None:
|
|
1299
|
+
"""Fala uma frase de exemplo para o usuário conferir o som."""
|
|
1300
|
+
bridge = self._speech_bridge()
|
|
1301
|
+
if bridge is not None and bridge.available:
|
|
1302
|
+
bridge.speak(
|
|
1303
|
+
_t("wiz.tts_sample", "Olá! Esta é a voz do Codis."), interrupt=True
|
|
1304
|
+
)
|
|
1305
|
+
if self._tts_status is not None:
|
|
1306
|
+
with contextlib.suppress(tk.TclError):
|
|
1307
|
+
self._tts_status.config(text=self._tts_status_text())
|
|
1308
|
+
|
|
1309
|
+
def _step_summary(self, t: Any) -> None:
|
|
1310
|
+
outer = tk.Frame(self._content, bg=t.floating_bg)
|
|
1311
|
+
outer.pack(fill="both", expand=True, padx=28, pady=(20, 16))
|
|
1312
|
+
|
|
1313
|
+
hero = tk.Frame(
|
|
1314
|
+
outer, bg=t.activity_bg, highlightthickness=1, highlightbackground=t.ok_fg
|
|
1315
|
+
)
|
|
1316
|
+
hero.pack(fill="x", pady=(0, 20))
|
|
1317
|
+
tk.Label(hero, text="\U0001f389", bg=t.activity_bg, font=(FONT_UI, 30)).pack(
|
|
1318
|
+
pady=(18, 4)
|
|
1319
|
+
)
|
|
1320
|
+
tk.Label(
|
|
1321
|
+
hero,
|
|
1322
|
+
text=_t("wiz.sum_title"),
|
|
1323
|
+
bg=t.activity_bg,
|
|
1324
|
+
fg=t.ok_fg,
|
|
1325
|
+
font=(FONT_UI, 17, "bold"),
|
|
1326
|
+
).pack()
|
|
1327
|
+
tk.Label(
|
|
1328
|
+
hero,
|
|
1329
|
+
text=_t("wiz.sum_sub"),
|
|
1330
|
+
bg=t.activity_bg,
|
|
1331
|
+
fg=t.fg_muted,
|
|
1332
|
+
font=(FONT_UI, 9),
|
|
1333
|
+
justify="center",
|
|
1334
|
+
wraplength=580,
|
|
1335
|
+
).pack(pady=(4, 18))
|
|
1336
|
+
|
|
1337
|
+
self._divider(t)
|
|
1338
|
+
|
|
1339
|
+
tk.Label(
|
|
1340
|
+
self._content,
|
|
1341
|
+
text=_t("wiz.sum_your_setup"),
|
|
1342
|
+
bg=t.floating_bg,
|
|
1343
|
+
fg=t.fg,
|
|
1344
|
+
font=(FONT_UI, 11, "bold"),
|
|
1345
|
+
).pack(padx=28, anchor="w", pady=(8, 8))
|
|
1346
|
+
|
|
1347
|
+
grid_f = tk.Frame(self._content, bg=t.floating_bg)
|
|
1348
|
+
grid_f.pack(fill="x", padx=28, pady=(0, 16))
|
|
1349
|
+
grid_f.columnconfigure(0, weight=1)
|
|
1350
|
+
grid_f.columnconfigure(1, weight=1)
|
|
1351
|
+
|
|
1352
|
+
on_s = _t("wiz.on")
|
|
1353
|
+
off_s = _t("wiz.off")
|
|
1354
|
+
items = [
|
|
1355
|
+
("\U0001f310", _t("wiz.sum_lang"), self._locale_var.get()),
|
|
1356
|
+
("\U0001f3a8", _t("wiz.sum_theme"), self._theme_var.get()),
|
|
1357
|
+
(
|
|
1358
|
+
"\u2712",
|
|
1359
|
+
_t("wiz.sum_font"),
|
|
1360
|
+
f"{self._font_var.get()} {self._size_var.get()}px",
|
|
1361
|
+
),
|
|
1362
|
+
("\U0001f5a5", _t("wiz.sum_scale"), self._scale_text()),
|
|
1363
|
+
("\u21e5", _t("wiz.sum_tab"), _t("wiz.spaces", n=self._tab_var.get())),
|
|
1364
|
+
("\U0001f4bb", _t("wiz.sum_shell"), self._shell_var2.get()),
|
|
1365
|
+
]
|
|
1366
|
+
for tg in ALL_TOGGLES:
|
|
1367
|
+
label = _t(tg.sum_key) if tg.sum_key else _t(tg.label_key, tg.label)
|
|
1368
|
+
items.append((tg.icon, label, on_s if self._opts[tg.key].get() else off_s))
|
|
1369
|
+
for i, (icon, key, val) in enumerate(items):
|
|
1370
|
+
r, c = divmod(i, 2)
|
|
1371
|
+
cell = tk.Frame(
|
|
1372
|
+
grid_f,
|
|
1373
|
+
bg=t.activity_bg,
|
|
1374
|
+
highlightthickness=1,
|
|
1375
|
+
highlightbackground=t.border,
|
|
1376
|
+
)
|
|
1377
|
+
cell.grid(row=r, column=c, padx=4, pady=3, sticky="ew")
|
|
1378
|
+
inn = tk.Frame(cell, bg=t.activity_bg, padx=10, pady=6)
|
|
1379
|
+
inn.pack(fill="x")
|
|
1380
|
+
tk.Label(
|
|
1381
|
+
inn, text=icon, bg=t.activity_bg, fg=t.fg, font=(FONT_UI, 12), width=2
|
|
1382
|
+
).pack(side="left")
|
|
1383
|
+
lf = tk.Frame(inn, bg=t.activity_bg)
|
|
1384
|
+
lf.pack(side="left", fill="x", expand=True, padx=6)
|
|
1385
|
+
tk.Label(
|
|
1386
|
+
lf,
|
|
1387
|
+
text=key,
|
|
1388
|
+
bg=t.activity_bg,
|
|
1389
|
+
fg=t.fg_muted,
|
|
1390
|
+
font=(FONT_UI, 7),
|
|
1391
|
+
anchor="w",
|
|
1392
|
+
).pack(fill="x")
|
|
1393
|
+
tk.Label(
|
|
1394
|
+
lf,
|
|
1395
|
+
text=val,
|
|
1396
|
+
bg=t.activity_bg,
|
|
1397
|
+
fg=t.fg,
|
|
1398
|
+
font=(FONT_UI, 9, "bold"),
|
|
1399
|
+
anchor="w",
|
|
1400
|
+
).pack(fill="x")
|
|
1401
|
+
|
|
1402
|
+
def _scale_text(self) -> str:
|
|
1403
|
+
if self._scale_auto.get():
|
|
1404
|
+
return _t("wiz.display_scale_auto", pct=self._auto_pct)
|
|
1405
|
+
return f"{int(self._scale_manual.get())}%"
|
|
1406
|
+
|
|
1407
|
+
def _apply_recommended(self) -> None:
|
|
1408
|
+
"""Volta todas as opções para os valores recomendados ao sistema."""
|
|
1409
|
+
rec = self._rec
|
|
1410
|
+
self._locale_var.set(rec.language)
|
|
1411
|
+
self._font_var.set(rec.font_family)
|
|
1412
|
+
self._size_var.set(rec.font_size)
|
|
1413
|
+
self._tab_var.set(rec.tab_size)
|
|
1414
|
+
self._scale_auto.set(True)
|
|
1415
|
+
self._scale_manual.set(self._auto_pct)
|
|
1416
|
+
values = initial_toggle_values(self._cfg.get, rec.toggles)
|
|
1417
|
+
for key, var in self._opts.items():
|
|
1418
|
+
var.set(values[key])
|
|
1419
|
+
with contextlib.suppress(Exception):
|
|
1420
|
+
I18n.get_instance().set_locale(rec.language)
|
|
1421
|
+
self._theme_var.set(rec.theme)
|
|
1422
|
+
self._tmgr.set(rec.theme)
|
|
1423
|
+
_patch_theme(self._tmgr.theme)
|
|
1424
|
+
self._rebuild_all()
|
|
1425
|
+
|
|
1426
|
+
def _info_row(self, parent: tk.Misc, t: Any, label: str, value: str) -> None:
|
|
1427
|
+
row = tk.Frame(parent, bg=t.activity_bg)
|
|
1428
|
+
row.pack(fill="x", padx=14, pady=3)
|
|
1429
|
+
tk.Label(
|
|
1430
|
+
row, text=label, bg=t.activity_bg, fg=t.fg_muted, font=(FONT_UI, 9), anchor="w"
|
|
1431
|
+
).pack(side="left")
|
|
1432
|
+
tk.Label(
|
|
1433
|
+
row, text=value, bg=t.activity_bg, fg=t.fg, font=(FONT_UI, 9, "bold"), anchor="e"
|
|
1434
|
+
).pack(side="right")
|
|
1435
|
+
|
|
1436
|
+
def _step_display(self, t: Any) -> None:
|
|
1437
|
+
self._section_title(_t("wiz.display_title"), t)
|
|
1438
|
+
self._section_desc(_t("wiz.display_desc"), t)
|
|
1439
|
+
|
|
1440
|
+
info = describe(self._profile)
|
|
1441
|
+
card = tk.Frame(
|
|
1442
|
+
self._content, bg=t.activity_bg, highlightthickness=1, highlightbackground=t.border
|
|
1443
|
+
)
|
|
1444
|
+
card.pack(fill="x", padx=28, pady=(0, 12))
|
|
1445
|
+
tk.Frame(card, bg=t.activity_bg, height=6).pack()
|
|
1446
|
+
self._info_row(
|
|
1447
|
+
card, t, _t("wiz.display_screen"),
|
|
1448
|
+
f"{info['resolution']} \u00b7 {info['dpi']} DPI \u00b7 {info['os_zoom']}%",
|
|
1449
|
+
)
|
|
1450
|
+
self._info_row(card, t, _t("wiz.display_text_scale"), f"{info['text_scale']}%")
|
|
1451
|
+
appearance = {True: "wiz.appearance_dark", False: "wiz.appearance_light"}.get(
|
|
1452
|
+
info["dark"], "wiz.appearance_unknown"
|
|
1453
|
+
)
|
|
1454
|
+
self._info_row(card, t, _t("wiz.display_appearance"), _t(appearance))
|
|
1455
|
+
memory = "\u2014" if info["memory_gb"] is None else f"{info['memory_gb']:g}"
|
|
1456
|
+
self._info_row(
|
|
1457
|
+
card, t, _t("wiz.display_hw"),
|
|
1458
|
+
_t("wiz.display_hw_value", gb=memory, cpus=info["cpus"] or "\u2014"),
|
|
1459
|
+
)
|
|
1460
|
+
tk.Frame(card, bg=t.activity_bg, height=6).pack()
|
|
1461
|
+
if info["low_end"]:
|
|
1462
|
+
tk.Label(
|
|
1463
|
+
self._content, text=_t("wiz.display_lowend"), bg=t.floating_bg, fg=t.fg_muted,
|
|
1464
|
+
font=(FONT_UI, 9), anchor="w", justify="left", wraplength=680,
|
|
1465
|
+
).pack(fill="x", padx=28, pady=(0, 10))
|
|
1466
|
+
|
|
1467
|
+
tk.Label(
|
|
1468
|
+
self._content, text=_t("wiz.display_scale"), bg=t.floating_bg, fg=t.fg,
|
|
1469
|
+
font=(FONT_UI, 10, "bold"), anchor="w",
|
|
1470
|
+
).pack(fill="x", padx=28, pady=(4, 4))
|
|
1471
|
+
scale_box = tk.Frame(self._content, bg=t.floating_bg)
|
|
1472
|
+
scale_box.pack(fill="x", padx=28)
|
|
1473
|
+
|
|
1474
|
+
manual_row = tk.Frame(scale_box, bg=t.floating_bg)
|
|
1475
|
+
slider = ttk.Scale(
|
|
1476
|
+
manual_row, from_=70, to=200, orient="horizontal", length=240,
|
|
1477
|
+
variable=self._scale_manual,
|
|
1478
|
+
)
|
|
1479
|
+
value_lbl = tk.Label(
|
|
1480
|
+
manual_row, text=f"{int(self._scale_manual.get())}%", bg=t.activity_bg, fg=t.fg,
|
|
1481
|
+
font=(FONT_MONO, 10), width=6, pady=3,
|
|
1482
|
+
)
|
|
1483
|
+
|
|
1484
|
+
def _on_slide(raw: str) -> None:
|
|
1485
|
+
snapped = int(round(float(raw) / 5.0) * 5)
|
|
1486
|
+
self._scale_manual.set(snapped)
|
|
1487
|
+
value_lbl.config(text=f"{snapped}%")
|
|
1488
|
+
|
|
1489
|
+
slider.config(command=_on_slide)
|
|
1490
|
+
|
|
1491
|
+
def _sync(*_: Any) -> None:
|
|
1492
|
+
state = "disabled" if self._scale_auto.get() else "normal"
|
|
1493
|
+
with contextlib.suppress(tk.TclError):
|
|
1494
|
+
slider.state(["disabled"] if state == "disabled" else ["!disabled"])
|
|
1495
|
+
|
|
1496
|
+
radio_style = {
|
|
1497
|
+
"bg": t.floating_bg, "fg": t.fg, "activebackground": t.floating_bg,
|
|
1498
|
+
"activeforeground": t.fg, "selectcolor": t.activity_bg, "font": (FONT_UI, 9),
|
|
1499
|
+
"highlightthickness": 0, "bd": 0, "anchor": "w", "cursor": "hand2",
|
|
1500
|
+
"variable": self._scale_auto, "command": _sync,
|
|
1501
|
+
}
|
|
1502
|
+
tk.Radiobutton(
|
|
1503
|
+
scale_box, text=_t("wiz.display_scale_auto", pct=self._auto_pct), value=True, **radio_style
|
|
1504
|
+
).pack(anchor="w")
|
|
1505
|
+
tk.Radiobutton(
|
|
1506
|
+
scale_box, text=_t("wiz.display_scale_manual"), value=False, **radio_style
|
|
1507
|
+
).pack(anchor="w", pady=(2, 0))
|
|
1508
|
+
manual_row.pack(anchor="w", padx=(22, 0), pady=(4, 0))
|
|
1509
|
+
slider.pack(side="left")
|
|
1510
|
+
value_lbl.pack(side="left", padx=(8, 0))
|
|
1511
|
+
_sync()
|
|
1512
|
+
|
|
1513
|
+
self._divider(t)
|
|
1514
|
+
apply_btn = tk.Label(
|
|
1515
|
+
self._content, text=_t("wiz.display_apply"), bg=t.btn_primary, fg="#000",
|
|
1516
|
+
font=(FONT_UI, 9, "bold"), padx=18, pady=7, cursor="hand2",
|
|
1517
|
+
)
|
|
1518
|
+
apply_btn.pack(anchor="w", padx=28, pady=(0, 20))
|
|
1519
|
+
apply_btn.bind("<Button-1>", lambda _e: self._apply_recommended())
|
|
1520
|
+
|
|
1521
|
+
def _apply_locale(self, code: str) -> None:
|
|
1522
|
+
self._locale_var.set(code)
|
|
1523
|
+
I18n.get_instance().set_locale(code)
|
|
1524
|
+
|
|
1525
|
+
def _next(self) -> None:
|
|
1526
|
+
if self._step < self.STEPS - 1:
|
|
1527
|
+
self._show_step(self._step + 1)
|
|
1528
|
+
else:
|
|
1529
|
+
self._finish()
|
|
1530
|
+
|
|
1531
|
+
def _prev(self) -> None:
|
|
1532
|
+
if self._step > 0:
|
|
1533
|
+
self._show_step(self._step - 1)
|
|
1534
|
+
|
|
1535
|
+
def _finish(self) -> None:
|
|
1536
|
+
self._cfg.set("language", self._locale_var.get())
|
|
1537
|
+
self._cfg.set("theme", self._theme_var.get())
|
|
1538
|
+
self._cfg.set("font_family", self._font_var.get())
|
|
1539
|
+
self._cfg.set("font_size", int(self._size_var.get()))
|
|
1540
|
+
self._cfg.set("tab_size", int(self._tab_var.get()))
|
|
1541
|
+
self._cfg.set("ui_scale", 0 if self._scale_auto.get() else int(self._scale_manual.get()))
|
|
1542
|
+
apply_toggles(self._cfg, {key: var.get() for key, var in self._opts.items()})
|
|
1543
|
+
self._cfg.set("default_shell", self._shell_var2.get())
|
|
1544
|
+
self._cfg.set("first_run_done", True)
|
|
1545
|
+
self._cfg.save()
|
|
1546
|
+
I18n.get_instance().set_locale(self._locale_var.get())
|
|
1547
|
+
self._tmgr.set(self._theme_var.get())
|
|
1548
|
+
_patch_theme(self._tmgr.theme)
|
|
1549
|
+
self.destroy()
|
|
1550
|
+
self._on_finish()
|