codis 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codis-1.1.1.dist-info/METADATA +194 -0
- codis-1.1.1.dist-info/RECORD +329 -0
- codis-1.1.1.dist-info/WHEEL +5 -0
- codis-1.1.1.dist-info/entry_points.txt +5 -0
- codis-1.1.1.dist-info/licenses/LICENSE +21 -0
- codis-1.1.1.dist-info/top_level.txt +2 -0
- run.py +190 -0
- src/__init__.py +1 -0
- src/__main__.py +81 -0
- src/_app_build.py +1507 -0
- src/_app_editor.py +1274 -0
- src/_app_kui.py +825 -0
- src/_app_lsp.py +625 -0
- src/_app_recovery.py +189 -0
- src/_app_settings.py +1385 -0
- src/_app_tools.py +2471 -0
- src/_app_webpreview.py +126 -0
- src/_font_safety.py +127 -0
- src/_shells.py +172 -0
- src/app.py +1488 -0
- src/chat/__init__.py +1 -0
- src/chat/adapters/__init__.py +33 -0
- src/chat/adapters/base.py +209 -0
- src/chat/adapters/discord.py +190 -0
- src/chat/adapters/http.py +78 -0
- src/chat/adapters/irc.py +360 -0
- src/chat/adapters/matrix.py +219 -0
- src/chat/adapters/mattermost.py +178 -0
- src/chat/adapters/mqtt.py +165 -0
- src/chat/adapters/slack.py +204 -0
- src/chat/adapters/telegram.py +117 -0
- src/chat/adapters/ws.py +154 -0
- src/chat/adapters/xmpp.py +337 -0
- src/chat/history.py +76 -0
- src/chat/models.py +207 -0
- src/chat/probe.py +79 -0
- src/chat/session.py +446 -0
- src/chat/util.py +125 -0
- src/collab/__init__.py +1 -0
- src/collab/net.py +411 -0
- src/collab/ot.py +311 -0
- src/collab/session.py +141 -0
- src/collab/tk_adapter.py +134 -0
- src/config.py +335 -0
- src/constants.py +2552 -0
- src/dep_catalog.py +446 -0
- src/diff/__init__.py +1 -0
- src/diff/engine.py +247 -0
- src/dpi.py +30 -0
- src/editor/__init__.py +1 -0
- src/editor/_pane_lsp.py +2937 -0
- src/editor/_pane_utils.py +171 -0
- src/editor/autocomplete.py +607 -0
- src/editor/code_folding.py +836 -0
- src/editor/color_preview.py +382 -0
- src/editor/complexity_lens.py +281 -0
- src/editor/diff_pane.py +623 -0
- src/editor/file_watcher.py +144 -0
- src/editor/focus_block.py +236 -0
- src/editor/heatmap.py +141 -0
- src/editor/inlay_hints.py +366 -0
- src/editor/inline_blame.py +429 -0
- src/editor/kdocs.py +3376 -0
- src/editor/large_file.py +488 -0
- src/editor/ligatures.py +180 -0
- src/editor/line_numbers.py +598 -0
- src/editor/minimap.py +691 -0
- src/editor/multi_cursor.py +269 -0
- src/editor/pane.py +2082 -0
- src/editor/rhythm.py +206 -0
- src/editor/save_hooks.py +43 -0
- src/editor/smart_selection.py +425 -0
- src/editor/smart_tips.py +719 -0
- src/editor/snippets.py +411 -0
- src/editor/sticky_note_gutter.py +410 -0
- src/editor/sticky_scroll.py +385 -0
- src/editor/suggest.py +464 -0
- src/editor/text_transforms.py +310 -0
- src/editor/vim_mode.py +1074 -0
- src/events/__init__.py +84 -0
- src/events/bus.py +427 -0
- src/events/correlator.py +244 -0
- src/events/kinds.py +125 -0
- src/events/pipeline.py +264 -0
- src/events/stream.py +416 -0
- src/events/window.py +204 -0
- src/extcompat/__init__.py +19 -0
- src/extcompat/code/__init__.py +13 -0
- src/extcompat/code/consent.py +162 -0
- src/extcompat/code/host.py +353 -0
- src/extcompat/code/hosts/py_host.py +763 -0
- src/extcompat/code/locate.py +105 -0
- src/extcompat/code/manager.py +325 -0
- src/extcompat/code/permissions.py +154 -0
- src/extcompat/code/sandbox.py +60 -0
- src/extcompat/colors.py +131 -0
- src/extcompat/common.py +184 -0
- src/extcompat/cson.py +269 -0
- src/extcompat/formats/__init__.py +22 -0
- src/extcompat/formats/_tm.py +189 -0
- src/extcompat/formats/_util.py +31 -0
- src/extcompat/formats/base16.py +66 -0
- src/extcompat/formats/brackets.py +172 -0
- src/extcompat/formats/eclipse.py +193 -0
- src/extcompat/formats/emacs.py +361 -0
- src/extcompat/formats/geany.py +147 -0
- src/extcompat/formats/generic.py +184 -0
- src/extcompat/formats/gtksource.py +117 -0
- src/extcompat/formats/helix.py +91 -0
- src/extcompat/formats/jetbrains.py +343 -0
- src/extcompat/formats/kate.py +130 -0
- src/extcompat/formats/micro.py +131 -0
- src/extcompat/formats/nano.py +111 -0
- src/extcompat/formats/notepadpp.py +140 -0
- src/extcompat/formats/pulsar.py +165 -0
- src/extcompat/formats/pyides.py +163 -0
- src/extcompat/formats/sublime.py +340 -0
- src/extcompat/jsonc.py +65 -0
- src/extcompat/lessish.py +128 -0
- src/extcompat/manager.py +122 -0
- src/extcompat/market/__init__.py +63 -0
- src/extcompat/market/sources.py +211 -0
- src/extcompat/model.py +88 -0
- src/extcompat/net.py +228 -0
- src/extcompat/openvsx.py +63 -0
- src/extcompat/readers.py +362 -0
- src/extcompat/registry.py +73 -0
- src/extcompat/safexml.py +63 -0
- src/extcompat/sexp.py +187 -0
- src/extcompat/sources.py +105 -0
- src/extcompat/store.py +276 -0
- src/extcompat/textmate.py +214 -0
- src/extcompat/themes.py +487 -0
- src/extcompat/yamlite.py +294 -0
- src/fileio.py +94 -0
- src/fs_ops.py +106 -0
- src/i18n.py +233 -0
- src/ia/__init__.py +1 -0
- src/ia/actions.py +295 -0
- src/ia/approval_gate.py +672 -0
- src/ia/checkpoints.py +308 -0
- src/ia/context_builder.py +921 -0
- src/ia/dialdiff.py +408 -0
- src/ia/iaspace.py +2078 -0
- src/ia/pair.py +296 -0
- src/ia/providers.py +954 -0
- src/ia/session.py +335 -0
- src/ia/toolbox.py +2524 -0
- src/launcher_actions.py +204 -0
- src/lint/__init__.py +1 -0
- src/lint/manager.py +1058 -0
- src/locales/.translate_manifest.json +64170 -0
- src/locales/de.json +4936 -0
- src/locales/en.json +4936 -0
- src/locales/es.json +4936 -0
- src/locales/fr.json +4936 -0
- src/locales/it.json +4936 -0
- src/locales/ja.json +4936 -0
- src/locales/ko.json +4936 -0
- src/locales/nl.json +4936 -0
- src/locales/pl.json +4936 -0
- src/locales/pt-BR.json +4936 -0
- src/locales/ru.json +4936 -0
- src/locales/tr.json +4936 -0
- src/locales/uk.json +4936 -0
- src/locales/zh-CN.json +4936 -0
- src/lsp/__init__.py +26 -0
- src/lsp/client.py +2300 -0
- src/lsp/dap_client.py +480 -0
- src/lsp/edits.py +84 -0
- src/lsp/framing.py +73 -0
- src/lsp/protocol.py +931 -0
- src/main.py +260 -0
- src/memtrim.py +91 -0
- src/plugins/__init__.py +1 -0
- src/plugins/api.py +1761 -0
- src/plugins/loader.py +571 -0
- src/plugins/process_runner.py +519 -0
- src/plugins/registry.py +342 -0
- src/plugins/safety.py +367 -0
- src/plugins/startup.py +195 -0
- src/plugins/store.py +1178 -0
- src/proc_registry.py +278 -0
- src/pyexec.py +394 -0
- src/recovery.py +259 -0
- src/stall_trace.py +92 -0
- src/standalone.py +1070 -0
- src/startup_profile.py +35 -0
- src/syntax/__init__.py +1 -0
- src/syntax/highlighter.py +776 -0
- src/syntax/patterns.py +584 -0
- src/system_profile.py +430 -0
- src/terminal/backends.py +658 -0
- src/terminal/internal.py +346 -0
- src/terminal/keys.py +138 -0
- src/terminal/palette.py +67 -0
- src/terminal/session.py +283 -0
- src/terminal/shells.py +79 -0
- src/terminal/view.py +489 -0
- src/terminal/vt.py +870 -0
- src/textfmt.py +22 -0
- src/theme/__init__.py +1 -0
- src/theme/base.py +1281 -0
- src/theme/colors.py +49 -0
- src/theme/manager.py +602 -0
- src/theme/utils.py +312 -0
- src/toolbox.py +329 -0
- src/trash_core.py +531 -0
- src/ui/__init__.py +1 -0
- src/ui/_perf_utils.py +285 -0
- src/ui/_persistence_utils.py +93 -0
- src/ui/accessibility.py +843 -0
- src/ui/activity_bar.py +860 -0
- src/ui/app_embed.py +434 -0
- src/ui/archive_panel.py +608 -0
- src/ui/bookmarks.py +314 -0
- src/ui/breadcrumb.py +383 -0
- src/ui/calculator_panel.py +982 -0
- src/ui/calendar_panel.py +1218 -0
- src/ui/chat_panel.py +1271 -0
- src/ui/chat_profile_dialog.py +278 -0
- src/ui/chat_render.py +128 -0
- src/ui/clock_panel.py +810 -0
- src/ui/code_outline.py +364 -0
- src/ui/code_runner.py +729 -0
- src/ui/code_stats.py +546 -0
- src/ui/collab_panel.py +1009 -0
- src/ui/color_picker.py +547 -0
- src/ui/command_palette.py +452 -0
- src/ui/cursor_manager.py +750 -0
- src/ui/custom_keywords_panel.py +413 -0
- src/ui/debug_panel.py +1037 -0
- src/ui/dependency_graph.py +692 -0
- src/ui/diff_panel.py +381 -0
- src/ui/docs_panel.py +514 -0
- src/ui/doom_embed.py +349 -0
- src/ui/dropdown.py +321 -0
- src/ui/easter_eggs.py +979 -0
- src/ui/env_manager.py +666 -0
- src/ui/extcode_bridge.py +215 -0
- src/ui/extcode_dialogs.py +412 -0
- src/ui/extcompat_dialog.py +583 -0
- src/ui/file_timeline.py +319 -0
- src/ui/file_tree.py +1208 -0
- src/ui/find_in_files.py +1355 -0
- src/ui/flowchart_panel.py +727 -0
- src/ui/formatter_panel.py +490 -0
- src/ui/git_auth.py +763 -0
- src/ui/git_clone_dialog.py +487 -0
- src/ui/git_panel.py +1483 -0
- src/ui/grab_safe.py +84 -0
- src/ui/internal_python_dialog.py +98 -0
- src/ui/k_ui/__init__.py +1305 -0
- src/ui/k_ui/_bgrenderer.py +317 -0
- src/ui/k_ui/_colors.py +213 -0
- src/ui/k_ui/_dock.py +545 -0
- src/ui/k_ui/_easter.py +290 -0
- src/ui/k_ui/_engine.py +5448 -0
- src/ui/k_ui/_perf.py +333 -0
- src/ui/k_ui/_tkutil.py +7 -0
- src/ui/k_ui/_tooltip.py +365 -0
- src/ui/k_ui/_widgets.py +1204 -0
- src/ui/k_ui/_world.py +837 -0
- src/ui/key_remapper.py +856 -0
- src/ui/launcher.py +1252 -0
- src/ui/lazy_panel.py +73 -0
- src/ui/macro_recorder.py +610 -0
- src/ui/menu_bar.py +898 -0
- src/ui/output_panel.py +321 -0
- src/ui/paint_canvas.py +1000 -0
- src/ui/paint_engine.py +535 -0
- src/ui/paint_panel.py +888 -0
- src/ui/panel_detach.py +112 -0
- src/ui/performance_panel.py +861 -0
- src/ui/pip_manager.py +1758 -0
- src/ui/plugin_panel.py +1586 -0
- src/ui/pomodoro_panel.py +447 -0
- src/ui/problems.py +566 -0
- src/ui/process_manager.py +1657 -0
- src/ui/project_templates.py +775 -0
- src/ui/recovery_dialog.py +122 -0
- src/ui/regex_playground.py +304 -0
- src/ui/remote_adapters.py +1398 -0
- src/ui/remote_browser.py +1224 -0
- src/ui/remote_profile_dialog.py +342 -0
- src/ui/render_panel.py +1293 -0
- src/ui/rest_client.py +549 -0
- src/ui/scratchpad.py +548 -0
- src/ui/search_bar.py +1274 -0
- src/ui/settings_editor.py +3349 -0
- src/ui/settings_window.py +1554 -0
- src/ui/snippets_panel.py +597 -0
- src/ui/sql_studio.py +1815 -0
- src/ui/status_bar.py +438 -0
- src/ui/tab_bar.py +654 -0
- src/ui/task_manager.py +1773 -0
- src/ui/terminal.py +525 -0
- src/ui/theme_preview_panel.py +851 -0
- src/ui/thread_safe_tk.py +152 -0
- src/ui/time_tracker.py +574 -0
- src/ui/tkbind.py +43 -0
- src/ui/todo_panel.py +358 -0
- src/ui/toolbox_panels.py +658 -0
- src/ui/trash_manager.py +657 -0
- src/ui/ui_scale.py +294 -0
- src/ui/ux_enhancements.py +41 -0
- src/ui/web_preview.py +397 -0
- src/ui/webdev.py +630 -0
- src/ui/welcome.py +567 -0
- src/ui/window_embed.py +1500 -0
- src/ui/wizard.py +1550 -0
- src/ui/workspace_switcher.py +418 -0
- src/ui/workspace_trust.py +370 -0
- src/ui/zen_audio.py +354 -0
- src/ui/zen_media.py +2271 -0
- src/ui/zen_media_client.py +303 -0
- src/ui/zen_media_host.py +329 -0
- src/ui/zen_player.py +907 -0
- src/ui/zen_player_widgets.py +700 -0
- src/updater/__init__.py +11 -0
- src/updater/assets.py +145 -0
- src/updater/backup.py +101 -0
- src/updater/channel.py +221 -0
- src/updater/dialog.py +492 -0
- src/updater/integrity.py +111 -0
- src/updater/manager.py +727 -0
- src/updater/result.py +114 -0
- src/venv_runtime.py +531 -0
- src/workspace_state.py +25 -0
src/ui/color_picker.py
ADDED
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
"""Seletor de cores integrado ao Codis.
|
|
2
|
+
|
|
3
|
+
Provê ``ColorPickerPopup``, uma janela flutuante com seleção de cor via
|
|
4
|
+
roda cromática, sliders HSV/RGB e campo hexadecimal, integrada ao
|
|
5
|
+
workflow de edição de arquivos CSS, SCSS e similares.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import colorsys
|
|
11
|
+
import contextlib
|
|
12
|
+
import logging
|
|
13
|
+
import re
|
|
14
|
+
import tkinter as tk
|
|
15
|
+
from collections.abc import Callable
|
|
16
|
+
|
|
17
|
+
from src.constants import FONT_MONO, FONT_UI
|
|
18
|
+
from src.i18n import _t
|
|
19
|
+
from src.theme.colors import hex_to_rgb
|
|
20
|
+
from src.ui.grab_safe import safe_grab_set
|
|
21
|
+
|
|
22
|
+
logger = logging.getLogger("Codis")
|
|
23
|
+
|
|
24
|
+
_HEX_RE = re.compile(r"#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b")
|
|
25
|
+
_RGB_RE = re.compile(r"rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)")
|
|
26
|
+
_HSL_RE = re.compile(
|
|
27
|
+
r"hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def detect_colors_in_line(line: str) -> list[tuple[int, int, str]]:
|
|
31
|
+
"""Return list of (start_col, end_col, hex_color) in *line*."""
|
|
32
|
+
results: list[tuple[int, int, str]] = []
|
|
33
|
+
for m in _HEX_RE.finditer(line):
|
|
34
|
+
hex_s = m.group(1)
|
|
35
|
+
if len(hex_s) == 3:
|
|
36
|
+
hex_s = "".join(c * 2 for c in hex_s)
|
|
37
|
+
results.append((m.start(), m.end(), f"#{hex_s.upper()}"))
|
|
38
|
+
for m in _RGB_RE.finditer(line):
|
|
39
|
+
r, g, b = int(m.group(1)), int(m.group(2)), int(m.group(3))
|
|
40
|
+
results.append((m.start(), m.end(), f"#{r:02X}{g:02X}{b:02X}"))
|
|
41
|
+
for m in _HSL_RE.finditer(line):
|
|
42
|
+
h, s, l_ = int(m.group(1)), int(m.group(2)), int(m.group(3))
|
|
43
|
+
r, g, b = _hsl_to_rgb(h, s / 100, l_ / 100)
|
|
44
|
+
results.append((m.start(), m.end(), f"#{r:02X}{g:02X}{b:02X}"))
|
|
45
|
+
return results
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _hsl_to_rgb(h: int, s: float, l_: float) -> tuple[int, int, int]:
|
|
49
|
+
r, g, b = colorsys.hls_to_rgb(h / 360, l_, s)
|
|
50
|
+
return int(r * 255), int(g * 255), int(b * 255)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _rgb_to_hex(r: int, g: int, b: int) -> str:
|
|
54
|
+
return f"#{r:02X}{g:02X}{b:02X}"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _rgb_to_hsl(r: int, g: int, b: int) -> tuple[int, int, int]:
|
|
58
|
+
h, l_, s = colorsys.rgb_to_hls(r / 255, g / 255, b / 255)
|
|
59
|
+
return round(h * 360), round(s * 100), round(l_ * 100)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class ColorPickerPopup(tk.Toplevel):
|
|
63
|
+
"""
|
|
64
|
+
Floating color picker with:
|
|
65
|
+
- Visual HSV gradient canvas
|
|
66
|
+
- Hue slider
|
|
67
|
+
- Opacity slider
|
|
68
|
+
- Hex / RGB / HSL inputs
|
|
69
|
+
- Recent colors palette
|
|
70
|
+
- Insert / Copy buttons
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
_RECENT: list[str] = []
|
|
74
|
+
_MAX_RECENT = 12
|
|
75
|
+
|
|
76
|
+
def __init__(
|
|
77
|
+
self,
|
|
78
|
+
parent: tk.Widget,
|
|
79
|
+
tmgr,
|
|
80
|
+
initial: str = "#4a9eff",
|
|
81
|
+
on_pick: Callable[[str], None] | None = None,
|
|
82
|
+
) -> None:
|
|
83
|
+
t = tmgr.theme
|
|
84
|
+
super().__init__(parent)
|
|
85
|
+
self.title(_t("ui.color_picker"))
|
|
86
|
+
self.resizable(False, False)
|
|
87
|
+
self.config(bg=t.floating_bg)
|
|
88
|
+
self.transient(parent)
|
|
89
|
+
safe_grab_set(self)
|
|
90
|
+
self.wm_attributes("-topmost", True)
|
|
91
|
+
|
|
92
|
+
self._tmgr = tmgr
|
|
93
|
+
self._on_pick = on_pick
|
|
94
|
+
self._hex_var = tk.StringVar(value=initial.upper())
|
|
95
|
+
|
|
96
|
+
try:
|
|
97
|
+
r, g, b = hex_to_rgb(initial)
|
|
98
|
+
except ValueError:
|
|
99
|
+
r, g, b = 74, 158, 255
|
|
100
|
+
|
|
101
|
+
h, s, v = self._rgb_to_hsv(r, g, b)
|
|
102
|
+
self._h = h
|
|
103
|
+
self._s = s
|
|
104
|
+
self._v = v
|
|
105
|
+
self._alpha = 1.0
|
|
106
|
+
|
|
107
|
+
self._build(t)
|
|
108
|
+
self._draw_sv_canvas()
|
|
109
|
+
self._draw_hue_slider()
|
|
110
|
+
self._update_from_hsv()
|
|
111
|
+
|
|
112
|
+
self.update_idletasks()
|
|
113
|
+
px = parent.winfo_rootx() + parent.winfo_width() // 2
|
|
114
|
+
py = parent.winfo_rooty() + parent.winfo_height() // 2
|
|
115
|
+
w, h2 = self.winfo_reqwidth(), self.winfo_reqheight()
|
|
116
|
+
self.geometry(f"+{px - w // 2}+{py - h2 // 2}")
|
|
117
|
+
|
|
118
|
+
def _build(self, t) -> None:
|
|
119
|
+
self._sv_size = 220
|
|
120
|
+
sv_frame = tk.Frame(self, bg=t.floating_bg)
|
|
121
|
+
sv_frame.pack(padx=12, pady=(12, 4))
|
|
122
|
+
|
|
123
|
+
self._sv_canvas = tk.Canvas(
|
|
124
|
+
sv_frame,
|
|
125
|
+
width=self._sv_size,
|
|
126
|
+
height=self._sv_size,
|
|
127
|
+
highlightthickness=1,
|
|
128
|
+
highlightbackground=t.border,
|
|
129
|
+
cursor="crosshair",
|
|
130
|
+
)
|
|
131
|
+
self._sv_canvas.pack()
|
|
132
|
+
self._sv_canvas.bind("<Button-1>", self._on_sv_click)
|
|
133
|
+
self._sv_canvas.bind("<B1-Motion>", self._on_sv_click)
|
|
134
|
+
|
|
135
|
+
hue_frame = tk.Frame(self, bg=t.floating_bg)
|
|
136
|
+
hue_frame.pack(fill="x", padx=12, pady=2)
|
|
137
|
+
tk.Label(
|
|
138
|
+
hue_frame,
|
|
139
|
+
text="H",
|
|
140
|
+
bg=t.floating_bg,
|
|
141
|
+
fg=t.fg_muted,
|
|
142
|
+
font=(FONT_UI, 8),
|
|
143
|
+
width=2,
|
|
144
|
+
).pack(side="left")
|
|
145
|
+
self._hue_canvas = tk.Canvas(
|
|
146
|
+
hue_frame,
|
|
147
|
+
width=220,
|
|
148
|
+
height=18,
|
|
149
|
+
highlightthickness=1,
|
|
150
|
+
highlightbackground=t.border,
|
|
151
|
+
cursor="sb_h_double_arrow",
|
|
152
|
+
)
|
|
153
|
+
self._hue_canvas.pack(side="left", padx=4)
|
|
154
|
+
self._hue_canvas.bind("<Button-1>", self._on_hue_click)
|
|
155
|
+
self._hue_canvas.bind("<B1-Motion>", self._on_hue_click)
|
|
156
|
+
|
|
157
|
+
alpha_frame = tk.Frame(self, bg=t.floating_bg)
|
|
158
|
+
alpha_frame.pack(fill="x", padx=12, pady=2)
|
|
159
|
+
tk.Label(
|
|
160
|
+
alpha_frame,
|
|
161
|
+
text="A",
|
|
162
|
+
bg=t.floating_bg,
|
|
163
|
+
fg=t.fg_muted,
|
|
164
|
+
font=(FONT_UI, 8),
|
|
165
|
+
width=2,
|
|
166
|
+
).pack(side="left")
|
|
167
|
+
self._alpha_canvas = tk.Canvas(
|
|
168
|
+
alpha_frame,
|
|
169
|
+
width=220,
|
|
170
|
+
height=18,
|
|
171
|
+
highlightthickness=1,
|
|
172
|
+
highlightbackground=t.border,
|
|
173
|
+
cursor="sb_h_double_arrow",
|
|
174
|
+
)
|
|
175
|
+
self._alpha_canvas.pack(side="left", padx=4)
|
|
176
|
+
self._alpha_canvas.bind("<Button-1>", self._on_alpha_click)
|
|
177
|
+
self._alpha_canvas.bind("<B1-Motion>", self._on_alpha_click)
|
|
178
|
+
|
|
179
|
+
info_row = tk.Frame(self, bg=t.floating_bg)
|
|
180
|
+
info_row.pack(fill="x", padx=12, pady=6)
|
|
181
|
+
|
|
182
|
+
self._preview = tk.Frame(
|
|
183
|
+
info_row,
|
|
184
|
+
width=48,
|
|
185
|
+
height=48,
|
|
186
|
+
bg="#4a9eff",
|
|
187
|
+
highlightthickness=1,
|
|
188
|
+
highlightbackground=t.border,
|
|
189
|
+
)
|
|
190
|
+
self._preview.pack(side="left", padx=(0, 10))
|
|
191
|
+
self._preview.pack_propagate(False)
|
|
192
|
+
|
|
193
|
+
inputs = tk.Frame(info_row, bg=t.floating_bg)
|
|
194
|
+
inputs.pack(side="left", fill="both", expand=True)
|
|
195
|
+
|
|
196
|
+
ew = {
|
|
197
|
+
"bg": t.input_bg,
|
|
198
|
+
"fg": t.fg,
|
|
199
|
+
"insertbackground": t.cursor,
|
|
200
|
+
"relief": "flat",
|
|
201
|
+
"bd": 0,
|
|
202
|
+
"highlightthickness": 1,
|
|
203
|
+
"highlightbackground": t.border,
|
|
204
|
+
"font": (FONT_MONO, 9),
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
hex_row = tk.Frame(inputs, bg=t.floating_bg)
|
|
208
|
+
hex_row.pack(fill="x", pady=1)
|
|
209
|
+
tk.Label(
|
|
210
|
+
hex_row,
|
|
211
|
+
text="Hex",
|
|
212
|
+
bg=t.floating_bg,
|
|
213
|
+
fg=t.fg_muted,
|
|
214
|
+
font=(FONT_UI, 8),
|
|
215
|
+
width=5,
|
|
216
|
+
anchor="w",
|
|
217
|
+
).pack(side="left")
|
|
218
|
+
self._hex_entry = tk.Entry(
|
|
219
|
+
hex_row, textvariable=self._hex_var, width=10, **ew)
|
|
220
|
+
self._hex_entry.pack(side="left")
|
|
221
|
+
self._hex_entry.bind("<Return>", lambda _: self._apply_hex())
|
|
222
|
+
self._hex_entry.bind("<FocusOut>", lambda _: self._apply_hex())
|
|
223
|
+
|
|
224
|
+
self._r_var = tk.IntVar()
|
|
225
|
+
self._g_var = tk.IntVar()
|
|
226
|
+
self._b_var = tk.IntVar()
|
|
227
|
+
rgb_row = tk.Frame(inputs, bg=t.floating_bg)
|
|
228
|
+
rgb_row.pack(fill="x", pady=1)
|
|
229
|
+
tk.Label(
|
|
230
|
+
rgb_row,
|
|
231
|
+
text="RGB",
|
|
232
|
+
bg=t.floating_bg,
|
|
233
|
+
fg=t.fg_muted,
|
|
234
|
+
font=(FONT_UI, 8),
|
|
235
|
+
width=5,
|
|
236
|
+
anchor="w",
|
|
237
|
+
).pack(side="left")
|
|
238
|
+
for var, w in ((self._r_var, 4), (self._g_var, 4), (self._b_var, 4)):
|
|
239
|
+
e = tk.Entry(rgb_row, textvariable=var, width=w, **ew)
|
|
240
|
+
e.pack(side="left", padx=1)
|
|
241
|
+
e.bind("<Return>", lambda _, v=var: self._apply_rgb())
|
|
242
|
+
e.bind("<FocusOut>", lambda _, v=var: self._apply_rgb())
|
|
243
|
+
|
|
244
|
+
self._hl_var = tk.IntVar()
|
|
245
|
+
self._sl_var = tk.IntVar()
|
|
246
|
+
self._ll_var = tk.IntVar()
|
|
247
|
+
hsl_row = tk.Frame(inputs, bg=t.floating_bg)
|
|
248
|
+
hsl_row.pack(fill="x", pady=1)
|
|
249
|
+
tk.Label(
|
|
250
|
+
hsl_row,
|
|
251
|
+
text="HSL",
|
|
252
|
+
bg=t.floating_bg,
|
|
253
|
+
fg=t.fg_muted,
|
|
254
|
+
font=(FONT_UI, 8),
|
|
255
|
+
width=5,
|
|
256
|
+
anchor="w",
|
|
257
|
+
).pack(side="left")
|
|
258
|
+
for var, _ in ((self._hl_var, "°"), (self._sl_var, "%"), (self._ll_var, "%")):
|
|
259
|
+
e = tk.Entry(hsl_row, textvariable=var, width=4, **ew)
|
|
260
|
+
e.pack(side="left", padx=1)
|
|
261
|
+
e.bind("<Return>", lambda _, v=var: self._apply_hsl())
|
|
262
|
+
e.bind("<FocusOut>", lambda _, v=var: self._apply_hsl())
|
|
263
|
+
|
|
264
|
+
palette_frame = tk.Frame(self, bg=t.floating_bg)
|
|
265
|
+
palette_frame.pack(fill="x", padx=12, pady=(2, 6))
|
|
266
|
+
tk.Label(
|
|
267
|
+
palette_frame,
|
|
268
|
+
text=_t("colorpicker.recent", "Recentes"),
|
|
269
|
+
bg=t.floating_bg,
|
|
270
|
+
fg=t.fg_muted,
|
|
271
|
+
font=(FONT_UI, 8),
|
|
272
|
+
).pack(anchor="w")
|
|
273
|
+
self._palette = tk.Frame(palette_frame, bg=t.floating_bg)
|
|
274
|
+
self._palette.pack(fill="x")
|
|
275
|
+
self._rebuild_palette(t)
|
|
276
|
+
|
|
277
|
+
btn_row = tk.Frame(self, bg=t.floating_bg)
|
|
278
|
+
btn_row.pack(fill="x", padx=12, pady=(4, 12))
|
|
279
|
+
|
|
280
|
+
copy_btn = tk.Label(
|
|
281
|
+
btn_row,
|
|
282
|
+
text=_t("colorpicker.copy", "Copiar"),
|
|
283
|
+
bg=t.btn_bg,
|
|
284
|
+
fg=t.fg,
|
|
285
|
+
font=(FONT_UI, 9),
|
|
286
|
+
cursor="hand2",
|
|
287
|
+
padx=14,
|
|
288
|
+
pady=4,
|
|
289
|
+
relief="flat",
|
|
290
|
+
)
|
|
291
|
+
copy_btn.pack(side="right", padx=4)
|
|
292
|
+
copy_btn.bind("<Button-1>", lambda _: self._copy())
|
|
293
|
+
copy_btn.bind("<Enter>", lambda _,
|
|
294
|
+
w=copy_btn: w.config(bg=t.btn_hover))
|
|
295
|
+
copy_btn.bind("<Leave>", lambda _, w=copy_btn: w.config(bg=t.btn_bg))
|
|
296
|
+
|
|
297
|
+
insert_btn = tk.Label(
|
|
298
|
+
btn_row,
|
|
299
|
+
text=_t("ui.insert_color"),
|
|
300
|
+
bg=t.btn_primary,
|
|
301
|
+
fg="#000",
|
|
302
|
+
font=(FONT_UI, 9, "bold"),
|
|
303
|
+
cursor="hand2",
|
|
304
|
+
padx=14,
|
|
305
|
+
pady=4,
|
|
306
|
+
relief="flat",
|
|
307
|
+
)
|
|
308
|
+
insert_btn.pack(side="right", padx=4)
|
|
309
|
+
insert_btn.bind("<Button-1>", lambda _: self._insert())
|
|
310
|
+
insert_btn.bind("<Enter>", lambda _,
|
|
311
|
+
w=insert_btn: w.config(bg=t.accent))
|
|
312
|
+
insert_btn.bind("<Leave>", lambda _,
|
|
313
|
+
w=insert_btn: w.config(bg=t.btn_primary))
|
|
314
|
+
|
|
315
|
+
cancel_btn = tk.Label(
|
|
316
|
+
btn_row,
|
|
317
|
+
text=_t("colorpicker.cancel", "Cancelar"),
|
|
318
|
+
bg=t.btn_bg,
|
|
319
|
+
fg=t.fg_muted,
|
|
320
|
+
font=(FONT_UI, 9),
|
|
321
|
+
cursor="hand2",
|
|
322
|
+
padx=10,
|
|
323
|
+
pady=4,
|
|
324
|
+
relief="flat",
|
|
325
|
+
)
|
|
326
|
+
cancel_btn.pack(side="left", padx=4)
|
|
327
|
+
cancel_btn.bind("<Button-1>", lambda _: self.destroy())
|
|
328
|
+
|
|
329
|
+
def _draw_sv_canvas(self) -> None:
|
|
330
|
+
"""Draw SV gradient for current hue."""
|
|
331
|
+
size = self._sv_size
|
|
332
|
+
self._sv_canvas.delete("all")
|
|
333
|
+
|
|
334
|
+
step = max(1, size // 64)
|
|
335
|
+
small = size // step
|
|
336
|
+
img_data: list[str] = []
|
|
337
|
+
for y in range(small):
|
|
338
|
+
row = []
|
|
339
|
+
for x in range(small):
|
|
340
|
+
s = x / small
|
|
341
|
+
v = 1 - y / small
|
|
342
|
+
r, g, b = (
|
|
343
|
+
round(c * 255) for c in colorsys.hsv_to_rgb(self._h / 360, s, v)
|
|
344
|
+
)
|
|
345
|
+
row.append(f"#{r:02X}{g:02X}{b:02X}")
|
|
346
|
+
img_data.append("{" + " ".join(row) + "}")
|
|
347
|
+
|
|
348
|
+
with contextlib.suppress(tk.TclError, AttributeError):
|
|
349
|
+
small_img = tk.PhotoImage(width=small, height=small)
|
|
350
|
+
small_img.put("\n".join(img_data))
|
|
351
|
+
|
|
352
|
+
self._sv_img = small_img.zoom(step, step)
|
|
353
|
+
|
|
354
|
+
if self._sv_img.width() != size or self._sv_img.height() != size:
|
|
355
|
+
self._sv_img = self._sv_img.subsample(
|
|
356
|
+
max(1, self._sv_img.width() // size),
|
|
357
|
+
max(1, self._sv_img.height() // size),
|
|
358
|
+
)
|
|
359
|
+
self._sv_canvas.create_image(0, 0, anchor="nw", image=self._sv_img)
|
|
360
|
+
self._sv_canvas.config(width=size, height=size)
|
|
361
|
+
|
|
362
|
+
cx = int(self._s * size)
|
|
363
|
+
cy = int((1 - self._v) * size)
|
|
364
|
+
r2 = 6
|
|
365
|
+
self._sv_canvas.create_oval(
|
|
366
|
+
cx - r2, cy - r2, cx + r2, cy + r2, outline="white", width=2
|
|
367
|
+
)
|
|
368
|
+
self._sv_canvas.create_oval(
|
|
369
|
+
cx - r2 + 2, cy - r2 + 2, cx + r2 - 2, cy + r2 - 2, outline="black", width=1
|
|
370
|
+
)
|
|
371
|
+
|
|
372
|
+
def _draw_hue_slider(self) -> None:
|
|
373
|
+
"""Renderiza a barra de seleção de matiz (hue) no canvas do seletor."""
|
|
374
|
+
w, h = 220, 18
|
|
375
|
+
self._hue_canvas.delete("all")
|
|
376
|
+
for x in range(w):
|
|
377
|
+
hue = x / w * 360
|
|
378
|
+
r, g, b = (round(c * 255)
|
|
379
|
+
for c in colorsys.hsv_to_rgb(hue / 360, 1, 1))
|
|
380
|
+
self._hue_canvas.create_line(
|
|
381
|
+
x, 0, x, h, fill=f"#{r:02X}{g:02X}{b:02X}")
|
|
382
|
+
|
|
383
|
+
cx = int(self._h / 360 * w)
|
|
384
|
+
self._hue_canvas.create_rectangle(
|
|
385
|
+
cx - 3, 0, cx + 3, h, outline="white", width=2
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
def _draw_alpha_slider(self) -> None:
|
|
389
|
+
"""Renderiza a barra de seleção de opacidade (alpha) no canvas."""
|
|
390
|
+
w, h = 220, 18
|
|
391
|
+
self._alpha_canvas.delete("all")
|
|
392
|
+
|
|
393
|
+
for i in range(0, w, 8):
|
|
394
|
+
for j in range(0, h, 8):
|
|
395
|
+
color = "#bbb" if (i // 8 + j // 8) % 2 == 0 else "#fff"
|
|
396
|
+
self._alpha_canvas.create_rectangle(
|
|
397
|
+
i, j, i + 8, j + 8, fill=color, outline=""
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
r, g, b = hex_to_rgb(self._hex_var.get())
|
|
401
|
+
for x in range(w):
|
|
402
|
+
alpha = x / w
|
|
403
|
+
|
|
404
|
+
cr = int(r * alpha + 255 * (1 - alpha))
|
|
405
|
+
cg = int(g * alpha + 255 * (1 - alpha))
|
|
406
|
+
cb = int(b * alpha + 255 * (1 - alpha))
|
|
407
|
+
self._alpha_canvas.create_line(
|
|
408
|
+
x, 0, x, h, fill=f"#{cr:02X}{cg:02X}{cb:02X}"
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
cx = int(self._alpha * w)
|
|
412
|
+
self._alpha_canvas.create_rectangle(
|
|
413
|
+
cx - 3, 0, cx + 3, h, outline="black", width=2
|
|
414
|
+
)
|
|
415
|
+
|
|
416
|
+
def _rebuild_palette(self, t=None) -> None:
|
|
417
|
+
if t is None:
|
|
418
|
+
t = self._tmgr.theme
|
|
419
|
+
for w in self._palette.winfo_children():
|
|
420
|
+
w.destroy()
|
|
421
|
+
if not self._RECENT:
|
|
422
|
+
return
|
|
423
|
+
for hex_c in self._RECENT[-self._MAX_RECENT:]:
|
|
424
|
+
sw = tk.Frame(
|
|
425
|
+
self._palette,
|
|
426
|
+
bg=hex_c,
|
|
427
|
+
width=18,
|
|
428
|
+
height=18,
|
|
429
|
+
cursor="hand2",
|
|
430
|
+
highlightthickness=1,
|
|
431
|
+
highlightbackground=t.border,
|
|
432
|
+
)
|
|
433
|
+
sw.pack(side="left", padx=1)
|
|
434
|
+
sw.pack_propagate(False)
|
|
435
|
+
sw.bind("<Button-1>", lambda _, c=hex_c: self._set_hex(c))
|
|
436
|
+
|
|
437
|
+
def _on_sv_click(self, e) -> None:
|
|
438
|
+
size = self._sv_size
|
|
439
|
+
self._s = max(0, min(1, e.x / size))
|
|
440
|
+
self._v = max(0, min(1, 1 - e.y / size))
|
|
441
|
+
self._update_from_hsv()
|
|
442
|
+
|
|
443
|
+
def _on_hue_click(self, e) -> None:
|
|
444
|
+
self._h = max(0, min(359, e.x / 220 * 360))
|
|
445
|
+
self._draw_sv_canvas()
|
|
446
|
+
self._draw_hue_slider()
|
|
447
|
+
self._update_from_hsv()
|
|
448
|
+
|
|
449
|
+
def _on_alpha_click(self, e) -> None:
|
|
450
|
+
self._alpha = max(0, min(1, e.x / 220))
|
|
451
|
+
self._draw_alpha_slider()
|
|
452
|
+
|
|
453
|
+
def _apply_hex(self) -> None:
|
|
454
|
+
"""Parseia o campo hex e aplica a cor resultante ao seletor."""
|
|
455
|
+
hex_c = self._hex_var.get().strip()
|
|
456
|
+
if not hex_c.startswith("#"):
|
|
457
|
+
hex_c = "#" + hex_c
|
|
458
|
+
with contextlib.suppress(ValueError, tk.TclError):
|
|
459
|
+
r, g, b = hex_to_rgb(hex_c)
|
|
460
|
+
self._h, self._s, self._v = self._rgb_to_hsv(r, g, b)
|
|
461
|
+
self._draw_sv_canvas()
|
|
462
|
+
self._draw_hue_slider()
|
|
463
|
+
self._update_from_hsv(update_hex=False)
|
|
464
|
+
|
|
465
|
+
def _apply_rgb(self) -> None:
|
|
466
|
+
"""Lê os campos R, G, B e aplica a cor resultante ao seletor."""
|
|
467
|
+
with contextlib.suppress(ValueError, tk.TclError):
|
|
468
|
+
r = max(0, min(255, self._r_var.get()))
|
|
469
|
+
g = max(0, min(255, self._g_var.get()))
|
|
470
|
+
b = max(0, min(255, self._b_var.get()))
|
|
471
|
+
hex_c = _rgb_to_hex(r, g, b)
|
|
472
|
+
self._hex_var.set(hex_c)
|
|
473
|
+
self._h, self._s, self._v = self._rgb_to_hsv(r, g, b)
|
|
474
|
+
self._draw_sv_canvas()
|
|
475
|
+
self._draw_hue_slider()
|
|
476
|
+
self._update_from_hsv(update_rgb=False)
|
|
477
|
+
|
|
478
|
+
def _apply_hsl(self) -> None:
|
|
479
|
+
"""Lê os campos H, S, L e aplica a cor resultante ao seletor."""
|
|
480
|
+
with contextlib.suppress(ValueError, tk.TclError):
|
|
481
|
+
h = self._hl_var.get()
|
|
482
|
+
s = self._sl_var.get() / 100
|
|
483
|
+
l_ = self._ll_var.get() / 100
|
|
484
|
+
r, g, b = _hsl_to_rgb(h, s, l_)
|
|
485
|
+
hex_c = _rgb_to_hex(r, g, b)
|
|
486
|
+
self._hex_var.set(hex_c)
|
|
487
|
+
self._h, self._s, self._v = self._rgb_to_hsv(r, g, b)
|
|
488
|
+
self._draw_sv_canvas()
|
|
489
|
+
self._draw_hue_slider()
|
|
490
|
+
self._update_from_hsv(update_hsl=False)
|
|
491
|
+
|
|
492
|
+
def _set_hex(self, hex_c: str) -> None:
|
|
493
|
+
self._hex_var.set(hex_c.upper())
|
|
494
|
+
self._apply_hex()
|
|
495
|
+
|
|
496
|
+
def _update_from_hsv(
|
|
497
|
+
self, *, update_hex=True, update_rgb=True, update_hsl=True
|
|
498
|
+
) -> None:
|
|
499
|
+
r, g, b = (
|
|
500
|
+
round(c * 255) for c in colorsys.hsv_to_rgb(self._h / 360, self._s, self._v)
|
|
501
|
+
)
|
|
502
|
+
hex_c = _rgb_to_hex(r, g, b)
|
|
503
|
+
|
|
504
|
+
if update_hex:
|
|
505
|
+
self._hex_var.set(hex_c)
|
|
506
|
+
if update_rgb:
|
|
507
|
+
self._r_var.set(r)
|
|
508
|
+
self._g_var.set(g)
|
|
509
|
+
self._b_var.set(b)
|
|
510
|
+
if update_hsl:
|
|
511
|
+
h, s, l_ = _rgb_to_hsl(r, g, b)
|
|
512
|
+
self._hl_var.set(h)
|
|
513
|
+
self._sl_var.set(s)
|
|
514
|
+
self._ll_var.set(l_)
|
|
515
|
+
|
|
516
|
+
self._preview.config(bg=hex_c)
|
|
517
|
+
with contextlib.suppress(tk.TclError):
|
|
518
|
+
self._draw_alpha_slider()
|
|
519
|
+
|
|
520
|
+
@staticmethod
|
|
521
|
+
def _rgb_to_hsv(r: int, g: int, b: int) -> tuple[float, float, float]:
|
|
522
|
+
h, s, v = colorsys.rgb_to_hsv(r / 255, g / 255, b / 255)
|
|
523
|
+
return h * 360, s, v
|
|
524
|
+
|
|
525
|
+
def _copy(self) -> None:
|
|
526
|
+
"""Copia os dados selecionados."""
|
|
527
|
+
hex_c = self._hex_var.get()
|
|
528
|
+
self.clipboard_clear()
|
|
529
|
+
self.clipboard_append(hex_c)
|
|
530
|
+
ColorPickerPopup._add_recent(hex_c)
|
|
531
|
+
self.destroy()
|
|
532
|
+
|
|
533
|
+
def _insert(self) -> None:
|
|
534
|
+
"""Insere elemento na posição indicada."""
|
|
535
|
+
hex_c = self._hex_var.get()
|
|
536
|
+
ColorPickerPopup._add_recent(hex_c)
|
|
537
|
+
if self._on_pick:
|
|
538
|
+
self._on_pick(hex_c)
|
|
539
|
+
self.destroy()
|
|
540
|
+
|
|
541
|
+
@classmethod
|
|
542
|
+
def _add_recent(cls, hex_c: str) -> None:
|
|
543
|
+
if hex_c in cls._RECENT:
|
|
544
|
+
cls._RECENT.remove(hex_c)
|
|
545
|
+
cls._RECENT.append(hex_c)
|
|
546
|
+
if len(cls._RECENT) > cls._MAX_RECENT:
|
|
547
|
+
cls._RECENT.pop(0)
|