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.
Files changed (329) hide show
  1. codis-1.1.1.dist-info/METADATA +194 -0
  2. codis-1.1.1.dist-info/RECORD +329 -0
  3. codis-1.1.1.dist-info/WHEEL +5 -0
  4. codis-1.1.1.dist-info/entry_points.txt +5 -0
  5. codis-1.1.1.dist-info/licenses/LICENSE +21 -0
  6. codis-1.1.1.dist-info/top_level.txt +2 -0
  7. run.py +190 -0
  8. src/__init__.py +1 -0
  9. src/__main__.py +81 -0
  10. src/_app_build.py +1507 -0
  11. src/_app_editor.py +1274 -0
  12. src/_app_kui.py +825 -0
  13. src/_app_lsp.py +625 -0
  14. src/_app_recovery.py +189 -0
  15. src/_app_settings.py +1385 -0
  16. src/_app_tools.py +2471 -0
  17. src/_app_webpreview.py +126 -0
  18. src/_font_safety.py +127 -0
  19. src/_shells.py +172 -0
  20. src/app.py +1488 -0
  21. src/chat/__init__.py +1 -0
  22. src/chat/adapters/__init__.py +33 -0
  23. src/chat/adapters/base.py +209 -0
  24. src/chat/adapters/discord.py +190 -0
  25. src/chat/adapters/http.py +78 -0
  26. src/chat/adapters/irc.py +360 -0
  27. src/chat/adapters/matrix.py +219 -0
  28. src/chat/adapters/mattermost.py +178 -0
  29. src/chat/adapters/mqtt.py +165 -0
  30. src/chat/adapters/slack.py +204 -0
  31. src/chat/adapters/telegram.py +117 -0
  32. src/chat/adapters/ws.py +154 -0
  33. src/chat/adapters/xmpp.py +337 -0
  34. src/chat/history.py +76 -0
  35. src/chat/models.py +207 -0
  36. src/chat/probe.py +79 -0
  37. src/chat/session.py +446 -0
  38. src/chat/util.py +125 -0
  39. src/collab/__init__.py +1 -0
  40. src/collab/net.py +411 -0
  41. src/collab/ot.py +311 -0
  42. src/collab/session.py +141 -0
  43. src/collab/tk_adapter.py +134 -0
  44. src/config.py +335 -0
  45. src/constants.py +2552 -0
  46. src/dep_catalog.py +446 -0
  47. src/diff/__init__.py +1 -0
  48. src/diff/engine.py +247 -0
  49. src/dpi.py +30 -0
  50. src/editor/__init__.py +1 -0
  51. src/editor/_pane_lsp.py +2937 -0
  52. src/editor/_pane_utils.py +171 -0
  53. src/editor/autocomplete.py +607 -0
  54. src/editor/code_folding.py +836 -0
  55. src/editor/color_preview.py +382 -0
  56. src/editor/complexity_lens.py +281 -0
  57. src/editor/diff_pane.py +623 -0
  58. src/editor/file_watcher.py +144 -0
  59. src/editor/focus_block.py +236 -0
  60. src/editor/heatmap.py +141 -0
  61. src/editor/inlay_hints.py +366 -0
  62. src/editor/inline_blame.py +429 -0
  63. src/editor/kdocs.py +3376 -0
  64. src/editor/large_file.py +488 -0
  65. src/editor/ligatures.py +180 -0
  66. src/editor/line_numbers.py +598 -0
  67. src/editor/minimap.py +691 -0
  68. src/editor/multi_cursor.py +269 -0
  69. src/editor/pane.py +2082 -0
  70. src/editor/rhythm.py +206 -0
  71. src/editor/save_hooks.py +43 -0
  72. src/editor/smart_selection.py +425 -0
  73. src/editor/smart_tips.py +719 -0
  74. src/editor/snippets.py +411 -0
  75. src/editor/sticky_note_gutter.py +410 -0
  76. src/editor/sticky_scroll.py +385 -0
  77. src/editor/suggest.py +464 -0
  78. src/editor/text_transforms.py +310 -0
  79. src/editor/vim_mode.py +1074 -0
  80. src/events/__init__.py +84 -0
  81. src/events/bus.py +427 -0
  82. src/events/correlator.py +244 -0
  83. src/events/kinds.py +125 -0
  84. src/events/pipeline.py +264 -0
  85. src/events/stream.py +416 -0
  86. src/events/window.py +204 -0
  87. src/extcompat/__init__.py +19 -0
  88. src/extcompat/code/__init__.py +13 -0
  89. src/extcompat/code/consent.py +162 -0
  90. src/extcompat/code/host.py +353 -0
  91. src/extcompat/code/hosts/py_host.py +763 -0
  92. src/extcompat/code/locate.py +105 -0
  93. src/extcompat/code/manager.py +325 -0
  94. src/extcompat/code/permissions.py +154 -0
  95. src/extcompat/code/sandbox.py +60 -0
  96. src/extcompat/colors.py +131 -0
  97. src/extcompat/common.py +184 -0
  98. src/extcompat/cson.py +269 -0
  99. src/extcompat/formats/__init__.py +22 -0
  100. src/extcompat/formats/_tm.py +189 -0
  101. src/extcompat/formats/_util.py +31 -0
  102. src/extcompat/formats/base16.py +66 -0
  103. src/extcompat/formats/brackets.py +172 -0
  104. src/extcompat/formats/eclipse.py +193 -0
  105. src/extcompat/formats/emacs.py +361 -0
  106. src/extcompat/formats/geany.py +147 -0
  107. src/extcompat/formats/generic.py +184 -0
  108. src/extcompat/formats/gtksource.py +117 -0
  109. src/extcompat/formats/helix.py +91 -0
  110. src/extcompat/formats/jetbrains.py +343 -0
  111. src/extcompat/formats/kate.py +130 -0
  112. src/extcompat/formats/micro.py +131 -0
  113. src/extcompat/formats/nano.py +111 -0
  114. src/extcompat/formats/notepadpp.py +140 -0
  115. src/extcompat/formats/pulsar.py +165 -0
  116. src/extcompat/formats/pyides.py +163 -0
  117. src/extcompat/formats/sublime.py +340 -0
  118. src/extcompat/jsonc.py +65 -0
  119. src/extcompat/lessish.py +128 -0
  120. src/extcompat/manager.py +122 -0
  121. src/extcompat/market/__init__.py +63 -0
  122. src/extcompat/market/sources.py +211 -0
  123. src/extcompat/model.py +88 -0
  124. src/extcompat/net.py +228 -0
  125. src/extcompat/openvsx.py +63 -0
  126. src/extcompat/readers.py +362 -0
  127. src/extcompat/registry.py +73 -0
  128. src/extcompat/safexml.py +63 -0
  129. src/extcompat/sexp.py +187 -0
  130. src/extcompat/sources.py +105 -0
  131. src/extcompat/store.py +276 -0
  132. src/extcompat/textmate.py +214 -0
  133. src/extcompat/themes.py +487 -0
  134. src/extcompat/yamlite.py +294 -0
  135. src/fileio.py +94 -0
  136. src/fs_ops.py +106 -0
  137. src/i18n.py +233 -0
  138. src/ia/__init__.py +1 -0
  139. src/ia/actions.py +295 -0
  140. src/ia/approval_gate.py +672 -0
  141. src/ia/checkpoints.py +308 -0
  142. src/ia/context_builder.py +921 -0
  143. src/ia/dialdiff.py +408 -0
  144. src/ia/iaspace.py +2078 -0
  145. src/ia/pair.py +296 -0
  146. src/ia/providers.py +954 -0
  147. src/ia/session.py +335 -0
  148. src/ia/toolbox.py +2524 -0
  149. src/launcher_actions.py +204 -0
  150. src/lint/__init__.py +1 -0
  151. src/lint/manager.py +1058 -0
  152. src/locales/.translate_manifest.json +64170 -0
  153. src/locales/de.json +4936 -0
  154. src/locales/en.json +4936 -0
  155. src/locales/es.json +4936 -0
  156. src/locales/fr.json +4936 -0
  157. src/locales/it.json +4936 -0
  158. src/locales/ja.json +4936 -0
  159. src/locales/ko.json +4936 -0
  160. src/locales/nl.json +4936 -0
  161. src/locales/pl.json +4936 -0
  162. src/locales/pt-BR.json +4936 -0
  163. src/locales/ru.json +4936 -0
  164. src/locales/tr.json +4936 -0
  165. src/locales/uk.json +4936 -0
  166. src/locales/zh-CN.json +4936 -0
  167. src/lsp/__init__.py +26 -0
  168. src/lsp/client.py +2300 -0
  169. src/lsp/dap_client.py +480 -0
  170. src/lsp/edits.py +84 -0
  171. src/lsp/framing.py +73 -0
  172. src/lsp/protocol.py +931 -0
  173. src/main.py +260 -0
  174. src/memtrim.py +91 -0
  175. src/plugins/__init__.py +1 -0
  176. src/plugins/api.py +1761 -0
  177. src/plugins/loader.py +571 -0
  178. src/plugins/process_runner.py +519 -0
  179. src/plugins/registry.py +342 -0
  180. src/plugins/safety.py +367 -0
  181. src/plugins/startup.py +195 -0
  182. src/plugins/store.py +1178 -0
  183. src/proc_registry.py +278 -0
  184. src/pyexec.py +394 -0
  185. src/recovery.py +259 -0
  186. src/stall_trace.py +92 -0
  187. src/standalone.py +1070 -0
  188. src/startup_profile.py +35 -0
  189. src/syntax/__init__.py +1 -0
  190. src/syntax/highlighter.py +776 -0
  191. src/syntax/patterns.py +584 -0
  192. src/system_profile.py +430 -0
  193. src/terminal/backends.py +658 -0
  194. src/terminal/internal.py +346 -0
  195. src/terminal/keys.py +138 -0
  196. src/terminal/palette.py +67 -0
  197. src/terminal/session.py +283 -0
  198. src/terminal/shells.py +79 -0
  199. src/terminal/view.py +489 -0
  200. src/terminal/vt.py +870 -0
  201. src/textfmt.py +22 -0
  202. src/theme/__init__.py +1 -0
  203. src/theme/base.py +1281 -0
  204. src/theme/colors.py +49 -0
  205. src/theme/manager.py +602 -0
  206. src/theme/utils.py +312 -0
  207. src/toolbox.py +329 -0
  208. src/trash_core.py +531 -0
  209. src/ui/__init__.py +1 -0
  210. src/ui/_perf_utils.py +285 -0
  211. src/ui/_persistence_utils.py +93 -0
  212. src/ui/accessibility.py +843 -0
  213. src/ui/activity_bar.py +860 -0
  214. src/ui/app_embed.py +434 -0
  215. src/ui/archive_panel.py +608 -0
  216. src/ui/bookmarks.py +314 -0
  217. src/ui/breadcrumb.py +383 -0
  218. src/ui/calculator_panel.py +982 -0
  219. src/ui/calendar_panel.py +1218 -0
  220. src/ui/chat_panel.py +1271 -0
  221. src/ui/chat_profile_dialog.py +278 -0
  222. src/ui/chat_render.py +128 -0
  223. src/ui/clock_panel.py +810 -0
  224. src/ui/code_outline.py +364 -0
  225. src/ui/code_runner.py +729 -0
  226. src/ui/code_stats.py +546 -0
  227. src/ui/collab_panel.py +1009 -0
  228. src/ui/color_picker.py +547 -0
  229. src/ui/command_palette.py +452 -0
  230. src/ui/cursor_manager.py +750 -0
  231. src/ui/custom_keywords_panel.py +413 -0
  232. src/ui/debug_panel.py +1037 -0
  233. src/ui/dependency_graph.py +692 -0
  234. src/ui/diff_panel.py +381 -0
  235. src/ui/docs_panel.py +514 -0
  236. src/ui/doom_embed.py +349 -0
  237. src/ui/dropdown.py +321 -0
  238. src/ui/easter_eggs.py +979 -0
  239. src/ui/env_manager.py +666 -0
  240. src/ui/extcode_bridge.py +215 -0
  241. src/ui/extcode_dialogs.py +412 -0
  242. src/ui/extcompat_dialog.py +583 -0
  243. src/ui/file_timeline.py +319 -0
  244. src/ui/file_tree.py +1208 -0
  245. src/ui/find_in_files.py +1355 -0
  246. src/ui/flowchart_panel.py +727 -0
  247. src/ui/formatter_panel.py +490 -0
  248. src/ui/git_auth.py +763 -0
  249. src/ui/git_clone_dialog.py +487 -0
  250. src/ui/git_panel.py +1483 -0
  251. src/ui/grab_safe.py +84 -0
  252. src/ui/internal_python_dialog.py +98 -0
  253. src/ui/k_ui/__init__.py +1305 -0
  254. src/ui/k_ui/_bgrenderer.py +317 -0
  255. src/ui/k_ui/_colors.py +213 -0
  256. src/ui/k_ui/_dock.py +545 -0
  257. src/ui/k_ui/_easter.py +290 -0
  258. src/ui/k_ui/_engine.py +5448 -0
  259. src/ui/k_ui/_perf.py +333 -0
  260. src/ui/k_ui/_tkutil.py +7 -0
  261. src/ui/k_ui/_tooltip.py +365 -0
  262. src/ui/k_ui/_widgets.py +1204 -0
  263. src/ui/k_ui/_world.py +837 -0
  264. src/ui/key_remapper.py +856 -0
  265. src/ui/launcher.py +1252 -0
  266. src/ui/lazy_panel.py +73 -0
  267. src/ui/macro_recorder.py +610 -0
  268. src/ui/menu_bar.py +898 -0
  269. src/ui/output_panel.py +321 -0
  270. src/ui/paint_canvas.py +1000 -0
  271. src/ui/paint_engine.py +535 -0
  272. src/ui/paint_panel.py +888 -0
  273. src/ui/panel_detach.py +112 -0
  274. src/ui/performance_panel.py +861 -0
  275. src/ui/pip_manager.py +1758 -0
  276. src/ui/plugin_panel.py +1586 -0
  277. src/ui/pomodoro_panel.py +447 -0
  278. src/ui/problems.py +566 -0
  279. src/ui/process_manager.py +1657 -0
  280. src/ui/project_templates.py +775 -0
  281. src/ui/recovery_dialog.py +122 -0
  282. src/ui/regex_playground.py +304 -0
  283. src/ui/remote_adapters.py +1398 -0
  284. src/ui/remote_browser.py +1224 -0
  285. src/ui/remote_profile_dialog.py +342 -0
  286. src/ui/render_panel.py +1293 -0
  287. src/ui/rest_client.py +549 -0
  288. src/ui/scratchpad.py +548 -0
  289. src/ui/search_bar.py +1274 -0
  290. src/ui/settings_editor.py +3349 -0
  291. src/ui/settings_window.py +1554 -0
  292. src/ui/snippets_panel.py +597 -0
  293. src/ui/sql_studio.py +1815 -0
  294. src/ui/status_bar.py +438 -0
  295. src/ui/tab_bar.py +654 -0
  296. src/ui/task_manager.py +1773 -0
  297. src/ui/terminal.py +525 -0
  298. src/ui/theme_preview_panel.py +851 -0
  299. src/ui/thread_safe_tk.py +152 -0
  300. src/ui/time_tracker.py +574 -0
  301. src/ui/tkbind.py +43 -0
  302. src/ui/todo_panel.py +358 -0
  303. src/ui/toolbox_panels.py +658 -0
  304. src/ui/trash_manager.py +657 -0
  305. src/ui/ui_scale.py +294 -0
  306. src/ui/ux_enhancements.py +41 -0
  307. src/ui/web_preview.py +397 -0
  308. src/ui/webdev.py +630 -0
  309. src/ui/welcome.py +567 -0
  310. src/ui/window_embed.py +1500 -0
  311. src/ui/wizard.py +1550 -0
  312. src/ui/workspace_switcher.py +418 -0
  313. src/ui/workspace_trust.py +370 -0
  314. src/ui/zen_audio.py +354 -0
  315. src/ui/zen_media.py +2271 -0
  316. src/ui/zen_media_client.py +303 -0
  317. src/ui/zen_media_host.py +329 -0
  318. src/ui/zen_player.py +907 -0
  319. src/ui/zen_player_widgets.py +700 -0
  320. src/updater/__init__.py +11 -0
  321. src/updater/assets.py +145 -0
  322. src/updater/backup.py +101 -0
  323. src/updater/channel.py +221 -0
  324. src/updater/dialog.py +492 -0
  325. src/updater/integrity.py +111 -0
  326. src/updater/manager.py +727 -0
  327. src/updater/result.py +114 -0
  328. src/venv_runtime.py +531 -0
  329. src/workspace_state.py +25 -0
