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/theme/colors.py ADDED
@@ -0,0 +1,49 @@
1
+ """Operações puras sobre cores ``#rrggbb`` (sem dependência do Tk).
2
+
3
+ Reúne o que antes existia em cópias nos painéis: conversão hex/RGB, mistura e
4
+ clareamento. ``src.theme.utils`` reexporta :func:`hex_to_rgb` por compatibilidade.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+
10
+ def hex_to_rgb(color: str) -> tuple[int, int, int]:
11
+ """Converte ``#rgb`` ou ``#rrggbb`` (``#`` opcional) em ``(r, g, b)`` de 0 a 255.
12
+
13
+ Raises:
14
+ ValueError: se o texto não for uma cor hexadecimal válida.
15
+ """
16
+ digits = color.lstrip("#")
17
+ if len(digits) == 3:
18
+ digits = "".join(c * 2 for c in digits)
19
+ if len(digits) != 6:
20
+ raise ValueError(f"Cor hexadecimal inválida: {color!r}")
21
+ return int(digits[0:2], 16), int(digits[2:4], 16), int(digits[4:6], 16)
22
+
23
+
24
+ def rgb_to_hex(r: int, g: int, b: int) -> str:
25
+ """Converte ``(r, g, b)`` em ``#rrggbb`` minúsculo."""
26
+ return f"#{r:02x}{g:02x}{b:02x}"
27
+
28
+
29
+ def mix(start: str, end: str, amount: float) -> str:
30
+ """Mistura ``start`` com ``end``: ``0`` devolve ``start`` e ``1`` devolve ``end``.
31
+
32
+ Entradas inválidas devolvem ``start`` sem levantar, para que um tema com uma
33
+ cor malformada não derrube a interface.
34
+ """
35
+ try:
36
+ a, b = hex_to_rgb(start), hex_to_rgb(end)
37
+ except ValueError:
38
+ return start
39
+ amount = max(0.0, min(1.0, amount))
40
+ return rgb_to_hex(*(round(x + (y - x) * amount) for x, y in zip(a, b, strict=True)))
41
+
42
+
43
+ def lighten(color: str, amount: int = 20) -> str:
44
+ """Soma ``amount`` a cada canal (limitado a 255); cor inválida volta inalterada."""
45
+ try:
46
+ r, g, b = hex_to_rgb(color)
47
+ except ValueError:
48
+ return color
49
+ return rgb_to_hex(min(255, r + amount), min(255, g + amount), min(255, b + amount))
src/theme/manager.py ADDED
@@ -0,0 +1,602 @@
1
+ """Codis - gerenciamento de tema visual: ThemeManager e funções de patch TTK."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import contextlib
6
+ import logging
7
+ import tkinter as tk
8
+ from collections.abc import Callable
9
+ from pathlib import Path as _Path
10
+ from typing import TYPE_CHECKING
11
+ from typing import Any as _Any
12
+
13
+ from src.theme.base import THEME_ORDER, THEMES, Theme
14
+
15
+ if TYPE_CHECKING:
16
+ from tkinter import ttk
17
+
18
+ logger = logging.getLogger("Codis")
19
+
20
+ try:
21
+ from tkinter import ttk as _ttk
22
+
23
+ _TK_AVAILABLE = True
24
+ except ImportError:
25
+ _TK_AVAILABLE = False
26
+
27
+
28
+ class ThemeManager:
29
+ """Gerencia o tema visual ativo do Codis.
30
+
31
+ Mantém referência ao tema atual, notifica callbacks ao trocar de tema,
32
+ aplica estilos TTK via :meth:`apply_ttk` e rotaciona temas via :meth:`cycle`.
33
+
34
+ Args:
35
+ initial: Nome do tema inicial. Usa o primeiro disponível se não encontrado.
36
+
37
+ Example::
38
+
39
+ tmgr = ThemeManager("dracula")
40
+ tmgr.on_change(lambda t: print(f"Tema: {t.name}"))
41
+ tmgr.set("nord")
42
+ tmgr.cycle()
43
+ """
44
+
45
+ def __init__(self, initial: str = "fluent_dark") -> None:
46
+ """Inicializa o gerenciador com o tema ``initial``, caindo no primeiro disponível se ausente."""
47
+ self._change_callbacks: list[Callable[[Theme], None]] = []
48
+ name = (
49
+ initial
50
+ if initial in THEMES
51
+ else (THEME_ORDER[0] if THEME_ORDER else "fluent_dark")
52
+ )
53
+ self.theme: Theme = THEMES.get(name, Theme())
54
+ _patch_theme(self.theme)
55
+
56
+ def set(self, name: str) -> None:
57
+ """
58
+ Se o nome não estiver registrado em ``THEMES``, emite aviso e mantém o atual.
59
+
60
+ Args:
61
+ name: Nome do tema registrado em ``THEMES``.
62
+ """
63
+ if name not in THEMES:
64
+ logger.warning(
65
+ "Tema '%s' não encontrado - mantendo '%s'.", name, self.theme.name
66
+ )
67
+ return
68
+ self.theme = THEMES[name]
69
+ _patch_theme(self.theme)
70
+ self._notify()
71
+
72
+ def cycle(self) -> None:
73
+ """Avança para o próximo tema em ``THEME_ORDER`` de forma circular."""
74
+ if not THEME_ORDER:
75
+ return
76
+ try:
77
+ idx = THEME_ORDER.index(self.theme.name)
78
+ except ValueError:
79
+ idx = -1
80
+ next_name = THEME_ORDER[(idx + 1) % len(THEME_ORDER)]
81
+ self.set(next_name)
82
+
83
+ def on_change(self, callback: Callable[[Theme], None]) -> None:
84
+ """Registra um callback invocado com o novo ``Theme`` a cada troca de tema."""
85
+ if callback not in self._change_callbacks:
86
+ self._change_callbacks.append(callback)
87
+
88
+ def apply_ttk(self) -> None:
89
+ """Aplica o tema atual ao sistema de estilos TTK.
90
+
91
+ Deve ser chamado após cada troca de tema para que widgets como
92
+ ``ttk.Scrollbar``, ``ttk.Treeview`` e ``ttk.Combobox`` reflitam
93
+ as cores corretas. Erros de estilo são suprimidos silenciosamente.
94
+ """
95
+ if not _TK_AVAILABLE:
96
+ return
97
+ t = self.theme
98
+ with contextlib.suppress(tk.TclError):
99
+ style = _ttk.Style()
100
+ style.theme_use("clam")
101
+ _apply_ttk_styles(style, t)
102
+
103
+ def token_map(self) -> dict:
104
+ """
105
+ Mapa token -> cor para o realce de sintaxe (SyntaxHL / LANG_RE).
106
+
107
+ Os nomes dos tokens vêm de ``src/syntax/patterns.py``; quando um token não tem
108
+ cor própria, usa-se o atributo equivalente do tema.
109
+ """
110
+ t = self.theme
111
+ return {
112
+ "keyword": t.t_keyword,
113
+ "type_kw": t.t_type,
114
+ "string": t.t_string,
115
+ "string_tmpl": t.t_string,
116
+ "number": t.t_number,
117
+ "operator": t.t_operator,
118
+ "comment_line": t.t_comment,
119
+ "comment_block": t.t_comment,
120
+ "decorator": t.t_decorator,
121
+ "func_def": t.t_func,
122
+ "func_call": t.t_func,
123
+ "class_def": t.t_keyword,
124
+ "class_name": t.t_type,
125
+ "variable": t.t_variable or t.fg,
126
+ "builtin": t.t_builtin or t.t_func,
127
+ "tag_open": t.t_tag or t.t_keyword,
128
+ "attr_name": t.t_attr or t.t_func,
129
+ "doctype": t.t_comment,
130
+ "heading": t.t_heading or t.t_keyword,
131
+ "bold": t.t_func,
132
+ "italic": t.t_string,
133
+ "blockquote": t.t_comment,
134
+ "table": t.t_type,
135
+ "link": t.t_link or t.accent,
136
+ "bool": t.t_constant or t.t_number,
137
+ "escape": t.t_escape or t.t_string,
138
+ "regexp": t.t_regex or t.t_string,
139
+ "directive": t.t_keyword,
140
+ "section": t.t_heading or t.t_keyword,
141
+ "shebang": t.t_comment,
142
+ "storage": t.t_keyword,
143
+ }
144
+
145
+ def _notify(self) -> None:
146
+ """Notifica todos os callbacks registrados sobre mudança de tema."""
147
+ for cb in list(self._change_callbacks):
148
+ try:
149
+ cb(self.theme)
150
+ except Exception as exc:
151
+ logger.warning(
152
+ "Callback de tema falhou (%s): %s", getattr(
153
+ cb, "__name__", cb), exc
154
+ )
155
+
156
+
157
+ def _scaled_rowheight(base: int = 22) -> int:
158
+ """Altura de linha do Treeview respeitando a escala global da UI."""
159
+ from src.ui.ui_scale import px
160
+
161
+ return px(base)
162
+
163
+
164
+ def _apply_ttk_styles(style: ttk.Style, t: Theme) -> None:
165
+ """
166
+ Configura estilos TTK completos para o tema fornecido.
167
+
168
+ Cobre os seguintes widgets:
169
+ * ``TScrollbar`` e ``Thin.Vertical.TScrollbar``
170
+ * ``Treeview`` e ``Treeview.Heading``
171
+ * ``TCombobox`` (inclui fix de dropdown)
172
+ * ``TEntry``
173
+ * ``TNotebook`` e ``TNotebook.Tab``
174
+ * ``TSeparator``
175
+ * ``TFrame`` / ``TLabel`` / ``TButton``
176
+ * ``TPanedwindow``
177
+
178
+ Parameters
179
+ ----------
180
+ style : ttk.Style
181
+ Instância do estilo TTK (já configurada com theme_use).
182
+ t : Theme
183
+ Tema ativo cujas cores serão aplicadas.
184
+ """
185
+
186
+ style.configure(
187
+ "Vertical.TScrollbar",
188
+ background=t.scroll_thumb,
189
+ troughcolor=t.scroll_bg,
190
+ borderwidth=0,
191
+ arrowsize=0,
192
+ relief="flat",
193
+ )
194
+ style.map(
195
+ "Vertical.TScrollbar",
196
+ background=[("active", t.accent), ("!active", t.scroll_thumb)],
197
+ )
198
+
199
+ style.configure(
200
+ "Thin.Vertical.TScrollbar",
201
+ background=t.scroll_thumb,
202
+ troughcolor=t.scroll_bg,
203
+ borderwidth=0,
204
+ arrowsize=0,
205
+ relief="flat",
206
+ width=6,
207
+ )
208
+ style.map(
209
+ "Thin.Vertical.TScrollbar",
210
+ background=[("active", t.accent), ("!active", t.scroll_thumb)],
211
+ )
212
+
213
+ style.configure(
214
+ "Treeview",
215
+ background=t.sidebar_bg,
216
+ foreground=t.fg,
217
+ fieldbackground=t.sidebar_bg,
218
+ borderwidth=0,
219
+ relief="flat",
220
+ rowheight=_scaled_rowheight(),
221
+ )
222
+ style.map(
223
+ "Treeview",
224
+ background=[("selected", t.sel_bg)],
225
+ foreground=[("selected", t.sel_fg)],
226
+ )
227
+ style.configure(
228
+ "Treeview.Heading",
229
+ background=t.tabbar_bg,
230
+ foreground=t.fg_muted,
231
+ borderwidth=0,
232
+ relief="flat",
233
+ )
234
+ style.map("Treeview.Heading", background=[("active", t.btn_hover)])
235
+
236
+ style.configure(
237
+ "TCombobox",
238
+ fieldbackground=t.input_bg,
239
+ background=t.btn_bg,
240
+ foreground=t.fg,
241
+ selectbackground=t.sel_bg,
242
+ selectforeground=t.sel_fg,
243
+ borderwidth=1,
244
+ relief="flat",
245
+ )
246
+ style.map(
247
+ "TCombobox",
248
+ fieldbackground=[("readonly", t.input_bg)],
249
+ selectbackground=[("readonly", t.sel_bg)],
250
+ foreground=[("disabled", t.fg_muted)],
251
+ )
252
+
253
+ style.configure(
254
+ "TEntry",
255
+ fieldbackground=t.input_bg,
256
+ foreground=t.fg,
257
+ insertcolor=t.cursor,
258
+ borderwidth=1,
259
+ relief="flat",
260
+ )
261
+ style.map(
262
+ "TEntry",
263
+ fieldbackground=[("disabled", t.bg)],
264
+ foreground=[("disabled", t.fg_muted)],
265
+ )
266
+
267
+ style.configure(
268
+ "TNotebook",
269
+ background=t.tabbar_bg,
270
+ borderwidth=0,
271
+ )
272
+ style.configure(
273
+ "TNotebook.Tab",
274
+ background=t.tabbar_bg,
275
+ foreground=t.tab_in_fg,
276
+ padding=[8, 4],
277
+ )
278
+ style.map(
279
+ "TNotebook.Tab",
280
+ background=[("selected", t.tab_act_bg)],
281
+ foreground=[("selected", t.tab_act_fg)],
282
+ )
283
+
284
+ style.configure("TSeparator", background=t.border)
285
+
286
+ style.configure("TFrame", background=t.bg)
287
+ style.configure("TLabel", background=t.bg, foreground=t.fg)
288
+ style.configure(
289
+ "TButton",
290
+ background=t.btn_bg,
291
+ foreground=t.btn_fg,
292
+ borderwidth=0,
293
+ relief="flat",
294
+ padding=[8, 4],
295
+ )
296
+ style.map("TButton", background=[
297
+ ("active", t.btn_hover), ("pressed", t.sel_bg)])
298
+
299
+ style.configure("TPanedwindow", background=t.border)
300
+
301
+ style.configure(
302
+ "TProgressbar",
303
+ background=t.accent,
304
+ troughcolor=t.input_bg,
305
+ borderwidth=0,
306
+ thickness=4,
307
+ )
308
+
309
+
310
+ def _patch_theme(t: Theme) -> None:
311
+ """
312
+ Preenche os campos opcionais de ``t`` com valores derivados das cores base.
313
+
314
+ Esta é a única função de patch de temas do Codis. Deve ser chamada:
315
+
316
+ * Por ``_patch_all_themes()`` na inicialização (temas embutidos).
317
+ * Por ``ThemeManager.__init__`` e ``ThemeManager.set()``, para que qualquer tema,
318
+ incluindo os criados dinamicamente (ex.: kui) ou por plugins, fique completo.
319
+
320
+ A função é idempotente: atributos já preenchidos não são sobrescritos.
321
+
322
+ Parameters
323
+ ----------
324
+ t : Theme
325
+ Tema a ser patcheado in-place.
326
+ """
327
+
328
+ def _fill(attr: str, value: str) -> None:
329
+ """Preenche `attr` com `value` apenas se estiver vazio/ausente."""
330
+ if not getattr(t, attr, None):
331
+ setattr(t, attr, value)
332
+
333
+ _fill("accent", t.btn_primary)
334
+ _fill("ok_fg", t.t_string or "#50fa7b")
335
+ _fill("warn_fg", t.t_number or "#ffb86c")
336
+ _fill("err_fg", t.t_type or "#ff5555")
337
+ _fill("btn_hover", t.sel_bg)
338
+ _fill("btn_fg", t.fg)
339
+ _fill("btn_primary_fg", "#ffffff" if t.dark else "#000000")
340
+ _fill("activity_bg", t.sidebar_bg)
341
+ _fill("input_bg", t.sel_bg)
342
+ _fill("floating_bg", t.panel_bg)
343
+
344
+ _syn = (
345
+ {
346
+ "t_keyword": "#ff79c6",
347
+ "t_string": "#f1fa8c",
348
+ "t_comment": "#6272a4",
349
+ "t_number": "#bd93f9",
350
+ "t_func": "#50fa7b",
351
+ "t_type": "#8be9fd",
352
+ "t_operator": "#ff79c6",
353
+ "t_decorator": "#ffb86c",
354
+ }
355
+ if t.dark
356
+ else {
357
+ "t_keyword": "#0000ff",
358
+ "t_string": "#a31515",
359
+ "t_comment": "#008000",
360
+ "t_number": "#098658",
361
+ "t_func": "#795e26",
362
+ "t_type": "#267f99",
363
+ "t_operator": "#000000",
364
+ "t_decorator": "#af00db",
365
+ }
366
+ )
367
+ for attr, fallback in _syn.items():
368
+ _fill(attr, fallback)
369
+
370
+ _fill("t_class", t.t_type)
371
+ _fill("t_variable", t.fg)
372
+ _fill("t_link", t.accent)
373
+ _fill("t_builtin", t.t_func)
374
+ _fill("t_tag", t.t_keyword)
375
+ _fill("t_attr", t.t_func)
376
+ _fill("t_heading", t.t_keyword)
377
+ _fill("t_regex", t.t_string)
378
+ _fill("t_constant", t.t_number)
379
+ _fill("t_escape", t.t_string)
380
+ _fill("t_embedded", t.t_func)
381
+ _fill("t_invalid", t.err_fg)
382
+ _fill("t_namespace", t.t_type)
383
+
384
+ _fill("statusbar_bg", t.activity_bg)
385
+ _fill("statusbar_fg", t.fg)
386
+ _fill("statusbar_sep", t.border)
387
+ _fill("statusbar_hover", t.btn_hover)
388
+
389
+ _fill("status_bg", t.statusbar_bg or t.activity_bg)
390
+ _fill("status_fg", t.statusbar_fg or t.fg)
391
+ _fill("status_err_bg", t.err_fg)
392
+ _fill("status_err_fg", t.bg)
393
+ _fill("status_warn_bg", t.warn_fg)
394
+ _fill("status_warn_fg", t.bg)
395
+
396
+ _fill("actbar_bg", t.activity_bg)
397
+
398
+ def _is_dark_color(hex_c: str) -> bool:
399
+ """Returns True if the hex color is dark (luminance < 0.35)."""
400
+ try:
401
+ h = hex_c.lstrip("#")
402
+ if len(h) == 3:
403
+ h = "".join(c * 2 for c in h)
404
+ r, g, b = int(h[0:2], 16), int(h[2:4], 16), int(h[4:6], 16)
405
+ lum = (0.299 * r + 0.587 * g + 0.114 * b) / 255
406
+ return lum < 0.35
407
+ except Exception:
408
+ return t.dark
409
+
410
+ _actbar_is_dark = _is_dark_color(t.activity_bg)
411
+ _actbar_icon_fg = "#c8c8c8" if _actbar_is_dark else t.fg_muted
412
+ _fill("actbar_fg", _actbar_icon_fg)
413
+ _fill("actbar_active_bg", t.sel_bg)
414
+ _fill("actbar_active_fg", "#ffffff" if _actbar_is_dark else t.fg)
415
+ _fill("activity_icon_active", "#ffffff" if _actbar_is_dark else t.fg)
416
+ _fill("activity_icon_inactive", _actbar_icon_fg)
417
+ _fill("activity_active_indicator", t.accent)
418
+
419
+ _fill("sidebar_fg", t.fg)
420
+ _fill("sidebar_header_fg", t.fg_muted)
421
+
422
+ _fill("breadcrumb_bg", t.tabbar_bg)
423
+ _fill("breadcrumb_fg", t.fg_muted)
424
+ _fill("breadcrumb_sep", t.border)
425
+ _fill("breadcrumb_active", t.fg)
426
+ _fill("breadcrumb_active_fg", t.fg)
427
+
428
+ _fill("tab_bg", t.tabbar_bg)
429
+ _fill("tab_fg", t.tab_in_fg)
430
+ _fill("tab_in_bg", t.tabbar_bg)
431
+ _fill("tab_active_bg", t.tab_act_bg)
432
+ _fill("tab_active_fg", t.tab_act_fg)
433
+ _fill("tab_act_border", t.accent)
434
+ _fill("tab_hover_bg", t.btn_hover)
435
+ _fill("tab_modified", t.warn_fg)
436
+
437
+ _fill("gutter_bg", t.sidebar_bg)
438
+ _fill("gutter_fg", t.fg_muted)
439
+ _fill("gutter_active_fg", t.fg)
440
+
441
+ _fill("minimap_bg", t.editor_bg)
442
+ _fill("minimap_viewport", t.sel_bg)
443
+ _fill("minimap_find", t.accent)
444
+ _fill("minimap_err", t.err_fg)
445
+ _fill("minimap_warn", t.warn_fg)
446
+
447
+ _fill("terminal_bg", t.panel_bg)
448
+ _fill("terminal_fg", t.fg)
449
+
450
+ from src.theme.utils import hex_blend as _blend_hex
451
+
452
+ if not getattr(t, "line_hl", None):
453
+ t.line_hl = _blend_hex(t.editor_bg, t.sel_bg, 0.2)
454
+ if not getattr(t, "line_hl2", None):
455
+ t.line_hl2 = getattr(t, "line_hl", t.editor_bg)
456
+ _fill("floating_border", t.border)
457
+ _fill("floating_shadow", t.bg)
458
+ _fill("comment_fg", t.t_comment)
459
+ _fill("ruler_color", t.border)
460
+ _fill("indent_guide", t.border)
461
+ _fill("whitespace", t.fg_muted)
462
+
463
+ _fill("input_border", t.border)
464
+ _fill("border_focus", t.accent)
465
+ _fill("overlay_bg", t.floating_bg)
466
+
467
+ _fill("scroll_hover", t.btn_hover)
468
+
469
+ _fill("btn_active", t.btn_primary)
470
+
471
+ _fill("err_bg", t.input_bg)
472
+ _fill("warn_bg", t.input_bg)
473
+ _fill("info_bg", t.input_bg)
474
+
475
+ _fill("fg_dim", t.fg_muted)
476
+ _fill("hint_fg", t.fg_muted)
477
+ _fill("info_fg", t.accent)
478
+
479
+ _fill("diff_add_bg", t.panel_bg)
480
+ _fill("diff_add_fg", t.ok_fg)
481
+ _fill("diff_del_bg", t.panel_bg)
482
+ _fill("diff_del_fg", t.err_fg)
483
+ _fill("diff_change_bg", t.panel_bg)
484
+ _fill("diff_change_fg", t.warn_fg)
485
+ _fill("diff_hunk_bg", t.input_bg)
486
+ _fill("diff_hunk_fg", t.accent)
487
+
488
+ _fill("shadow_color", t.bg)
489
+
490
+ if not getattr(t, "shadow_color", None):
491
+ t.shadow_color = t.bg
492
+
493
+ from src.theme.utils import hex_glow as _glow
494
+
495
+ _fill("panel_header_bg", _blend_hex(t.panel_bg, t.bg, 0.35))
496
+ _fill("card_selected_bg", _blend_hex(t.floating_bg, t.accent, 0.16))
497
+ _fill("input_focus_border", _glow(t.accent, 0.3))
498
+ _fill("shimmer_bg", _blend_hex(t.floating_bg, "#ffffff", 0.06))
499
+ _fill("list_hover_bg", _blend_hex(t.panel_bg, t.accent, 0.10))
500
+ _fill("settings_active_bg", _blend_hex(t.sel_bg, t.accent, 0.18))
501
+
502
+
503
+ def _patch_all_themes() -> None:
504
+ """
505
+ Aplica ``_patch_theme`` a todos os temas embutidos.
506
+
507
+ Deve rodar após ``_define_themes()`` e antes de criar qualquer widget; é seguro
508
+ chamá-lo mais de uma vez.
509
+ """
510
+ for theme in THEMES.values():
511
+ with contextlib.suppress(tk.TclError):
512
+ _patch_theme(theme)
513
+
514
+
515
+ def _apply_statusbar_patches() -> None:
516
+ """
517
+ Aplica patches de compatibilidade para a StatusBar e widgets especiais.
518
+
519
+ Atualmente configura o estilo ``Thin.Vertical.TScrollbar`` com largura
520
+ mínima de 6px e sem bordas, para uso em caixas de texto de painel.
521
+
522
+ Deve ser chamado após ``apply_ttk()`` na inicialização do aplicativo.
523
+ Esta função é idempotente - múltiplas chamadas são seguras.
524
+ """
525
+ if not _TK_AVAILABLE:
526
+ return
527
+ with contextlib.suppress(tk.TclError):
528
+ style = _ttk.Style()
529
+ style.configure(
530
+ "Thin.Vertical.TScrollbar",
531
+ borderwidth=0,
532
+ arrowsize=0,
533
+ relief="flat",
534
+ width=6,
535
+ )
536
+
537
+ style.configure("StatusBar.TSeparator", background="#444444")
538
+
539
+
540
+ _CUSTOM_ICONS_DIR = _Path(__file__).parent / "icons"
541
+ _CUSTOM_CURSORS_DIR = _Path(__file__).parent / "cursors"
542
+
543
+ _icon_cache: dict[str, _Any] = {}
544
+
545
+
546
+ def apply_custom_cursor(root: _Any, cursor_name: str) -> bool:
547
+ """Aplica um cursor customizado à janela raiz.
548
+
549
+ Tenta usar cursores nativos primeiro (nome Tk), depois busca
550
+ arquivos .cursor / .gif / .png em src/theme/cursors/.
551
+
552
+ Args:
553
+ root: Janela Tk raiz.
554
+ cursor_name: Nome do cursor (ex: "arrow", "hand2", "crosshair",
555
+ ou nome de arquivo em src/theme/cursors/).
556
+
557
+ Returns:
558
+ True se aplicado com sucesso, False caso contrário.
559
+ """
560
+ _TK_CURSORS = {
561
+ "default",
562
+ "arrow",
563
+ "crosshair",
564
+ "hand2",
565
+ "move",
566
+ "sb_h_double_arrow",
567
+ "sb_v_double_arrow",
568
+ "xterm",
569
+ "watch",
570
+ "target",
571
+ "plus",
572
+ "circle",
573
+ "X_cursor",
574
+ "pirate",
575
+ "gobbler",
576
+ "fleur",
577
+ "heart",
578
+ "star",
579
+ }
580
+ if cursor_name in _TK_CURSORS:
581
+ with contextlib.suppress(Exception):
582
+ root.config(cursor=cursor_name)
583
+ return True
584
+
585
+ for ext in (".gif", ".png", ".cur"):
586
+ path = _CUSTOM_CURSORS_DIR / f"{cursor_name}{ext}"
587
+ if not path.exists():
588
+ continue
589
+ try:
590
+ if ext in (".png", ".gif"):
591
+ import sys
592
+
593
+ if sys.platform == "win32":
594
+ root.config(cursor=f"@{path}")
595
+ else:
596
+ root.config(cursor=f"@{path} black")
597
+ else:
598
+ root.config(cursor=f"@{path}")
599
+ return True
600
+ except tk.TclError:
601
+ continue
602
+ return False