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
|
@@ -0,0 +1,851 @@
|
|
|
1
|
+
"""Codis - ThemePreviewPanel.
|
|
2
|
+
|
|
3
|
+
Painel de pré-visualização de temas estilo wizard.
|
|
4
|
+
Exibe uma amostra realista da UI antes de confirmar a troca.
|
|
5
|
+
|
|
6
|
+
Funcionalidades:
|
|
7
|
+
- Grade de cartões com todos os temas (nome + ícone dark/light)
|
|
8
|
+
- Preview ao vivo: miniatura de código, sidebar, tabbar, status bar
|
|
9
|
+
- Botão de aplicar com escolha Completo / Rápido
|
|
10
|
+
- Navegação por teclado (setas, Enter, Escape)
|
|
11
|
+
- Filtro por nome e por polaridade (dark / light / todos)
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import contextlib
|
|
17
|
+
import logging
|
|
18
|
+
import tkinter as tk
|
|
19
|
+
from collections.abc import Callable
|
|
20
|
+
from tkinter import ttk
|
|
21
|
+
from typing import TYPE_CHECKING
|
|
22
|
+
|
|
23
|
+
from src.constants import FONT_MONO, FONT_UI
|
|
24
|
+
from src.i18n import _t
|
|
25
|
+
from src.theme.base import THEME_ORDER, THEMES, Theme
|
|
26
|
+
from src.theme.utils import hex_blend as _hex_blend
|
|
27
|
+
from src.ui._perf_utils import debounce_canvas
|
|
28
|
+
|
|
29
|
+
logger = logging.getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
if TYPE_CHECKING:
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
_SAMPLE_CODE = """\
|
|
35
|
+
def greet(name: str) -> str:
|
|
36
|
+
# Saudação personalizada
|
|
37
|
+
msg = f"Hello, {name}!"
|
|
38
|
+
return msg
|
|
39
|
+
|
|
40
|
+
class Counter:
|
|
41
|
+
def __init__(self, start=0):
|
|
42
|
+
self.value = start
|
|
43
|
+
|
|
44
|
+
def tick(self) -> int:
|
|
45
|
+
self.value += 1
|
|
46
|
+
return self.value
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
_SAMPLE_LINES = _SAMPLE_CODE.splitlines()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class _ThemeCard(tk.Frame):
|
|
53
|
+
"""Cartão compacto com miniatura de UI e nome do tema."""
|
|
54
|
+
|
|
55
|
+
_W = 160
|
|
56
|
+
_H = 110
|
|
57
|
+
|
|
58
|
+
def __init__(
|
|
59
|
+
self,
|
|
60
|
+
parent: tk.Widget,
|
|
61
|
+
theme: Theme,
|
|
62
|
+
on_select: Callable[[str], None],
|
|
63
|
+
on_apply: Callable[[str], None],
|
|
64
|
+
*,
|
|
65
|
+
active: bool = False,
|
|
66
|
+
) -> None:
|
|
67
|
+
t = theme
|
|
68
|
+
border_color = t.accent if active else t.border
|
|
69
|
+
super().__init__(
|
|
70
|
+
parent,
|
|
71
|
+
bg=border_color,
|
|
72
|
+
width=self._W + 2,
|
|
73
|
+
height=self._H + 2,
|
|
74
|
+
cursor="hand2",
|
|
75
|
+
)
|
|
76
|
+
self.pack_propagate(False)
|
|
77
|
+
|
|
78
|
+
self._theme = theme
|
|
79
|
+
self._on_select = on_select
|
|
80
|
+
self._on_apply = on_apply
|
|
81
|
+
self._active = active
|
|
82
|
+
|
|
83
|
+
self._inner = tk.Frame(self, bg=t.bg, width=self._W, height=self._H)
|
|
84
|
+
self._inner.place(x=1, y=1, width=self._W, height=self._H)
|
|
85
|
+
self._inner.pack_propagate(False)
|
|
86
|
+
|
|
87
|
+
self._build_thumbnail()
|
|
88
|
+
|
|
89
|
+
label_frame = tk.Frame(self._inner, bg=t.tabbar_bg)
|
|
90
|
+
label_frame.place(x=0, y=self._H - 22, width=self._W, height=22)
|
|
91
|
+
|
|
92
|
+
tk.Label(
|
|
93
|
+
label_frame,
|
|
94
|
+
text=("🌙 " if t.dark else "☀ ") + t.name.replace("_", " ").title(),
|
|
95
|
+
bg=t.tabbar_bg,
|
|
96
|
+
fg=t.tab_act_fg if active else t.tab_in_fg,
|
|
97
|
+
font=(FONT_UI, 7, "bold" if active else "normal"),
|
|
98
|
+
anchor="w",
|
|
99
|
+
padx=4,
|
|
100
|
+
).place(x=0, y=0, width=self._W, height=22)
|
|
101
|
+
|
|
102
|
+
for w in self._collect_widgets(self):
|
|
103
|
+
w.bind("<Button-1>", self._on_click)
|
|
104
|
+
w.bind("<Double-Button-1>", self._on_double_click)
|
|
105
|
+
|
|
106
|
+
def _collect_widgets(self, w: tk.Widget) -> list:
|
|
107
|
+
result = [w]
|
|
108
|
+
for child in w.winfo_children():
|
|
109
|
+
result.extend(self._collect_widgets(child))
|
|
110
|
+
return result
|
|
111
|
+
|
|
112
|
+
def _build_thumbnail(self) -> None:
|
|
113
|
+
t = self._theme
|
|
114
|
+
h = self._H - 22
|
|
115
|
+
|
|
116
|
+
sb = tk.Frame(self._inner, bg=t.sidebar_bg, width=28, height=h)
|
|
117
|
+
sb.place(x=0, y=0, width=28, height=h)
|
|
118
|
+
|
|
119
|
+
tk.Frame(self._inner, bg=t.activity_bg, width=8, height=h).place(
|
|
120
|
+
x=0, y=0, width=8, height=h
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
for i, (icon, fg_) in enumerate(
|
|
124
|
+
[("≡", t.fg_muted), ("⌂", t.fg_muted), ("☰", t.fg_muted)]
|
|
125
|
+
):
|
|
126
|
+
tk.Label(sb, text=icon, bg=t.sidebar_bg, fg=fg_, font=(FONT_UI, 6)).place(
|
|
127
|
+
x=10, y=5 + i * 16
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
tb_h = 14
|
|
131
|
+
tb = tk.Frame(self._inner, bg=t.tabbar_bg, height=tb_h)
|
|
132
|
+
tb.place(x=28, y=0, width=self._W - 28, height=tb_h)
|
|
133
|
+
tk.Frame(tb, bg=t.tab_act_bg, width=38, height=tb_h).place(
|
|
134
|
+
x=0, y=0, width=38, height=tb_h
|
|
135
|
+
)
|
|
136
|
+
tk.Label(
|
|
137
|
+
tb, text="file.py", bg=t.tab_act_bg, fg=t.tab_act_fg, font=(FONT_UI, 5)
|
|
138
|
+
).place(x=2, y=2)
|
|
139
|
+
tk.Label(
|
|
140
|
+
tb, text="main.py", bg=t.tabbar_bg, fg=t.tab_in_fg, font=(FONT_UI, 5)
|
|
141
|
+
).place(x=42, y=2)
|
|
142
|
+
|
|
143
|
+
ed_y = tb_h
|
|
144
|
+
ed_h = h - tb_h - 10
|
|
145
|
+
ed_w = self._W - 28
|
|
146
|
+
ed = tk.Frame(self._inner, bg=t.editor_bg)
|
|
147
|
+
ed.place(x=28, y=ed_y, width=ed_w, height=ed_h)
|
|
148
|
+
|
|
149
|
+
gutter_w = 18
|
|
150
|
+
tk.Frame(ed, bg=t.sidebar_bg, width=gutter_w, height=ed_h).place(
|
|
151
|
+
x=0, y=0, width=gutter_w, height=ed_h
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
colors = [t.t_keyword, t.fg, t.t_comment,
|
|
155
|
+
t.t_string, t.t_func, t.t_number]
|
|
156
|
+
for i in range(min(5, ed_h // 9)):
|
|
157
|
+
col = colors[i % len(colors)]
|
|
158
|
+
bar_w = [30, 50, 40, 55, 35][i % 5]
|
|
159
|
+
tk.Frame(ed, bg=col, height=3, width=bar_w).place(
|
|
160
|
+
x=gutter_w + 3, y=4 + i * 9, width=bar_w, height=3
|
|
161
|
+
)
|
|
162
|
+
num_fg = _hex_blend(t.sidebar_bg, t.fg_muted, 0.7)
|
|
163
|
+
tk.Label(
|
|
164
|
+
ed,
|
|
165
|
+
text=str(i + 1),
|
|
166
|
+
bg=t.sidebar_bg,
|
|
167
|
+
fg=num_fg,
|
|
168
|
+
font=(FONT_UI, 4),
|
|
169
|
+
anchor="e",
|
|
170
|
+
width=2,
|
|
171
|
+
).place(x=1, y=3 + i * 9)
|
|
172
|
+
|
|
173
|
+
sb2 = tk.Frame(self._inner, bg=t.activity_bg, height=10)
|
|
174
|
+
sb2.place(x=28, y=h - 10, width=self._W - 28, height=10)
|
|
175
|
+
tk.Label(
|
|
176
|
+
sb2, text="● main Ln 1", bg=t.activity_bg, fg=t.fg_muted, font=(FONT_UI, 4)
|
|
177
|
+
).place(x=2, y=1)
|
|
178
|
+
|
|
179
|
+
def _on_click(self, _event: tk.Event) -> None:
|
|
180
|
+
self._on_select(self._theme.name)
|
|
181
|
+
|
|
182
|
+
def _on_double_click(self, _event: tk.Event) -> None:
|
|
183
|
+
self._on_apply(self._theme.name)
|
|
184
|
+
|
|
185
|
+
def mark_active(self, active: bool) -> None:
|
|
186
|
+
"""Atualiza o visual de seleção."""
|
|
187
|
+
t = self._theme
|
|
188
|
+
border = t.accent if active else t.border
|
|
189
|
+
self.config(bg=border)
|
|
190
|
+
self._active = active
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
class _ThemePreview(tk.Frame):
|
|
194
|
+
"""Preview detalhado do tema selecionado."""
|
|
195
|
+
|
|
196
|
+
def __init__(self, parent: tk.Widget) -> None:
|
|
197
|
+
super().__init__(parent, bg="#1e1e1e")
|
|
198
|
+
self._theme: Theme | None = None
|
|
199
|
+
self._build_placeholder()
|
|
200
|
+
|
|
201
|
+
def _build_placeholder(self) -> None:
|
|
202
|
+
tk.Label(
|
|
203
|
+
self,
|
|
204
|
+
text=_t("themepreview.select_hint", "← Selecione um tema"),
|
|
205
|
+
bg="#1e1e1e",
|
|
206
|
+
fg="#555555",
|
|
207
|
+
font=(FONT_UI, 10),
|
|
208
|
+
).pack(expand=True)
|
|
209
|
+
|
|
210
|
+
def show(self, theme: Theme) -> None:
|
|
211
|
+
"""Renderiza o preview para o tema fornecido."""
|
|
212
|
+
self._theme = theme
|
|
213
|
+
for w in self.winfo_children():
|
|
214
|
+
with contextlib.suppress(tk.TclError):
|
|
215
|
+
w.destroy()
|
|
216
|
+
self.config(bg=theme.bg)
|
|
217
|
+
self._render(theme)
|
|
218
|
+
|
|
219
|
+
def _render(self, t: Theme) -> None:
|
|
220
|
+
header = tk.Frame(self, bg=t.tabbar_bg)
|
|
221
|
+
header.pack(fill="x")
|
|
222
|
+
tk.Label(
|
|
223
|
+
header,
|
|
224
|
+
text=("🌙 " if t.dark else "☀ ") + t.name.replace("_", " ").title(),
|
|
225
|
+
bg=t.tabbar_bg,
|
|
226
|
+
fg=t.tab_act_fg,
|
|
227
|
+
font=(FONT_UI, 11, "bold"),
|
|
228
|
+
anchor="w",
|
|
229
|
+
padx=10,
|
|
230
|
+
pady=6,
|
|
231
|
+
).pack(fill="x")
|
|
232
|
+
|
|
233
|
+
body = tk.Frame(self, bg=t.bg)
|
|
234
|
+
body.pack(fill="both", expand=True)
|
|
235
|
+
|
|
236
|
+
sidebar = tk.Frame(body, bg=t.sidebar_bg, width=130)
|
|
237
|
+
sidebar.pack(side="left", fill="y")
|
|
238
|
+
sidebar.pack_propagate(False)
|
|
239
|
+
|
|
240
|
+
tk.Label(
|
|
241
|
+
sidebar,
|
|
242
|
+
text=_t("themepreview.explorer_label", "EXPLORER"),
|
|
243
|
+
bg=t.sidebar_bg,
|
|
244
|
+
fg=t.fg_muted,
|
|
245
|
+
font=(FONT_UI, 7, "bold"),
|
|
246
|
+
anchor="w",
|
|
247
|
+
padx=8,
|
|
248
|
+
pady=4,
|
|
249
|
+
).pack(fill="x")
|
|
250
|
+
|
|
251
|
+
for name, depth in [
|
|
252
|
+
("src/", 0),
|
|
253
|
+
("app.py", 1),
|
|
254
|
+
("config.py", 1),
|
|
255
|
+
("ui/", 0),
|
|
256
|
+
("theme.py", 1),
|
|
257
|
+
]:
|
|
258
|
+
indent = depth * 10
|
|
259
|
+
row = tk.Frame(sidebar, bg=t.sidebar_bg)
|
|
260
|
+
row.pack(fill="x")
|
|
261
|
+
if depth == 0:
|
|
262
|
+
icon, fg_ = "▾", t.fg
|
|
263
|
+
else:
|
|
264
|
+
icon, fg_ = " 🗎", t.fg_muted
|
|
265
|
+
tk.Label(
|
|
266
|
+
row,
|
|
267
|
+
text=icon,
|
|
268
|
+
bg=t.sidebar_bg,
|
|
269
|
+
fg=fg_,
|
|
270
|
+
font=(FONT_UI, 8),
|
|
271
|
+
padx=6 + indent,
|
|
272
|
+
).pack(side="left")
|
|
273
|
+
col = t.accent if name == "app.py" else fg_
|
|
274
|
+
tk.Label(row, text=name, bg=t.sidebar_bg, fg=col, font=(FONT_UI, 8)).pack(
|
|
275
|
+
side="left"
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
ed_frame = tk.Frame(body, bg=t.editor_bg)
|
|
279
|
+
ed_frame.pack(side="left", fill="both", expand=True)
|
|
280
|
+
|
|
281
|
+
tabbar = tk.Frame(ed_frame, bg=t.tabbar_bg, height=28)
|
|
282
|
+
tabbar.pack(fill="x")
|
|
283
|
+
tabbar.pack_propagate(False)
|
|
284
|
+
for tab, active in [("app.py", True), ("config.py", False)]:
|
|
285
|
+
bg_ = t.tab_act_bg if active else t.tabbar_bg
|
|
286
|
+
fg_ = t.tab_act_fg if active else t.tab_in_fg
|
|
287
|
+
frm = tk.Frame(tabbar, bg=bg_)
|
|
288
|
+
frm.pack(side="left")
|
|
289
|
+
tk.Label(
|
|
290
|
+
frm, text=tab, bg=bg_, fg=fg_, font=(FONT_UI, 8), padx=10, pady=5
|
|
291
|
+
).pack()
|
|
292
|
+
if active:
|
|
293
|
+
tk.Frame(frm, bg=t.accent, height=2).pack(fill="x")
|
|
294
|
+
|
|
295
|
+
code_area = tk.Frame(ed_frame, bg=t.editor_bg)
|
|
296
|
+
code_area.pack(fill="both", expand=True, padx=0, pady=0)
|
|
297
|
+
|
|
298
|
+
gutter = tk.Frame(code_area, bg=t.sidebar_bg, width=36)
|
|
299
|
+
gutter.pack(side="left", fill="y")
|
|
300
|
+
gutter.pack_propagate(False)
|
|
301
|
+
|
|
302
|
+
text_area = tk.Frame(code_area, bg=t.editor_bg)
|
|
303
|
+
text_area.pack(side="left", fill="both", expand=True, padx=4)
|
|
304
|
+
|
|
305
|
+
for i, line in enumerate(_SAMPLE_LINES[:11]):
|
|
306
|
+
line_bg = _hex_blend(t.editor_bg, t.sel_bg,
|
|
307
|
+
0.15) if i == 1 else t.editor_bg
|
|
308
|
+
row = tk.Frame(text_area, bg=line_bg)
|
|
309
|
+
row.pack(fill="x")
|
|
310
|
+
|
|
311
|
+
gn = tk.Label(
|
|
312
|
+
gutter,
|
|
313
|
+
text=str(i + 1),
|
|
314
|
+
bg=t.sidebar_bg,
|
|
315
|
+
fg=t.fg_muted,
|
|
316
|
+
font=(FONT_MONO, 7),
|
|
317
|
+
anchor="e",
|
|
318
|
+
width=3,
|
|
319
|
+
pady=0,
|
|
320
|
+
)
|
|
321
|
+
gn.pack(fill="x", padx=(0, 4))
|
|
322
|
+
|
|
323
|
+
stripped = line.rstrip()
|
|
324
|
+
if not stripped:
|
|
325
|
+
tk.Label(row, text=" ", bg=line_bg, font=(FONT_MONO, 8)).pack(
|
|
326
|
+
side="left"
|
|
327
|
+
)
|
|
328
|
+
continue
|
|
329
|
+
|
|
330
|
+
indent = len(stripped) - len(stripped.lstrip())
|
|
331
|
+
if indent:
|
|
332
|
+
tk.Label(row, text=" " * indent, bg=line_bg, font=(FONT_MONO, 8)).pack(
|
|
333
|
+
side="left"
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
rest = stripped.lstrip()
|
|
337
|
+
if rest.startswith("#"):
|
|
338
|
+
tk.Label(
|
|
339
|
+
row,
|
|
340
|
+
text=rest,
|
|
341
|
+
bg=line_bg,
|
|
342
|
+
fg=t.t_comment,
|
|
343
|
+
font=(FONT_MONO, 8, "italic"),
|
|
344
|
+
).pack(side="left")
|
|
345
|
+
continue
|
|
346
|
+
|
|
347
|
+
tokens = rest.split()
|
|
348
|
+
first = tokens[0] if tokens else ""
|
|
349
|
+
if first in ("def", "class", "return"):
|
|
350
|
+
tk.Label(
|
|
351
|
+
row,
|
|
352
|
+
text=first + " ",
|
|
353
|
+
bg=line_bg,
|
|
354
|
+
fg=t.t_keyword,
|
|
355
|
+
font=(FONT_MONO, 8, "bold"),
|
|
356
|
+
).pack(side="left")
|
|
357
|
+
remainder = rest[len(first):]
|
|
358
|
+
paren = remainder.find("(")
|
|
359
|
+
colon = remainder.find(":")
|
|
360
|
+
split_at = (
|
|
361
|
+
paren if paren != -1 else colon if colon != -
|
|
362
|
+
1 else len(remainder)
|
|
363
|
+
)
|
|
364
|
+
name_part = remainder[:split_at].strip()
|
|
365
|
+
rest_part = remainder[split_at:]
|
|
366
|
+
name_col = t.t_func if first == "def" else t.t_type
|
|
367
|
+
if name_part:
|
|
368
|
+
tk.Label(
|
|
369
|
+
row,
|
|
370
|
+
text=name_part,
|
|
371
|
+
bg=line_bg,
|
|
372
|
+
fg=name_col,
|
|
373
|
+
font=(FONT_MONO, 8),
|
|
374
|
+
).pack(side="left")
|
|
375
|
+
if rest_part:
|
|
376
|
+
tk.Label(
|
|
377
|
+
row, text=rest_part, bg=line_bg, fg=t.fg, font=(
|
|
378
|
+
FONT_MONO, 8)
|
|
379
|
+
).pack(side="left")
|
|
380
|
+
elif "=" in rest and not rest.startswith("="):
|
|
381
|
+
parts = rest.split("=", 1)
|
|
382
|
+
tk.Label(
|
|
383
|
+
row, text=parts[0] + "=", bg=line_bg, fg=t.fg, font=(FONT_MONO, 8)
|
|
384
|
+
).pack(side="left")
|
|
385
|
+
val = parts[1].strip() if len(parts) > 1 else ""
|
|
386
|
+
val_col = (
|
|
387
|
+
t.t_string
|
|
388
|
+
if val.startswith(('f"', '"', "'"))
|
|
389
|
+
else t.t_number if val[0:1].isdigit() else t.fg
|
|
390
|
+
)
|
|
391
|
+
tk.Label(
|
|
392
|
+
row, text=val, bg=line_bg, fg=val_col, font=(FONT_MONO, 8)
|
|
393
|
+
).pack(side="left")
|
|
394
|
+
else:
|
|
395
|
+
tk.Label(row, text=rest, bg=line_bg, fg=t.fg, font=(FONT_MONO, 8)).pack(
|
|
396
|
+
side="left"
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
statusbar = tk.Frame(ed_frame, bg=t.activity_bg, height=20)
|
|
400
|
+
statusbar.pack(fill="x", side="bottom")
|
|
401
|
+
statusbar.pack_propagate(False)
|
|
402
|
+
tk.Label(
|
|
403
|
+
statusbar,
|
|
404
|
+
text="⎇ main Python UTF-8 Ln 2, Col 1 ●",
|
|
405
|
+
bg=t.activity_bg,
|
|
406
|
+
fg=t.statusbar_fg or t.fg,
|
|
407
|
+
font=(FONT_UI, 7),
|
|
408
|
+
anchor="w",
|
|
409
|
+
padx=8,
|
|
410
|
+
).pack(side="left", fill="y")
|
|
411
|
+
tk.Label(
|
|
412
|
+
statusbar,
|
|
413
|
+
text=t.name.replace("_", " ").title(),
|
|
414
|
+
bg=t.accent,
|
|
415
|
+
fg=t.btn_primary_fg or "#ffffff",
|
|
416
|
+
font=(FONT_UI, 7, "bold"),
|
|
417
|
+
padx=6,
|
|
418
|
+
).pack(side="right", fill="y")
|
|
419
|
+
|
|
420
|
+
pal_frame = tk.Frame(self, bg=t.panel_bg)
|
|
421
|
+
pal_frame.pack(fill="x", pady=(0, 0))
|
|
422
|
+
tk.Label(
|
|
423
|
+
pal_frame,
|
|
424
|
+
text=_t("themepreview.syntax_palette", "Paleta de Sintaxe"),
|
|
425
|
+
bg=t.panel_bg,
|
|
426
|
+
fg=t.fg_muted,
|
|
427
|
+
font=(FONT_UI, 7),
|
|
428
|
+
anchor="w",
|
|
429
|
+
padx=8,
|
|
430
|
+
pady=3,
|
|
431
|
+
).pack(fill="x")
|
|
432
|
+
swatches = tk.Frame(pal_frame, bg=t.panel_bg)
|
|
433
|
+
swatches.pack(fill="x", padx=8, pady=(0, 6))
|
|
434
|
+
for label, color in [
|
|
435
|
+
("kw", t.t_keyword),
|
|
436
|
+
("str", t.t_string),
|
|
437
|
+
("num", t.t_number),
|
|
438
|
+
("fn", t.t_func),
|
|
439
|
+
("type", t.t_type),
|
|
440
|
+
("op", t.t_operator),
|
|
441
|
+
("//", t.t_comment),
|
|
442
|
+
("@", t.t_decorator),
|
|
443
|
+
]:
|
|
444
|
+
col_frame = tk.Frame(swatches, bg=t.panel_bg)
|
|
445
|
+
col_frame.pack(side="left", padx=3)
|
|
446
|
+
tk.Frame(col_frame, bg=color, width=18, height=10).pack()
|
|
447
|
+
tk.Label(
|
|
448
|
+
col_frame, text=label, bg=t.panel_bg, fg=t.fg_muted, font=(
|
|
449
|
+
FONT_UI, 6)
|
|
450
|
+
).pack()
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
class ThemePreviewPanel(tk.Toplevel):
|
|
454
|
+
"""Janela wizard de seleção de tema com preview ao vivo."""
|
|
455
|
+
|
|
456
|
+
_W = 900
|
|
457
|
+
_H = 560
|
|
458
|
+
|
|
459
|
+
def __init__(
|
|
460
|
+
self,
|
|
461
|
+
parent: tk.Tk,
|
|
462
|
+
current_theme: Theme,
|
|
463
|
+
on_full: Callable[[str], None] | None = None,
|
|
464
|
+
on_fast: Callable[[str], None] | None = None,
|
|
465
|
+
on_cancel: Callable[[], None] | None = None,
|
|
466
|
+
) -> None:
|
|
467
|
+
super().__init__(parent)
|
|
468
|
+
self._parent = parent
|
|
469
|
+
self._on_full = on_full
|
|
470
|
+
self._on_fast = on_fast
|
|
471
|
+
self._on_cancel = on_cancel
|
|
472
|
+
self._selected: str = current_theme.name
|
|
473
|
+
self._current: str = current_theme.name
|
|
474
|
+
self._cards: dict[str, _ThemeCard] = {}
|
|
475
|
+
self._filter_var = tk.StringVar()
|
|
476
|
+
self._polar_var = tk.StringVar(value="all")
|
|
477
|
+
self._closed = False
|
|
478
|
+
self._reflow_job: str | None = None
|
|
479
|
+
self._cols = 0
|
|
480
|
+
|
|
481
|
+
self.title("Codis - Temas")
|
|
482
|
+
self.resizable(True, True)
|
|
483
|
+
self.attributes("-topmost", True)
|
|
484
|
+
self.overrideredirect(False)
|
|
485
|
+
|
|
486
|
+
t = current_theme
|
|
487
|
+
self.configure(bg=t.bg)
|
|
488
|
+
|
|
489
|
+
self._t = t
|
|
490
|
+
self._center()
|
|
491
|
+
self._build(t)
|
|
492
|
+
self._select(current_theme.name, scroll=True)
|
|
493
|
+
|
|
494
|
+
self.bind("<Escape>", lambda _: self._cancel())
|
|
495
|
+
self.bind("<Return>", lambda _: self._apply_fast())
|
|
496
|
+
self.protocol("WM_DELETE_WINDOW", self._cancel)
|
|
497
|
+
self.focus_force()
|
|
498
|
+
|
|
499
|
+
def _center(self) -> None:
|
|
500
|
+
self._parent.update_idletasks()
|
|
501
|
+
px = self._parent.winfo_rootx()
|
|
502
|
+
py = self._parent.winfo_rooty()
|
|
503
|
+
pw = self._parent.winfo_width()
|
|
504
|
+
ph = self._parent.winfo_height()
|
|
505
|
+
x = px + (pw - self._W) // 2
|
|
506
|
+
y = py + (ph - self._H) // 2
|
|
507
|
+
self.geometry(f"{self._W}x{self._H}+{x}+{y}")
|
|
508
|
+
|
|
509
|
+
def _build(self, t: Theme) -> None:
|
|
510
|
+
hdr = tk.Frame(self, bg=t.tabbar_bg)
|
|
511
|
+
hdr.pack(fill="x")
|
|
512
|
+
|
|
513
|
+
tk.Label(
|
|
514
|
+
hdr,
|
|
515
|
+
text=_t("theme.select_theme", "Selecionar Tema"),
|
|
516
|
+
bg=t.tabbar_bg,
|
|
517
|
+
fg=t.fg,
|
|
518
|
+
font=(FONT_UI, 12, "bold"),
|
|
519
|
+
anchor="w",
|
|
520
|
+
padx=12,
|
|
521
|
+
pady=8,
|
|
522
|
+
).pack(side="left")
|
|
523
|
+
|
|
524
|
+
tk.Button(
|
|
525
|
+
hdr,
|
|
526
|
+
text="✕",
|
|
527
|
+
bg=t.tabbar_bg,
|
|
528
|
+
fg=t.fg_muted,
|
|
529
|
+
activebackground=t.btn_hover,
|
|
530
|
+
activeforeground=t.fg,
|
|
531
|
+
relief="flat",
|
|
532
|
+
bd=0,
|
|
533
|
+
padx=8,
|
|
534
|
+
pady=6,
|
|
535
|
+
cursor="hand2",
|
|
536
|
+
font=(FONT_UI, 10),
|
|
537
|
+
command=self._cancel,
|
|
538
|
+
).pack(side="right")
|
|
539
|
+
|
|
540
|
+
filter_bar = tk.Frame(self, bg=t.sidebar_bg)
|
|
541
|
+
filter_bar.pack(fill="x")
|
|
542
|
+
|
|
543
|
+
tk.Label(
|
|
544
|
+
filter_bar,
|
|
545
|
+
text="🔍",
|
|
546
|
+
bg=t.sidebar_bg,
|
|
547
|
+
fg=t.fg_muted,
|
|
548
|
+
font=(FONT_UI, 9),
|
|
549
|
+
padx=8,
|
|
550
|
+
).pack(side="left")
|
|
551
|
+
|
|
552
|
+
search_entry = tk.Entry(
|
|
553
|
+
filter_bar,
|
|
554
|
+
textvariable=self._filter_var,
|
|
555
|
+
bg=t.input_bg,
|
|
556
|
+
fg=t.fg,
|
|
557
|
+
insertbackground=t.cursor,
|
|
558
|
+
relief="flat",
|
|
559
|
+
font=(FONT_UI, 9),
|
|
560
|
+
bd=0,
|
|
561
|
+
)
|
|
562
|
+
search_entry.pack(side="left", fill="x",
|
|
563
|
+
expand=True, pady=4, padx=(0, 8))
|
|
564
|
+
self._filter_var.trace_add("write", lambda *_: self._apply_filter())
|
|
565
|
+
|
|
566
|
+
for label, val in [("Todos", "all"), ("🌙 Dark", "dark"), ("☀ Light", "light")]:
|
|
567
|
+
tk.Radiobutton(
|
|
568
|
+
filter_bar,
|
|
569
|
+
text=label,
|
|
570
|
+
variable=self._polar_var,
|
|
571
|
+
value=val,
|
|
572
|
+
bg=t.sidebar_bg,
|
|
573
|
+
fg=t.fg,
|
|
574
|
+
activebackground=t.sidebar_bg,
|
|
575
|
+
activeforeground=t.accent,
|
|
576
|
+
selectcolor=t.sidebar_bg,
|
|
577
|
+
font=(FONT_UI, 8),
|
|
578
|
+
relief="flat",
|
|
579
|
+
bd=0,
|
|
580
|
+
command=self._apply_filter,
|
|
581
|
+
).pack(side="left", padx=4)
|
|
582
|
+
|
|
583
|
+
paned = tk.PanedWindow(
|
|
584
|
+
self, orient="horizontal", bg=t.border, sashwidth=3, sashrelief="flat"
|
|
585
|
+
)
|
|
586
|
+
paned.pack(fill="both", expand=True)
|
|
587
|
+
|
|
588
|
+
left = tk.Frame(paned, bg=t.sidebar_bg)
|
|
589
|
+
paned.add(left, width=320, stretch="never")
|
|
590
|
+
|
|
591
|
+
canvas_frame = tk.Frame(left, bg=t.sidebar_bg)
|
|
592
|
+
canvas_frame.pack(fill="both", expand=True)
|
|
593
|
+
|
|
594
|
+
self._canvas = tk.Canvas(
|
|
595
|
+
canvas_frame, bg=t.sidebar_bg, bd=0, highlightthickness=0
|
|
596
|
+
)
|
|
597
|
+
vscroll = ttk.Scrollbar(
|
|
598
|
+
canvas_frame, orient="vertical", command=self._canvas.yview
|
|
599
|
+
)
|
|
600
|
+
self._canvas.configure(yscrollcommand=vscroll.set)
|
|
601
|
+
vscroll.pack(side="right", fill="y")
|
|
602
|
+
self._canvas.pack(side="left", fill="both", expand=True)
|
|
603
|
+
|
|
604
|
+
self._card_frame = tk.Frame(self._canvas, bg=t.sidebar_bg)
|
|
605
|
+
self._canvas_window = self._canvas.create_window(
|
|
606
|
+
(0, 0), window=self._card_frame, anchor="nw"
|
|
607
|
+
)
|
|
608
|
+
|
|
609
|
+
debounce_canvas(
|
|
610
|
+
self._canvas, self._canvas_window, ms=40, extra_widget=self._card_frame
|
|
611
|
+
)
|
|
612
|
+
self._canvas.bind("<Configure>", self._schedule_reflow, add="+")
|
|
613
|
+
self._canvas.bind(
|
|
614
|
+
"<MouseWheel>",
|
|
615
|
+
lambda e: self._canvas.yview_scroll(-1 *
|
|
616
|
+
(e.delta // 120), "units"),
|
|
617
|
+
)
|
|
618
|
+
self._canvas.bind(
|
|
619
|
+
"<Button-4>", lambda _: self._canvas.yview_scroll(-1, "units")
|
|
620
|
+
)
|
|
621
|
+
self._canvas.bind(
|
|
622
|
+
"<Button-5>", lambda _: self._canvas.yview_scroll(1, "units"))
|
|
623
|
+
|
|
624
|
+
right = tk.Frame(paned, bg=t.bg)
|
|
625
|
+
paned.add(right, stretch="always")
|
|
626
|
+
|
|
627
|
+
self._preview = _ThemePreview(right)
|
|
628
|
+
self._preview.pack(fill="both", expand=True)
|
|
629
|
+
|
|
630
|
+
footer = tk.Frame(self, bg=t.panel_bg)
|
|
631
|
+
footer.pack(fill="x")
|
|
632
|
+
|
|
633
|
+
self._selected_label = tk.Label(
|
|
634
|
+
footer,
|
|
635
|
+
text="",
|
|
636
|
+
bg=t.panel_bg,
|
|
637
|
+
fg=t.fg_muted,
|
|
638
|
+
font=(FONT_UI, 8),
|
|
639
|
+
anchor="w",
|
|
640
|
+
padx=12,
|
|
641
|
+
)
|
|
642
|
+
self._selected_label.pack(side="left")
|
|
643
|
+
|
|
644
|
+
tk.Button(
|
|
645
|
+
footer,
|
|
646
|
+
text=_t("theme.cancel", "Cancelar"),
|
|
647
|
+
bg=t.btn_bg,
|
|
648
|
+
fg=t.btn_fg,
|
|
649
|
+
activebackground=t.btn_hover,
|
|
650
|
+
activeforeground=t.fg,
|
|
651
|
+
relief="flat",
|
|
652
|
+
bd=0,
|
|
653
|
+
padx=12,
|
|
654
|
+
pady=6,
|
|
655
|
+
cursor="hand2",
|
|
656
|
+
font=(FONT_UI, 9),
|
|
657
|
+
command=self._cancel,
|
|
658
|
+
).pack(side="right", padx=(4, 8), pady=6)
|
|
659
|
+
|
|
660
|
+
self._fast_btn = tk.Button(
|
|
661
|
+
footer,
|
|
662
|
+
text=_t("theme.apply_quick", "Aplicar Rapido"),
|
|
663
|
+
bg=t.btn_bg,
|
|
664
|
+
fg=t.btn_fg,
|
|
665
|
+
activebackground=t.btn_hover,
|
|
666
|
+
activeforeground=t.fg,
|
|
667
|
+
relief="flat",
|
|
668
|
+
bd=0,
|
|
669
|
+
padx=12,
|
|
670
|
+
pady=6,
|
|
671
|
+
cursor="hand2",
|
|
672
|
+
font=(FONT_UI, 9),
|
|
673
|
+
command=self._apply_fast,
|
|
674
|
+
)
|
|
675
|
+
self._fast_btn.pack(side="right", padx=4, pady=6)
|
|
676
|
+
|
|
677
|
+
self._full_btn = tk.Button(
|
|
678
|
+
footer,
|
|
679
|
+
text=_t("theme.apply_full", "✦ Aplicar Completo"),
|
|
680
|
+
bg=t.accent,
|
|
681
|
+
fg=t.btn_primary_fg or "#ffffff",
|
|
682
|
+
activebackground=t.sel_bg,
|
|
683
|
+
activeforeground=t.sel_fg,
|
|
684
|
+
relief="flat",
|
|
685
|
+
bd=0,
|
|
686
|
+
padx=12,
|
|
687
|
+
pady=6,
|
|
688
|
+
cursor="hand2",
|
|
689
|
+
font=(FONT_UI, 9, "bold"),
|
|
690
|
+
command=self._apply_full,
|
|
691
|
+
)
|
|
692
|
+
self._full_btn.pack(side="right", padx=4, pady=6)
|
|
693
|
+
|
|
694
|
+
self._populate_cards()
|
|
695
|
+
|
|
696
|
+
def _column_count(self) -> int:
|
|
697
|
+
"""Calcula quantas colunas de cards cabem na largura atual do canvas.
|
|
698
|
+
|
|
699
|
+
Cada card ocupa ``_ThemeCard._W`` mais 10 px de padding (5 de cada lado).
|
|
700
|
+
Antes de a janela ser exibida a largura ainda é mínima, e então vale 2.
|
|
701
|
+
"""
|
|
702
|
+
try:
|
|
703
|
+
canvas_w = self._canvas.winfo_width()
|
|
704
|
+
except tk.TclError:
|
|
705
|
+
return 2
|
|
706
|
+
card_w = _ThemeCard._W + 10
|
|
707
|
+
return max(1, canvas_w // card_w) if canvas_w > card_w else 2
|
|
708
|
+
|
|
709
|
+
def _schedule_reflow(self, _event: tk.Event | None = None) -> None:
|
|
710
|
+
"""Agenda (com debounce de 120 ms) o reflow da grade ao redimensionar o canvas."""
|
|
711
|
+
if self._closed:
|
|
712
|
+
return
|
|
713
|
+
if self._reflow_job is not None:
|
|
714
|
+
with contextlib.suppress(tk.TclError):
|
|
715
|
+
self.after_cancel(self._reflow_job)
|
|
716
|
+
self._reflow_job = None
|
|
717
|
+
with contextlib.suppress(tk.TclError):
|
|
718
|
+
self._reflow_job = self.after(120, self._run_reflow)
|
|
719
|
+
|
|
720
|
+
def _run_reflow(self) -> None:
|
|
721
|
+
"""Reconstrói a grade apenas se o número de colunas mudou."""
|
|
722
|
+
self._reflow_job = None
|
|
723
|
+
if self._closed or self._column_count() == self._cols:
|
|
724
|
+
return
|
|
725
|
+
self._apply_filter()
|
|
726
|
+
|
|
727
|
+
def _shutdown(self) -> None:
|
|
728
|
+
"""Marca o painel como fechado e cancela trabalho agendado."""
|
|
729
|
+
self._closed = True
|
|
730
|
+
if self._reflow_job is not None:
|
|
731
|
+
with contextlib.suppress(tk.TclError):
|
|
732
|
+
self.after_cancel(self._reflow_job)
|
|
733
|
+
self._reflow_job = None
|
|
734
|
+
|
|
735
|
+
def _populate_cards(self, filter_text: str = "", polar: str = "all") -> None:
|
|
736
|
+
"""Reconstrói a grade de cards aplicando o filtro atual."""
|
|
737
|
+
if self._closed:
|
|
738
|
+
return
|
|
739
|
+
for w in self._card_frame.winfo_children():
|
|
740
|
+
with contextlib.suppress(tk.TclError):
|
|
741
|
+
w.destroy()
|
|
742
|
+
self._cards.clear()
|
|
743
|
+
|
|
744
|
+
col = 0
|
|
745
|
+
row_ = 0
|
|
746
|
+
max_cols = self._column_count()
|
|
747
|
+
self._cols = max_cols
|
|
748
|
+
|
|
749
|
+
visible = []
|
|
750
|
+
for name in THEME_ORDER:
|
|
751
|
+
theme = THEMES.get(name)
|
|
752
|
+
if not theme:
|
|
753
|
+
continue
|
|
754
|
+
if filter_text and filter_text.lower() not in name.lower():
|
|
755
|
+
continue
|
|
756
|
+
if polar == "dark" and not theme.dark:
|
|
757
|
+
continue
|
|
758
|
+
if polar == "light" and theme.dark:
|
|
759
|
+
continue
|
|
760
|
+
visible.append(theme)
|
|
761
|
+
|
|
762
|
+
for theme in visible:
|
|
763
|
+
try:
|
|
764
|
+
card = _ThemeCard(
|
|
765
|
+
self._card_frame,
|
|
766
|
+
theme,
|
|
767
|
+
on_select=self._select,
|
|
768
|
+
on_apply=self._apply_fast,
|
|
769
|
+
active=(theme.name == self._selected),
|
|
770
|
+
)
|
|
771
|
+
except (tk.TclError, AttributeError) as exc:
|
|
772
|
+
logger.warning("Preview do tema '%s' ignorado: %s", theme.name, exc)
|
|
773
|
+
continue
|
|
774
|
+
card.grid(row=row_, column=col, padx=5, pady=5, sticky="nw")
|
|
775
|
+
self._cards[theme.name] = card
|
|
776
|
+
col += 1
|
|
777
|
+
if col >= max_cols:
|
|
778
|
+
col = 0
|
|
779
|
+
row_ += 1
|
|
780
|
+
|
|
781
|
+
self._card_frame.update_idletasks()
|
|
782
|
+
|
|
783
|
+
def _apply_filter(self) -> None:
|
|
784
|
+
if self._closed:
|
|
785
|
+
return
|
|
786
|
+
self._populate_cards(
|
|
787
|
+
filter_text=self._filter_var.get(),
|
|
788
|
+
polar=self._polar_var.get(),
|
|
789
|
+
)
|
|
790
|
+
card = self._cards.get(self._selected)
|
|
791
|
+
if card:
|
|
792
|
+
card.mark_active(True)
|
|
793
|
+
|
|
794
|
+
def _select(self, name: str, scroll: bool = False) -> None:
|
|
795
|
+
"""Seleciona um tema e atualiza o preview."""
|
|
796
|
+
theme = THEMES.get(name)
|
|
797
|
+
if not theme:
|
|
798
|
+
return
|
|
799
|
+
|
|
800
|
+
prev = self._cards.get(self._selected)
|
|
801
|
+
if prev:
|
|
802
|
+
prev.mark_active(False)
|
|
803
|
+
|
|
804
|
+
self._selected = name
|
|
805
|
+
|
|
806
|
+
card = self._cards.get(name)
|
|
807
|
+
if card:
|
|
808
|
+
card.mark_active(True)
|
|
809
|
+
if scroll:
|
|
810
|
+
self._canvas.update_idletasks()
|
|
811
|
+
with contextlib.suppress(tk.TclError):
|
|
812
|
+
cy = card.winfo_y()
|
|
813
|
+
self._canvas.yview_moveto(
|
|
814
|
+
cy / max(self._card_frame.winfo_height(), 1)
|
|
815
|
+
)
|
|
816
|
+
|
|
817
|
+
try:
|
|
818
|
+
self._preview.show(theme)
|
|
819
|
+
except (tk.TclError, AttributeError) as exc:
|
|
820
|
+
logger.warning("Falha ao renderizar o preview de '%s': %s", name, exc)
|
|
821
|
+
|
|
822
|
+
display = name.replace("_", " ").title()
|
|
823
|
+
current_marker = " <- atual" if name == self._current else ""
|
|
824
|
+
self._selected_label.config(
|
|
825
|
+
text=f"Selecionado: {display}{current_marker}")
|
|
826
|
+
|
|
827
|
+
def _apply_fast(self) -> None:
|
|
828
|
+
if self._closed:
|
|
829
|
+
return
|
|
830
|
+
name = self._selected
|
|
831
|
+
self._shutdown()
|
|
832
|
+
self.destroy()
|
|
833
|
+
if self._on_fast:
|
|
834
|
+
self._on_fast(name)
|
|
835
|
+
|
|
836
|
+
def _apply_full(self) -> None:
|
|
837
|
+
if self._closed:
|
|
838
|
+
return
|
|
839
|
+
name = self._selected
|
|
840
|
+
self._shutdown()
|
|
841
|
+
self.destroy()
|
|
842
|
+
if self._on_full:
|
|
843
|
+
self._on_full(name)
|
|
844
|
+
|
|
845
|
+
def _cancel(self) -> None:
|
|
846
|
+
if self._closed:
|
|
847
|
+
return
|
|
848
|
+
self._shutdown()
|
|
849
|
+
self.destroy()
|
|
850
|
+
if self._on_cancel:
|
|
851
|
+
self._on_cancel()
|