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
src/standalone.py ADDED
@@ -0,0 +1,1070 @@
1
+ """Codis - Modos Standalone.
2
+
3
+ Executa qualquer módulo do Codis de forma isolada, inicializando apenas as
4
+ dependências mínimas (tema, i18n, config). A maioria dos painéis é descrita em
5
+ _PANEL_REGISTRY como dados; apenas casos com UI extra (regex, player,
6
+ acessibilidade, color-picker, archive) têm funções próprias.
7
+
8
+ Uso:
9
+ python run.py --home Tela inicial (área de trabalho com atalhos)
10
+ python run.py --editor [arq] Editor completo (ignora a preferência startup_screen)
11
+ python run.py --player Zen Media Player
12
+ python run.py --pomodoro Pomodoro Timer
13
+ python run.py --scratch Bloco de Notas
14
+ python run.py --regex Regex Playground
15
+ python run.py --rest REST Client
16
+ python run.py --diff A B Diff Viewer (com arquivos opcionais)
17
+ python run.py --color-picker Seletor de Cores
18
+ python run.py --snippets Gerenciador de Snippets
19
+ python run.py --paint [img] Editor de Imagens
20
+ python run.py --accessibility Painel de Acessibilidade
21
+ python run.py --sql SQL Studio
22
+ python run.py --tasks Gerenciador de Tarefas
23
+ python run.py --pip Gerenciador de Pacotes Pip
24
+ python run.py --git [dir] Painel Git
25
+ python run.py --formatter Formatador JSON/YAML/TOML/XML
26
+ python run.py --env Variáveis de Ambiente
27
+ python run.py --calendar Calendário com Lembretes
28
+ python run.py --clock Relógio / Alarmes / Cronômetro
29
+ python run.py --calculator Calculadora Científica
30
+ python run.py --flowchart [file] Gerador de Fluxograma
31
+ python run.py --todo Lista de Tarefas Rápidas
32
+ python run.py --output Painel de Output
33
+ python run.py --terminal [dir] Terminal Integrado
34
+ python run.py --processes Gerenciador de Processos do Sistema
35
+ python run.py --render [file] Preview HTML/Markdown/SVG
36
+ python run.py --stats [dir] Estatísticas de Código
37
+ python run.py --plugins Gerenciador de Plugins
38
+ python run.py --ssh Conexão SSH Remota
39
+ python run.py --archive [file] Visualizador de Arquivo Compactado
40
+ python run.py --help Lista todos os modos
41
+
42
+ Ao fechar a janela standalone, o processo encerra automaticamente.
43
+ """
44
+
45
+ from __future__ import annotations
46
+
47
+ import contextlib
48
+ import logging
49
+ import sys
50
+ import tkinter as tk
51
+ from collections.abc import Callable
52
+ from pathlib import Path
53
+ from typing import Any
54
+
55
+ logger = logging.getLogger("Codis.Standalone")
56
+
57
+
58
+ def _bootstrap() -> tuple[tk.Tk, Any, Any]:
59
+ """Inicializa tema, config e i18n; retorna (root, tmgr, cfg).
60
+
61
+ Mantém root oculto - a janela do painel cuida de si mesma.
62
+ Os imports são locais para início rápido; apenas o necessário é
63
+ carregado antes do Tk().
64
+ """
65
+ from src.config import ConfigManager
66
+ from src.constants import CONFIG_DIR, PLUGINS_DIR, SNIPPETS_DIR, THEMES_DIR
67
+ from src.dpi import apply_windows_dpi_fix
68
+ from src.i18n import I18n
69
+ from src.syntax.patterns import _compile_all_patterns
70
+ from src.theme.base import _define_themes
71
+ from src.theme.manager import ThemeManager, _patch_all_themes, _patch_theme
72
+ from src.ui.thread_safe_tk import install as install_thread_safe_tk
73
+ from src.ui.ui_scale import UIScaler
74
+
75
+ for d in (CONFIG_DIR, PLUGINS_DIR, SNIPPETS_DIR, THEMES_DIR):
76
+ with contextlib.suppress(OSError):
77
+ d.mkdir(parents=True, exist_ok=True)
78
+
79
+ with contextlib.suppress(Exception):
80
+ _compile_all_patterns()
81
+
82
+ _define_themes()
83
+ _patch_all_themes()
84
+
85
+ root = tk.Tk()
86
+ root.withdraw()
87
+ install_thread_safe_tk(root)
88
+ apply_windows_dpi_fix(root)
89
+
90
+ cfg = ConfigManager()
91
+ with contextlib.suppress(Exception):
92
+ I18n.get_instance().set_locale(cfg.get("language", "pt-BR"))
93
+ tmgr = ThemeManager(cfg.get("theme", "fluent_dark"))
94
+ _patch_theme(tmgr.theme)
95
+ tmgr.apply_ttk()
96
+ try:
97
+ UIScaler(root, cfg).start()
98
+ except Exception as exc:
99
+ logger.warning("Escala da interface indisponível: %s", exc)
100
+
101
+ return root, tmgr, cfg
102
+
103
+
104
+ def _mainloop(root: tk.Tk, win: tk.Toplevel) -> None:
105
+ """Executa o mainloop e encerra o processo quando *win* for fechado."""
106
+
107
+ def _on_close() -> None:
108
+ with contextlib.suppress(tk.TclError):
109
+ win.destroy()
110
+ with contextlib.suppress(tk.TclError):
111
+ root.destroy()
112
+
113
+ win.protocol("WM_DELETE_WINDOW", _on_close)
114
+ win.deiconify()
115
+ win.focus_force()
116
+
117
+ def _poll() -> None:
118
+ if not win.winfo_exists():
119
+ with contextlib.suppress(tk.TclError):
120
+ root.destroy()
121
+ return
122
+ root.after(250, _poll)
123
+
124
+ root.after(250, _poll)
125
+ try:
126
+ root.mainloop()
127
+ except KeyboardInterrupt:
128
+ with contextlib.suppress(tk.TclError):
129
+ root.destroy()
130
+
131
+
132
+ def _fallback_label(win: tk.Toplevel, bg: str, fg: str, msg: str) -> None:
133
+ """Exibe mensagem de erro amigável quando um painel não está disponível."""
134
+ tk.Label(
135
+ win,
136
+ text=f"⚠ {msg}",
137
+ bg=bg,
138
+ fg=fg,
139
+ font=("Arial", 11),
140
+ justify="left",
141
+ padx=20,
142
+ pady=20,
143
+ ).pack(expand=True)
144
+
145
+
146
+ class _PanelSpec:
147
+ """Especificação de um painel standalone.
148
+
149
+ Attributes:
150
+ title_i18n: chave i18n para o título da janela.
151
+ title_def: título padrão (se i18n não encontrar).
152
+ geometry: string de geometria Tk (ex.: ``"1100x760"``).
153
+ bg_attr: atributo do Theme usado como bg da janela (ex.: ``"panel_bg"``).
154
+ cls_path: caminho dotted para a classe do painel (ex.: ``"src.ui.sql_studio.SQLStudioPanel"``).
155
+ resizable: tuple (w, h) para ``win.resizable()``.
156
+ post_build: callable(panel, win, root, cfg, path_arg) chamado após pack() do painel.
157
+ takes_cfg: ``False`` para painéis cujo construtor é ``(parent, tmgr)``, sem a config.
158
+ """
159
+
160
+ __slots__ = (
161
+ "title_i18n",
162
+ "title_def",
163
+ "geometry",
164
+ "bg_attr",
165
+ "cls_path",
166
+ "resizable",
167
+ "post_build",
168
+ "takes_cfg",
169
+ )
170
+
171
+ def __init__(
172
+ self,
173
+ title_i18n: str,
174
+ title_def: str,
175
+ geometry: str,
176
+ bg_attr: str = "panel_bg",
177
+ cls_path: str = "",
178
+ resizable: tuple[bool, bool] = (True, True),
179
+ post_build: Callable | None = None,
180
+ takes_cfg: bool = True,
181
+ ) -> None:
182
+ self.title_i18n = title_i18n
183
+ self.title_def = title_def
184
+ self.geometry = geometry
185
+ self.bg_attr = bg_attr
186
+ self.cls_path = cls_path
187
+ self.resizable = resizable
188
+ self.post_build = post_build
189
+ self.takes_cfg = takes_cfg
190
+
191
+
192
+ def _run_spec(spec: _PanelSpec, path_arg: str | None = None) -> None:
193
+ """Instancia e exibe um painel descrito por *spec*."""
194
+ from src.i18n import _t
195
+
196
+ root, tmgr, cfg = _bootstrap()
197
+ t = tmgr.theme
198
+ bg = getattr(t, spec.bg_attr, t.bg)
199
+
200
+ win = tk.Toplevel(root)
201
+ win.title(_t(spec.title_i18n, spec.title_def))
202
+ win.geometry(spec.geometry)
203
+ win.resizable(*spec.resizable)
204
+ win.config(bg=bg)
205
+
206
+ if spec.cls_path:
207
+ mod_path, cls_name = spec.cls_path.rsplit(".", 1)
208
+ try:
209
+ import importlib
210
+
211
+ mod = importlib.import_module(mod_path)
212
+ cls = getattr(mod, cls_name)
213
+ panel = cls(win, tmgr, cfg) if spec.takes_cfg else cls(win, tmgr)
214
+ panel.pack(fill="both", expand=True)
215
+ if spec.post_build:
216
+ spec.post_build(panel, win, root, cfg, path_arg)
217
+ except Exception as exc:
218
+ logger.warning("%s não disponível: %s", cls_name, exc)
219
+ _fallback_label(
220
+ win, bg, t.fg, f"{cls_name} não disponível:\n{exc}")
221
+
222
+ _mainloop(root, win)
223
+
224
+
225
+ def _post_fit(panel, win, *_args) -> None:
226
+ """post_build: ajusta minsize ao tamanho natural (para paineis fixos)."""
227
+ with contextlib.suppress(tk.TclError):
228
+ win.update_idletasks()
229
+ win.minsize(win.winfo_reqwidth(), win.winfo_reqheight())
230
+
231
+
232
+ def _post_load_file(panel, _win, _root, _cfg, path_arg) -> None:
233
+ """post_build: carrega arquivo se path_arg for fornecido."""
234
+ if path_arg:
235
+ fp = Path(path_arg)
236
+ if fp.exists():
237
+ with contextlib.suppress(Exception):
238
+ panel.load_file(str(fp))
239
+
240
+
241
+ def _post_workspace(panel, _win, _root, _cfg, path_arg) -> None:
242
+ """post_build: define workspace se path_arg for um diretório."""
243
+ if path_arg:
244
+ workdir = Path(path_arg).resolve()
245
+ with contextlib.suppress(Exception):
246
+ panel.set_workspace(workdir)
247
+
248
+
249
+ _REGISTRY: dict[str, _PanelSpec] = {
250
+ "--pomodoro": _PanelSpec(
251
+ "standalone.pomodoro.title",
252
+ "Codis - Pomodoro Timer",
253
+ "400x280",
254
+ "panel_bg",
255
+ "src.ui.pomodoro_panel.PomodoroPanel",
256
+ resizable=(False, False),
257
+ post_build=_post_fit,
258
+ ),
259
+ "--scratch": _PanelSpec(
260
+ "standalone.scratch.title",
261
+ "Codis - Bloco de Notas",
262
+ "720x540",
263
+ "sidebar_bg",
264
+ "src.ui.scratchpad.ScratchpadPane",
265
+ takes_cfg=False,
266
+ ),
267
+ "--rest": _PanelSpec(
268
+ "standalone.rest.title",
269
+ "Codis - REST Client",
270
+ "1050x720",
271
+ "panel_bg",
272
+ "src.ui.rest_client.RestClientPanel",
273
+ ),
274
+ "--sql": _PanelSpec(
275
+ "standalone.sql.title",
276
+ "Codis - SQL Studio",
277
+ "1100x760",
278
+ "panel_bg",
279
+ "src.ui.sql_studio.SQLStudioPanel",
280
+ ),
281
+ "--tasks": _PanelSpec(
282
+ "standalone.tasks.title",
283
+ "Codis - Gerenciador de Tarefas",
284
+ "1050x720",
285
+ "panel_bg",
286
+ "src.ui.task_manager.TaskManagerPanel",
287
+ ),
288
+ "--pip": _PanelSpec(
289
+ "standalone.pip.title",
290
+ "Codis - Pip Manager",
291
+ "1000x720",
292
+ "panel_bg",
293
+ "src.ui.pip_manager.PipManagerPanel",
294
+ ),
295
+ "--formatter": _PanelSpec(
296
+ "standalone.formatter.title",
297
+ "Codis - Formatter",
298
+ "1000x700",
299
+ "panel_bg",
300
+ "src.ui.formatter_panel.FormatterPanel",
301
+ ),
302
+ "--env": _PanelSpec(
303
+ "standalone.env.title",
304
+ "Codis - Variáveis de Ambiente",
305
+ "900x660",
306
+ "panel_bg",
307
+ "src.ui.env_manager.EnvManagerPanel",
308
+ ),
309
+ "--calendar": _PanelSpec(
310
+ "standalone.calendar.title",
311
+ "Codis - Calendário",
312
+ "820x640",
313
+ "panel_bg",
314
+ "src.ui.calendar_panel.CalendarPanel",
315
+ ),
316
+ "--clock": _PanelSpec(
317
+ "standalone.clock.title",
318
+ "Codis - Relógio",
319
+ "480x420",
320
+ "panel_bg",
321
+ "src.ui.clock_panel.ClockPanel",
322
+ ),
323
+ "--calculator": _PanelSpec(
324
+ "standalone.calculator.title",
325
+ "Codis - Calculadora",
326
+ "360x560",
327
+ "panel_bg",
328
+ "src.ui.calculator_panel.CalculatorPanel",
329
+ resizable=(False, True),
330
+ post_build=_post_fit,
331
+ ),
332
+ "--todo": _PanelSpec(
333
+ "standalone.todo.title",
334
+ "Codis - Todo",
335
+ "560x600",
336
+ "panel_bg",
337
+ "src.ui.todo_panel.TodoPanel",
338
+ ),
339
+ "--output": _PanelSpec(
340
+ "standalone.output.title",
341
+ "Codis - Output",
342
+ "900x600",
343
+ "panel_bg",
344
+ "src.ui.output_panel.OutputPanel",
345
+ ),
346
+ "--processes": _PanelSpec(
347
+ "standalone.processes.title",
348
+ "Codis - Processos do Sistema",
349
+ "1100x700",
350
+ "panel_bg",
351
+ "src.ui.process_manager.ProcessManagerPanel",
352
+ ),
353
+ "--flowchart": _PanelSpec(
354
+ "standalone.flowchart.title",
355
+ "Codis - Flowchart",
356
+ "1050x720",
357
+ "panel_bg",
358
+ "src.ui.flowchart_panel.FlowchartPanel",
359
+ post_build=_post_load_file,
360
+ ),
361
+ "--render": _PanelSpec(
362
+ "standalone.render.title",
363
+ "Codis - Preview",
364
+ "1000x720",
365
+ "panel_bg",
366
+ "src.ui.render_panel.RenderPanel",
367
+ post_build=_post_load_file,
368
+ ),
369
+ "--stats": _PanelSpec(
370
+ "standalone.stats.title",
371
+ "Codis - Estatísticas de Código",
372
+ "900x640",
373
+ "panel_bg",
374
+ "src.ui.code_stats.CodeStatsPanel",
375
+ post_build=_post_workspace,
376
+ ),
377
+ }
378
+
379
+ _REGISTRY["--preview"] = _REGISTRY["--render"]
380
+ _REGISTRY["--encode"] = _PanelSpec(
381
+ "standalone.encode.title",
382
+ "Codis - Codificadores",
383
+ "860x680",
384
+ "panel_bg",
385
+ "src.ui.toolbox_panels.EncodersPanel",
386
+ )
387
+ _REGISTRY["--generate"] = _PanelSpec(
388
+ "standalone.generate.title",
389
+ "Codis - Geradores",
390
+ "760x560",
391
+ "panel_bg",
392
+ "src.ui.toolbox_panels.GeneratorsPanel",
393
+ )
394
+ _REGISTRY["--hex"] = _PanelSpec(
395
+ "standalone.hex.title",
396
+ "Codis - Visualizador Hex",
397
+ "1000x680",
398
+ "panel_bg",
399
+ "src.ui.toolbox_panels.HexViewerPanel",
400
+ post_build=_post_load_file,
401
+ )
402
+ _REGISTRY["--serve"] = _PanelSpec(
403
+ "standalone.serve.title",
404
+ "Codis - Servidor Local",
405
+ "720x560",
406
+ "panel_bg",
407
+ "src.ui.toolbox_panels.ServerPanel",
408
+ post_build=_post_workspace,
409
+ )
410
+ _REGISTRY["--procs"] = _REGISTRY["--processes"]
411
+ _REGISTRY["--calc"] = _REGISTRY["--calculator"]
412
+
413
+
414
+ def run_player() -> None:
415
+ """Abre o Zen Player de forma standalone (janela flutuante)."""
416
+ from src.ui.zen_media import ZenMediaPlayer
417
+ from src.ui.zen_player import MODE_FLOATING, ZenPlayerHost
418
+
419
+ root, tmgr, cfg = _bootstrap()
420
+
421
+ player = ZenMediaPlayer(tk_root=root)
422
+ saved = cfg.get("zen_media_playlist", [])
423
+ if saved:
424
+ player.set_playlist(saved)
425
+ host = ZenPlayerHost(root, player, cfg, tmgr, dock_before=None,
426
+ on_minimize=None)
427
+ host.set_mode(MODE_FLOATING)
428
+ win = host._win
429
+
430
+ def _on_close() -> None:
431
+ player.shutdown()
432
+ host.destroy()
433
+ with contextlib.suppress(tk.TclError):
434
+ root.destroy()
435
+
436
+ if win is not None:
437
+ win.protocol("WM_DELETE_WINDOW", _on_close)
438
+ win.focus_force()
439
+
440
+ def _poll() -> None:
441
+ if win is None or not win.winfo_exists():
442
+ with contextlib.suppress(tk.TclError):
443
+ root.destroy()
444
+ return
445
+ root.after(300, _poll)
446
+
447
+ root.after(300, _poll)
448
+ try:
449
+ root.mainloop()
450
+ except KeyboardInterrupt:
451
+ player.stop()
452
+ with contextlib.suppress(tk.TclError):
453
+ root.destroy()
454
+
455
+
456
+ def run_regex() -> None:
457
+ """Abre o Regex Playground standalone com área de texto de teste."""
458
+ from src.constants import FONT_MONO, FONT_UI
459
+ from src.i18n import _t
460
+ from src.ui.regex_playground import RegexPlayground
461
+
462
+ root, tmgr, _ = _bootstrap()
463
+ t = tmgr.theme
464
+
465
+ win = tk.Toplevel(root)
466
+ win.title(_t("standalone.regex.title", "Codis - Regex Playground"))
467
+ win.geometry("900x640")
468
+ win.config(bg=t.panel_bg)
469
+
470
+ frame_text = tk.Frame(win, bg=t.panel_bg)
471
+ frame_text.pack(fill="both", expand=True, side="top", padx=8, pady=(8, 0))
472
+
473
+ tk.Label(
474
+ frame_text,
475
+ text=_t("standalone.regex.input_label", "Texto de teste:"),
476
+ bg=t.panel_bg,
477
+ fg=t.fg_muted,
478
+ font=(FONT_UI, 8),
479
+ ).pack(anchor="w")
480
+
481
+ test_text = tk.Text(
482
+ frame_text,
483
+ height=12,
484
+ bg=t.editor_bg,
485
+ fg=t.fg,
486
+ font=(FONT_MONO, 11),
487
+ relief="flat",
488
+ bd=0,
489
+ insertbackground=t.cursor,
490
+ highlightthickness=1,
491
+ highlightbackground=t.border,
492
+ )
493
+ test_text.pack(fill="both", expand=True, pady=(0, 4))
494
+
495
+ def _get_text() -> str:
496
+ return test_text.get("1.0", "end-1c")
497
+
498
+ def _apply_replace(pattern: str, replacement: str, flags: str) -> None:
499
+ import re
500
+
501
+ flag_val = 0
502
+ if "i" in flags:
503
+ flag_val |= re.IGNORECASE
504
+ if "m" in flags:
505
+ flag_val |= re.MULTILINE
506
+ new_content = re.sub(pattern, replacement, _get_text(), flags=flag_val)
507
+ test_text.delete("1.0", "end")
508
+ test_text.insert("1.0", new_content)
509
+
510
+ RegexPlayground(win, tmgr, get_text=_get_text, apply_replace=_apply_replace).pack(
511
+ fill="x", side="bottom"
512
+ )
513
+ _mainloop(root, win)
514
+
515
+
516
+ def run_diff(file_a: str | None = None, file_b: str | None = None) -> None:
517
+ """Abre o Diff Viewer standalone, com ou sem arquivos pré-carregados."""
518
+ from src.i18n import _t
519
+ from src.ui.diff_panel import DiffPanel
520
+
521
+ root, tmgr, cfg = _bootstrap()
522
+ t = tmgr.theme
523
+
524
+ win = tk.Toplevel(root)
525
+ win.title(_t("standalone.diff.title", "Codis - Diff Viewer"))
526
+ win.geometry("1150x720")
527
+ win.config(bg=t.editor_bg)
528
+
529
+ try:
530
+ pane = DiffPanel(win, tmgr, cfg)
531
+ pane.pack(fill="both", expand=True)
532
+ if file_a and file_b:
533
+ pa, pb = Path(file_a), Path(file_b)
534
+ if pa.exists() and pb.exists():
535
+ pane.load_files(str(pa), str(pb))
536
+ except Exception as exc:
537
+ logger.warning("DiffPanel não disponível: %s", exc)
538
+ _fallback_label(win, t.editor_bg, t.fg, f"Diff não disponível:\n{exc}")
539
+
540
+ _mainloop(root, win)
541
+
542
+
543
+ def _center_host(root: tk.Tk) -> tk.Toplevel:
544
+ """Janela de 1x1 pixel no centro da tela para servir de pai a diálogos.
545
+
546
+ A raiz fica oculta e um diálogo ``transient`` de uma janela oculta pode nem aparecer;
547
+ um pai visível também faz o diálogo abrir centralizado em vez de no canto da tela.
548
+ """
549
+ host = tk.Toplevel(root)
550
+ host.overrideredirect(True)
551
+ host.geometry(f"1x1+{root.winfo_screenwidth() // 2}+{root.winfo_screenheight() // 2}")
552
+ host.update_idletasks()
553
+ return host
554
+
555
+
556
+ def run_color_picker() -> None:
557
+ """Abre o Color Picker standalone; \"Inserir\" copia a cor escolhida para a área de transferência."""
558
+ from src.ui.color_picker import ColorPickerPopup
559
+
560
+ root, tmgr, _ = _bootstrap()
561
+
562
+ def _copy(color: str) -> None:
563
+ with contextlib.suppress(tk.TclError):
564
+ root.clipboard_clear()
565
+ root.clipboard_append(color)
566
+ root.update()
567
+
568
+ try:
569
+ popup = ColorPickerPopup(_center_host(root), tmgr, "#4f9eff", _copy)
570
+ except Exception as exc:
571
+ logger.warning("ColorPicker não disponível: %s", exc)
572
+ with contextlib.suppress(tk.TclError):
573
+ root.destroy()
574
+ return
575
+ _mainloop(root, popup)
576
+
577
+
578
+ def run_snippets() -> None:
579
+ """Abre o Gerenciador de Snippets standalone."""
580
+ from src.editor.snippets import SnippetEngine
581
+ from src.i18n import _t
582
+ from src.ui.snippets_panel import SnippetsPanel
583
+
584
+ root, tmgr, _ = _bootstrap()
585
+ t = tmgr.theme
586
+ try:
587
+ engine = SnippetEngine()
588
+ win = tk.Toplevel(root)
589
+ win.title(_t("standalone.snippets.title", "Codis - Snippets"))
590
+ win.geometry("820x620")
591
+ win.config(bg=t.panel_bg)
592
+ SnippetsPanel(win, tmgr, engine, get_editor=lambda: None).pack(
593
+ fill="both", expand=True
594
+ )
595
+ _mainloop(root, win)
596
+ except Exception as exc:
597
+ logger.warning("SnippetsPanel não disponível: %s", exc)
598
+ with contextlib.suppress(tk.TclError):
599
+ root.destroy()
600
+
601
+
602
+ def run_paint(image_path: str | None = None) -> None:
603
+ """Abre o Editor de Imagens standalone."""
604
+ from src.i18n import _t
605
+ from src.ui.paint_panel import PaintPanel
606
+
607
+ root, tmgr, _ = _bootstrap()
608
+ t = tmgr.theme
609
+ win = tk.Toplevel(root)
610
+ win.title(_t("standalone.paint.title", "Codis - Editor de Imagens"))
611
+ win.geometry("1000x700")
612
+ win.config(bg=t.panel_bg)
613
+ initial = Path(image_path) if image_path else None
614
+ PaintPanel(win, tmgr, initial_path=initial).pack(fill="both", expand=True)
615
+ _mainloop(root, win)
616
+
617
+
618
+ def run_accessibility() -> None:
619
+ """Abre o painel de Acessibilidade standalone."""
620
+ from src.ui.accessibility import AccessibilityManager, AccessibilityPanel
621
+
622
+ root, tmgr, cfg = _bootstrap()
623
+ try:
624
+ mgr = AccessibilityManager(None, cfg, tmgr)
625
+ win = AccessibilityPanel(_center_host(root), mgr, tmgr)
626
+ except Exception as exc:
627
+ logger.warning("AccessibilityPanel não disponível: %s", exc)
628
+ with contextlib.suppress(tk.TclError):
629
+ root.destroy()
630
+ return
631
+ _mainloop(root, win)
632
+
633
+
634
+ def run_git(directory: str | None = None) -> None:
635
+ """Abre o Painel Git standalone, opcionalmente em um diretório."""
636
+ from src.i18n import _t
637
+ from src.ui.git_panel import GitPanel
638
+
639
+ root, tmgr, cfg = _bootstrap()
640
+ t = tmgr.theme
641
+ workdir = Path(directory).resolve() if directory else Path.cwd()
642
+ win = tk.Toplevel(root)
643
+ win.title(_t("standalone.git.title", "Codis - Git"))
644
+ win.geometry("900x700")
645
+ win.config(bg=t.panel_bg)
646
+ GitPanel(win, tmgr, cfg, root_path=workdir).pack(fill="both", expand=True)
647
+ _mainloop(root, win)
648
+
649
+
650
+ def run_terminal(cwd: str | None = None) -> None:
651
+ """Abre o Terminal integrado standalone."""
652
+ from src.i18n import _t
653
+ from src.ui.terminal import TerminalPanel
654
+
655
+ root, tmgr, cfg = _bootstrap()
656
+ t = tmgr.theme
657
+ workdir = Path(cwd).resolve() if cwd else Path.cwd()
658
+ win = tk.Toplevel(root)
659
+ win.title(_t("standalone.terminal.title", "Codis - Terminal"))
660
+ win.geometry("1000x640")
661
+ win.config(bg=t.terminal_bg)
662
+ TerminalPanel(win, tmgr, cfg, cwd=str(workdir)
663
+ ).pack(fill="both", expand=True)
664
+ _mainloop(root, win)
665
+
666
+
667
+ def run_plugins() -> None:
668
+ """Abre o Gerenciador de Plugins standalone."""
669
+ from src.i18n import _t
670
+ from src.plugins.loader import PluginLoader
671
+ from src.ui.plugin_panel import PluginPanel
672
+
673
+ root, tmgr, cfg = _bootstrap()
674
+ t = tmgr.theme
675
+ win = tk.Toplevel(root)
676
+ win.title(_t("standalone.plugins.title", "Codis - Plugins"))
677
+ win.geometry("1050x720")
678
+ win.config(bg=t.panel_bg)
679
+ try:
680
+ loader = PluginLoader(cfg)
681
+ PluginPanel(win, tmgr, loader, cfg).pack(fill="both", expand=True)
682
+ except Exception as exc:
683
+ logger.warning("PluginPanel não disponível: %s", exc)
684
+ _fallback_label(win, t.panel_bg, t.fg,
685
+ f"Plugins não disponível:\n{exc}")
686
+ _mainloop(root, win)
687
+
688
+
689
+ def _open_in_editor(target: str, line: int | None = None) -> None:
690
+ """Abre ``target`` (e a linha, se houver) numa janela do editor, sem bloquear a ferramenta."""
691
+ from src.pyexec import spawn_codis
692
+
693
+ spec = f"{target}:{line}" if line else str(target)
694
+ with contextlib.suppress(OSError):
695
+ spawn_codis(["--editor", spec])
696
+
697
+
698
+ def _standalone_dialog(window: tk.Toplevel) -> tk.Toplevel:
699
+ """Solta uma janela do vínculo ``transient`` com a raiz oculta.
700
+
701
+ Janelas feitas para o editor se declaram filhas da janela principal; aqui a raiz
702
+ fica escondida e, em alguns sistemas, a filha de uma janela escondida também some.
703
+ """
704
+ with contextlib.suppress(tk.TclError):
705
+ window.wm_transient("")
706
+ return window
707
+
708
+
709
+ def _tool_window(root: tk.Tk, tmgr: Any, title: str, size: str) -> tk.Toplevel:
710
+ win = tk.Toplevel(root)
711
+ win.title(title)
712
+ win.geometry(size)
713
+ win.config(bg=tmgr.theme.panel_bg)
714
+ return win
715
+
716
+
717
+ def run_settings() -> None:
718
+ """Abre a janela de Configurações do Codis."""
719
+ from src.ui.settings_window import SettingsWindow
720
+
721
+ root, tmgr, cfg = _bootstrap()
722
+ _mainloop(root, _standalone_dialog(SettingsWindow(root, tmgr, cfg)))
723
+
724
+
725
+ def run_trash(directory: str | None = None) -> None:
726
+ """Abre a Lixeira do Codis para uma pasta."""
727
+ from src.i18n import _t
728
+ from src.ui.trash_manager import TrashPanel
729
+
730
+ root, tmgr, cfg = _bootstrap()
731
+ workdir = Path(directory).resolve() if directory else Path.cwd()
732
+ win = _tool_window(root, tmgr, _t("standalone.trash.title", "Codis - Lixeira"), "760x560")
733
+ TrashPanel(win, tmgr, cfg, workspace=workdir).pack(fill="both", expand=True)
734
+ _mainloop(root, win)
735
+
736
+
737
+ def run_time() -> None:
738
+ """Abre o painel de tempo de código."""
739
+ from src.i18n import _t
740
+ from src.ui.time_tracker import TimeTrackerModel, TimeTrackerPanel
741
+
742
+ root, tmgr, _cfg = _bootstrap()
743
+ win = _tool_window(root, tmgr, _t("standalone.time.title", "Codis - Tempo de código"), "560x640")
744
+ TimeTrackerPanel(win, tmgr, TimeTrackerModel()).pack(fill="both", expand=True)
745
+ _mainloop(root, win)
746
+
747
+
748
+ def run_performance() -> None:
749
+ """Abre a janela do modo desempenho."""
750
+ from src.ui.performance_panel import PerformancePanel
751
+
752
+ root, tmgr, cfg = _bootstrap()
753
+ _mainloop(root, _standalone_dialog(PerformancePanel(root, cfg, tmgr)))
754
+
755
+
756
+ def run_deps(directory: str | None = None) -> None:
757
+ """Abre o grafo de dependências Python de uma pasta."""
758
+ from src.i18n import _t
759
+ from src.ui.dependency_graph import DependencyGraphPanel
760
+
761
+ root, tmgr, _cfg = _bootstrap()
762
+ workdir = Path(directory).resolve() if directory else Path.cwd()
763
+ win = _tool_window(root, tmgr, _t("standalone.deps.title", "Codis - Dependências") + f" - {workdir.name}", "900x680")
764
+ DependencyGraphPanel(
765
+ win, tmgr, workspace=workdir, on_open_file=lambda path: _open_in_editor(str(path))
766
+ ).pack(fill="both", expand=True)
767
+ _mainloop(root, win)
768
+
769
+
770
+ def run_search(directory: str | None = None) -> None:
771
+ """Busca texto ou expressão regular nos arquivos de uma pasta."""
772
+ from src.i18n import _t
773
+ from src.ui.find_in_files import FindInFilesPanel
774
+
775
+ root, tmgr, cfg = _bootstrap()
776
+ workdir = Path(directory).resolve() if directory else Path.cwd()
777
+ win = _tool_window(root, tmgr, _t("standalone.search.title", "Codis - Buscar em arquivos") + f" - {workdir.name}", "860x640")
778
+ FindInFilesPanel(
779
+ win,
780
+ tmgr,
781
+ cfg,
782
+ get_root=lambda: workdir,
783
+ get_editor=lambda: None,
784
+ on_open=lambda path, line=None: _open_in_editor(str(path), line),
785
+ ).pack(fill="both", expand=True)
786
+ _mainloop(root, win)
787
+
788
+
789
+ def run_new_project() -> None:
790
+ """Cria um projeto a partir de um template e o abre no editor."""
791
+ from src.ui.project_templates import ProjectTemplateDialog, TemplateStore
792
+
793
+ root, tmgr, cfg = _bootstrap()
794
+ dialog = ProjectTemplateDialog(
795
+ root, tmgr, TemplateStore(), on_open=lambda path: _open_in_editor(str(path)), cfg=cfg
796
+ )
797
+ _mainloop(root, _standalone_dialog(dialog))
798
+
799
+
800
+ def run_ssh() -> None:
801
+ """Abre o explorador de arquivos remotos standalone."""
802
+ from src.i18n import _t
803
+ from src.ui.remote_browser import RemoteBrowserPanel
804
+
805
+ root, tmgr, cfg = _bootstrap()
806
+ t = tmgr.theme
807
+ win = tk.Toplevel(root)
808
+ win.title(_t("rbrowser.window_title", "Codis - Arquivos Remotos"))
809
+ from src.ui.remote_browser import fit_toplevel
810
+
811
+ fit_toplevel(win, 1050, 700)
812
+ win.config(bg=t.sidebar_bg)
813
+ try:
814
+ RemoteBrowserPanel(win, tmgr, cfg).pack(fill="both", expand=True)
815
+ except Exception as exc:
816
+ logger.warning("RemoteBrowserPanel não disponível: %s", exc)
817
+ _fallback_label(
818
+ win, t.panel_bg, t.fg, f"Explorador remoto não disponível:\n{exc}"
819
+ )
820
+ _mainloop(root, win)
821
+
822
+
823
+ def run_archive(file_path: str | None = None) -> None:
824
+ """Abre o Visualizador de Arquivos Compactados standalone."""
825
+ from tkinter import filedialog
826
+
827
+ from src.i18n import _t
828
+ from src.ui.archive_panel import ArchivePanel
829
+
830
+ root, tmgr, _ = _bootstrap()
831
+ t = tmgr.theme
832
+
833
+ if not file_path:
834
+ root.deiconify()
835
+ chosen = filedialog.askopenfilename(
836
+ title=_t("standalone.archive.pick_title",
837
+ "Abrir arquivo compactado"),
838
+ filetypes=[
839
+ (
840
+ _t("standalone.archive.filetypes_arch", "Arquivos Compactados"),
841
+ "*.zip *.tar *.tar.gz *.tar.bz2 *.tar.xz *.gz *.7z *.rar",
842
+ ),
843
+ (_t("standalone.archive.filetypes_all", "Todos os arquivos"), "*.*"),
844
+ ],
845
+ )
846
+ root.withdraw()
847
+ if not chosen:
848
+ root.destroy()
849
+ return
850
+ file_path = chosen
851
+
852
+ fp = Path(file_path)
853
+ if not fp.exists():
854
+ logger.error("Arquivo não encontrado: %s", fp)
855
+ root.destroy()
856
+ return
857
+
858
+ win = tk.Toplevel(root)
859
+ win.title(
860
+ _t("standalone.archive.title", "Codis - Visualizador de Arquivo")
861
+ + f" - {fp.name}"
862
+ )
863
+ win.geometry("900x640")
864
+ win.config(bg=t.panel_bg)
865
+ try:
866
+ ArchivePanel(win, fp, on_open_file=None).pack(fill="both", expand=True)
867
+ except Exception as exc:
868
+ logger.warning("ArchivePanel não disponível: %s", exc)
869
+ _fallback_label(win, t.panel_bg, t.fg,
870
+ f"Visualizador não disponível:\n{exc}")
871
+ _mainloop(root, win)
872
+
873
+
874
+ def _make_registry_runner(flag: str) -> Callable:
875
+ def _run(path_arg: str | None = None) -> None:
876
+ _run_spec(_REGISTRY[flag], path_arg)
877
+
878
+ return _run
879
+
880
+
881
+ def run_home() -> None:
882
+ """Abre a tela inicial: uma área de trabalho com atalhos para o editor e as ferramentas."""
883
+ from src.ui.launcher import LauncherPanel
884
+
885
+ root, tmgr, cfg = _bootstrap()
886
+ win = tk.Toplevel(root)
887
+ LauncherPanel(win, tmgr, cfg).pack(fill="both", expand=True)
888
+ _mainloop(root, win)
889
+
890
+
891
+ _SPECIAL: dict[str, Callable] = {
892
+ "--home": run_home,
893
+ "--player": run_player,
894
+ "--regex": run_regex,
895
+ "--diff": run_diff,
896
+ "--color-picker": run_color_picker,
897
+ "--snippets": run_snippets,
898
+ "--paint": run_paint,
899
+ "--accessibility": run_accessibility,
900
+ "--a11y": run_accessibility,
901
+ "--git": run_git,
902
+ "--terminal": run_terminal,
903
+ "--plugins": run_plugins,
904
+ "--ssh": run_ssh,
905
+ "--archive": run_archive,
906
+ "--settings": run_settings,
907
+ "--trash": run_trash,
908
+ "--time": run_time,
909
+ "--performance": run_performance,
910
+ "--deps": run_deps,
911
+ "--search": run_search,
912
+ "--new-project": run_new_project,
913
+ }
914
+
915
+ run_pomodoro = _make_registry_runner("--pomodoro")
916
+ run_scratch = _make_registry_runner("--scratch")
917
+ run_rest = _make_registry_runner("--rest")
918
+ run_sql = _make_registry_runner("--sql")
919
+ run_tasks = _make_registry_runner("--tasks")
920
+ run_pip = _make_registry_runner("--pip")
921
+ run_formatter = _make_registry_runner("--formatter")
922
+ run_env = _make_registry_runner("--env")
923
+ run_calendar = _make_registry_runner("--calendar")
924
+ run_clock = _make_registry_runner("--clock")
925
+ run_calculator = _make_registry_runner("--calculator")
926
+ run_todo = _make_registry_runner("--todo")
927
+ run_output = _make_registry_runner("--output")
928
+ run_processes = _make_registry_runner("--processes")
929
+ run_flowchart = _make_registry_runner("--flowchart")
930
+ run_render = _make_registry_runner("--render")
931
+ run_stats = _make_registry_runner("--stats")
932
+
933
+ _ALL_MODES: dict[str, str] = {
934
+ "--home": "Tela Inicial (área de trabalho)",
935
+ "--player": "Zen Media Player",
936
+ "--pomodoro": "Pomodoro Timer",
937
+ "--scratch": "Bloco de Notas",
938
+ "--regex": "Regex Playground",
939
+ "--rest": "REST Client",
940
+ "--diff": "Diff Viewer [A B]",
941
+ "--color-picker": "Seletor de Cores",
942
+ "--snippets": "Gerenciador de Snippets",
943
+ "--paint": "Editor de Imagens [img]",
944
+ "--accessibility": "Painel de Acessibilidade (alias --a11y)",
945
+ "--sql": "SQL Studio",
946
+ "--tasks": "Gerenciador de Tarefas (Kanban)",
947
+ "--pip": "Gerenciador de Pacotes Pip",
948
+ "--git": "Painel Git [dir]",
949
+ "--formatter": "Formatador JSON/YAML/TOML/XML",
950
+ "--env": "Variáveis de Ambiente",
951
+ "--calendar": "Calendário com Lembretes",
952
+ "--clock": "Relógio / Alarmes / Cronômetro",
953
+ "--calculator": "Calculadora Científica (alias --calc)",
954
+ "--flowchart": "Gerador de Fluxograma [py]",
955
+ "--todo": "Lista de Tarefas Rápidas",
956
+ "--output": "Painel de Output",
957
+ "--terminal": "Terminal Integrado [dir]",
958
+ "--processes": "Gerenciador de Processos (alias --procs)",
959
+ "--render": "Preview HTML/Markdown/SVG [file] (alias --preview)",
960
+ "--stats": "Estatísticas de Código [dir]",
961
+ "--plugins": "Gerenciador de Plugins",
962
+ "--ssh": "Conexão SSH Remota",
963
+ "--archive": "Visualizador de Arquivo [file]",
964
+ "--encode": "Codificadores (Base64, URL, hash, JWT)",
965
+ "--generate": "Geradores (UUID, senha, lorem, timestamp)",
966
+ "--hex": "Visualizador Hex [file]",
967
+ "--serve": "Servidor Local com recarga [dir]",
968
+ "--search": "Buscar em Arquivos [dir]",
969
+ "--deps": "Grafo de Dependências [dir]",
970
+ "--trash": "Lixeira [dir]",
971
+ "--time": "Tempo de Código",
972
+ "--performance": "Modo Desempenho",
973
+ "--settings": "Configurações",
974
+ "--new-project": "Novo Projeto (templates)",
975
+ }
976
+
977
+
978
+ def _print_help() -> None:
979
+ w = 20
980
+ print()
981
+ print(" Codis - Modos Standalone")
982
+ print(" " + "─" * 54)
983
+ print(" Uso: python run.py [MODO] [ARGS]")
984
+ print()
985
+ for flag, desc in _ALL_MODES.items():
986
+ print(f" {flag:<{w}} {desc}")
987
+ print()
988
+ print(" Exemplos:")
989
+ print(" python run.py --sql")
990
+ print(" python run.py --diff antes.py depois.py")
991
+ print(" python run.py --git /meu/projeto")
992
+ print(" python run.py --paint foto.png")
993
+ print(" python run.py --render index.html")
994
+ print(" python run.py arquivo.py (abre no editor)")
995
+ print(" python run.py --editor (editor, mesmo com startup_screen = launcher)")
996
+ print()
997
+
998
+
999
+ def _starts_with_home() -> bool:
1000
+ """``True`` se a preferência ``startup_screen`` manda abrir pela tela inicial."""
1001
+ from src.config import ConfigManager
1002
+
1003
+ return ConfigManager().get("startup_screen", "editor") == "launcher"
1004
+
1005
+
1006
+ def dispatch(argv: list[str]) -> bool:
1007
+ """Verifica argv e executa o modo standalone correspondente.
1008
+
1009
+ Returns:
1010
+ True se um modo standalone foi executado (processo deve encerrar).
1011
+ False se nenhum modo foi identificado (execução normal do editor).
1012
+ """
1013
+ if "--editor" in argv:
1014
+ # Abre o editor completo mesmo com ``startup_screen = launcher``; a flag não é um arquivo.
1015
+ sys.argv[:] = [arg for arg in sys.argv if arg != "--editor"]
1016
+ return False
1017
+
1018
+ if not argv:
1019
+ if not _starts_with_home():
1020
+ return False
1021
+ run_home()
1022
+ return True
1023
+
1024
+ flag = argv[0].lower()
1025
+
1026
+ if flag in ("--help", "-h", "help"):
1027
+ _print_help()
1028
+ return True
1029
+
1030
+ logging.basicConfig(
1031
+ level=logging.WARNING,
1032
+ format="%(levelname)s %(name)s - %(message)s",
1033
+ )
1034
+
1035
+ if flag == "--diff":
1036
+ run_diff(
1037
+ argv[1] if len(argv) > 1 else None,
1038
+ argv[2] if len(argv) > 2 else None,
1039
+ )
1040
+ return True
1041
+
1042
+ _with_one_arg = {
1043
+ "--paint",
1044
+ "--git",
1045
+ "--flowchart",
1046
+ "--terminal",
1047
+ "--render",
1048
+ "--preview",
1049
+ "--stats",
1050
+ "--archive",
1051
+ "--hex",
1052
+ "--serve",
1053
+ "--search",
1054
+ "--deps",
1055
+ "--trash",
1056
+ }
1057
+ if flag in _with_one_arg:
1058
+ fn = _SPECIAL.get(flag) or _make_registry_runner(flag)
1059
+ fn(argv[1] if len(argv) > 1 else None)
1060
+ return True
1061
+
1062
+ if flag in _REGISTRY:
1063
+ _run_spec(_REGISTRY[flag])
1064
+ return True
1065
+
1066
+ if flag in _SPECIAL:
1067
+ _SPECIAL[flag]()
1068
+ return True
1069
+
1070
+ return False