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/scratchpad.py
ADDED
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
"""Codis - ScratchpadPane.
|
|
2
|
+
|
|
3
|
+
Recursos:
|
|
4
|
+
- Múltiplas abas de rascunho nomeadas (até 5)
|
|
5
|
+
- Salvo automaticamente (debounce 500ms) por aba
|
|
6
|
+
- Contador de palavras/linhas/chars em tempo real
|
|
7
|
+
- Botão de inserção rápida: data/hora, separador, etc.
|
|
8
|
+
- Busca inline com Ctrl+F
|
|
9
|
+
- Exportar aba para arquivo .txt
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import contextlib
|
|
15
|
+
import json
|
|
16
|
+
import logging
|
|
17
|
+
import re
|
|
18
|
+
import tkinter as tk
|
|
19
|
+
from datetime import datetime
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from tkinter import filedialog, ttk
|
|
22
|
+
|
|
23
|
+
from src.constants import FONT_MONO, FONT_UI
|
|
24
|
+
from src.i18n import _t
|
|
25
|
+
|
|
26
|
+
logger = logging.getLogger("Codis")
|
|
27
|
+
|
|
28
|
+
_SCRATCH_DIR = Path.home() / ".codis" / "scratchpads"
|
|
29
|
+
_STATE_FILE = _SCRATCH_DIR / "_state.json"
|
|
30
|
+
_MAX_TABS = 5
|
|
31
|
+
_DEFAULT_TABS = ["Rascunho 1"]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ScratchpadPane(tk.Frame):
|
|
35
|
+
"""
|
|
36
|
+
Bloco de notas persistente com múltiplas abas nomeadas.
|
|
37
|
+
|
|
38
|
+
Cada aba é salva individualmente em ~/.codis/scratchpads/<nome>.txt
|
|
39
|
+
com debounce de 500ms. Duplo-clique na aba para renomear.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, parent: tk.Widget, tmgr) -> None:
|
|
43
|
+
t = tmgr.theme
|
|
44
|
+
super().__init__(parent, bg=t.sidebar_bg)
|
|
45
|
+
self._tmgr = tmgr
|
|
46
|
+
self._save_job: str | None = None
|
|
47
|
+
self._tabs: list[str] = []
|
|
48
|
+
self._active = 0
|
|
49
|
+
self._contents: dict[str, str] = {}
|
|
50
|
+
self._search_visible = False
|
|
51
|
+
|
|
52
|
+
_SCRATCH_DIR.mkdir(parents=True, exist_ok=True)
|
|
53
|
+
self._load_state()
|
|
54
|
+
self._build()
|
|
55
|
+
self._load_tab(self._active)
|
|
56
|
+
|
|
57
|
+
def _load_state(self) -> None:
|
|
58
|
+
try:
|
|
59
|
+
state = json.loads(_STATE_FILE.read_text(encoding="utf-8"))
|
|
60
|
+
self._tabs = state.get("tabs", _DEFAULT_TABS) or _DEFAULT_TABS
|
|
61
|
+
self._active = min(state.get("active", 0), len(self._tabs) - 1)
|
|
62
|
+
except (OSError, json.JSONDecodeError, ValueError):
|
|
63
|
+
self._tabs = list(_DEFAULT_TABS)
|
|
64
|
+
self._active = 0
|
|
65
|
+
|
|
66
|
+
def _save_state(self) -> None:
|
|
67
|
+
with contextlib.suppress(OSError):
|
|
68
|
+
_STATE_FILE.write_text(
|
|
69
|
+
json.dumps(
|
|
70
|
+
{"tabs": self._tabs, "active": self._active}, ensure_ascii=False
|
|
71
|
+
),
|
|
72
|
+
encoding="utf-8",
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
def _tab_file(self, name: str) -> Path:
|
|
76
|
+
safe = re.sub(r"[^\w\-. ]", "_", name)[:40]
|
|
77
|
+
return _SCRATCH_DIR / f"{safe}.txt"
|
|
78
|
+
|
|
79
|
+
def _load_tab(self, idx: int) -> None:
|
|
80
|
+
if not self._tabs:
|
|
81
|
+
return
|
|
82
|
+
name = self._tabs[idx]
|
|
83
|
+
if name not in self._contents:
|
|
84
|
+
try:
|
|
85
|
+
self._contents[name] = self._tab_file(name).read_text(
|
|
86
|
+
encoding="utf-8", errors="replace"
|
|
87
|
+
)
|
|
88
|
+
except OSError:
|
|
89
|
+
self._contents[name] = ""
|
|
90
|
+
with contextlib.suppress(tk.TclError):
|
|
91
|
+
self._text.delete("1.0", "end")
|
|
92
|
+
self._text.insert("1.0", self._contents[name])
|
|
93
|
+
self._update_stats()
|
|
94
|
+
|
|
95
|
+
def _save_current(self) -> None:
|
|
96
|
+
self._save_job = None
|
|
97
|
+
if not self._tabs:
|
|
98
|
+
return
|
|
99
|
+
name = self._tabs[self._active]
|
|
100
|
+
content = self._text.get("1.0", "end-1c")
|
|
101
|
+
self._contents[name] = content
|
|
102
|
+
with contextlib.suppress(OSError):
|
|
103
|
+
f = self._tab_file(name)
|
|
104
|
+
tmp = f.with_suffix(".tmp")
|
|
105
|
+
tmp.write_text(content, encoding="utf-8")
|
|
106
|
+
tmp.replace(f)
|
|
107
|
+
self._save_state()
|
|
108
|
+
with contextlib.suppress(tk.TclError):
|
|
109
|
+
self._status_lbl.config(text=_t("scratch.saved", "✔ salvo"))
|
|
110
|
+
self.after(2000, lambda: self._status_lbl.config(text=""))
|
|
111
|
+
|
|
112
|
+
def _schedule_save(self) -> None:
|
|
113
|
+
if self._save_job:
|
|
114
|
+
with contextlib.suppress(tk.TclError):
|
|
115
|
+
self.after_cancel(self._save_job)
|
|
116
|
+
self._save_job = self.after(500, self._save_current)
|
|
117
|
+
self._status_lbl.config(text="...")
|
|
118
|
+
|
|
119
|
+
def _build(self) -> None:
|
|
120
|
+
t = self._tmgr.theme
|
|
121
|
+
|
|
122
|
+
hdr = tk.Frame(self, bg=t.activity_bg, height=34)
|
|
123
|
+
hdr.pack(fill="x")
|
|
124
|
+
hdr.pack_propagate(False)
|
|
125
|
+
|
|
126
|
+
tk.Label(hdr, text=" 📝", bg=t.activity_bg, fg=t.fg, font=(FONT_UI, 10)).pack(
|
|
127
|
+
side="left"
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
self._status_lbl = tk.Label(
|
|
131
|
+
hdr, text="", bg=t.activity_bg, fg=t.ok_fg, font=(FONT_UI, 7)
|
|
132
|
+
)
|
|
133
|
+
self._status_lbl.pack(side="right", padx=6)
|
|
134
|
+
|
|
135
|
+
exp_btn = tk.Label(
|
|
136
|
+
hdr,
|
|
137
|
+
text="↑",
|
|
138
|
+
bg=t.activity_bg,
|
|
139
|
+
fg=t.fg_muted,
|
|
140
|
+
font=(FONT_UI, 11),
|
|
141
|
+
cursor="hand2",
|
|
142
|
+
padx=4,
|
|
143
|
+
)
|
|
144
|
+
exp_btn.pack(side="right")
|
|
145
|
+
exp_btn.bind("<Button-1>", self._export)
|
|
146
|
+
self._tooltip(exp_btn, "Exportar como .txt")
|
|
147
|
+
|
|
148
|
+
srch_btn = tk.Label(
|
|
149
|
+
hdr,
|
|
150
|
+
text="🔍",
|
|
151
|
+
bg=t.activity_bg,
|
|
152
|
+
fg=t.fg_muted,
|
|
153
|
+
font=(FONT_UI, 9),
|
|
154
|
+
cursor="hand2",
|
|
155
|
+
padx=4,
|
|
156
|
+
)
|
|
157
|
+
srch_btn.pack(side="right")
|
|
158
|
+
srch_btn.bind("<Button-1>", self._toggle_search)
|
|
159
|
+
self._tooltip(srch_btn, "Busca (Ctrl+F)")
|
|
160
|
+
|
|
161
|
+
ins_btn = tk.Label(
|
|
162
|
+
hdr,
|
|
163
|
+
text="⊕",
|
|
164
|
+
bg=t.activity_bg,
|
|
165
|
+
fg=t.fg_muted,
|
|
166
|
+
font=(FONT_UI, 11),
|
|
167
|
+
cursor="hand2",
|
|
168
|
+
padx=4,
|
|
169
|
+
)
|
|
170
|
+
ins_btn.pack(side="right")
|
|
171
|
+
ins_btn.bind("<Button-1>", self._quick_insert_menu)
|
|
172
|
+
self._tooltip(ins_btn, "Inserir data / separador")
|
|
173
|
+
|
|
174
|
+
self._tabs_frame = tk.Frame(self, bg=t.tabbar_bg, height=26)
|
|
175
|
+
self._tabs_frame.pack(fill="x")
|
|
176
|
+
self._tabs_frame.pack_propagate(False)
|
|
177
|
+
self._rebuild_tabs()
|
|
178
|
+
|
|
179
|
+
self._search_frame = tk.Frame(self, bg=t.editor_bg)
|
|
180
|
+
self._search_var = tk.StringVar()
|
|
181
|
+
self._search_var.trace_add("write", lambda *_: self._do_search())
|
|
182
|
+
srch_inner = tk.Frame(self._search_frame, bg=t.editor_bg)
|
|
183
|
+
srch_inner.pack(fill="x", padx=4, pady=2)
|
|
184
|
+
tk.Label(
|
|
185
|
+
srch_inner, text="🔍", bg=t.editor_bg, fg=t.fg_muted, font=(FONT_UI, 9)
|
|
186
|
+
).pack(side="left")
|
|
187
|
+
self._search_entry = tk.Entry(
|
|
188
|
+
srch_inner,
|
|
189
|
+
textvariable=self._search_var,
|
|
190
|
+
bg=t.input_bg,
|
|
191
|
+
fg=t.fg,
|
|
192
|
+
insertbackground=t.t_func,
|
|
193
|
+
relief="flat",
|
|
194
|
+
bd=2,
|
|
195
|
+
font=(FONT_UI, 9),
|
|
196
|
+
)
|
|
197
|
+
self._search_entry.pack(side="left", fill="x", expand=True, padx=4)
|
|
198
|
+
self._match_lbl = tk.Label(
|
|
199
|
+
srch_inner, text="", bg=t.editor_bg, fg=t.fg_muted, font=(FONT_UI, 8)
|
|
200
|
+
)
|
|
201
|
+
self._match_lbl.pack(side="left", padx=4)
|
|
202
|
+
tk.Label(
|
|
203
|
+
srch_inner,
|
|
204
|
+
text="✕",
|
|
205
|
+
bg=t.editor_bg,
|
|
206
|
+
fg=t.fg_muted,
|
|
207
|
+
cursor="hand2",
|
|
208
|
+
font=(FONT_UI, 9),
|
|
209
|
+
).pack(side="right", padx=4)
|
|
210
|
+
self.bind("<Button-1>", self._hide_search)
|
|
211
|
+
self._search_entry.bind("<Escape>", self._hide_search)
|
|
212
|
+
self._search_entry.bind(
|
|
213
|
+
"<Return>", lambda e: self._do_search(next_match=True))
|
|
214
|
+
|
|
215
|
+
txt_frame = tk.Frame(self, bg=t.sidebar_bg)
|
|
216
|
+
txt_frame.pack(fill="both", expand=True)
|
|
217
|
+
|
|
218
|
+
vsb = ttk.Scrollbar(txt_frame, orient="vertical")
|
|
219
|
+
vsb.pack(side="right", fill="y")
|
|
220
|
+
|
|
221
|
+
self._text = tk.Text(
|
|
222
|
+
txt_frame,
|
|
223
|
+
bg=t.editor_bg,
|
|
224
|
+
fg=t.fg,
|
|
225
|
+
insertbackground=t.cursor,
|
|
226
|
+
font=(FONT_MONO, 10),
|
|
227
|
+
relief="flat",
|
|
228
|
+
bd=0,
|
|
229
|
+
padx=10,
|
|
230
|
+
pady=8,
|
|
231
|
+
wrap="word",
|
|
232
|
+
undo=True,
|
|
233
|
+
)
|
|
234
|
+
self._text.config(yscrollcommand=vsb.set)
|
|
235
|
+
vsb.config(command=self._text.yview)
|
|
236
|
+
self._text.pack(fill="both", expand=True)
|
|
237
|
+
self._text.tag_config(
|
|
238
|
+
"search_hi", background=getattr(t, "sel_bg", "#264f78"), foreground=t.fg
|
|
239
|
+
)
|
|
240
|
+
self._text.bind("<KeyRelease>", self._on_change)
|
|
241
|
+
self._text.bind("<Control-f>", self._toggle_search)
|
|
242
|
+
self._text.bind("<Control-F>", self._toggle_search)
|
|
243
|
+
self._text.bind("<Control-s>", lambda e: self._save_current())
|
|
244
|
+
|
|
245
|
+
footer = tk.Frame(self, bg=t.activity_bg, height=20)
|
|
246
|
+
footer.pack(fill="x")
|
|
247
|
+
footer.pack_propagate(False)
|
|
248
|
+
self._stats_lbl = tk.Label(
|
|
249
|
+
footer,
|
|
250
|
+
text="",
|
|
251
|
+
bg=t.activity_bg,
|
|
252
|
+
fg=t.fg_muted,
|
|
253
|
+
font=(FONT_UI, 7),
|
|
254
|
+
anchor="e",
|
|
255
|
+
)
|
|
256
|
+
self._stats_lbl.pack(side="right", padx=6, fill="y")
|
|
257
|
+
|
|
258
|
+
clr = tk.Label(
|
|
259
|
+
footer,
|
|
260
|
+
text=_t("scratch.clear", "✕ limpar"),
|
|
261
|
+
bg=t.activity_bg,
|
|
262
|
+
fg=t.fg_muted,
|
|
263
|
+
font=(FONT_UI, 7),
|
|
264
|
+
cursor="hand2",
|
|
265
|
+
)
|
|
266
|
+
clr.pack(side="left", padx=6, fill="y")
|
|
267
|
+
clr.bind("<Button-1>", self._clear)
|
|
268
|
+
|
|
269
|
+
def _rebuild_tabs(self) -> None:
|
|
270
|
+
t = self._tmgr.theme
|
|
271
|
+
for w in self._tabs_frame.winfo_children():
|
|
272
|
+
w.destroy()
|
|
273
|
+
|
|
274
|
+
for i, name in enumerate(self._tabs):
|
|
275
|
+
is_active = i == self._active
|
|
276
|
+
bg = t.tab_active_bg if is_active else t.tab_bg
|
|
277
|
+
fg = t.tab_active_fg if is_active else t.tab_fg
|
|
278
|
+
|
|
279
|
+
tab_frame = tk.Frame(self._tabs_frame, bg=bg, cursor="hand2")
|
|
280
|
+
tab_frame.pack(side="left", fill="y", padx=(0, 1))
|
|
281
|
+
|
|
282
|
+
lbl = tk.Label(
|
|
283
|
+
tab_frame,
|
|
284
|
+
text=f" {name} ",
|
|
285
|
+
bg=bg,
|
|
286
|
+
fg=fg,
|
|
287
|
+
font=(FONT_UI, 8, "bold" if is_active else "normal"),
|
|
288
|
+
padx=2,
|
|
289
|
+
cursor="hand2",
|
|
290
|
+
)
|
|
291
|
+
lbl.pack(side="left", fill="y")
|
|
292
|
+
|
|
293
|
+
if is_active and len(self._tabs) > 1:
|
|
294
|
+
close = tk.Label(
|
|
295
|
+
tab_frame,
|
|
296
|
+
text="✕",
|
|
297
|
+
bg=bg,
|
|
298
|
+
fg=t.fg_muted,
|
|
299
|
+
font=(FONT_UI, 7),
|
|
300
|
+
cursor="hand2",
|
|
301
|
+
padx=2,
|
|
302
|
+
)
|
|
303
|
+
close.pack(side="left", fill="y")
|
|
304
|
+
close.bind("<Button-1>", lambda e, idx=i: self._close_tab(idx))
|
|
305
|
+
|
|
306
|
+
if is_active:
|
|
307
|
+
tk.Frame(tab_frame, bg=t.accent, height=2).pack(
|
|
308
|
+
side="bottom", fill="x")
|
|
309
|
+
|
|
310
|
+
for w in (tab_frame, lbl):
|
|
311
|
+
w.bind("<Button-1>", lambda e, idx=i: self._switch_tab(idx))
|
|
312
|
+
w.bind("<Double-1>", lambda e, idx=i: self._rename_tab(idx))
|
|
313
|
+
|
|
314
|
+
if len(self._tabs) < _MAX_TABS:
|
|
315
|
+
add = tk.Label(
|
|
316
|
+
self._tabs_frame,
|
|
317
|
+
text=" ⊕ ",
|
|
318
|
+
bg=t.tab_bg,
|
|
319
|
+
fg=t.fg_muted,
|
|
320
|
+
font=(FONT_UI, 9),
|
|
321
|
+
cursor="hand2",
|
|
322
|
+
)
|
|
323
|
+
add.pack(side="left", fill="y", padx=2)
|
|
324
|
+
add.bind("<Button-1>", lambda e: self._new_tab())
|
|
325
|
+
|
|
326
|
+
def _switch_tab(self, idx: int) -> None:
|
|
327
|
+
if self._tabs:
|
|
328
|
+
self._contents[self._tabs[self._active]
|
|
329
|
+
] = self._text.get("1.0", "end-1c")
|
|
330
|
+
self._active = idx
|
|
331
|
+
self._load_tab(idx)
|
|
332
|
+
self._rebuild_tabs()
|
|
333
|
+
|
|
334
|
+
def _new_tab(self) -> None:
|
|
335
|
+
n = len(self._tabs) + 1
|
|
336
|
+
name = f"Rascunho {n}"
|
|
337
|
+
while name in self._tabs:
|
|
338
|
+
n += 1
|
|
339
|
+
name = f"Rascunho {n}"
|
|
340
|
+
self._tabs.append(name)
|
|
341
|
+
self._contents[name] = ""
|
|
342
|
+
self._switch_tab(len(self._tabs) - 1)
|
|
343
|
+
|
|
344
|
+
def _close_tab(self, idx: int) -> None:
|
|
345
|
+
if len(self._tabs) <= 1:
|
|
346
|
+
return
|
|
347
|
+
name = self._tabs.pop(idx)
|
|
348
|
+
self._contents.pop(name, None)
|
|
349
|
+
new_idx = min(idx, len(self._tabs) - 1)
|
|
350
|
+
self._active = new_idx
|
|
351
|
+
self._load_tab(new_idx)
|
|
352
|
+
self._rebuild_tabs()
|
|
353
|
+
self._save_state()
|
|
354
|
+
|
|
355
|
+
def _rename_tab(self, idx: int) -> None:
|
|
356
|
+
t = self._tmgr.theme
|
|
357
|
+
old = self._tabs[idx]
|
|
358
|
+
win = tk.Toplevel(self)
|
|
359
|
+
win.wm_overrideredirect(True)
|
|
360
|
+
win.wm_attributes("-topmost", True)
|
|
361
|
+
win.configure(bg=t.floating_bg)
|
|
362
|
+
win.geometry(
|
|
363
|
+
f"220x36+{self.winfo_rootx() + 40}+{self.winfo_rooty() + 30}")
|
|
364
|
+
var = tk.StringVar(value=old)
|
|
365
|
+
ent = tk.Entry(
|
|
366
|
+
win,
|
|
367
|
+
textvariable=var,
|
|
368
|
+
bg=t.input_bg,
|
|
369
|
+
fg=t.fg,
|
|
370
|
+
insertbackground=t.t_func,
|
|
371
|
+
relief="flat",
|
|
372
|
+
bd=2,
|
|
373
|
+
font=(FONT_UI, 9),
|
|
374
|
+
width=20,
|
|
375
|
+
)
|
|
376
|
+
ent.pack(fill="both", expand=True, padx=4, pady=4)
|
|
377
|
+
ent.select_range(0, "end")
|
|
378
|
+
ent.focus_set()
|
|
379
|
+
|
|
380
|
+
def _confirm(e=None):
|
|
381
|
+
new = var.get().strip()
|
|
382
|
+
if new and new != old and new not in self._tabs:
|
|
383
|
+
content = self._contents.pop(old, "")
|
|
384
|
+
self._tabs[idx] = new
|
|
385
|
+
self._contents[new] = content
|
|
386
|
+
self._rebuild_tabs()
|
|
387
|
+
self._save_state()
|
|
388
|
+
win.destroy()
|
|
389
|
+
|
|
390
|
+
ent.bind("<Return>", _confirm)
|
|
391
|
+
ent.bind("<Escape>", lambda e: win.destroy())
|
|
392
|
+
win.bind("<FocusOut>", lambda e: win.destroy())
|
|
393
|
+
|
|
394
|
+
def _on_change(self, _e=None) -> None:
|
|
395
|
+
self._update_stats()
|
|
396
|
+
self._schedule_save()
|
|
397
|
+
|
|
398
|
+
def _update_stats(self) -> None:
|
|
399
|
+
content = self._text.get("1.0", "end-1c")
|
|
400
|
+
words = len(re.findall(r"\S+", content))
|
|
401
|
+
chars = len(content)
|
|
402
|
+
lines = content.count("\n") + 1 if content else 0
|
|
403
|
+
with contextlib.suppress(tk.TclError):
|
|
404
|
+
self._stats_lbl.config(
|
|
405
|
+
text=f"{words} palavras - {chars} chars - {lines} linhas"
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
def _clear(self, _e=None) -> None:
|
|
409
|
+
self._text.delete("1.0", "end")
|
|
410
|
+
self._on_change()
|
|
411
|
+
|
|
412
|
+
def _toggle_search(self, _e=None) -> None:
|
|
413
|
+
if self._search_visible:
|
|
414
|
+
self._hide_search()
|
|
415
|
+
else:
|
|
416
|
+
self._search_frame.pack(after=self._tabs_frame, fill="x")
|
|
417
|
+
self._search_visible = True
|
|
418
|
+
self._search_entry.focus_set()
|
|
419
|
+
return "break"
|
|
420
|
+
|
|
421
|
+
def _hide_search(self, _e=None) -> None:
|
|
422
|
+
self._search_frame.pack_forget()
|
|
423
|
+
self._search_visible = False
|
|
424
|
+
self._text.tag_remove("search_hi", "1.0", "end")
|
|
425
|
+
self._match_lbl.config(text="")
|
|
426
|
+
self._text.focus_set()
|
|
427
|
+
|
|
428
|
+
def _do_search(self, next_match: bool = False) -> None:
|
|
429
|
+
q = self._search_var.get()
|
|
430
|
+
self._text.tag_remove("search_hi", "1.0", "end")
|
|
431
|
+
if not q:
|
|
432
|
+
self._match_lbl.config(text="")
|
|
433
|
+
return
|
|
434
|
+
count = 0
|
|
435
|
+
start = "1.0"
|
|
436
|
+
first = None
|
|
437
|
+
while True:
|
|
438
|
+
pos = self._text.search(q, start, nocase=True, stopindex="end")
|
|
439
|
+
if not pos:
|
|
440
|
+
break
|
|
441
|
+
end = f"{pos}+{len(q)}c"
|
|
442
|
+
self._text.tag_add("search_hi", pos, end)
|
|
443
|
+
if first is None:
|
|
444
|
+
first = pos
|
|
445
|
+
count += 1
|
|
446
|
+
start = end
|
|
447
|
+
self._match_lbl.config(
|
|
448
|
+
text=f"{count} resultado{'s' if count != 1 else ''}")
|
|
449
|
+
if first:
|
|
450
|
+
self._text.see(first)
|
|
451
|
+
|
|
452
|
+
def _quick_insert_menu(self, event: tk.Event) -> None:
|
|
453
|
+
t = self._tmgr.theme
|
|
454
|
+
menu = tk.Menu(
|
|
455
|
+
self,
|
|
456
|
+
tearoff=False,
|
|
457
|
+
bg=t.floating_bg,
|
|
458
|
+
fg=t.fg,
|
|
459
|
+
activebackground=t.sel_bg,
|
|
460
|
+
activeforeground=t.sel_fg,
|
|
461
|
+
relief="flat",
|
|
462
|
+
bd=0,
|
|
463
|
+
)
|
|
464
|
+
now = datetime.now()
|
|
465
|
+
menu.add_command(
|
|
466
|
+
label=f"📅 Data: {now.strftime('%d/%m/%Y')}",
|
|
467
|
+
command=lambda: self._insert(now.strftime("%d/%m/%Y")),
|
|
468
|
+
)
|
|
469
|
+
menu.add_command(
|
|
470
|
+
label=f"🕐 Data+Hora: {now.strftime('%d/%m/%Y %H:%M')}",
|
|
471
|
+
command=lambda: self._insert(now.strftime("%d/%m/%Y %H:%M")),
|
|
472
|
+
)
|
|
473
|
+
menu.add_separator()
|
|
474
|
+
menu.add_command(
|
|
475
|
+
label=_t("scratchpad.separator"),
|
|
476
|
+
command=lambda: self._insert("\n" + "-" * 40 + "\n"),
|
|
477
|
+
)
|
|
478
|
+
menu.add_command(
|
|
479
|
+
label=_t("scratchpad.title_block"),
|
|
480
|
+
command=lambda: self._insert("\n" + "=" * 40 + "\n"),
|
|
481
|
+
)
|
|
482
|
+
menu.add_separator()
|
|
483
|
+
menu.add_command(
|
|
484
|
+
label=_t("scratchpad.task_open"), command=lambda: self._insert("[ ] ")
|
|
485
|
+
)
|
|
486
|
+
menu.add_command(
|
|
487
|
+
label=_t("scratchpad.task_done"), command=lambda: self._insert("[x] ")
|
|
488
|
+
)
|
|
489
|
+
try:
|
|
490
|
+
menu.tk_popup(event.x_root, event.y_root)
|
|
491
|
+
finally:
|
|
492
|
+
menu.grab_release()
|
|
493
|
+
|
|
494
|
+
def _insert(self, text: str) -> None:
|
|
495
|
+
try:
|
|
496
|
+
self._text.insert("insert", text)
|
|
497
|
+
except tk.TclError:
|
|
498
|
+
self._text.insert("end", text)
|
|
499
|
+
self._on_change()
|
|
500
|
+
|
|
501
|
+
def _export(self, _e=None) -> None:
|
|
502
|
+
name = self._tabs[self._active] if self._tabs else "rascunho"
|
|
503
|
+
content = self._text.get("1.0", "end-1c")
|
|
504
|
+
path = filedialog.asksaveasfilename(
|
|
505
|
+
defaultextension=".txt",
|
|
506
|
+
filetypes=[("Texto", "*.txt"),
|
|
507
|
+
("Markdown", "*.md"), ("Todos", "*.*")],
|
|
508
|
+
initialfile=f"{name}.txt",
|
|
509
|
+
title=_t("scratchpad.export_title", "Exportar bloco de notas"),
|
|
510
|
+
)
|
|
511
|
+
if path:
|
|
512
|
+
with contextlib.suppress(OSError):
|
|
513
|
+
Path(path).write_text(content, encoding="utf-8")
|
|
514
|
+
|
|
515
|
+
def _tooltip(self, widget: tk.Widget, text: str) -> None:
|
|
516
|
+
tip: list[tk.Toplevel | None] = [None]
|
|
517
|
+
|
|
518
|
+
def _show(e):
|
|
519
|
+
t = self._tmgr.theme
|
|
520
|
+
tip[0] = tk.Toplevel(widget)
|
|
521
|
+
tip[0].wm_overrideredirect(True)
|
|
522
|
+
tip[0].wm_attributes("-topmost", True)
|
|
523
|
+
tk.Label(
|
|
524
|
+
tip[0],
|
|
525
|
+
text=text,
|
|
526
|
+
bg=t.floating_bg,
|
|
527
|
+
fg=t.fg,
|
|
528
|
+
font=(FONT_UI, 8),
|
|
529
|
+
padx=6,
|
|
530
|
+
pady=2,
|
|
531
|
+
).pack()
|
|
532
|
+
tip[0].geometry(f"+{e.x_root + 10}+{e.y_root + 14}")
|
|
533
|
+
|
|
534
|
+
def _hide(e):
|
|
535
|
+
if tip[0]:
|
|
536
|
+
with contextlib.suppress(tk.TclError):
|
|
537
|
+
tip[0].destroy()
|
|
538
|
+
tip[0] = None
|
|
539
|
+
|
|
540
|
+
widget.bind("<Enter>", _show)
|
|
541
|
+
widget.bind("<Leave>", _hide)
|
|
542
|
+
|
|
543
|
+
def apply_theme(self, t) -> None:
|
|
544
|
+
"""Aplica o tema ``t`` ao scratchpad."""
|
|
545
|
+
self.config(bg=t.sidebar_bg)
|
|
546
|
+
with contextlib.suppress(tk.TclError):
|
|
547
|
+
self._text.config(bg=t.editor_bg, fg=t.fg,
|
|
548
|
+
insertbackground=t.cursor)
|