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/toolbox_panels.py
ADDED
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
"""Painéis dos utilitários da tela inicial. A lógica fica em :mod:`src.toolbox`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import contextlib
|
|
6
|
+
import logging
|
|
7
|
+
import os
|
|
8
|
+
import time
|
|
9
|
+
import tkinter as tk
|
|
10
|
+
import webbrowser
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from tkinter import filedialog, messagebox
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from src import toolbox as tb
|
|
16
|
+
from src.constants import FONT_MONO, FONT_UI
|
|
17
|
+
from src.i18n import _t
|
|
18
|
+
from src.textfmt import format_size
|
|
19
|
+
|
|
20
|
+
logger = logging.getLogger("Codis")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _button(parent: tk.Misc, theme: Any, text: str, command: Any, *, accent: bool = False) -> tk.Button:
|
|
24
|
+
return tk.Button(
|
|
25
|
+
parent,
|
|
26
|
+
text=text,
|
|
27
|
+
command=command,
|
|
28
|
+
bg=theme.accent if accent else theme.sidebar_bg,
|
|
29
|
+
fg="#ffffff" if accent else theme.fg,
|
|
30
|
+
activebackground=theme.accent,
|
|
31
|
+
activeforeground="#ffffff",
|
|
32
|
+
relief="flat",
|
|
33
|
+
bd=0,
|
|
34
|
+
padx=10,
|
|
35
|
+
pady=4,
|
|
36
|
+
font=(FONT_UI, 9),
|
|
37
|
+
cursor="hand2",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _text_box(parent: tk.Misc, theme: Any, *, height: int = 8, readonly: bool = False) -> tk.Text:
|
|
42
|
+
box = tk.Text(
|
|
43
|
+
parent,
|
|
44
|
+
height=height,
|
|
45
|
+
bg=theme.editor_bg,
|
|
46
|
+
fg=theme.fg,
|
|
47
|
+
insertbackground=theme.cursor,
|
|
48
|
+
font=(FONT_MONO, 10),
|
|
49
|
+
relief="flat",
|
|
50
|
+
bd=0,
|
|
51
|
+
wrap="word",
|
|
52
|
+
undo=True,
|
|
53
|
+
highlightthickness=1,
|
|
54
|
+
highlightbackground=theme.border,
|
|
55
|
+
highlightcolor=theme.accent,
|
|
56
|
+
)
|
|
57
|
+
if readonly:
|
|
58
|
+
box.config(state="disabled")
|
|
59
|
+
return box
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _set_text(box: tk.Text, text: str) -> None:
|
|
63
|
+
state = str(box.cget("state"))
|
|
64
|
+
box.config(state="normal")
|
|
65
|
+
box.delete("1.0", "end")
|
|
66
|
+
box.insert("1.0", text)
|
|
67
|
+
box.config(state=state)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _copy(widget: tk.Misc, text: str) -> None:
|
|
71
|
+
with contextlib.suppress(tk.TclError):
|
|
72
|
+
widget.clipboard_clear()
|
|
73
|
+
widget.clipboard_append(text)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _label(parent: tk.Misc, theme: Any, text: str, *, muted: bool = False, bg: str | None = None) -> tk.Label:
|
|
77
|
+
return tk.Label(
|
|
78
|
+
parent,
|
|
79
|
+
text=text,
|
|
80
|
+
bg=bg or theme.panel_bg,
|
|
81
|
+
fg=theme.fg_muted if muted else theme.fg,
|
|
82
|
+
font=(FONT_UI, 9),
|
|
83
|
+
anchor="w",
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# Codificadores
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class EncodersPanel(tk.Frame):
|
|
91
|
+
"""Converte texto entre Base64, URL, HTML e hexadecimal; calcula hashes e decodifica JWT."""
|
|
92
|
+
|
|
93
|
+
def __init__(self, parent: tk.Misc, tmgr: Any, cfg: Any = None) -> None:
|
|
94
|
+
t = tmgr.theme
|
|
95
|
+
super().__init__(parent, bg=t.panel_bg)
|
|
96
|
+
self._t = t
|
|
97
|
+
self._job: str | None = None
|
|
98
|
+
self._operation = tk.StringVar(value=next(iter(tb.OPERATIONS)))
|
|
99
|
+
|
|
100
|
+
bar = tk.Frame(self, bg=t.panel_bg)
|
|
101
|
+
bar.pack(fill="x", padx=10, pady=(10, 4))
|
|
102
|
+
_label(bar, t, _t("toolbox.operation", "Operação:")).pack(side="left")
|
|
103
|
+
menu = tk.OptionMenu(bar, self._operation, *tb.OPERATIONS, command=lambda _v: self._convert())
|
|
104
|
+
menu.config(bg=t.sidebar_bg, fg=t.fg, activebackground=t.accent, activeforeground="#ffffff",
|
|
105
|
+
relief="flat", bd=0, highlightthickness=0, font=(FONT_UI, 9))
|
|
106
|
+
menu["menu"].config(bg=t.floating_bg, fg=t.fg, activebackground=t.accent, activeforeground="#ffffff")
|
|
107
|
+
menu.pack(side="left", padx=8)
|
|
108
|
+
_button(bar, t, _t("toolbox.swap", "Usar saída como entrada"), self._swap).pack(side="right")
|
|
109
|
+
_button(bar, t, _t("toolbox.copy_output", "Copiar saída"), self._copy_output, accent=True).pack(side="right", padx=6)
|
|
110
|
+
|
|
111
|
+
_label(self, t, _t("toolbox.input", "Entrada"), muted=True).pack(fill="x", padx=10)
|
|
112
|
+
self._input = _text_box(self, t, height=9)
|
|
113
|
+
self._input.pack(fill="both", expand=True, padx=10, pady=(0, 6))
|
|
114
|
+
self._input.bind("<<Modified>>", self._on_modified)
|
|
115
|
+
|
|
116
|
+
self._status = _label(self, t, "", muted=True)
|
|
117
|
+
self._status.pack(fill="x", padx=10)
|
|
118
|
+
_label(self, t, _t("toolbox.output", "Saída"), muted=True).pack(fill="x", padx=10)
|
|
119
|
+
self._output = _text_box(self, t, height=9, readonly=True)
|
|
120
|
+
self._output.pack(fill="both", expand=True, padx=10, pady=(0, 10))
|
|
121
|
+
|
|
122
|
+
def _on_modified(self, _event: tk.Event) -> None:
|
|
123
|
+
if not self._input.edit_modified():
|
|
124
|
+
return
|
|
125
|
+
self._input.edit_modified(False)
|
|
126
|
+
if self._job is not None:
|
|
127
|
+
self.after_cancel(self._job)
|
|
128
|
+
self._job = self.after(120, self._convert)
|
|
129
|
+
|
|
130
|
+
def _convert(self) -> None:
|
|
131
|
+
self._job = None
|
|
132
|
+
text = self._input.get("1.0", "end-1c")
|
|
133
|
+
if not text:
|
|
134
|
+
_set_text(self._output, "")
|
|
135
|
+
self._status.config(text="")
|
|
136
|
+
return
|
|
137
|
+
try:
|
|
138
|
+
result = tb.convert(self._operation.get(), text)
|
|
139
|
+
except tb.ConversionError as exc:
|
|
140
|
+
_set_text(self._output, "")
|
|
141
|
+
self._status.config(text=f"⚠ {exc}", fg=getattr(self._t, "error_fg", "#ff5555"))
|
|
142
|
+
return
|
|
143
|
+
_set_text(self._output, result)
|
|
144
|
+
self._status.config(text=_t("toolbox.chars", "{n} caracteres na saída", n=len(result)), fg=self._t.fg_muted)
|
|
145
|
+
|
|
146
|
+
def _output_text(self) -> str:
|
|
147
|
+
return self._output.get("1.0", "end-1c")
|
|
148
|
+
|
|
149
|
+
def _copy_output(self) -> None:
|
|
150
|
+
_copy(self, self._output_text())
|
|
151
|
+
|
|
152
|
+
def _swap(self) -> None:
|
|
153
|
+
result = self._output_text()
|
|
154
|
+
if result:
|
|
155
|
+
self._input.delete("1.0", "end")
|
|
156
|
+
self._input.insert("1.0", result)
|
|
157
|
+
self._convert()
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
# Geradores
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class GeneratorsPanel(tk.Frame):
|
|
164
|
+
"""UUID, senhas, texto de preenchimento e conversão de timestamps."""
|
|
165
|
+
|
|
166
|
+
_TABS = ("uuid", "password", "lorem", "timestamp")
|
|
167
|
+
|
|
168
|
+
def __init__(self, parent: tk.Misc, tmgr: Any, cfg: Any = None) -> None:
|
|
169
|
+
t = tmgr.theme
|
|
170
|
+
super().__init__(parent, bg=t.panel_bg)
|
|
171
|
+
self._t = t
|
|
172
|
+
self._tabs: dict[str, tk.Frame] = {}
|
|
173
|
+
self._tab_buttons: dict[str, tk.Button] = {}
|
|
174
|
+
|
|
175
|
+
bar = tk.Frame(self, bg=t.panel_bg)
|
|
176
|
+
bar.pack(fill="x", padx=10, pady=(10, 4))
|
|
177
|
+
titles = {
|
|
178
|
+
"uuid": "UUID",
|
|
179
|
+
"password": _t("toolbox.tab.password", "Senha"),
|
|
180
|
+
"lorem": "Lorem ipsum",
|
|
181
|
+
"timestamp": "Timestamp",
|
|
182
|
+
}
|
|
183
|
+
for key in self._TABS:
|
|
184
|
+
button = _button(bar, t, titles[key], lambda k=key: self._show(k))
|
|
185
|
+
button.pack(side="left", padx=(0, 6))
|
|
186
|
+
self._tab_buttons[key] = button
|
|
187
|
+
self._tabs[key] = tk.Frame(self, bg=t.panel_bg)
|
|
188
|
+
|
|
189
|
+
self._build_uuid(self._tabs["uuid"])
|
|
190
|
+
self._build_password(self._tabs["password"])
|
|
191
|
+
self._build_lorem(self._tabs["lorem"])
|
|
192
|
+
self._build_timestamp(self._tabs["timestamp"])
|
|
193
|
+
self._show("uuid")
|
|
194
|
+
|
|
195
|
+
def _show(self, key: str) -> None:
|
|
196
|
+
for name, frame in self._tabs.items():
|
|
197
|
+
frame.pack_forget()
|
|
198
|
+
self._tab_buttons[name].config(bg=self._t.accent if name == key else self._t.sidebar_bg,
|
|
199
|
+
fg="#ffffff" if name == key else self._t.fg)
|
|
200
|
+
self._tabs[key].pack(fill="both", expand=True, padx=10, pady=(4, 10))
|
|
201
|
+
|
|
202
|
+
def _row(self, parent: tk.Misc) -> tk.Frame:
|
|
203
|
+
row = tk.Frame(parent, bg=self._t.panel_bg)
|
|
204
|
+
row.pack(fill="x", pady=(0, 6))
|
|
205
|
+
return row
|
|
206
|
+
|
|
207
|
+
def _spin(self, parent: tk.Misc, var: tk.IntVar, low: int, high: int) -> tk.Spinbox:
|
|
208
|
+
t = self._t
|
|
209
|
+
spin = tk.Spinbox(parent, from_=low, to=high, textvariable=var, width=5, bg=t.editor_bg, fg=t.fg,
|
|
210
|
+
insertbackground=t.cursor, relief="flat", font=(FONT_UI, 9),
|
|
211
|
+
buttonbackground=t.sidebar_bg, highlightthickness=1, highlightbackground=t.border)
|
|
212
|
+
spin.pack(side="left", padx=(4, 12))
|
|
213
|
+
return spin
|
|
214
|
+
|
|
215
|
+
def _int(self, var: tk.IntVar, default: int) -> int:
|
|
216
|
+
try:
|
|
217
|
+
return int(var.get())
|
|
218
|
+
except (tk.TclError, ValueError):
|
|
219
|
+
return default
|
|
220
|
+
|
|
221
|
+
# UUID
|
|
222
|
+
def _build_uuid(self, frame: tk.Frame) -> None:
|
|
223
|
+
t = self._t
|
|
224
|
+
self._uuid_version = tk.StringVar(value="v4")
|
|
225
|
+
self._uuid_count = tk.IntVar(value=5)
|
|
226
|
+
row = self._row(frame)
|
|
227
|
+
for value in ("v4", "v7"):
|
|
228
|
+
tk.Radiobutton(row, text=value.upper(), value=value, variable=self._uuid_version, bg=t.panel_bg,
|
|
229
|
+
fg=t.fg, selectcolor=t.sidebar_bg, activebackground=t.panel_bg, activeforeground=t.fg,
|
|
230
|
+
font=(FONT_UI, 9)).pack(side="left", padx=(0, 8))
|
|
231
|
+
_label(row, t, _t("toolbox.quantity", "Quantidade:")).pack(side="left")
|
|
232
|
+
self._spin(row, self._uuid_count, 1, 500)
|
|
233
|
+
_button(row, t, _t("toolbox.generate", "Gerar"), self._gen_uuid, accent=True).pack(side="left")
|
|
234
|
+
_button(row, t, _t("toolbox.copy", "Copiar"), lambda: _copy(self, self._uuid_out.get("1.0", "end-1c"))).pack(side="right")
|
|
235
|
+
self._uuid_out = _text_box(frame, t, height=12)
|
|
236
|
+
self._uuid_out.pack(fill="both", expand=True)
|
|
237
|
+
self._gen_uuid()
|
|
238
|
+
|
|
239
|
+
def _gen_uuid(self) -> None:
|
|
240
|
+
make = tb.uuid7 if self._uuid_version.get() == "v7" else tb.uuid4
|
|
241
|
+
count = max(1, min(500, self._int(self._uuid_count, 5)))
|
|
242
|
+
_set_text(self._uuid_out, "\n".join(make() for _ in range(count)))
|
|
243
|
+
|
|
244
|
+
# Senha
|
|
245
|
+
def _build_password(self, frame: tk.Frame) -> None:
|
|
246
|
+
t = self._t
|
|
247
|
+
self._pw_length = tk.IntVar(value=20)
|
|
248
|
+
self._pw_opts = {
|
|
249
|
+
"lower": tk.BooleanVar(value=True),
|
|
250
|
+
"upper": tk.BooleanVar(value=True),
|
|
251
|
+
"digits": tk.BooleanVar(value=True),
|
|
252
|
+
"symbols": tk.BooleanVar(value=True),
|
|
253
|
+
"avoid_ambiguous": tk.BooleanVar(value=True),
|
|
254
|
+
}
|
|
255
|
+
row = self._row(frame)
|
|
256
|
+
_label(row, t, _t("toolbox.length", "Tamanho:")).pack(side="left")
|
|
257
|
+
self._spin(row, self._pw_length, 4, 128)
|
|
258
|
+
_button(row, t, _t("toolbox.generate", "Gerar"), self._gen_password, accent=True).pack(side="left")
|
|
259
|
+
_button(row, t, _t("toolbox.copy", "Copiar"), lambda: _copy(self, self._pw_out.get())).pack(side="right")
|
|
260
|
+
opts = self._row(frame)
|
|
261
|
+
labels = {
|
|
262
|
+
"lower": "a-z", "upper": "A-Z", "digits": "0-9", "symbols": "!@#",
|
|
263
|
+
"avoid_ambiguous": _t("toolbox.avoid_ambiguous", "Evitar ambíguos (I l 1 O 0)"),
|
|
264
|
+
}
|
|
265
|
+
for key, var in self._pw_opts.items():
|
|
266
|
+
tk.Checkbutton(opts, text=labels[key], variable=var, command=self._gen_password, bg=t.panel_bg,
|
|
267
|
+
fg=t.fg, selectcolor=t.sidebar_bg, activebackground=t.panel_bg, activeforeground=t.fg,
|
|
268
|
+
font=(FONT_UI, 9)).pack(side="left", padx=(0, 10))
|
|
269
|
+
self._pw_out = tk.Entry(frame, bg=t.editor_bg, fg=t.fg, font=(FONT_MONO, 13), relief="flat",
|
|
270
|
+
insertbackground=t.cursor, justify="center", highlightthickness=1,
|
|
271
|
+
highlightbackground=t.border)
|
|
272
|
+
self._pw_out.pack(fill="x", pady=(8, 4), ipady=8)
|
|
273
|
+
self._pw_info = _label(frame, t, "", muted=True)
|
|
274
|
+
self._pw_info.pack(fill="x")
|
|
275
|
+
self._gen_password()
|
|
276
|
+
|
|
277
|
+
def _gen_password(self) -> None:
|
|
278
|
+
opts = {k: v.get() for k, v in self._pw_opts.items()}
|
|
279
|
+
try:
|
|
280
|
+
pwd = tb.generate_password(self._int(self._pw_length, 20), **opts)
|
|
281
|
+
except ValueError as exc:
|
|
282
|
+
self._pw_out.delete(0, "end")
|
|
283
|
+
self._pw_info.config(text=f"⚠ {exc}", fg=getattr(self._t, "error_fg", "#ff5555"))
|
|
284
|
+
return
|
|
285
|
+
self._pw_out.delete(0, "end")
|
|
286
|
+
self._pw_out.insert(0, pwd)
|
|
287
|
+
pool = len(set(pwd))
|
|
288
|
+
bits = tb.password_entropy_bits(pwd, max(pool, 2))
|
|
289
|
+
self._pw_info.config(text=_t("toolbox.entropy", "Entropia aproximada: {bits:.0f} bits", bits=bits), fg=self._t.fg_muted)
|
|
290
|
+
|
|
291
|
+
# Lorem
|
|
292
|
+
def _build_lorem(self, frame: tk.Frame) -> None:
|
|
293
|
+
t = self._t
|
|
294
|
+
self._lorem_paragraphs = tk.IntVar(value=3)
|
|
295
|
+
self._lorem_sentences = tk.IntVar(value=4)
|
|
296
|
+
row = self._row(frame)
|
|
297
|
+
_label(row, t, _t("toolbox.paragraphs", "Parágrafos:")).pack(side="left")
|
|
298
|
+
self._spin(row, self._lorem_paragraphs, 1, 50)
|
|
299
|
+
_label(row, t, _t("toolbox.sentences", "Frases:")).pack(side="left")
|
|
300
|
+
self._spin(row, self._lorem_sentences, 1, 20)
|
|
301
|
+
_button(row, t, _t("toolbox.generate", "Gerar"), self._gen_lorem, accent=True).pack(side="left")
|
|
302
|
+
_button(row, t, _t("toolbox.copy", "Copiar"), lambda: _copy(self, self._lorem_out.get("1.0", "end-1c"))).pack(side="right")
|
|
303
|
+
self._lorem_out = _text_box(frame, t, height=12)
|
|
304
|
+
self._lorem_out.pack(fill="both", expand=True)
|
|
305
|
+
self._gen_lorem()
|
|
306
|
+
|
|
307
|
+
def _gen_lorem(self) -> None:
|
|
308
|
+
_set_text(self._lorem_out, tb.lorem_ipsum(self._int(self._lorem_paragraphs, 3), self._int(self._lorem_sentences, 4)))
|
|
309
|
+
|
|
310
|
+
# Timestamp
|
|
311
|
+
def _build_timestamp(self, frame: tk.Frame) -> None:
|
|
312
|
+
t = self._t
|
|
313
|
+
self._ts_var = tk.StringVar(value=str(int(time.time())))
|
|
314
|
+
row = self._row(frame)
|
|
315
|
+
entry = tk.Entry(row, textvariable=self._ts_var, bg=t.editor_bg, fg=t.fg, font=(FONT_MONO, 11), relief="flat",
|
|
316
|
+
insertbackground=t.cursor, highlightthickness=1, highlightbackground=t.border)
|
|
317
|
+
entry.pack(side="left", fill="x", expand=True, ipady=4, padx=(0, 8))
|
|
318
|
+
entry.bind("<Return>", lambda _e: self._convert_ts())
|
|
319
|
+
_button(row, t, _t("toolbox.now", "Agora"), self._ts_now).pack(side="left", padx=(0, 6))
|
|
320
|
+
_button(row, t, _t("toolbox.convert", "Converter"), self._convert_ts, accent=True).pack(side="left")
|
|
321
|
+
_label(frame, t, _t("toolbox.ts_hint", "Aceita segundos, milissegundos ou uma data como 2026-11-23 14:30:00 (UTC)."),
|
|
322
|
+
muted=True).pack(fill="x", pady=(0, 6))
|
|
323
|
+
self._ts_out = _text_box(frame, t, height=8, readonly=True)
|
|
324
|
+
self._ts_out.pack(fill="both", expand=True)
|
|
325
|
+
self._convert_ts()
|
|
326
|
+
|
|
327
|
+
def _ts_now(self) -> None:
|
|
328
|
+
self._ts_var.set(str(int(time.time())))
|
|
329
|
+
self._convert_ts()
|
|
330
|
+
|
|
331
|
+
def _convert_ts(self) -> None:
|
|
332
|
+
try:
|
|
333
|
+
_set_text(self._ts_out, tb.describe_timestamp(self._ts_var.get()))
|
|
334
|
+
except tb.ConversionError as exc:
|
|
335
|
+
_set_text(self._ts_out, f"⚠ {exc}")
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
# Visualizador hex
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
class HexViewerPanel(tk.Frame):
|
|
342
|
+
"""Mostra um arquivo em hexadecimal, por páginas, com ir-para e busca (somente leitura)."""
|
|
343
|
+
|
|
344
|
+
PAGE = 16 * 1024
|
|
345
|
+
WIDTH = 16
|
|
346
|
+
|
|
347
|
+
def __init__(self, parent: tk.Misc, tmgr: Any, cfg: Any = None) -> None:
|
|
348
|
+
t = tmgr.theme
|
|
349
|
+
super().__init__(parent, bg=t.panel_bg)
|
|
350
|
+
self._t = t
|
|
351
|
+
self._path: str | None = None
|
|
352
|
+
self._size = 0
|
|
353
|
+
self._start = 0
|
|
354
|
+
self._last_hit = -1
|
|
355
|
+
self._hit_len = 0
|
|
356
|
+
self._goto = tk.StringVar()
|
|
357
|
+
self._query = tk.StringVar()
|
|
358
|
+
self._as_hex = tk.BooleanVar(value=False)
|
|
359
|
+
|
|
360
|
+
top = tk.Frame(self, bg=t.panel_bg)
|
|
361
|
+
top.pack(fill="x", padx=10, pady=(10, 4))
|
|
362
|
+
_button(top, t, _t("toolbox.open_file", "Abrir arquivo…"), self.open_dialog, accent=True).pack(side="left")
|
|
363
|
+
self._info = _label(top, t, _t("toolbox.no_file", "Nenhum arquivo aberto"), muted=True)
|
|
364
|
+
self._info.pack(side="left", padx=10)
|
|
365
|
+
|
|
366
|
+
nav = tk.Frame(self, bg=t.panel_bg)
|
|
367
|
+
nav.pack(fill="x", padx=10, pady=(0, 6))
|
|
368
|
+
_button(nav, t, "◀", self.prev_page).pack(side="left")
|
|
369
|
+
_button(nav, t, "▶", self.next_page).pack(side="left", padx=(4, 12))
|
|
370
|
+
_label(nav, t, _t("toolbox.goto", "Ir para:")).pack(side="left")
|
|
371
|
+
goto = self._entry(nav, self._goto, 12)
|
|
372
|
+
goto.bind("<Return>", lambda _e: self.goto_text(self._goto.get()))
|
|
373
|
+
_label(nav, t, _t("toolbox.search", "Buscar:")).pack(side="left", padx=(12, 0))
|
|
374
|
+
query = self._entry(nav, self._query, 22)
|
|
375
|
+
query.bind("<Return>", lambda _e: self.search(self._query.get(), self._as_hex.get()))
|
|
376
|
+
tk.Checkbutton(nav, text="hex", variable=self._as_hex, bg=t.panel_bg, fg=t.fg, selectcolor=t.sidebar_bg,
|
|
377
|
+
activebackground=t.panel_bg, activeforeground=t.fg, font=(FONT_UI, 9)).pack(side="left", padx=4)
|
|
378
|
+
_button(nav, t, _t("toolbox.find_next", "Próxima"),
|
|
379
|
+
lambda: self.search(self._query.get(), self._as_hex.get())).pack(side="left")
|
|
380
|
+
|
|
381
|
+
body = tk.Frame(self, bg=t.panel_bg)
|
|
382
|
+
body.pack(fill="both", expand=True, padx=10, pady=(0, 10))
|
|
383
|
+
self._view = tk.Text(body, bg=t.editor_bg, fg=t.fg, font=(FONT_MONO, 10), relief="flat", bd=0, wrap="none",
|
|
384
|
+
highlightthickness=1, highlightbackground=t.border, state="disabled", cursor="arrow")
|
|
385
|
+
scroll = tk.Scrollbar(body, command=self._view.yview)
|
|
386
|
+
self._view.config(yscrollcommand=scroll.set)
|
|
387
|
+
scroll.pack(side="right", fill="y")
|
|
388
|
+
self._view.pack(side="left", fill="both", expand=True)
|
|
389
|
+
self._view.tag_configure("offset", foreground=t.fg_muted)
|
|
390
|
+
self._view.tag_configure("hit", background=t.accent, foreground="#ffffff")
|
|
391
|
+
self._view.bind("<Prior>", lambda _e: self.prev_page())
|
|
392
|
+
self._view.bind("<Next>", lambda _e: self.next_page())
|
|
393
|
+
self._status = _label(self, t, "", muted=True)
|
|
394
|
+
self._status.pack(fill="x", padx=10, pady=(0, 6))
|
|
395
|
+
|
|
396
|
+
def _entry(self, parent: tk.Misc, var: tk.StringVar, width: int) -> tk.Entry:
|
|
397
|
+
t = self._t
|
|
398
|
+
entry = tk.Entry(parent, textvariable=var, width=width, bg=t.editor_bg, fg=t.fg, relief="flat",
|
|
399
|
+
insertbackground=t.cursor, font=(FONT_MONO, 10), highlightthickness=1,
|
|
400
|
+
highlightbackground=t.border)
|
|
401
|
+
entry.pack(side="left", padx=(4, 0), ipady=3)
|
|
402
|
+
return entry
|
|
403
|
+
|
|
404
|
+
# Arquivo
|
|
405
|
+
def open_dialog(self) -> None:
|
|
406
|
+
chosen = filedialog.askopenfilename(parent=self)
|
|
407
|
+
if chosen:
|
|
408
|
+
self.load_file(chosen)
|
|
409
|
+
|
|
410
|
+
def load_file(self, path: str) -> None:
|
|
411
|
+
"""Abre ``path`` no início."""
|
|
412
|
+
try:
|
|
413
|
+
size = os.path.getsize(path)
|
|
414
|
+
except OSError as exc:
|
|
415
|
+
messagebox.showerror(_t("toolbox.hex_title", "Visualizador hex"), str(exc), parent=self)
|
|
416
|
+
return
|
|
417
|
+
self._path, self._size, self._last_hit = path, size, -1
|
|
418
|
+
self._show_page(0)
|
|
419
|
+
|
|
420
|
+
def _show_page(self, start: int) -> None:
|
|
421
|
+
if self._path is None:
|
|
422
|
+
return
|
|
423
|
+
start = max(0, min(start, max(0, self._size - 1))) // self.WIDTH * self.WIDTH
|
|
424
|
+
try:
|
|
425
|
+
with open(self._path, "rb") as handle:
|
|
426
|
+
handle.seek(start)
|
|
427
|
+
data = handle.read(self.PAGE)
|
|
428
|
+
except OSError as exc:
|
|
429
|
+
self._status.config(text=f"⚠ {exc}")
|
|
430
|
+
return
|
|
431
|
+
self._start = start
|
|
432
|
+
self._view.config(state="normal")
|
|
433
|
+
self._view.delete("1.0", "end")
|
|
434
|
+
for line in tb.hexdump_lines(data, start, self.WIDTH):
|
|
435
|
+
self._view.insert("end", line[:8], "offset")
|
|
436
|
+
self._view.insert("end", line[8:] + "\n")
|
|
437
|
+
self._view.config(state="disabled")
|
|
438
|
+
self._view.yview_moveto(0)
|
|
439
|
+
end = start + len(data)
|
|
440
|
+
self._info.config(text=f"{Path(self._path).name} - {format_size(self._size)}")
|
|
441
|
+
self._status.config(text=_t("toolbox.range", "Offsets 0x{a:x} a 0x{b:x} de 0x{c:x}", a=start, b=max(start, end - 1), c=self._size),
|
|
442
|
+
fg=self._t.fg_muted)
|
|
443
|
+
self._mark_hit()
|
|
444
|
+
|
|
445
|
+
def next_page(self) -> None:
|
|
446
|
+
if self._path and self._start + self.PAGE < self._size:
|
|
447
|
+
self._show_page(self._start + self.PAGE)
|
|
448
|
+
|
|
449
|
+
def prev_page(self) -> None:
|
|
450
|
+
if self._path and self._start > 0:
|
|
451
|
+
self._show_page(self._start - self.PAGE)
|
|
452
|
+
|
|
453
|
+
def goto_text(self, text: str) -> None:
|
|
454
|
+
"""Vai para um offset decimal ou hexadecimal (``0x1f40``)."""
|
|
455
|
+
if self._path is None:
|
|
456
|
+
return
|
|
457
|
+
try:
|
|
458
|
+
offset = int(text.strip(), 0)
|
|
459
|
+
except ValueError:
|
|
460
|
+
self._status.config(text=_t("toolbox.bad_offset", "⚠ Offset inválido (use 8192 ou 0x2000)"),
|
|
461
|
+
fg=getattr(self._t, "error_fg", "#ff5555"))
|
|
462
|
+
return
|
|
463
|
+
self._last_hit = -1
|
|
464
|
+
self._show_page(offset // self.PAGE * self.PAGE)
|
|
465
|
+
self._scroll_to(offset)
|
|
466
|
+
|
|
467
|
+
def _scroll_to(self, offset: int) -> None:
|
|
468
|
+
line = (offset - self._start) // self.WIDTH + 1
|
|
469
|
+
self._view.see(f"{max(1, line)}.0")
|
|
470
|
+
|
|
471
|
+
def search(self, query: str, as_hex: bool) -> None:
|
|
472
|
+
"""Procura ``query`` (texto ou hex) depois da última ocorrência e mostra a página dela."""
|
|
473
|
+
if self._path is None:
|
|
474
|
+
return
|
|
475
|
+
try:
|
|
476
|
+
needle = tb.parse_search_bytes(query, as_hex=as_hex)
|
|
477
|
+
except tb.ConversionError as exc:
|
|
478
|
+
self._status.config(text=f"⚠ {exc}", fg=getattr(self._t, "error_fg", "#ff5555"))
|
|
479
|
+
return
|
|
480
|
+
begin = self._last_hit + 1 if self._last_hit >= 0 else self._start
|
|
481
|
+
offset = tb.find_bytes(self._path, needle, begin)
|
|
482
|
+
if offset < 0 and begin > 0:
|
|
483
|
+
offset = tb.find_bytes(self._path, needle, 0)
|
|
484
|
+
if offset < 0:
|
|
485
|
+
self._status.config(text=_t("toolbox.not_found", "Não encontrado"), fg=getattr(self._t, "error_fg", "#ff5555"))
|
|
486
|
+
return
|
|
487
|
+
self._last_hit, self._hit_len = offset, len(needle)
|
|
488
|
+
page = offset // self.PAGE * self.PAGE
|
|
489
|
+
if page != self._start:
|
|
490
|
+
self._show_page(page)
|
|
491
|
+
else:
|
|
492
|
+
self._mark_hit()
|
|
493
|
+
self._scroll_to(offset)
|
|
494
|
+
self._status.config(text=_t("toolbox.found_at", "Encontrado em 0x{o:x}", o=offset), fg=self._t.fg_muted)
|
|
495
|
+
|
|
496
|
+
def _mark_hit(self) -> None:
|
|
497
|
+
self._view.tag_remove("hit", "1.0", "end")
|
|
498
|
+
if self._last_hit < 0:
|
|
499
|
+
return
|
|
500
|
+
for index in range(self._last_hit, self._last_hit + self._hit_len):
|
|
501
|
+
if not self._start <= index < self._start + self.PAGE:
|
|
502
|
+
continue
|
|
503
|
+
row, col = divmod(index - self._start, self.WIDTH)
|
|
504
|
+
line = row + 1
|
|
505
|
+
hex_col = 10 + col * 3
|
|
506
|
+
self._view.tag_add("hit", f"{line}.{hex_col}", f"{line}.{hex_col + 2}")
|
|
507
|
+
ascii_col = 10 + self.WIDTH * 3 - 1 + 2 + 1 + col
|
|
508
|
+
self._view.tag_add("hit", f"{line}.{ascii_col}", f"{line}.{ascii_col + 1}")
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
# Servidor local
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
class ServerPanel(tk.Frame):
|
|
515
|
+
"""Serve uma pasta em ``127.0.0.1`` com recarga automática, para ver HTML, SVG e Markdown no navegador."""
|
|
516
|
+
|
|
517
|
+
_SERVED = (".html", ".htm", ".md", ".markdown", ".svg")
|
|
518
|
+
|
|
519
|
+
def __init__(self, parent: tk.Misc, tmgr: Any, cfg: Any = None) -> None:
|
|
520
|
+
t = tmgr.theme
|
|
521
|
+
super().__init__(parent, bg=t.panel_bg)
|
|
522
|
+
self._t = t
|
|
523
|
+
self._tmgr = tmgr
|
|
524
|
+
self._server: Any = None
|
|
525
|
+
self._folder_path: Path | None = None
|
|
526
|
+
self._files: list[Path] = []
|
|
527
|
+
self._live = tk.BooleanVar(value=True)
|
|
528
|
+
|
|
529
|
+
top = tk.Frame(self, bg=t.panel_bg)
|
|
530
|
+
top.pack(fill="x", padx=10, pady=(10, 4))
|
|
531
|
+
_button(top, t, _t("toolbox.choose_folder", "Escolher pasta…"), self.choose_folder).pack(side="left")
|
|
532
|
+
self._folder = _label(top, t, _t("toolbox.no_folder", "Nenhuma pasta escolhida"), muted=True)
|
|
533
|
+
self._folder.pack(side="left", padx=10)
|
|
534
|
+
|
|
535
|
+
ctl = tk.Frame(self, bg=t.panel_bg)
|
|
536
|
+
ctl.pack(fill="x", padx=10, pady=(0, 6))
|
|
537
|
+
self._toggle = _button(ctl, t, _t("toolbox.start", "Iniciar"), self.toggle, accent=True)
|
|
538
|
+
self._toggle.pack(side="left")
|
|
539
|
+
tk.Checkbutton(ctl, text=_t("toolbox.live_reload", "Recarregar a página ao salvar"), variable=self._live,
|
|
540
|
+
command=self._on_live_changed, bg=t.panel_bg, fg=t.fg, selectcolor=t.sidebar_bg,
|
|
541
|
+
activebackground=t.panel_bg, activeforeground=t.fg, font=(FONT_UI, 9)).pack(side="left", padx=12)
|
|
542
|
+
self._url_var = tk.StringVar()
|
|
543
|
+
url = tk.Entry(self, textvariable=self._url_var, state="readonly", readonlybackground=t.editor_bg, fg=t.fg,
|
|
544
|
+
relief="flat", font=(FONT_MONO, 11), highlightthickness=1, highlightbackground=t.border)
|
|
545
|
+
url.pack(fill="x", padx=10, ipady=5)
|
|
546
|
+
actions = tk.Frame(self, bg=t.panel_bg)
|
|
547
|
+
actions.pack(fill="x", padx=10, pady=6)
|
|
548
|
+
_button(actions, t, _t("toolbox.open_browser", "Abrir no navegador"), self.open_browser).pack(side="left")
|
|
549
|
+
_button(actions, t, _t("toolbox.copy_url", "Copiar endereço"), lambda: _copy(self, self._url_var.get())).pack(side="left", padx=6)
|
|
550
|
+
_button(actions, t, _t("toolbox.refresh", "Atualizar lista"), self._scan).pack(side="right")
|
|
551
|
+
|
|
552
|
+
_label(self, t, _t("toolbox.pages", "Páginas (duplo clique abre no navegador)"), muted=True).pack(fill="x", padx=10)
|
|
553
|
+
self._list = tk.Listbox(self, bg=t.editor_bg, fg=t.fg, selectbackground=t.accent, selectforeground="#ffffff",
|
|
554
|
+
relief="flat", font=(FONT_UI, 10), activestyle="none", highlightthickness=1,
|
|
555
|
+
highlightbackground=t.border)
|
|
556
|
+
self._list.pack(fill="both", expand=True, padx=10, pady=(0, 6))
|
|
557
|
+
self._list.bind("<Double-Button-1>", lambda _e: self.open_selected())
|
|
558
|
+
self._status = _label(self, t, "", muted=True)
|
|
559
|
+
self._status.pack(fill="x", padx=10, pady=(0, 8))
|
|
560
|
+
self.bind("<Destroy>", self._on_destroy, add="+")
|
|
561
|
+
|
|
562
|
+
# Pasta
|
|
563
|
+
def choose_folder(self) -> None:
|
|
564
|
+
chosen = filedialog.askdirectory(parent=self)
|
|
565
|
+
if chosen:
|
|
566
|
+
self.set_workspace(Path(chosen))
|
|
567
|
+
|
|
568
|
+
def set_workspace(self, path: Path) -> None:
|
|
569
|
+
"""Define a pasta servida (reinicia o servidor se já estava ativo)."""
|
|
570
|
+
was_running = self._server is not None
|
|
571
|
+
self._stop()
|
|
572
|
+
self._folder_path = Path(path).resolve()
|
|
573
|
+
self._folder.config(text=str(self._folder_path))
|
|
574
|
+
self._scan()
|
|
575
|
+
if was_running:
|
|
576
|
+
self._start()
|
|
577
|
+
|
|
578
|
+
def _scan(self) -> None:
|
|
579
|
+
self._list.delete(0, "end")
|
|
580
|
+
self._files = []
|
|
581
|
+
if self._folder_path is None:
|
|
582
|
+
return
|
|
583
|
+
skip = {".git", "node_modules", "__pycache__", ".venv", "venv"}
|
|
584
|
+
for base, dirs, names in os.walk(self._folder_path):
|
|
585
|
+
dirs[:] = sorted(d for d in dirs if d not in skip)
|
|
586
|
+
for name in sorted(names):
|
|
587
|
+
if name.lower().endswith(self._SERVED):
|
|
588
|
+
self._files.append(Path(base) / name)
|
|
589
|
+
if len(self._files) >= 2000:
|
|
590
|
+
break
|
|
591
|
+
for path in self._files:
|
|
592
|
+
self._list.insert("end", path.relative_to(self._folder_path).as_posix())
|
|
593
|
+
if not self._files:
|
|
594
|
+
self._list.insert("end", _t("toolbox.no_pages", "(nenhum .html, .md ou .svg nesta pasta)"))
|
|
595
|
+
|
|
596
|
+
# Servidor
|
|
597
|
+
def toggle(self) -> None:
|
|
598
|
+
if self._server is None:
|
|
599
|
+
self._start()
|
|
600
|
+
else:
|
|
601
|
+
self._stop()
|
|
602
|
+
|
|
603
|
+
def _start(self) -> None:
|
|
604
|
+
if self._folder_path is None:
|
|
605
|
+
self.choose_folder()
|
|
606
|
+
if self._folder_path is None:
|
|
607
|
+
return
|
|
608
|
+
from src.ui import webdev
|
|
609
|
+
|
|
610
|
+
md_renderer = None
|
|
611
|
+
with contextlib.suppress(Exception):
|
|
612
|
+
from src.ui.web_preview import markdown_page
|
|
613
|
+
|
|
614
|
+
md_renderer = lambda text, title: markdown_page(text, title, self._tmgr) # noqa: E731
|
|
615
|
+
try:
|
|
616
|
+
self._server = webdev.DevServer(self._folder_path, md_renderer=md_renderer, live_reload=self._live.get())
|
|
617
|
+
port = self._server.start()
|
|
618
|
+
except OSError as exc:
|
|
619
|
+
self._server = None
|
|
620
|
+
self._status.config(text=f"⚠ {exc}", fg=getattr(self._t, "error_fg", "#ff5555"))
|
|
621
|
+
return
|
|
622
|
+
self._url_var.set(f"http://127.0.0.1:{port}/")
|
|
623
|
+
self._toggle.config(text=_t("toolbox.stop", "Parar"))
|
|
624
|
+
self._status.config(text=_t("toolbox.serving", "Servindo {folder}", folder=self._folder_path.name), fg=self._t.fg_muted)
|
|
625
|
+
|
|
626
|
+
def _stop(self) -> None:
|
|
627
|
+
if self._server is not None:
|
|
628
|
+
with contextlib.suppress(Exception):
|
|
629
|
+
self._server.stop()
|
|
630
|
+
self._server = None
|
|
631
|
+
self._url_var.set("")
|
|
632
|
+
with contextlib.suppress(tk.TclError):
|
|
633
|
+
self._toggle.config(text=_t("toolbox.start", "Iniciar"))
|
|
634
|
+
self._status.config(text="")
|
|
635
|
+
|
|
636
|
+
def _on_live_changed(self) -> None:
|
|
637
|
+
if self._server is not None:
|
|
638
|
+
self._stop()
|
|
639
|
+
self._start()
|
|
640
|
+
|
|
641
|
+
def open_browser(self) -> None:
|
|
642
|
+
url = self._url_var.get()
|
|
643
|
+
if url:
|
|
644
|
+
webbrowser.open(url)
|
|
645
|
+
|
|
646
|
+
def open_selected(self) -> None:
|
|
647
|
+
selection = self._list.curselection()
|
|
648
|
+
if not selection or self._server is None or selection[0] >= len(self._files):
|
|
649
|
+
if self._server is None:
|
|
650
|
+
self._status.config(text=_t("toolbox.start_first", "Inicie o servidor primeiro"))
|
|
651
|
+
return
|
|
652
|
+
url = self._server.url_for(self._files[selection[0]])
|
|
653
|
+
if url:
|
|
654
|
+
webbrowser.open(url)
|
|
655
|
+
|
|
656
|
+
def _on_destroy(self, event: tk.Event) -> None:
|
|
657
|
+
if event.widget is self:
|
|
658
|
+
self._stop()
|