@@ -0,0 +1,215 @@
1
+ """Liga o código de uma extensão (em outro processo) ao editor: documento ativo, edições, diálogos e paleta."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import contextlib
6
+ import logging
7
+ import threading
8
+ import tkinter as tk
9
+ from collections.abc import Callable
10
+ from tkinter import messagebox, simpledialog
11
+ from typing import Any
12
+
13
+ from src.i18n import _t
14
+ from src.plugins.registry import CommandInfo
15
+
16
+ logger = logging.getLogger("Codis.ExtCode")
17
+
18
+ UI_WAIT_SECONDS = 900 # o usuário pode demorar para responder a uma pergunta da extensão
19
+
20
+
21
+ def _utf16_col(line: str, col: int) -> int:
22
+ """Coluna do Tk (caracteres) em unidades UTF-16, como as APIs de origem contam."""
23
+ return sum(2 if ord(ch) > 0xFFFF else 1 for ch in line[:col])
24
+
25
+
26
+ class TkBridge:
27
+ """Implementa ``CodeBridge``. Todos os métodos podem ser chamados de threads de apoio."""
28
+
29
+ def __init__(self, app: Any) -> None:
30
+ self._app = app
31
+
32
+ # --- execução na thread da interface ---------------------------------------------------
33
+
34
+ def _on_ui(self, fn: Callable[[], Any]) -> Any:
35
+ done = threading.Event()
36
+ box: dict[str, Any] = {}
37
+
38
+ def run() -> None:
39
+ try:
40
+ box["value"] = fn()
41
+ except BaseException as exc: # repassado à thread que pediu
42
+ box["error"] = exc
43
+ finally:
44
+ done.set()
45
+
46
+ self._app._root.after(0, run)
47
+ if not done.wait(UI_WAIT_SECONDS):
48
+ raise TimeoutError("a interface não respondeu a tempo")
49
+ if "error" in box:
50
+ raise box["error"]
51
+ return box.get("value")
52
+
53
+ # --- CodeBridge ------------------------------------------------------------------------
54
+
55
+ def context(self) -> dict[str, Any]:
56
+ return self._on_ui(self._snapshot)
57
+
58
+ def _snapshot(self) -> dict[str, Any]:
59
+ app = self._app
60
+ workspace = [str(app._workspace)] if getattr(app, "_workspace", None) else []
61
+ pane = getattr(app, "_active_pane", None)
62
+ if pane is None or not hasattr(pane, "text"):
63
+ return {"document": None, "selections": [], "workspace": workspace}
64
+ widget = pane.text
65
+ text = widget.get("1.0", "end-1c")
66
+ lines = text.split("\n")
67
+
68
+ def pos(index: str) -> dict[str, int]:
69
+ line, col = (int(x) for x in widget.index(index).split("."))
70
+ line = min(line, len(lines))
71
+ return {"line": line - 1, "character": _utf16_col(lines[line - 1], col)}
72
+
73
+ ranges = widget.tag_ranges("sel")
74
+ if ranges:
75
+ selection = {"start": pos(str(ranges[0])), "end": pos(str(ranges[1]))}
76
+ else:
77
+ cursor = pos("insert")
78
+ selection = {"start": cursor, "end": dict(cursor)}
79
+ document = {"text": text, "path": str(pane.path) if pane.path else None, "lang": pane.lang, "dirty": False}
80
+ return {"document": document, "selections": [selection], "workspace": workspace}
81
+
82
+ def request(self, ext_id: str, op: str, payload: dict[str, Any]) -> Any:
83
+ handler = getattr(self, f"_req_{op}", None)
84
+ if handler is None:
85
+ raise ValueError(f"pedido não suportado: {op}")
86
+ return handler(ext_id, payload)
87
+
88
+ def event(self, ext_id: str, op: str, payload: dict[str, Any]) -> None:
89
+ if op == "status":
90
+ text = str(payload.get("text") or "")
91
+ if text:
92
+ self._notify(text[:200], "info")
93
+ elif op == "error":
94
+ text = str(payload.get("text") or "")
95
+ self._app._root.after(0, lambda: messagebox.showerror(self._title(ext_id), text, parent=self._app._root))
96
+ elif op == "unsupported":
97
+ logger.info("Extensão %s usou uma API sem suporte: %s", ext_id, payload.get("api"))
98
+
99
+ # --- pedidos ---------------------------------------------------------------------------
100
+
101
+ def _title(self, ext_id: str) -> str:
102
+ return _t("extcode.dialog_title", "Extensão: {id}", id=ext_id)
103
+
104
+ def _notify(self, text: str, level: str) -> None:
105
+ status = getattr(self._app, "_status", None)
106
+ if status is not None:
107
+ self._app._root.after(0, lambda: status.notify(text, 4000, level))
108
+
109
+ def _req_edit(self, ext_id: str, payload: dict[str, Any]) -> dict[str, Any]:
110
+ edits = payload.get("edits")
111
+ if not isinstance(edits, list):
112
+ raise ValueError("edições inválidas")
113
+
114
+ def apply() -> dict[str, Any]:
115
+ pane = getattr(self._app, "_active_pane", None)
116
+ if pane is None:
117
+ raise RuntimeError("não há arquivo aberto no editor")
118
+ pane.apply_lsp_edits(edits)
119
+ return {"ok": True, "text": pane.text.get("1.0", "end-1c")}
120
+
121
+ return self._on_ui(apply)
122
+
123
+ def _req_message(self, ext_id: str, payload: dict[str, Any]) -> int | None:
124
+ level, text = str(payload.get("level") or "info"), str(payload.get("text") or "")
125
+ items = [str(i) for i in payload.get("items") or []]
126
+ if not items:
127
+ self._notify(text[:300], {"warning": "warn", "error": "error"}.get(level, "info"))
128
+ return None
129
+ return self._on_ui(lambda: _choice(self._app._root, self._title(ext_id), text, items))
130
+
131
+ def _req_input(self, ext_id: str, payload: dict[str, Any]) -> str | None:
132
+ def ask() -> str | None:
133
+ return simpledialog.askstring(
134
+ self._title(ext_id), str(payload.get("prompt") or ""), initialvalue=str(payload.get("value") or ""),
135
+ show="*" if payload.get("password") else "", parent=self._app._root,
136
+ )
137
+
138
+ return self._on_ui(ask)
139
+
140
+ def _req_pick(self, ext_id: str, payload: dict[str, Any]) -> Any:
141
+ items = [str(i) for i in payload.get("items") or []]
142
+ title = str(payload.get("title") or self._title(ext_id))
143
+ return self._on_ui(lambda: _pick(self._app._root, title, items, bool(payload.get("multi"))))
144
+
145
+ def _req_clipboard(self, ext_id: str, payload: dict[str, Any]) -> str | None:
146
+ root = self._app._root
147
+
148
+ def run() -> str | None:
149
+ if payload.get("op") == "write":
150
+ root.clipboard_clear()
151
+ root.clipboard_append(str(payload.get("text") or ""))
152
+ return None
153
+ with contextlib.suppress(tk.TclError):
154
+ return root.clipboard_get()
155
+ return ""
156
+
157
+ return self._on_ui(run)
158
+
159
+
160
+ def _choice(root: tk.Misc, title: str, text: str, items: list[str]) -> int | None:
161
+ """Mensagem com um botão por item; devolve o índice escolhido ou ``None`` se fechada."""
162
+ win = tk.Toplevel(root)
163
+ win.title(title)
164
+ win.transient(root)
165
+ result: list[int | None] = [None]
166
+ tk.Label(win, text=text, justify="left", wraplength=420, padx=16, pady=14).pack()
167
+ row = tk.Frame(win)
168
+ row.pack(padx=16, pady=(0, 12))
169
+ for i, label in enumerate(items):
170
+ tk.Button(row, text=label, padx=10, command=lambda i=i: (result.__setitem__(0, i), win.destroy())).pack(side="left", padx=4)
171
+ win.grab_set()
172
+ root.wait_window(win)
173
+ return result[0]
174
+
175
+
176
+ def _pick(root: tk.Misc, title: str, items: list[str], multi: bool) -> Any:
177
+ win = tk.Toplevel(root)
178
+ win.title(title)
179
+ win.transient(root)
180
+ win.geometry("420x360")
181
+ box = tk.Listbox(win, selectmode="extended" if multi else "browse", exportselection=False)
182
+ for item in items:
183
+ box.insert("end", item)
184
+ box.pack(fill="both", expand=True, padx=10, pady=10)
185
+ result: list[Any] = [None]
186
+
187
+ def accept(_e: object = None) -> None:
188
+ picked = list(box.curselection())
189
+ if picked:
190
+ result[0] = picked if multi else picked[0]
191
+ win.destroy()
192
+
193
+ box.bind("<Double-Button-1>", accept)
194
+ box.bind("<Return>", accept)
195
+ win.bind("<Escape>", lambda _e: win.destroy())
196
+ tk.Button(win, text=_t("extcode.ok", "OK"), command=accept, padx=14).pack(pady=(0, 10))
197
+ box.focus_set()
198
+ win.grab_set()
199
+ root.wait_window(win)
200
+ return result[0]
201
+
202
+
203
+ class AppCommandSink:
204
+ """Coloca os comandos da extensão na paleta do Codis e os tira de lá."""
205
+
206
+ def __init__(self, app: Any) -> None:
207
+ self._app = app
208
+
209
+ def add(self, owner: str, cmd_id: str, label: str, category: str, handler: Callable[[], Any]) -> None:
210
+ self._app._commands.register(
211
+ CommandInfo(id=cmd_id, label=label, handler=handler, owner=owner, category=category, doc="")
212
+ )
213
+
214
+ def remove(self, owner: str) -> None:
215
+ self._app._commands.remove_owner(owner)
@@ -0,0 +1,412 @@
1
+ """Diálogos da execução de código de extensões: avisos de risco, confirmações e saída do processo."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import contextlib
6
+ import os
7
+ import subprocess
8
+ import sys
9
+ import tkinter as tk
10
+ from collections.abc import Callable
11
+ from pathlib import Path
12
+ from typing import Any
13
+
14
+ from src.constants import FONT_MONO, FONT_UI
15
+ from src.extcompat import Extension
16
+ from src.extcompat.code import RISK_PHRASE, permissions, phrase_for, phrase_ok
17
+ from src.extcompat.code.locate import RuntimeInfo
18
+ from src.extcompat.code.sandbox import LaunchPlan
19
+ from src.i18n import _t
20
+
21
+ GLOBAL_WARNING = (
22
+ "Executar o código de uma extensão é um RISCO IMENSO.\n\n"
23
+ "Uma extensão é um programa. Ao executá-la, ela roda no seu computador com os seus privilégios e pode "
24
+ "enviar dados pela rede e, conforme as permissões que você conceder, ler, alterar e apagar arquivos e abrir "
25
+ "outros programas. O Codis a executa em um processo separado, com ambiente reduzido e limites, mas isso "
26
+ "reduz acidentes: NÃO é uma barreira segura contra código malicioso.\n\n"
27
+ "Por padrão cada extensão recebe o mínimo. Processos, arquivos, módulos nativos, variáveis de ambiente e a "
28
+ "remoção total do isolamento são permissões que você concede, uma a uma, em cada extensão.\n\n"
29
+ "Antes de sequer baixar uma extensão, leia e audite o código-fonte dela (repositório, dependências e "
30
+ "histórico) e confie no autor. Muitas extensões não vão funcionar: só uma parte pequena da API do "
31
+ "editor de origem é reproduzida."
32
+ )
33
+
34
+ RUN_WARNING = (
35
+ "O código abaixo vai ser executado no seu computador. Abra a pasta, leia os arquivos e só continue se "
36
+ "confiar nele. A confirmação vale para este conteúdo exato (impressão digital SHA-256) e para as "
37
+ "permissões marcadas: se qualquer arquivo mudar, o Codis pede de novo."
38
+ )
39
+
40
+ _RISK_TEXT = {
41
+ permissions.NONE: "Nível de risco: padrão. A extensão roda no isolamento básico.",
42
+ permissions.MEDIUM: "Nível de risco: médio.",
43
+ permissions.HIGH: "Nível de risco: ALTO.",
44
+ permissions.CRITICAL: "Nível de risco: CRÍTICO. Nada isola esta extensão do seu computador.",
45
+ }
46
+ _RISK_LABEL = {permissions.MEDIUM: "médio", permissions.HIGH: "alto", permissions.CRITICAL: "crítico"}
47
+
48
+
49
+ def open_folder(path: Path) -> None:
50
+ """Abre a pasta no gerenciador de arquivos do sistema, para o usuário auditar o código."""
51
+ with contextlib.suppress(OSError):
52
+ if sys.platform.startswith("win"):
53
+ os.startfile(path) # type: ignore[attr-defined] # noqa: S606
54
+ elif sys.platform == "darwin":
55
+ subprocess.Popen(["open", str(path)]) # noqa: S603, S607
56
+ else:
57
+ subprocess.Popen(["xdg-open", str(path)]) # noqa: S603, S607
58
+
59
+
60
+ class _ConfirmDialog(tk.Toplevel):
61
+ """Aviso com caixas de marcação e uma frase digitada; o botão só habilita com tudo certo."""
62
+
63
+ def __init__(
64
+ self,
65
+ parent: tk.Misc,
66
+ theme: Any,
67
+ *,
68
+ title: str,
69
+ warning: str,
70
+ details: str = "",
71
+ checks: list[str],
72
+ phrase: str,
73
+ action: str,
74
+ extra: list[tuple[str, Callable[[], None]]] | None = None,
75
+ ) -> None:
76
+ super().__init__(parent)
77
+ t = theme
78
+ self.result = False
79
+ self._phrase = phrase
80
+ self.title(title)
81
+ self.configure(bg=t.floating_bg)
82
+ self.geometry("680x620" if details else "680x500")
83
+ self.minsize(560, 420)
84
+ self.transient(parent)
85
+
86
+ tk.Label(
87
+ self, text=warning, justify="left", anchor="w", wraplength=640, bg=t.floating_bg, fg=t.err_fg,
88
+ font=(FONT_UI, 10, "bold"),
89
+ ).pack(fill="x", padx=16, pady=(14, 8))
90
+ if details:
91
+ box = tk.Text(
92
+ self, height=9, wrap="word", bd=0, highlightthickness=1, highlightbackground=t.border, bg=t.input_bg,
93
+ fg=t.fg, font=(FONT_MONO, 9), padx=8, pady=6,
94
+ )
95
+ box.insert("1.0", details)
96
+ box.configure(state="disabled")
97
+ box.pack(fill="both", expand=True, padx=16)
98
+
99
+ self._vars: list[tk.BooleanVar] = []
100
+ for text in checks:
101
+ var = tk.BooleanVar(value=False)
102
+ var.trace_add("write", lambda *_a: self._update())
103
+ self._vars.append(var)
104
+ tk.Checkbutton(
105
+ self, text=text, variable=var, justify="left", anchor="w", wraplength=620, bg=t.floating_bg, fg=t.fg,
106
+ selectcolor=t.input_bg, activebackground=t.floating_bg, activeforeground=t.fg, font=(FONT_UI, 9),
107
+ ).pack(fill="x", padx=16, pady=2)
108
+
109
+ tk.Label(
110
+ self, text=_t("extcode.type_phrase", "Para continuar, digite: {phrase}", phrase=phrase), anchor="w",
111
+ bg=t.floating_bg, fg=t.fg_muted, font=(FONT_UI, 9),
112
+ ).pack(fill="x", padx=16, pady=(10, 2))
113
+ self._entry_var = tk.StringVar()
114
+ self._entry_var.trace_add("write", lambda *_a: self._update())
115
+ entry = tk.Entry(
116
+ self, textvariable=self._entry_var, bg=t.input_bg, fg=t.fg, insertbackground=t.fg, relief="flat",
117
+ font=(FONT_UI, 10),
118
+ )
119
+ entry.pack(fill="x", padx=16, ipady=4)
120
+ entry.focus_set()
121
+
122
+ row = tk.Frame(self, bg=t.floating_bg)
123
+ row.pack(fill="x", padx=16, pady=12)
124
+ self._go = tk.Button(
125
+ row, text=action, command=self._accept, state="disabled", relief="flat", padx=14, pady=4,
126
+ bg=t.btn_primary, fg=t.btn_primary_fg, font=(FONT_UI, 9),
127
+ )
128
+ self._go.pack(side="right")
129
+ tk.Button(
130
+ row, text=_t("extcode.cancel", "Cancelar"), command=self.destroy, relief="flat", padx=14, pady=4,
131
+ bg=t.btn_bg, fg=t.btn_fg, font=(FONT_UI, 9),
132
+ ).pack(side="right", padx=6)
133
+ for label, fn in extra or []:
134
+ tk.Button(
135
+ row, text=label, command=fn, relief="flat", padx=12, pady=4, bg=t.btn_bg, fg=t.btn_fg, font=(FONT_UI, 9)
136
+ ).pack(side="left", padx=(0, 6))
137
+ self.bind("<Escape>", lambda _e: self.destroy())
138
+ self.grab_set()
139
+
140
+ def _update(self) -> None:
141
+ ok = all(v.get() for v in self._vars) and phrase_ok(self._entry_var.get(), self._phrase)
142
+ self._go.configure(state="normal" if ok else "disabled")
143
+
144
+ def _accept(self) -> None:
145
+ self.result = True
146
+ self.destroy()
147
+
148
+
149
+ class _ConsentDialog(tk.Toplevel):
150
+ """Confirmação por extensão: o usuário marca as permissões e o aviso, a frase e as declarações acompanham o risco."""
151
+
152
+ def __init__(
153
+ self,
154
+ parent: tk.Misc,
155
+ theme: Any,
156
+ *,
157
+ title: str,
158
+ details: str,
159
+ initial: frozenset[str],
160
+ hints: dict[str, list[str]],
161
+ runtime_notes: Callable[[frozenset[str]], tuple[str, ...]],
162
+ action: str,
163
+ extra: list[tuple[str, Callable[[], None]]] | None = None,
164
+ ) -> None:
165
+ super().__init__(parent)
166
+ self._t = t = theme
167
+ self.result: frozenset[str] | None = None
168
+ self._runtime_notes = runtime_notes
169
+ self.title(title)
170
+ self.configure(bg=t.floating_bg)
171
+ self.geometry("700x680")
172
+ self.minsize(580, 480)
173
+ self.transient(parent)
174
+
175
+ tk.Label(
176
+ self, text=_t("extcode.run_warning", RUN_WARNING), justify="left", anchor="w", wraplength=660,
177
+ bg=t.floating_bg, fg=t.err_fg, font=(FONT_UI, 10, "bold"),
178
+ ).pack(fill="x", padx=16, pady=(14, 8))
179
+
180
+ footer = tk.Frame(self, bg=t.floating_bg)
181
+ footer.pack(side="bottom", fill="x")
182
+ body = self._scrolling_body()
183
+
184
+ box = tk.Text(
185
+ body, height=8, wrap="word", bd=0, highlightthickness=1, highlightbackground=t.border, bg=t.input_bg,
186
+ fg=t.fg, font=(FONT_MONO, 9), padx=8, pady=6,
187
+ )
188
+ box.insert("1.0", details)
189
+ box.configure(state="disabled")
190
+ box.pack(fill="x", padx=16)
191
+
192
+ tk.Label(
193
+ body, text=_t("extcode.perm_title", "Permissões desta extensão"), anchor="w", bg=t.floating_bg, fg=t.fg,
194
+ font=(FONT_UI, 10, "bold"),
195
+ ).pack(fill="x", padx=16, pady=(12, 0))
196
+ tk.Label(
197
+ body, anchor="w", justify="left", wraplength=640, bg=t.floating_bg, fg=t.fg_muted, font=(FONT_UI, 9),
198
+ text=_t("extcode.perm_intro", "Sem nenhuma marcada, a extensão só lê a própria pasta, grava só nos próprios dados, "
199
+ "não abre processos nem carrega código nativo e recebe um ambiente sem credenciais."),
200
+ ).pack(fill="x", padx=16, pady=(0, 4))
201
+
202
+ self._perm_vars: dict[str, tk.BooleanVar] = {}
203
+ self._perm_boxes: dict[str, tk.Checkbutton] = {}
204
+ for perm in permissions.CATALOG:
205
+ var = tk.BooleanVar(value=perm.id in initial)
206
+ var.trace_add("write", lambda *_a: self._changed())
207
+ self._perm_vars[perm.id] = var
208
+ box_btn = tk.Checkbutton(
209
+ body, text=f"{perm.label} · risco {_RISK_LABEL[perm.risk]}", variable=var, anchor="w", justify="left",
210
+ bg=t.floating_bg, fg=t.err_fg if perm.risk != permissions.MEDIUM else t.warn_fg, selectcolor=t.input_bg,
211
+ activebackground=t.floating_bg, activeforeground=t.fg, font=(FONT_UI, 9, "bold"),
212
+ )
213
+ box_btn.pack(fill="x", padx=16, pady=(4, 0))
214
+ self._perm_boxes[perm.id] = box_btn
215
+ seen = hints.get(perm.id)
216
+ text = perm.grants + (f"\nO código parece usar isto: {', '.join(seen)}" if seen else "")
217
+ tk.Label(
218
+ body, text=text, anchor="w", justify="left", wraplength=620, bg=t.floating_bg, fg=t.fg_muted,
219
+ font=(FONT_UI, 9),
220
+ ).pack(fill="x", padx=(40, 16))
221
+
222
+ self._level = tk.Label(body, anchor="w", justify="left", wraplength=640, bg=t.floating_bg, font=(FONT_UI, 10, "bold"))
223
+ self._level.pack(fill="x", padx=16, pady=(12, 0))
224
+ self._danger = tk.Label(
225
+ body, anchor="w", justify="left", wraplength=640, bg=t.floating_bg, fg=t.fg, font=(FONT_UI, 9)
226
+ )
227
+ self._danger.pack(fill="x", padx=16)
228
+ self._notes = tk.Label(
229
+ body, anchor="w", justify="left", wraplength=640, bg=t.floating_bg, fg=t.warn_fg, font=(FONT_UI, 9, "bold")
230
+ )
231
+ self._notes.pack(fill="x", padx=16, pady=(4, 0))
232
+
233
+ # Declarações: as duas primeiras sempre; as demais aparecem conforme o nível de risco.
234
+ self._checks_frame = tk.Frame(body, bg=t.floating_bg)
235
+ self._checks_frame.pack(fill="x", padx=16, pady=(10, 8))
236
+ self._checks: list[tuple[str, tk.BooleanVar, tk.Checkbutton]] = []
237
+ for need, text in (
238
+ (permissions.NONE, _t("extcode.check_read", "Auditei o código desta extensão e confio nele (ou assumo o risco de não o ter feito).")),
239
+ (permissions.NONE, _t("extcode.check_power", "Entendo que ela pode usar a rede e agir com os meus privilégios dentro dos limites acima.")),
240
+ (permissions.HIGH, _t("extcode.check_perm", "Concedi cada permissão marcada de propósito e sei o que ela libera.")),
241
+ (permissions.CRITICAL, _t("extcode.check_wide", "Entendo que, sem isolamento, esta extensão pode fazer com o meu computador tudo o que eu posso fazer.")),
242
+ ):
243
+ var = tk.BooleanVar(value=False)
244
+ var.trace_add("write", lambda *_a: self._update())
245
+ widget = tk.Checkbutton(
246
+ self._checks_frame, text=text, variable=var, justify="left", anchor="w", wraplength=620, bg=t.floating_bg,
247
+ fg=t.fg, selectcolor=t.input_bg, activebackground=t.floating_bg, activeforeground=t.fg, font=(FONT_UI, 9),
248
+ )
249
+ self._checks.append((need, var, widget))
250
+
251
+ self._phrase_label = tk.Label(footer, anchor="w", bg=t.floating_bg, fg=t.fg_muted, font=(FONT_UI, 9))
252
+ self._phrase_label.pack(fill="x", padx=16, pady=(8, 2))
253
+ self._entry_var = tk.StringVar()
254
+ self._entry_var.trace_add("write", lambda *_a: self._update())
255
+ entry = tk.Entry(
256
+ footer, textvariable=self._entry_var, bg=t.input_bg, fg=t.fg, insertbackground=t.fg, relief="flat", font=(FONT_UI, 10)
257
+ )
258
+ entry.pack(fill="x", padx=16, ipady=4)
259
+ row = tk.Frame(footer, bg=t.floating_bg)
260
+ row.pack(fill="x", padx=16, pady=10)
261
+ self._go = tk.Button(
262
+ row, text=action, command=self._accept, state="disabled", relief="flat", padx=14, pady=4,
263
+ bg=t.btn_primary, fg=t.btn_primary_fg, font=(FONT_UI, 9),
264
+ )
265
+ self._go.pack(side="right")
266
+ tk.Button(
267
+ row, text=_t("extcode.cancel", "Cancelar"), command=self.destroy, relief="flat", padx=14, pady=4,
268
+ bg=t.btn_bg, fg=t.btn_fg, font=(FONT_UI, 9),
269
+ ).pack(side="right", padx=6)
270
+ for label, fn in extra or []:
271
+ tk.Button(row, text=label, command=fn, relief="flat", padx=12, pady=4, bg=t.btn_bg, fg=t.btn_fg, font=(FONT_UI, 9)).pack(
272
+ side="left", padx=(0, 6)
273
+ )
274
+ self.bind("<Escape>", lambda _e: self.destroy())
275
+ self._changed()
276
+ entry.focus_set()
277
+ self.grab_set()
278
+
279
+ def _scrolling_body(self) -> tk.Frame:
280
+ """Área central rolável: com todas as permissões e declarações a janela não cabe em telas pequenas."""
281
+ t = self._t
282
+ holder = tk.Frame(self, bg=t.floating_bg)
283
+ holder.pack(fill="both", expand=True)
284
+ canvas = tk.Canvas(holder, bg=t.floating_bg, highlightthickness=0)
285
+ bar = tk.Scrollbar(holder, orient="vertical", command=canvas.yview)
286
+ canvas.configure(yscrollcommand=bar.set)
287
+ bar.pack(side="right", fill="y")
288
+ canvas.pack(side="left", fill="both", expand=True)
289
+ inner = tk.Frame(canvas, bg=t.floating_bg)
290
+ window = canvas.create_window((0, 0), window=inner, anchor="nw")
291
+ inner.bind("<Configure>", lambda _e: canvas.configure(scrollregion=canvas.bbox("all")))
292
+ canvas.bind("<Configure>", lambda e: canvas.itemconfigure(window, width=e.width))
293
+
294
+ def wheel(event: tk.Event) -> None:
295
+ canvas.yview_scroll(-1 if (event.num == 4 or event.delta > 0) else 1, "units")
296
+
297
+ for seq in ("<MouseWheel>", "<Button-4>", "<Button-5>"):
298
+ self.bind_all(seq, wheel)
299
+ self.bind("<Destroy>", lambda e: [self.unbind_all(q) for q in ("<MouseWheel>", "<Button-4>", "<Button-5>")] if e.widget is self else None)
300
+ return inner
301
+
302
+ def _selected(self) -> frozenset[str]:
303
+ return frozenset(pid for pid, var in self._perm_vars.items() if var.get())
304
+
305
+ def _changed(self) -> None:
306
+ t = self._t
307
+ selected = self._selected()
308
+ wide = permissions.UNRESTRICTED in selected
309
+ for pid, widget in self._perm_boxes.items():
310
+ if pid != permissions.UNRESTRICTED:
311
+ widget.configure(state="disabled" if wide else "normal")
312
+ level = permissions.level(selected)
313
+ self._level.configure(
314
+ text=_t("extcode.risk_" + level, _RISK_TEXT[level]),
315
+ fg=t.ok_fg if level == permissions.NONE else (t.warn_fg if level == permissions.MEDIUM else t.err_fg),
316
+ )
317
+ danger = [permissions.BY_ID[p].danger for p in permissions.ordered(selected) if not (wide and p != permissions.UNRESTRICTED)]
318
+ self._danger.configure(text="\n".join(f"• {d}" for d in danger))
319
+ self._notes.configure(text="\n".join(self._runtime_notes(selected)))
320
+ needed = [(n, v, w) for n, v, w in self._checks if self._applies(n, level)]
321
+ for _n, _v, widget in self._checks:
322
+ widget.pack_forget()
323
+ for _n, _v, widget in needed:
324
+ widget.pack(fill="x", pady=2)
325
+ self._phrase_label.configure(text=_t("extcode.type_phrase", "Para continuar, digite: {phrase}", phrase=phrase_for(selected)))
326
+ self._update()
327
+
328
+ @staticmethod
329
+ def _applies(need: str, level: str) -> bool:
330
+ order = (permissions.NONE, permissions.MEDIUM, permissions.HIGH, permissions.CRITICAL)
331
+ return order.index(level) >= order.index(need)
332
+
333
+ def _update(self) -> None:
334
+ selected = self._selected()
335
+ level = permissions.level(selected)
336
+ checks_ok = all(v.get() for n, v, _w in self._checks if self._applies(n, level))
337
+ self._go.configure(state="normal" if checks_ok and phrase_ok(self._entry_var.get(), phrase_for(selected)) else "disabled")
338
+
339
+ def _accept(self) -> None:
340
+ self.result = self._selected()
341
+ self.destroy()
342
+
343
+
344
+ def ask_global_risk(parent: tk.Misc, theme: Any) -> bool:
345
+ """Liga a execução de código de extensões, depois de três confirmações e da frase de risco."""
346
+ dlg = _ConfirmDialog(
347
+ parent, theme,
348
+ title=_t("extcode.global_title", "Executar código de extensões"),
349
+ warning=_t("extcode.global_warning", GLOBAL_WARNING),
350
+ checks=[
351
+ _t("extcode.check_risk", "Entendo que isto representa um risco imenso para o meu computador e para os meus dados."),
352
+ _t("extcode.check_audit", "Vou auditar o código de cada extensão antes de baixá-la ou instalá-la."),
353
+ _t("extcode.check_assume", "Assumo todos os riscos de executar código de terceiros."),
354
+ ],
355
+ phrase=RISK_PHRASE,
356
+ action=_t("extcode.global_action", "Liberar execução de código"),
357
+ )
358
+ parent.wait_window(dlg)
359
+ return dlg.result
360
+
361
+
362
+ def ask_extension_consent(
363
+ parent: tk.Misc,
364
+ theme: Any,
365
+ ext: Extension,
366
+ runtime: RuntimeInfo,
367
+ digest: tuple[str, int, int],
368
+ plan_for: Callable[[frozenset[str]], LaunchPlan],
369
+ current: frozenset[str] = frozenset(),
370
+ ) -> frozenset[str] | None:
371
+ """Confirma a execução do código desta extensão e as permissões extras.
372
+
373
+ Devolve o conjunto de permissões escolhido (vazio é o isolamento básico) ou ``None`` se o usuário desistiu.
374
+ O conteúdo exato é identificado pelo SHA-256.
375
+ """
376
+ assert ext.code is not None
377
+ commands = "\n".join(f" • {c.title} [{c.id}]" for c in ext.code.commands[:25]) or " (nenhum comando declarado)"
378
+ details = (
379
+ f"Extensão: {ext.name} {ext.version} ({ext.id})\n"
380
+ f"Autor: {ext.publisher or '-'}\n"
381
+ f"Executa em: {runtime.path} (v{runtime.version})\n"
382
+ f"Entrada: {ext.code.entry}\n"
383
+ f"Arquivos: {digest[1]} ({digest[2] / 1024:.0f} KiB)\n"
384
+ f"SHA-256: {digest[0]}\n\n"
385
+ f"Comandos que irão para a paleta:\n{commands}\n"
386
+ )
387
+ dlg = _ConsentDialog(
388
+ parent, theme,
389
+ title=_t("extcode.run_title", "Executar o código desta extensão"),
390
+ details=details,
391
+ initial=current,
392
+ hints=permissions.detect(ext.path),
393
+ runtime_notes=lambda selected: plan_for(selected).notes,
394
+ action=_t("extcode.run_action", "Executar esta extensão"),
395
+ extra=[(_t("extcode.open_folder", "Abrir pasta para auditar"), lambda: open_folder(ext.path))],
396
+ )
397
+ parent.wait_window(dlg)
398
+ return dlg.result
399
+
400
+
401
+ def show_output(parent: tk.Misc, theme: Any, title: str, lines: list[str]) -> None:
402
+ t = theme
403
+ win = tk.Toplevel(parent)
404
+ win.title(title)
405
+ win.configure(bg=t.floating_bg)
406
+ win.geometry("720x420")
407
+ win.transient(parent)
408
+ box = tk.Text(win, wrap="word", bd=0, bg=t.input_bg, fg=t.fg, font=(FONT_MONO, 9), padx=8, pady=6)
409
+ box.insert("1.0", "\n".join(lines) or _t("extcode.no_output", "(sem saída até agora)"))
410
+ box.configure(state="disabled")
411
+ box.pack(fill="both", expand=True, padx=8, pady=8)
412
+ win.bind("<Escape>", lambda _e: win.destroy())