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,700 @@
1
+ """Codis - Widgets do Zen Player.
2
+
3
+ Todos os ícones são desenhados como vetores no ``tk.Canvas`` (polígonos,
4
+ linhas e arcos). Nada depende de fonte emoji, o que também evita a classe de
5
+ crashes do Tk/Xft com fontes coloridas.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import contextlib
11
+ import tkinter as tk
12
+ from collections.abc import Callable
13
+ from dataclasses import dataclass
14
+ from tkinter import filedialog, simpledialog
15
+ from typing import Any
16
+
17
+ from src.constants import FONT_UI
18
+ from src.theme.utils import alpha_blend_hex
19
+ from src.ui import zen_audio as za
20
+
21
+
22
+ @dataclass
23
+ class Palette:
24
+ """Cores do player derivadas do tema + cor de destaque da capa."""
25
+
26
+ bg: str = "#14141f"
27
+ surface: str = "#1d1d2b"
28
+ surface_hi: str = "#27273a"
29
+ fg: str = "#e8eaf6"
30
+ fg_dim: str = "#8b90a8"
31
+ accent: str = "#7c4dff"
32
+ track: str = "#2c2c40"
33
+
34
+ @classmethod
35
+ def from_theme(cls, theme: Any, accent: str | None = None) -> Palette:
36
+ """Monta a paleta a partir de um objeto de tema (campos opcionais)."""
37
+ bg = getattr(theme, "floating_bg", None) or getattr(theme, "bg", cls.bg)
38
+ fg = getattr(theme, "fg", cls.fg)
39
+ dim = getattr(theme, "fg_muted", cls.fg_dim)
40
+ acc = accent or getattr(theme, "accent", cls.accent)
41
+ try:
42
+ return cls(
43
+ bg=bg,
44
+ surface=alpha_blend_hex(fg, bg, 0.06),
45
+ surface_hi=alpha_blend_hex(fg, bg, 0.12),
46
+ fg=fg,
47
+ fg_dim=dim,
48
+ accent=acc,
49
+ track=alpha_blend_hex(fg, bg, 0.16),
50
+ )
51
+ except (ValueError, TypeError):
52
+ return cls(accent=acc)
53
+
54
+
55
+ def draw_icon(c: tk.Canvas, kind: str, cx: float, cy: float, s: float, color: str,
56
+ tag: str = "icon") -> None:
57
+ """Desenha o ícone ``kind`` centrado em (cx, cy) com "raio" ``s``."""
58
+ kw = {"fill": color, "outline": "", "tags": tag}
59
+ ln = {"fill": color, "width": max(1.6, s * 0.16), "capstyle": "round",
60
+ "joinstyle": "round", "tags": tag}
61
+ if kind == "play":
62
+ c.create_polygon(cx - s * 0.55, cy - s * 0.75, cx - s * 0.55, cy + s * 0.75,
63
+ cx + s * 0.8, cy, **kw)
64
+ elif kind == "pause":
65
+ w = s * 0.38
66
+ c.create_rectangle(cx - s * 0.7, cy - s * 0.75, cx - s * 0.7 + w, cy + s * 0.75, **kw)
67
+ c.create_rectangle(cx + s * 0.7 - w, cy - s * 0.75, cx + s * 0.7, cy + s * 0.75, **kw)
68
+ elif kind in ("next", "prev"):
69
+ d = 1 if kind == "next" else -1
70
+ c.create_polygon(cx - d * s * 0.75, cy - s * 0.65, cx - d * s * 0.75, cy + s * 0.65,
71
+ cx + d * s * 0.45, cy, **kw)
72
+ c.create_rectangle(cx + d * s * 0.6 - s * 0.1, cy - s * 0.65,
73
+ cx + d * s * 0.6 + s * 0.1, cy + s * 0.65, **kw)
74
+ elif kind == "shuffle":
75
+ c.create_line(cx - s, cy + s * 0.6, cx - s * 0.2, cy + s * 0.6, cx + s * 0.3, cy - s * 0.6,
76
+ cx + s * 0.75, cy - s * 0.6, **ln)
77
+ c.create_line(cx - s, cy - s * 0.6, cx - s * 0.2, cy - s * 0.6, cx + s * 0.3, cy + s * 0.6,
78
+ cx + s * 0.75, cy + s * 0.6, **ln)
79
+ for yy in (-0.6, 0.6):
80
+ c.create_polygon(cx + s * 0.7, cy + s * yy - s * 0.3, cx + s * 1.05, cy + s * yy,
81
+ cx + s * 0.7, cy + s * yy + s * 0.3, **kw)
82
+ elif kind in ("repeat", "repeat_one"):
83
+ c.create_line(cx - s * 0.9, cy + s * 0.15, cx - s * 0.9, cy - s * 0.35, cx - s * 0.5, cy - s * 0.65,
84
+ cx + s * 0.55, cy - s * 0.65, **ln)
85
+ c.create_line(cx + s * 0.9, cy - s * 0.15, cx + s * 0.9, cy + s * 0.35, cx + s * 0.5, cy + s * 0.65,
86
+ cx - s * 0.55, cy + s * 0.65, **ln)
87
+ c.create_polygon(cx + s * 0.5, cy - s * 0.98, cx + s * 0.95, cy - s * 0.65, cx + s * 0.5, cy - s * 0.32, **kw)
88
+ c.create_polygon(cx - s * 0.5, cy + s * 0.32, cx - s * 0.95, cy + s * 0.65, cx - s * 0.5, cy + s * 0.98, **kw)
89
+ if kind == "repeat_one":
90
+ c.create_text(cx, cy, text="1", fill=color, font=(FONT_UI, max(6, int(s * 0.62)), "bold"),
91
+ tags=tag)
92
+ elif kind == "eq":
93
+ for i, h in enumerate((0.55, 1.0, 0.7)):
94
+ x = cx + (i - 1) * s * 0.78
95
+ c.create_line(x, cy - s * 0.95, x, cy + s * 0.95, **{**ln, "width": max(1.2, s * 0.1)})
96
+ ky = cy + s * (0.5 - h) * 1.1
97
+ c.create_oval(x - s * 0.28, ky - s * 0.28, x + s * 0.28, ky + s * 0.28, **kw)
98
+ elif kind == "queue":
99
+ for i in range(3):
100
+ y = cy + (i - 1) * s * 0.62
101
+ c.create_line(cx - s * 0.2, y, cx + s * 0.95, y, **ln)
102
+ c.create_oval(cx - s * 0.95, y - s * 0.12, cx - s * 0.65, y + s * 0.18, **kw)
103
+ elif kind in ("dock", "undock"):
104
+ c.create_rectangle(cx - s * 0.95, cy - s * 0.75, cx + s * 0.95, cy + s * 0.75,
105
+ outline=color, width=max(1.4, s * 0.14), tags=tag)
106
+ y0 = cy + s * 0.1 if kind == "dock" else cy - s * 0.75
107
+ y1 = cy + s * 0.75 if kind == "dock" else cy - s * 0.15
108
+ c.create_rectangle(cx - s * 0.95, y0, cx + s * 0.95, y1, **kw)
109
+ elif kind == "minimize":
110
+ c.create_line(cx - s * 0.7, cy + s * 0.3, cx + s * 0.7, cy + s * 0.3, **ln)
111
+ elif kind == "close":
112
+ c.create_line(cx - s * 0.6, cy - s * 0.6, cx + s * 0.6, cy + s * 0.6, **ln)
113
+ c.create_line(cx + s * 0.6, cy - s * 0.6, cx - s * 0.6, cy + s * 0.6, **ln)
114
+ elif kind == "pin":
115
+ c.create_oval(cx - s * 0.5, cy - s * 0.95, cx + s * 0.5, cy + s * 0.05, **kw)
116
+ c.create_line(cx, cy + s * 0.05, cx, cy + s * 0.95, **ln)
117
+ elif kind in ("volume", "mute"):
118
+ c.create_polygon(cx - s * 0.95, cy - s * 0.3, cx - s * 0.5, cy - s * 0.3, cx - s * 0.05, cy - s * 0.75,
119
+ cx - s * 0.05, cy + s * 0.75, cx - s * 0.5, cy + s * 0.3, cx - s * 0.95, cy + s * 0.3,
120
+ **kw)
121
+ if kind == "volume":
122
+ c.create_arc(cx - s * 0.2, cy - s * 0.55, cx + s * 0.6, cy + s * 0.55, start=-50, extent=100,
123
+ style="arc", outline=color, width=max(1.4, s * 0.14), tags=tag)
124
+ c.create_arc(cx - s * 0.25, cy - s * 0.95, cx + s * 1.0, cy + s * 0.95, start=-50, extent=100,
125
+ style="arc", outline=color, width=max(1.4, s * 0.14), tags=tag)
126
+ else:
127
+ c.create_line(cx + s * 0.3, cy - s * 0.4, cx + s * 0.95, cy + s * 0.4, **ln)
128
+ c.create_line(cx + s * 0.95, cy - s * 0.4, cx + s * 0.3, cy + s * 0.4, **ln)
129
+ elif kind == "plus":
130
+ c.create_line(cx - s * 0.7, cy, cx + s * 0.7, cy, **ln)
131
+ c.create_line(cx, cy - s * 0.7, cx, cy + s * 0.7, **ln)
132
+ elif kind == "folder":
133
+ c.create_polygon(cx - s, cy - s * 0.55, cx - s * 0.2, cy - s * 0.55, cx + s * 0.05, cy - s * 0.25,
134
+ cx + s, cy - s * 0.25, cx + s, cy + s * 0.7, cx - s, cy + s * 0.7, **kw)
135
+
136
+
137
+ class FlatButton(tk.Canvas):
138
+ """Botão vetorial com hover/press, estado "ativo" e fundo opcional circular."""
139
+
140
+ def __init__(self, parent: tk.Misc, kind: str, command: Callable[[], None] | None,
141
+ pal: Palette, size: int = 32, icon_scale: float = 0.36,
142
+ filled: bool = False, tooltip: str = "") -> None:
143
+ super().__init__(parent, width=size, height=size, bg=parent.cget("bg"),
144
+ highlightthickness=0, bd=0, cursor="hand2")
145
+ self.kind = kind
146
+ self._cmd = command
147
+ self._pal = pal
148
+ self._size = size
149
+ self._scale = icon_scale
150
+ self._filled = filled
151
+ self._active = False
152
+ self._hover = False
153
+ self._down = False
154
+ self._tooltip = tooltip
155
+ self._tip: tk.Toplevel | None = None
156
+ self._tip_job: str | None = None
157
+ self.bind("<Enter>", self._on_enter)
158
+ self.bind("<Leave>", self._on_leave)
159
+ self.bind("<ButtonPress-1>", self._on_press)
160
+ self.bind("<ButtonRelease-1>", self._on_release)
161
+ self.bind("<Destroy>", lambda _e: self._hide_tip(), add="+")
162
+ self.redraw()
163
+
164
+ def set_kind(self, kind: str) -> None:
165
+ """Troca o ícone."""
166
+ if kind != self.kind:
167
+ self.kind = kind
168
+ self.redraw()
169
+
170
+ def set_active(self, active: bool) -> None:
171
+ """Marca o botão como ligado (usa a cor de destaque)."""
172
+ if active != self._active:
173
+ self._active = active
174
+ self.redraw()
175
+
176
+ def set_palette(self, pal: Palette) -> None:
177
+ """Atualiza cores (tema ou cor da capa)."""
178
+ self._pal = pal
179
+ with contextlib.suppress(tk.TclError):
180
+ self.configure(bg=self.master.cget("bg"))
181
+ self.redraw()
182
+
183
+ def redraw(self) -> None:
184
+ """Redesenha o botão conforme o estado atual."""
185
+ self.delete("all")
186
+ s = self._size
187
+ pal = self._pal
188
+ if self._filled:
189
+ fill = pal.accent if not self._down else alpha_blend_hex("#000000", pal.accent, 0.25)
190
+ if self._hover and not self._down:
191
+ fill = alpha_blend_hex("#ffffff", pal.accent, 0.18)
192
+ self.create_oval(1, 1, s - 1, s - 1, fill=fill, outline="")
193
+ color = "#ffffff"
194
+ else:
195
+ if self._hover or self._down:
196
+ self.create_oval(2, 2, s - 2, s - 2,
197
+ fill=pal.surface_hi if not self._down else pal.track, outline="")
198
+ color = pal.accent if self._active else (pal.fg if self._hover else pal.fg_dim)
199
+ draw_icon(self, self.kind, s / 2, s / 2, s * self._scale, color)
200
+
201
+ def _on_enter(self, _e: tk.Event) -> None:
202
+ self._hover = True
203
+ self.redraw()
204
+ if self._tooltip:
205
+ self._tip_job = self.after(550, self._show_tip)
206
+
207
+ def _on_leave(self, _e: tk.Event) -> None:
208
+ self._hover = False
209
+ self._down = False
210
+ self._hide_tip()
211
+ self.redraw()
212
+
213
+ def _on_press(self, _e: tk.Event) -> None:
214
+ self._down = True
215
+ self._hide_tip()
216
+ self.redraw()
217
+
218
+ def _on_release(self, e: tk.Event) -> None:
219
+ was_down = self._down
220
+ self._down = False
221
+ self.redraw()
222
+ inside = 0 <= e.x <= self._size and 0 <= e.y <= self._size
223
+ if was_down and inside and self._cmd:
224
+ self._cmd()
225
+
226
+ def _show_tip(self) -> None:
227
+ self._tip_job = None
228
+ if self._tip is not None or not self._tooltip:
229
+ return
230
+ with contextlib.suppress(tk.TclError):
231
+ tip = tk.Toplevel(self)
232
+ tip.wm_overrideredirect(True)
233
+ tip.attributes("-topmost", True)
234
+ tk.Label(tip, text=self._tooltip, bg=self._pal.surface_hi, fg=self._pal.fg,
235
+ font=(FONT_UI, 8), padx=7, pady=3, bd=0).pack()
236
+ tip.update_idletasks()
237
+ x = self.winfo_rootx() + self._size // 2 - tip.winfo_reqwidth() // 2
238
+ y = self.winfo_rooty() - tip.winfo_reqheight() - 6
239
+ if y < 0:
240
+ y = self.winfo_rooty() + self._size + 6
241
+ tip.geometry(f"+{max(0, x)}+{y}")
242
+ self._tip = tip
243
+
244
+ def _hide_tip(self) -> None:
245
+ if self._tip_job is not None:
246
+ with contextlib.suppress(tk.TclError, ValueError):
247
+ self.after_cancel(self._tip_job)
248
+ self._tip_job = None
249
+ if self._tip is not None:
250
+ with contextlib.suppress(tk.TclError):
251
+ self._tip.destroy()
252
+ self._tip = None
253
+
254
+
255
+ class SeekBar(tk.Canvas):
256
+ """Barra horizontal arrastável (progresso ou volume) com hover e knob."""
257
+
258
+ def __init__(self, parent: tk.Misc, pal: Palette, height: int = 18,
259
+ on_seek: Callable[[float], None] | None = None,
260
+ on_drag: Callable[[float], None] | None = None,
261
+ hover_text: Callable[[float], str] | None = None) -> None:
262
+ super().__init__(parent, height=height, bg=parent.cget("bg"), highlightthickness=0,
263
+ bd=0, cursor="hand2")
264
+ self._pal = pal
265
+ self._value = 0.0
266
+ self._buffer = 0.0
267
+ self._dragging = False
268
+ self._hover = False
269
+ self._hover_x: int | None = None
270
+ self._on_seek = on_seek
271
+ self._on_drag = on_drag
272
+ self._hover_text = hover_text
273
+ self.bind("<Configure>", lambda _e: self.redraw())
274
+ self.bind("<Enter>", self._enter)
275
+ self.bind("<Leave>", self._leave)
276
+ self.bind("<Motion>", self._motion)
277
+ self.bind("<ButtonPress-1>", self._press)
278
+ self.bind("<B1-Motion>", self._move)
279
+ self.bind("<ButtonRelease-1>", self._release)
280
+
281
+ @property
282
+ def dragging(self) -> bool:
283
+ """Se o usuário está arrastando o controle."""
284
+ return self._dragging
285
+
286
+ def set_value(self, value: float) -> None:
287
+ """Define o valor (0..1) sem disparar callbacks."""
288
+ value = max(0.0, min(1.0, value))
289
+ if abs(value - self._value) > 1e-4 and not self._dragging:
290
+ self._value = value
291
+ self.redraw()
292
+
293
+ def set_palette(self, pal: Palette) -> None:
294
+ """Atualiza as cores."""
295
+ self._pal = pal
296
+ with contextlib.suppress(tk.TclError):
297
+ self.configure(bg=self.master.cget("bg"))
298
+ self.redraw()
299
+
300
+ def _frac(self, x: int) -> float:
301
+ w = max(self.winfo_width(), 1)
302
+ pad = 7
303
+ return max(0.0, min(1.0, (x - pad) / max(w - 2 * pad, 1)))
304
+
305
+ def redraw(self) -> None:
306
+ """Redesenha trilho, preenchimento e knob."""
307
+ self.delete("all")
308
+ w, h = max(self.winfo_width(), 2), max(self.winfo_height(), 2)
309
+ pad, cy = 7, h / 2
310
+ grow = 1 if (self._hover or self._dragging) else 0
311
+ th = 3 + grow * 2
312
+ x1 = w - pad
313
+ self.create_line(pad, cy, x1, cy, fill=self._pal.track, width=th, capstyle="round")
314
+ xv = pad + (x1 - pad) * self._value
315
+ if xv > pad:
316
+ self.create_line(pad, cy, xv, cy, fill=self._pal.accent, width=th, capstyle="round")
317
+ if self._hover or self._dragging:
318
+ r = 6
319
+ self.create_oval(xv - r, cy - r, xv + r, cy + r, fill="#ffffff", outline=self._pal.accent, width=2)
320
+ if self._hover_x is not None and self._hover_text and not self._dragging:
321
+ text = self._hover_text(self._frac(self._hover_x))
322
+ tx = min(max(self._hover_x, 22), w - 22)
323
+ self.create_text(tx, 1, text=text, fill=self._pal.fg, anchor="n", font=(FONT_UI, 7))
324
+
325
+ def _enter(self, _e: tk.Event) -> None:
326
+ self._hover = True
327
+ self.redraw()
328
+
329
+ def _leave(self, _e: tk.Event) -> None:
330
+ self._hover = False
331
+ self._hover_x = None
332
+ self.redraw()
333
+
334
+ def _motion(self, e: tk.Event) -> None:
335
+ self._hover_x = e.x
336
+ self.redraw()
337
+
338
+ def _press(self, e: tk.Event) -> None:
339
+ self._dragging = True
340
+ self._value = self._frac(e.x)
341
+ self.redraw()
342
+ if self._on_drag:
343
+ self._on_drag(self._value)
344
+
345
+ def _move(self, e: tk.Event) -> None:
346
+ self._value = self._frac(e.x)
347
+ self.redraw()
348
+ if self._on_drag:
349
+ self._on_drag(self._value)
350
+
351
+ def _release(self, e: tk.Event) -> None:
352
+ self._value = self._frac(e.x)
353
+ self._dragging = False
354
+ self.redraw()
355
+ if self._on_seek:
356
+ self._on_seek(self._value)
357
+
358
+
359
+ class EqualizerPanel(tk.Frame):
360
+ """Equalizador de 10 bandas com presets, presets próprios e curva suave.
361
+
362
+ O estado é persistido na configuração (``zen_eq_*``) e aplicado ao motor
363
+ via ``player.set_equalizer``. Várias instâncias (janela, dock, popup)
364
+ ficam sincronizadas por :meth:`sync_from_player`.
365
+ """
366
+
367
+ COL_W = 34
368
+ MARGIN = 30
369
+ H = 190
370
+
371
+ def __init__(self, parent: tk.Misc, player: Any, cfg: Any, pal: Palette,
372
+ on_state_changed: Callable[[], None] | None = None) -> None:
373
+ super().__init__(parent, bg=pal.bg)
374
+ self._player = player
375
+ self._cfg = cfg
376
+ self._pal = pal
377
+ self._on_state_changed = on_state_changed
378
+ self._gains = za.clamp_gains(player.eq_gains)
379
+ self._enabled = player.eq_enabled
380
+ self._custom: dict[str, list[float]] = dict(cfg.get("zen_eq_custom", {}) or {})
381
+ self._drag_band: int | None = None
382
+ self._build()
383
+ self._redraw()
384
+
385
+ def _build(self) -> None:
386
+ pal = self._pal
387
+ top = tk.Frame(self, bg=pal.bg)
388
+ top.pack(fill="x", pady=(0, 6))
389
+
390
+ self._power = tk.Canvas(top, width=44, height=22, bg=pal.bg, highlightthickness=0,
391
+ cursor="hand2")
392
+ self._power.pack(side="left")
393
+ self._power.bind("<Button-1>", lambda _e: self.set_enabled(not self._enabled))
394
+
395
+ self._preset_var = tk.StringVar(value="Flat")
396
+ self._preset_text = tk.StringVar(value="Flat ▾")
397
+ self._preset_btn = tk.Menubutton(
398
+ top, textvariable=self._preset_text, bg=pal.surface, fg=pal.fg,
399
+ activebackground=pal.surface_hi, activeforeground=pal.fg, relief="flat", bd=0,
400
+ font=(FONT_UI, 9), padx=12, pady=4, cursor="hand2", indicatoron=False, width=14,
401
+ anchor="w")
402
+ self._preset_btn.pack(side="left", padx=8)
403
+ self._menu = tk.Menu(self._preset_btn, tearoff=False, bg=pal.surface, fg=pal.fg,
404
+ activebackground=pal.accent, activeforeground="#ffffff", bd=0,
405
+ relief="flat", font=(FONT_UI, 9))
406
+ self._preset_btn.configure(menu=self._menu)
407
+
408
+ self._delete_lbl: tk.Label | None = None
409
+ for text, cmd in (("Resetar", self.reset), ("Salvar preset", self._save_preset),
410
+ ("Excluir", self._delete_preset)):
411
+ b = tk.Label(top, text=text, bg=pal.bg, fg=pal.fg_dim, font=(FONT_UI, 9),
412
+ cursor="hand2", padx=6)
413
+ if text == "Excluir":
414
+ self._delete_lbl = b
415
+ else:
416
+ b.pack(side="right")
417
+ b.bind("<Button-1>", lambda _e, c=cmd: c())
418
+ b.bind("<Enter>", lambda _e, w=b: w.configure(fg=pal.fg))
419
+ b.bind("<Leave>", lambda _e, w=b: w.configure(fg=pal.fg_dim))
420
+
421
+ width = self.MARGIN + self.COL_W * len(za.EQ_BANDS_HZ)
422
+ self._cv = tk.Canvas(self, width=width, height=self.H, bg=pal.bg, highlightthickness=0)
423
+ self._cv.pack(fill="x")
424
+ self._cv.bind("<Configure>", lambda _e: self._redraw())
425
+ self._cv.bind("<ButtonPress-1>", self._press)
426
+ self._cv.bind("<B1-Motion>", self._drag)
427
+ self._cv.bind("<ButtonRelease-1>", lambda _e: self._release())
428
+ self._cv.bind("<Double-Button-1>", self._reset_band)
429
+ self._cv.bind("<MouseWheel>", self._wheel)
430
+ self._cv.bind("<Button-4>", lambda e: self._wheel(e, 120))
431
+ self._cv.bind("<Button-5>", lambda e: self._wheel(e, -120))
432
+ self._rebuild_menu()
433
+
434
+ def _rebuild_menu(self) -> None:
435
+ self._menu.delete(0, "end")
436
+ for name in za.EQ_PRESETS:
437
+ self._menu.add_command(label=name, command=lambda n=name: self.apply_preset(n))
438
+ if self._custom:
439
+ self._menu.add_separator()
440
+ for name in sorted(self._custom):
441
+ self._menu.add_command(label=f"★ {name}",
442
+ command=lambda n=name: self.apply_custom(n))
443
+
444
+ def current_preset_name(self) -> str:
445
+ """Nome do preset que coincide com os ganhos, ou ``Personalizado``."""
446
+ match = za.match_preset(self._gains)
447
+ if match:
448
+ return match
449
+ for name, gains in self._custom.items():
450
+ if za.clamp_gains(gains) == self._gains:
451
+ return name
452
+ return "Personalizado"
453
+
454
+ def sync_from_player(self) -> None:
455
+ """Relê o estado do motor (outra instância pode ter mudado)."""
456
+ self._gains = za.clamp_gains(self._player.eq_gains)
457
+ self._enabled = self._player.eq_enabled
458
+ self._redraw()
459
+
460
+ def set_palette(self, pal: Palette) -> None:
461
+ """Atualiza cores e redesenha."""
462
+ self._pal = pal
463
+ self._redraw()
464
+
465
+ def set_enabled(self, enabled: bool) -> None:
466
+ """Liga/desliga o equalizador."""
467
+ self._enabled = enabled
468
+ self._commit()
469
+
470
+ def apply_preset(self, name: str) -> None:
471
+ """Aplica um preset embutido."""
472
+ self._gains = za.clamp_gains(za.EQ_PRESETS.get(name))
473
+ self._enabled = True
474
+ self._commit()
475
+
476
+ def apply_custom(self, name: str) -> None:
477
+ """Aplica um preset salvo pelo usuário."""
478
+ self._gains = za.clamp_gains(self._custom.get(name))
479
+ self._enabled = True
480
+ self._commit()
481
+
482
+ def reset(self) -> None:
483
+ """Volta tudo para 0 dB."""
484
+ self.apply_preset(za.DEFAULT_PRESET)
485
+
486
+ def _commit(self) -> None:
487
+ self._player.set_equalizer(self._gains, self._enabled)
488
+ with contextlib.suppress(Exception):
489
+ self._cfg.set("zen_eq_gains", self._gains)
490
+ self._cfg.set("zen_eq_enabled", self._enabled)
491
+ self._redraw()
492
+ if self._on_state_changed:
493
+ self._on_state_changed()
494
+
495
+ def _save_preset(self) -> None:
496
+ name = simpledialog.askstring("Salvar preset", "Nome do preset:", parent=self.winfo_toplevel())
497
+ name = (name or "").strip()[:24]
498
+ if not name or name in za.EQ_PRESETS:
499
+ return
500
+ self._custom[name] = list(self._gains)
501
+ with contextlib.suppress(Exception):
502
+ self._cfg.set("zen_eq_custom", self._custom)
503
+ self._rebuild_menu()
504
+ self._redraw()
505
+
506
+ def _delete_preset(self) -> None:
507
+ name = self.current_preset_name()
508
+ if name in self._custom:
509
+ del self._custom[name]
510
+ with contextlib.suppress(Exception):
511
+ self._cfg.set("zen_eq_custom", self._custom)
512
+ self._rebuild_menu()
513
+ self._redraw()
514
+
515
+ def _band_at(self, x: int) -> int:
516
+ return max(0, min(len(self._gains) - 1, int((x - self.MARGIN) // self._col_width())))
517
+
518
+ def _col_width(self) -> float:
519
+ width = max(self._cv.winfo_width(), self.MARGIN + len(self._gains))
520
+ return (width - self.MARGIN) / len(self._gains)
521
+
522
+ def _gain_at(self, y: int) -> float:
523
+ top, bottom = 22, self.H - 26
524
+ frac = 1 - (y - top) / max(bottom - top, 1)
525
+ gain = za.EQ_MIN_DB + frac * (za.EQ_MAX_DB - za.EQ_MIN_DB)
526
+ return round(max(za.EQ_MIN_DB, min(za.EQ_MAX_DB, gain)) * 2) / 2
527
+
528
+ def _press(self, e: tk.Event) -> None:
529
+ self._drag_band = self._band_at(e.x)
530
+ self._set_band(self._drag_band, self._gain_at(e.y))
531
+
532
+ def _drag(self, e: tk.Event) -> None:
533
+ if self._drag_band is not None:
534
+ self._set_band(self._drag_band, self._gain_at(e.y))
535
+
536
+ def _release(self) -> None:
537
+ self._drag_band = None
538
+
539
+ def _reset_band(self, e: tk.Event) -> None:
540
+ self._set_band(self._band_at(e.x), 0.0)
541
+
542
+ def _wheel(self, e: tk.Event, delta: int | None = None) -> None:
543
+ d = delta if delta is not None else e.delta
544
+ band = self._band_at(e.x)
545
+ self._set_band(band, self._gains[band] + (0.5 if d > 0 else -0.5))
546
+
547
+ def _set_band(self, band: int, gain: float) -> None:
548
+ gain = round(max(za.EQ_MIN_DB, min(za.EQ_MAX_DB, gain)), 1)
549
+ if gain == self._gains[band] and self._enabled:
550
+ return
551
+ self._gains[band] = gain
552
+ self._enabled = True
553
+ self._commit()
554
+
555
+ def _redraw(self) -> None:
556
+ pal = self._pal
557
+ accent = pal.accent if self._enabled else pal.fg_dim
558
+ name = self.current_preset_name()
559
+ self._preset_var.set(name)
560
+ self._preset_text.set(f"{name} ▾")
561
+ if self._delete_lbl is not None:
562
+ if name in self._custom:
563
+ if not self._delete_lbl.winfo_ismapped():
564
+ self._delete_lbl.pack(side="right")
565
+ else:
566
+ self._delete_lbl.pack_forget()
567
+ p = self._power
568
+ p.delete("all")
569
+ p.create_rectangle(2, 3, 42, 19, fill=accent if self._enabled else pal.track, outline="")
570
+ p.create_oval(2, 3, 18, 19, fill=accent if self._enabled else pal.track, outline="")
571
+ p.create_oval(26, 3, 42, 19, fill=accent if self._enabled else pal.track, outline="")
572
+ kx = 27 if self._enabled else 3
573
+ p.create_oval(kx, 4, kx + 14, 18, fill="#ffffff", outline="")
574
+
575
+ c = self._cv
576
+ c.delete("all")
577
+ margin = self.MARGIN
578
+ w = max(c.winfo_width(), margin + len(self._gains))
579
+ col = (w - margin) / len(self._gains)
580
+ top, bottom = 22, self.H - 26
581
+ mid = (top + bottom) / 2
582
+
583
+ for db in (-12, -6, 0, 6, 12):
584
+ y = bottom - (db - za.EQ_MIN_DB) / (za.EQ_MAX_DB - za.EQ_MIN_DB) * (bottom - top)
585
+ c.create_line(margin - 4, y, w, y, fill=pal.track if db else pal.fg_dim,
586
+ dash=() if db == 0 else (2, 4))
587
+ c.create_text(margin - 8, y, text=f"{db:+d}" if db else "0", anchor="e",
588
+ fill=pal.fg_dim, font=(FONT_UI, 7))
589
+
590
+ pts: list[float] = []
591
+ for i, g in enumerate(self._gains):
592
+ x = margin + col * (i + 0.5)
593
+ y = bottom - (g - za.EQ_MIN_DB) / (za.EQ_MAX_DB - za.EQ_MIN_DB) * (bottom - top)
594
+ pts += [x, y]
595
+ c.create_line(x, top, x, bottom, fill=pal.track, width=4, capstyle="round")
596
+ c.create_line(x, mid, x, y, fill=accent, width=4, capstyle="round")
597
+ c.create_text(x, bottom + 14, text=za.EQ_BAND_LABELS[i], fill=pal.fg_dim,
598
+ font=(FONT_UI, 8))
599
+ if g:
600
+ c.create_text(x, y - 13 if g > 0 else y + 13, text=f"{g:+g}", fill=pal.fg,
601
+ font=(FONT_UI, 7))
602
+ if len(pts) >= 4:
603
+ c.create_line(*pts, fill=alpha_blend_hex(accent, pal.bg, 0.55), width=2, smooth=True)
604
+ for i in range(len(self._gains)):
605
+ x, y = pts[2 * i], pts[2 * i + 1]
606
+ c.create_oval(x - 7, y - 7, x + 7, y + 7, fill="#ffffff", outline=accent, width=2)
607
+
608
+
609
+ class QueuePanel(tk.Frame):
610
+ """Lista de reprodução com faixa atual destacada, adicionar e remover."""
611
+
612
+ def __init__(self, parent: tk.Misc, player: Any, cfg: Any, pal: Palette,
613
+ on_changed: Callable[[], None] | None = None) -> None:
614
+ super().__init__(parent, bg=pal.bg)
615
+ self._player = player
616
+ self._cfg = cfg
617
+ self._pal = pal
618
+ self._on_changed = on_changed
619
+
620
+ bar = tk.Frame(self, bg=pal.bg)
621
+ bar.pack(fill="x", pady=(0, 6))
622
+ self._count = tk.Label(bar, text="", bg=pal.bg, fg=pal.fg_dim, font=(FONT_UI, 9))
623
+ self._count.pack(side="left")
624
+ for kind, tip, cmd in (("folder", "Adicionar pasta", self._add_folder),
625
+ ("plus", "Adicionar arquivos", self._add_files)):
626
+ FlatButton(bar, kind, cmd, pal, size=28, tooltip=tip).pack(side="right")
627
+ rm = tk.Label(bar, text="Remover", bg=pal.bg, fg=pal.fg_dim, font=(FONT_UI, 9),
628
+ cursor="hand2", padx=8)
629
+ rm.pack(side="right")
630
+ rm.bind("<Button-1>", lambda _e: self._remove_selected())
631
+
632
+ holder = tk.Frame(self, bg=pal.surface)
633
+ holder.pack(fill="both", expand=True)
634
+ self._lb = tk.Listbox(holder, bg=pal.surface, fg=pal.fg, selectbackground=pal.surface_hi,
635
+ selectforeground=pal.fg, activestyle="none", bd=0,
636
+ highlightthickness=0, font=(FONT_UI, 10), exportselection=False)
637
+ sb = tk.Scrollbar(holder, orient="vertical", command=self._lb.yview)
638
+ self._lb.configure(yscrollcommand=sb.set)
639
+ self._lb.pack(side="left", fill="both", expand=True, padx=4, pady=4)
640
+ sb.pack(side="right", fill="y")
641
+ self._lb.bind("<Double-Button-1>", self._play_selected)
642
+ self._lb.bind("<Return>", self._play_selected)
643
+ self._lb.bind("<Delete>", lambda _e: self._remove_selected())
644
+ self.refresh()
645
+
646
+ def set_palette(self, pal: Palette) -> None:
647
+ """Atualiza as cores."""
648
+ self._pal = pal
649
+ self._lb.configure(selectbackground=pal.surface_hi, selectforeground=pal.fg)
650
+ self.refresh()
651
+
652
+ def refresh(self) -> None:
653
+ """Recarrega a lista e destaca a faixa atual."""
654
+ tracks = self._player.playlist
655
+ cur = self._player.current_index
656
+ with contextlib.suppress(tk.TclError):
657
+ self._lb.delete(0, "end")
658
+ for i, t in enumerate(tracks):
659
+ prefix = "▶ " if i == cur and self._player.is_playing else f"{i + 1:>2} "
660
+ self._lb.insert("end", prefix + t.get("name", "?"))
661
+ if i == cur:
662
+ self._lb.itemconfig(i, fg=self._pal.accent)
663
+ self._count.configure(text=f"{len(tracks)} faixa(s)")
664
+ if 0 <= cur < len(tracks):
665
+ self._lb.see(cur)
666
+
667
+ def _persist(self) -> None:
668
+ with contextlib.suppress(Exception):
669
+ self._cfg.set("zen_media_playlist", self._player.playlist)
670
+ self.refresh()
671
+ if self._on_changed:
672
+ self._on_changed()
673
+
674
+ def _play_selected(self, _e: tk.Event | None = None) -> None:
675
+ sel = self._lb.curselection()
676
+ if sel:
677
+ self._player.play_index(int(sel[0]))
678
+
679
+ def _remove_selected(self) -> None:
680
+ for idx in reversed(self._lb.curselection()):
681
+ self._player.remove_track(int(idx))
682
+ self._persist()
683
+
684
+ def _add_files(self) -> None:
685
+ exts = " ".join(f"*{e}" for e in sorted(self._player.AUDIO_EXTENSIONS))
686
+ paths = filedialog.askopenfilenames(
687
+ parent=self.winfo_toplevel(), title="Adicionar mídia",
688
+ filetypes=[("Áudio e vídeo", exts), ("Todos", "*.*")])
689
+ from pathlib import Path
690
+
691
+ for p in paths:
692
+ self._player.add_track(Path(p).stem, p)
693
+ if paths:
694
+ self._persist()
695
+
696
+ def _add_folder(self) -> None:
697
+ folder = filedialog.askdirectory(parent=self.winfo_toplevel(), title="Adicionar pasta")
698
+ if folder:
699
+ self._player.load_folder(folder)
700
+ self._persist()