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/paint_panel.py
ADDED
|
@@ -0,0 +1,888 @@
|
|
|
1
|
+
"""Codis - Editor de Imagens Integrado / Paint.
|
|
2
|
+
|
|
3
|
+
Ferramentas:
|
|
4
|
+
- Pincel suavizado com anti-aliasing e opacidade
|
|
5
|
+
- Pincel pixel-art (duro, sem AA)
|
|
6
|
+
- Spray / Aerógrafo
|
|
7
|
+
- Borracha
|
|
8
|
+
- Balde de tinta com tolerância ajustável (flood fill otimizado)
|
|
9
|
+
- Linha, Retângulo (outline/fill), Elipse (outline/fill), Polígono
|
|
10
|
+
- Seleção retangular: recortar, copiar, colar, mover, deletar
|
|
11
|
+
- Texto com escolha de fonte e tamanho
|
|
12
|
+
- Conta-gotas (clique esquerdo=cor primária, direito=secundária)
|
|
13
|
+
- Zoom 6.25%-3200% com Ctrl+Scroll; pan com botão do meio/espaço+drag
|
|
14
|
+
- Grid de pixels ativado com zoom >= 8x
|
|
15
|
+
- Desfazer / Refazer ilimitado por memória (Ctrl+Z / Ctrl+Y)
|
|
16
|
+
- Abrir / Salvar PNG, JPG, BMP, WEBP, GIF
|
|
17
|
+
- Paleta de cores rápida (32 swatches) com slots customizáveis
|
|
18
|
+
- Cores primária e secundária (clique direito usa cor secundária)
|
|
19
|
+
- Opacidade do pincel ajustável
|
|
20
|
+
- Redimensionar canvas com ou sem resize da imagem
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import contextlib
|
|
26
|
+
import logging
|
|
27
|
+
import tkinter as tk
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
from tkinter import colorchooser, filedialog, messagebox, ttk
|
|
30
|
+
from typing import Any
|
|
31
|
+
|
|
32
|
+
from src.constants import FONT_MONO, FONT_UI
|
|
33
|
+
from src.i18n import _t
|
|
34
|
+
from src.ui.grab_safe import safe_grab_set
|
|
35
|
+
from src.ui.paint_canvas import (
|
|
36
|
+
CANVAS_H as _CANVAS_H,
|
|
37
|
+
)
|
|
38
|
+
from src.ui.paint_canvas import (
|
|
39
|
+
CANVAS_W as _CANVAS_W,
|
|
40
|
+
)
|
|
41
|
+
from src.ui.paint_canvas import (
|
|
42
|
+
HAS_PIL as _HAS_PIL,
|
|
43
|
+
)
|
|
44
|
+
from src.ui.paint_canvas import (
|
|
45
|
+
MAX_ZOOM as _MAX_ZOOM,
|
|
46
|
+
)
|
|
47
|
+
from src.ui.paint_canvas import (
|
|
48
|
+
MIN_ZOOM as _MIN_ZOOM,
|
|
49
|
+
)
|
|
50
|
+
from src.ui.paint_canvas import (
|
|
51
|
+
ZOOM_STEPS as _ZOOM_STEPS,
|
|
52
|
+
)
|
|
53
|
+
from src.ui.paint_canvas import (
|
|
54
|
+
PaintCanvas,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
logger = logging.getLogger("Codis.Paint")
|
|
58
|
+
|
|
59
|
+
_PALETTE_COLORS: list[str] = [
|
|
60
|
+
"#000000",
|
|
61
|
+
"#444444",
|
|
62
|
+
"#888888",
|
|
63
|
+
"#bbbbbb",
|
|
64
|
+
"#ffffff",
|
|
65
|
+
"#ff0000",
|
|
66
|
+
"#ff6600",
|
|
67
|
+
"#ffcc00",
|
|
68
|
+
"#ffff00",
|
|
69
|
+
"#99cc00",
|
|
70
|
+
"#00aa00",
|
|
71
|
+
"#00cc99",
|
|
72
|
+
"#0099ff",
|
|
73
|
+
"#0033ff",
|
|
74
|
+
"#6600cc",
|
|
75
|
+
"#cc00aa",
|
|
76
|
+
"#ff99aa",
|
|
77
|
+
"#ffcc99",
|
|
78
|
+
"#ffff99",
|
|
79
|
+
"#ccffcc",
|
|
80
|
+
"#99ffff",
|
|
81
|
+
"#99ccff",
|
|
82
|
+
"#cc99ff",
|
|
83
|
+
"#ffaaff",
|
|
84
|
+
"#660000",
|
|
85
|
+
"#663300",
|
|
86
|
+
"#996600",
|
|
87
|
+
"#336600",
|
|
88
|
+
"#003366",
|
|
89
|
+
"#330066",
|
|
90
|
+
"#3d2b1f",
|
|
91
|
+
"#f5f5dc",
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
_TOOLS: list[tuple[str, str, str]] = [
|
|
95
|
+
("brush", "✏", "Pincel suave"),
|
|
96
|
+
("pixel", "⬛", "Pincel pixel"),
|
|
97
|
+
("spray", "💨", "Spray/Aerógrafo"),
|
|
98
|
+
("eraser", "◻", "Borracha"),
|
|
99
|
+
("fill", "🪣", "Balde de tinta"),
|
|
100
|
+
("line", "╱", "Linha"),
|
|
101
|
+
("rect", "▭", "Retângulo"),
|
|
102
|
+
("ellipse", "◯", "Elipse"),
|
|
103
|
+
("polygon", "⬡", "Polígono"),
|
|
104
|
+
("select", "⬚", "Seleção rect."),
|
|
105
|
+
("text", "T", "Texto"),
|
|
106
|
+
("eyedrop", "🔍", "Conta-gotas"),
|
|
107
|
+
("pan", "✋", "Panorâmica"),
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class PaintPanel(tk.Frame):
|
|
112
|
+
"""Painel de edição de imagens do Codis."""
|
|
113
|
+
|
|
114
|
+
def __init__(
|
|
115
|
+
self, parent: tk.Widget, tmgr: Any, initial_path: Path | None = None
|
|
116
|
+
) -> None:
|
|
117
|
+
t = tmgr.theme
|
|
118
|
+
super().__init__(parent, bg=t.panel_bg)
|
|
119
|
+
self._tmgr = tmgr
|
|
120
|
+
self._current_path: Path | None = None
|
|
121
|
+
self._tool_btns: dict[str, tk.Button] = {}
|
|
122
|
+
|
|
123
|
+
self._build_ui(t)
|
|
124
|
+
self._select_tool("brush")
|
|
125
|
+
self._canvas.on_change = self._on_canvas_change
|
|
126
|
+
self._canvas.on_tool_request = self._select_tool
|
|
127
|
+
self._bind_shortcuts()
|
|
128
|
+
|
|
129
|
+
if initial_path and initial_path.exists():
|
|
130
|
+
self._canvas.open_image(initial_path)
|
|
131
|
+
self._current_path = initial_path
|
|
132
|
+
self._on_canvas_change()
|
|
133
|
+
|
|
134
|
+
def _bind_shortcuts(self) -> None:
|
|
135
|
+
"""Ctrl+S/Shift+S/O/N e Ctrl+0 (ajustar) - estavam na documentação mas nunca foram ligados."""
|
|
136
|
+
top = self.winfo_toplevel()
|
|
137
|
+
self._shortcut_ids: list[tuple[str, str]] = []
|
|
138
|
+
|
|
139
|
+
def inside() -> bool:
|
|
140
|
+
try:
|
|
141
|
+
w = self.focus_get()
|
|
142
|
+
if w is None:
|
|
143
|
+
return bool(self.winfo_viewable())
|
|
144
|
+
return str(w).startswith(str(self))
|
|
145
|
+
except tk.TclError:
|
|
146
|
+
return False
|
|
147
|
+
|
|
148
|
+
def bind(seq: str, fn: Any) -> None:
|
|
149
|
+
def handler(_e: tk.Event) -> str | None:
|
|
150
|
+
if inside():
|
|
151
|
+
fn()
|
|
152
|
+
return "break"
|
|
153
|
+
return None
|
|
154
|
+
with contextlib.suppress(tk.TclError):
|
|
155
|
+
self._shortcut_ids.append((seq, top.bind(seq, handler, add="+")))
|
|
156
|
+
|
|
157
|
+
bind("<Control-s>", lambda: self._on_save())
|
|
158
|
+
bind("<Control-S>", lambda: self._on_save_as())
|
|
159
|
+
bind("<Control-o>", lambda: self._on_open())
|
|
160
|
+
bind("<Control-n>", lambda: self._on_new())
|
|
161
|
+
bind("<Control-0>", lambda: self._zoom_fit())
|
|
162
|
+
self.bind("<Destroy>", self._unbind_shortcuts, add="+")
|
|
163
|
+
|
|
164
|
+
def _unbind_shortcuts(self, event: tk.Event | None = None) -> None:
|
|
165
|
+
if event is not None and event.widget is not self:
|
|
166
|
+
return
|
|
167
|
+
top = self.winfo_toplevel()
|
|
168
|
+
for seq, fid in getattr(self, "_shortcut_ids", []):
|
|
169
|
+
with contextlib.suppress(tk.TclError):
|
|
170
|
+
top.unbind(seq, fid)
|
|
171
|
+
self._shortcut_ids = []
|
|
172
|
+
|
|
173
|
+
def _on_canvas_change(self) -> None:
|
|
174
|
+
"""Atualiza título/dimensões quando a imagem muda."""
|
|
175
|
+
img = self._canvas.image
|
|
176
|
+
if img is not None:
|
|
177
|
+
pct = int(self._canvas.zoom * 100)
|
|
178
|
+
self._img_info_var.set(f"{img.width}×{img.height} px\n{pct}% zoom")
|
|
179
|
+
name = self._current_path.name if self._current_path else _t("paint.untitled", "Sem título")
|
|
180
|
+
mark = " •" if self._canvas.modified else ""
|
|
181
|
+
self._dim_var.set(f"{name}{mark}")
|
|
182
|
+
|
|
183
|
+
def _confirm_discard(self) -> bool:
|
|
184
|
+
"""True se pode descartar a imagem atual (salvando antes, se o usuário quiser)."""
|
|
185
|
+
if not self._canvas.modified:
|
|
186
|
+
return True
|
|
187
|
+
ans = messagebox.askyesnocancel(
|
|
188
|
+
_t("paint.unsaved_title", "Alterações não salvas"),
|
|
189
|
+
_t("paint.unsaved_msg", "Salvar as alterações antes de continuar?"), parent=self)
|
|
190
|
+
if ans is None:
|
|
191
|
+
return False
|
|
192
|
+
if ans:
|
|
193
|
+
self._on_save()
|
|
194
|
+
return not self._canvas.modified
|
|
195
|
+
return True
|
|
196
|
+
|
|
197
|
+
def _build_ui(self, t: Any) -> None:
|
|
198
|
+
self._build_toolbar(t)
|
|
199
|
+
body = tk.Frame(self, bg=t.panel_bg)
|
|
200
|
+
body.pack(fill="both", expand=True)
|
|
201
|
+
self._build_sidebar(body, t)
|
|
202
|
+
self._build_canvas_area(body, t)
|
|
203
|
+
self._build_statusbar(t)
|
|
204
|
+
|
|
205
|
+
def _build_toolbar(self, t: Any) -> None:
|
|
206
|
+
"""Toolbar com ferramentas, opções e arquivo."""
|
|
207
|
+
tb = tk.Frame(self, bg=t.sidebar_bg)
|
|
208
|
+
tb.pack(fill="x")
|
|
209
|
+
tb1 = tk.Frame(tb, bg=t.sidebar_bg)
|
|
210
|
+
tb1.pack(fill="x")
|
|
211
|
+
tb2 = tk.Frame(tb, bg=t.sidebar_bg)
|
|
212
|
+
tb2.pack(fill="x", pady=(0, 2))
|
|
213
|
+
|
|
214
|
+
tool_frame = tk.Frame(tb1, bg=t.sidebar_bg)
|
|
215
|
+
tool_frame.pack(side="left", padx=2)
|
|
216
|
+
|
|
217
|
+
for tool_id, icon, tip in _TOOLS:
|
|
218
|
+
btn = tk.Button(
|
|
219
|
+
tool_frame,
|
|
220
|
+
text=icon,
|
|
221
|
+
width=3,
|
|
222
|
+
height=1,
|
|
223
|
+
bg=t.sidebar_bg,
|
|
224
|
+
fg=t.fg,
|
|
225
|
+
activebackground=t.accent,
|
|
226
|
+
activeforeground="#fff",
|
|
227
|
+
relief="flat",
|
|
228
|
+
font=(FONT_UI, 11),
|
|
229
|
+
bd=0,
|
|
230
|
+
padx=2,
|
|
231
|
+
pady=3,
|
|
232
|
+
command=lambda tid=tool_id: self._select_tool(tid),
|
|
233
|
+
)
|
|
234
|
+
btn.pack(side="left", padx=1, pady=2)
|
|
235
|
+
self._create_tooltip(btn, tip)
|
|
236
|
+
self._tool_btns[tool_id] = btn
|
|
237
|
+
|
|
238
|
+
opt_frame = tk.Frame(tb2, bg=t.sidebar_bg)
|
|
239
|
+
opt_frame.pack(side="left", padx=4)
|
|
240
|
+
|
|
241
|
+
self._fill_var = tk.BooleanVar(value=False)
|
|
242
|
+
fill_cb = tk.Checkbutton(
|
|
243
|
+
opt_frame,
|
|
244
|
+
text=_t("paint.fill"),
|
|
245
|
+
variable=self._fill_var,
|
|
246
|
+
bg=t.sidebar_bg,
|
|
247
|
+
fg=t.fg,
|
|
248
|
+
selectcolor=t.panel_bg,
|
|
249
|
+
activebackground=t.sidebar_bg,
|
|
250
|
+
activeforeground=t.fg,
|
|
251
|
+
font=(FONT_UI, 8),
|
|
252
|
+
relief="flat",
|
|
253
|
+
command=self._on_fill_toggle,
|
|
254
|
+
)
|
|
255
|
+
fill_cb.pack(anchor="w")
|
|
256
|
+
self._create_tooltip(
|
|
257
|
+
fill_cb, "Preencher formas (retângulo, elipse, polígono)")
|
|
258
|
+
|
|
259
|
+
ttk.Separator(tb2, orient="vertical").pack(
|
|
260
|
+
side="left", fill="y", padx=4, pady=4)
|
|
261
|
+
|
|
262
|
+
sz_frame = tk.Frame(tb2, bg=t.sidebar_bg)
|
|
263
|
+
sz_frame.pack(side="left", padx=2)
|
|
264
|
+
tk.Label(
|
|
265
|
+
sz_frame,
|
|
266
|
+
text=_t("paint.size_label"),
|
|
267
|
+
bg=t.sidebar_bg,
|
|
268
|
+
fg=t.fg_muted,
|
|
269
|
+
font=(FONT_UI, 8),
|
|
270
|
+
).pack(side="left")
|
|
271
|
+
self._size_var = tk.IntVar(value=4)
|
|
272
|
+
sz_spin = tk.Spinbox(
|
|
273
|
+
sz_frame,
|
|
274
|
+
from_=1,
|
|
275
|
+
to=200,
|
|
276
|
+
width=4,
|
|
277
|
+
textvariable=self._size_var,
|
|
278
|
+
bg=t.editor_bg,
|
|
279
|
+
fg=t.fg,
|
|
280
|
+
relief="flat",
|
|
281
|
+
buttonbackground=t.sidebar_bg,
|
|
282
|
+
font=(FONT_UI, 9),
|
|
283
|
+
command=self._on_size_change,
|
|
284
|
+
)
|
|
285
|
+
sz_spin.pack(side="left", padx=2)
|
|
286
|
+
sz_spin.bind("<Return>", lambda _: self._on_size_change())
|
|
287
|
+
|
|
288
|
+
ttk.Separator(tb2, orient="vertical").pack(
|
|
289
|
+
side="left", fill="y", padx=4, pady=4)
|
|
290
|
+
|
|
291
|
+
op_frame = tk.Frame(tb2, bg=t.sidebar_bg)
|
|
292
|
+
op_frame.pack(side="left", padx=2)
|
|
293
|
+
tk.Label(
|
|
294
|
+
op_frame,
|
|
295
|
+
text=_t("paint.opacity_label"),
|
|
296
|
+
bg=t.sidebar_bg,
|
|
297
|
+
fg=t.fg_muted,
|
|
298
|
+
font=(FONT_UI, 8),
|
|
299
|
+
).pack(side="left")
|
|
300
|
+
self._opacity_var = tk.IntVar(value=100)
|
|
301
|
+
op_scale = ttk.Scale(
|
|
302
|
+
op_frame,
|
|
303
|
+
from_=1,
|
|
304
|
+
to=100,
|
|
305
|
+
orient="horizontal",
|
|
306
|
+
length=70,
|
|
307
|
+
variable=self._opacity_var,
|
|
308
|
+
command=self._on_opacity_change,
|
|
309
|
+
)
|
|
310
|
+
op_scale.pack(side="left", padx=2)
|
|
311
|
+
self._opacity_label = tk.Label(
|
|
312
|
+
op_frame, text="100%", bg=t.sidebar_bg, fg=t.fg, font=(FONT_UI, 8), width=4
|
|
313
|
+
)
|
|
314
|
+
self._opacity_label.pack(side="left")
|
|
315
|
+
|
|
316
|
+
ttk.Separator(tb2, orient="vertical").pack(
|
|
317
|
+
side="left", fill="y", padx=4, pady=4)
|
|
318
|
+
|
|
319
|
+
tol_frame = tk.Frame(tb2, bg=t.sidebar_bg)
|
|
320
|
+
tol_frame.pack(side="left", padx=2)
|
|
321
|
+
tk.Label(
|
|
322
|
+
tol_frame,
|
|
323
|
+
text=_t("paint.tolerance_label"),
|
|
324
|
+
bg=t.sidebar_bg,
|
|
325
|
+
fg=t.fg_muted,
|
|
326
|
+
font=(FONT_UI, 8),
|
|
327
|
+
).pack(side="left")
|
|
328
|
+
self._tol_var = tk.IntVar(value=30)
|
|
329
|
+
tol_spin = tk.Spinbox(
|
|
330
|
+
tol_frame,
|
|
331
|
+
from_=0,
|
|
332
|
+
to=255,
|
|
333
|
+
width=4,
|
|
334
|
+
textvariable=self._tol_var,
|
|
335
|
+
bg=t.editor_bg,
|
|
336
|
+
fg=t.fg,
|
|
337
|
+
relief="flat",
|
|
338
|
+
buttonbackground=t.sidebar_bg,
|
|
339
|
+
font=(FONT_UI, 9),
|
|
340
|
+
command=self._on_tol_change,
|
|
341
|
+
)
|
|
342
|
+
tol_spin.pack(side="left")
|
|
343
|
+
|
|
344
|
+
ttk.Separator(tb1, orient="vertical").pack(
|
|
345
|
+
side="left", fill="y", padx=4, pady=4)
|
|
346
|
+
|
|
347
|
+
file_frame = tk.Frame(tb1, bg=t.sidebar_bg)
|
|
348
|
+
file_frame.pack(side="left", padx=2)
|
|
349
|
+
for label, cmd in [
|
|
350
|
+
("Novo", self._on_new),
|
|
351
|
+
("Abrir", self._on_open),
|
|
352
|
+
("Salvar", self._on_save),
|
|
353
|
+
("Salvar...", self._on_save_as),
|
|
354
|
+
("↔ Resize", self._on_resize),
|
|
355
|
+
("↶", lambda: self._canvas.undo()),
|
|
356
|
+
("↷", lambda: self._canvas.redo()),
|
|
357
|
+
]:
|
|
358
|
+
btn = tk.Button(
|
|
359
|
+
file_frame,
|
|
360
|
+
text=label,
|
|
361
|
+
bg=t.panel_bg,
|
|
362
|
+
fg=t.fg,
|
|
363
|
+
activebackground=t.accent,
|
|
364
|
+
activeforeground="#fff",
|
|
365
|
+
relief="flat",
|
|
366
|
+
font=(FONT_UI, 9),
|
|
367
|
+
padx=6,
|
|
368
|
+
pady=2,
|
|
369
|
+
command=cmd,
|
|
370
|
+
)
|
|
371
|
+
btn.pack(side="left", padx=1, pady=3)
|
|
372
|
+
|
|
373
|
+
zoom_r = tk.Frame(tb1, bg=t.sidebar_bg)
|
|
374
|
+
zoom_r.pack(side="right", padx=4)
|
|
375
|
+
tk.Button(
|
|
376
|
+
zoom_r,
|
|
377
|
+
text="−",
|
|
378
|
+
font=(FONT_UI, 11),
|
|
379
|
+
relief="flat",
|
|
380
|
+
bg=t.sidebar_bg,
|
|
381
|
+
fg=t.fg,
|
|
382
|
+
padx=4,
|
|
383
|
+
command=self._zoom_out,
|
|
384
|
+
).pack(side="left")
|
|
385
|
+
self._zoom_label = tk.Label(
|
|
386
|
+
zoom_r, text="100%", bg=t.sidebar_bg, fg=t.fg, font=(FONT_UI, 8), width=5
|
|
387
|
+
)
|
|
388
|
+
self._zoom_label.pack(side="left")
|
|
389
|
+
tk.Button(
|
|
390
|
+
zoom_r,
|
|
391
|
+
text="+",
|
|
392
|
+
font=(FONT_UI, 11),
|
|
393
|
+
relief="flat",
|
|
394
|
+
bg=t.sidebar_bg,
|
|
395
|
+
fg=t.fg,
|
|
396
|
+
padx=4,
|
|
397
|
+
command=self._zoom_in,
|
|
398
|
+
).pack(side="left")
|
|
399
|
+
tk.Button(
|
|
400
|
+
zoom_r,
|
|
401
|
+
text="⊡",
|
|
402
|
+
font=(FONT_UI, 10),
|
|
403
|
+
relief="flat",
|
|
404
|
+
bg=t.sidebar_bg,
|
|
405
|
+
fg=t.fg,
|
|
406
|
+
padx=4,
|
|
407
|
+
command=self._zoom_fit,
|
|
408
|
+
).pack(side="left")
|
|
409
|
+
self._create_tooltip(
|
|
410
|
+
zoom_r, "Zoom: Ctrl+Scroll | Botão do meio: panorâmica")
|
|
411
|
+
|
|
412
|
+
def _build_sidebar(self, parent: tk.Widget, t: Any) -> None:
|
|
413
|
+
"""Sidebar esquerda: cores primária/secundária + paleta."""
|
|
414
|
+
sb = tk.Frame(parent, bg=t.sidebar_bg, width=110)
|
|
415
|
+
sb.pack(side="left", fill="y")
|
|
416
|
+
sb.pack_propagate(False)
|
|
417
|
+
|
|
418
|
+
clr_frame = tk.Frame(sb, bg=t.sidebar_bg)
|
|
419
|
+
clr_frame.pack(pady=8)
|
|
420
|
+
|
|
421
|
+
tk.Label(
|
|
422
|
+
clr_frame,
|
|
423
|
+
text=_t("paint.colors_label"),
|
|
424
|
+
bg=t.sidebar_bg,
|
|
425
|
+
fg=t.fg_muted,
|
|
426
|
+
font=(FONT_UI, 7),
|
|
427
|
+
).pack()
|
|
428
|
+
|
|
429
|
+
swatch_area = tk.Frame(clr_frame, bg=t.sidebar_bg)
|
|
430
|
+
swatch_area.pack()
|
|
431
|
+
|
|
432
|
+
self._color2_btn = tk.Label(
|
|
433
|
+
swatch_area,
|
|
434
|
+
bg="#ffffff",
|
|
435
|
+
width=4,
|
|
436
|
+
height=2,
|
|
437
|
+
relief="solid",
|
|
438
|
+
bd=1,
|
|
439
|
+
cursor="hand2",
|
|
440
|
+
)
|
|
441
|
+
self._color2_btn.place(x=22, y=12)
|
|
442
|
+
|
|
443
|
+
self._color1_btn = tk.Label(
|
|
444
|
+
swatch_area,
|
|
445
|
+
bg="#000000",
|
|
446
|
+
width=4,
|
|
447
|
+
height=2,
|
|
448
|
+
relief="solid",
|
|
449
|
+
bd=2,
|
|
450
|
+
cursor="hand2",
|
|
451
|
+
)
|
|
452
|
+
self._color1_btn.place(x=6, y=2)
|
|
453
|
+
|
|
454
|
+
swatch_area.config(width=64, height=46)
|
|
455
|
+
|
|
456
|
+
self._color1_btn.bind(
|
|
457
|
+
"<Button-1>", lambda _: self._pick_color(primary=True))
|
|
458
|
+
self._color2_btn.bind(
|
|
459
|
+
"<Button-1>", lambda _: self._pick_color(primary=False))
|
|
460
|
+
self._color1_btn.bind("<Button-3>", lambda _: self._swap_colors())
|
|
461
|
+
self._color2_btn.bind("<Button-3>", lambda _: self._swap_colors())
|
|
462
|
+
|
|
463
|
+
swap_btn = tk.Label(
|
|
464
|
+
swatch_area,
|
|
465
|
+
text="⇄",
|
|
466
|
+
bg=t.sidebar_bg,
|
|
467
|
+
fg=t.fg,
|
|
468
|
+
font=(FONT_UI, 9),
|
|
469
|
+
cursor="hand2",
|
|
470
|
+
)
|
|
471
|
+
swap_btn.place(x=44, y=28)
|
|
472
|
+
swap_btn.bind("<Button-1>", lambda _: self._swap_colors())
|
|
473
|
+
|
|
474
|
+
tk.Label(
|
|
475
|
+
clr_frame,
|
|
476
|
+
text="↑esc. | ↓fund.",
|
|
477
|
+
bg=t.sidebar_bg,
|
|
478
|
+
fg=t.fg_muted,
|
|
479
|
+
font=(FONT_UI, 6),
|
|
480
|
+
).pack()
|
|
481
|
+
|
|
482
|
+
ttk.Separator(sb, orient="horizontal").pack(fill="x", padx=4, pady=4)
|
|
483
|
+
|
|
484
|
+
tk.Label(
|
|
485
|
+
sb,
|
|
486
|
+
text=_t("paint.palette_label"),
|
|
487
|
+
bg=t.sidebar_bg,
|
|
488
|
+
fg=t.fg_muted,
|
|
489
|
+
font=(FONT_UI, 7),
|
|
490
|
+
).pack()
|
|
491
|
+
|
|
492
|
+
pal_frame = tk.Frame(sb, bg=t.sidebar_bg)
|
|
493
|
+
pal_frame.pack(padx=4, pady=2)
|
|
494
|
+
|
|
495
|
+
self._palette_btns: list[tk.Label] = []
|
|
496
|
+
for i, c in enumerate(_PALETTE_COLORS):
|
|
497
|
+
row, col = divmod(i, 4)
|
|
498
|
+
btn = tk.Label(
|
|
499
|
+
pal_frame, bg=c, width=2, height=1, relief="flat", bd=1, cursor="hand2"
|
|
500
|
+
)
|
|
501
|
+
btn.grid(row=row, column=col, padx=1, pady=1)
|
|
502
|
+
btn.bind("<Button-1>", lambda _,
|
|
503
|
+
cc=c: self._set_color(cc, primary=True))
|
|
504
|
+
btn.bind("<Button-3>", lambda _,
|
|
505
|
+
cc=c: self._set_color(cc, primary=False))
|
|
506
|
+
btn.bind(
|
|
507
|
+
"<Double-Button-1>",
|
|
508
|
+
lambda _, b=btn, idx=i: self._customize_palette(b, idx),
|
|
509
|
+
)
|
|
510
|
+
self._palette_btns.append(btn)
|
|
511
|
+
|
|
512
|
+
tk.Label(
|
|
513
|
+
sb,
|
|
514
|
+
text="2x-clique: editar cor",
|
|
515
|
+
bg=t.sidebar_bg,
|
|
516
|
+
fg=t.fg_muted,
|
|
517
|
+
font=(FONT_UI, 6),
|
|
518
|
+
).pack(pady=(2, 0))
|
|
519
|
+
|
|
520
|
+
ttk.Separator(sb, orient="horizontal").pack(fill="x", padx=4, pady=4)
|
|
521
|
+
|
|
522
|
+
self._img_info_var = tk.StringVar(value="800×600 px")
|
|
523
|
+
tk.Label(
|
|
524
|
+
sb,
|
|
525
|
+
textvariable=self._img_info_var,
|
|
526
|
+
bg=t.sidebar_bg,
|
|
527
|
+
fg=t.fg_muted,
|
|
528
|
+
font=(FONT_UI, 7),
|
|
529
|
+
wraplength=100,
|
|
530
|
+
).pack(padx=4)
|
|
531
|
+
|
|
532
|
+
def _build_canvas_area(self, parent: tk.Widget, t: Any) -> None:
|
|
533
|
+
"""Área de desenho com scrollbars."""
|
|
534
|
+
frame = tk.Frame(parent, bg=t.panel_bg)
|
|
535
|
+
frame.pack(side="left", fill="both", expand=True)
|
|
536
|
+
|
|
537
|
+
vsb = ttk.Scrollbar(frame, orient="vertical")
|
|
538
|
+
hsb = ttk.Scrollbar(frame, orient="horizontal")
|
|
539
|
+
vsb.pack(side="right", fill="y")
|
|
540
|
+
hsb.pack(side="bottom", fill="x")
|
|
541
|
+
|
|
542
|
+
self._canvas = PaintCanvas(
|
|
543
|
+
frame,
|
|
544
|
+
self._tmgr,
|
|
545
|
+
status_cb=self._set_status,
|
|
546
|
+
zoom_cb=self._on_zoom_change,
|
|
547
|
+
yscrollcommand=vsb.set,
|
|
548
|
+
xscrollcommand=hsb.set,
|
|
549
|
+
)
|
|
550
|
+
self._canvas.pack(fill="both", expand=True)
|
|
551
|
+
vsb.config(command=self._canvas.yview)
|
|
552
|
+
hsb.config(command=self._canvas.xview)
|
|
553
|
+
self._canvas.on_color_pick = self._on_color_pick
|
|
554
|
+
|
|
555
|
+
def _build_statusbar(self, t: Any) -> None:
|
|
556
|
+
progress_bar = tk.Frame(self, bg=t.sidebar_bg, height=22)
|
|
557
|
+
progress_bar.pack(fill="x")
|
|
558
|
+
progress_bar.pack_propagate(False)
|
|
559
|
+
|
|
560
|
+
self._status_var = tk.StringVar(
|
|
561
|
+
value="Pronto - Ctrl+Z desfazer · Ctrl+Scroll zoom · Scroll rola · Botão do meio/Espaço: pan · Shift: reta/quadrado/círculo"
|
|
562
|
+
)
|
|
563
|
+
tk.Label(
|
|
564
|
+
progress_bar,
|
|
565
|
+
textvariable=self._status_var,
|
|
566
|
+
bg=t.sidebar_bg,
|
|
567
|
+
fg=t.fg_muted,
|
|
568
|
+
font=(FONT_UI, 8),
|
|
569
|
+
anchor="w",
|
|
570
|
+
).pack(side="left", padx=8)
|
|
571
|
+
|
|
572
|
+
if not _HAS_PIL:
|
|
573
|
+
tk.Label(
|
|
574
|
+
progress_bar,
|
|
575
|
+
text="⚠ Pillow não instalado - pip install Pillow",
|
|
576
|
+
bg=t.sidebar_bg,
|
|
577
|
+
fg="#FFA500",
|
|
578
|
+
font=(FONT_UI, 7),
|
|
579
|
+
).pack(side="right", padx=6)
|
|
580
|
+
|
|
581
|
+
self._dim_var = tk.StringVar(value="")
|
|
582
|
+
tk.Label(
|
|
583
|
+
progress_bar,
|
|
584
|
+
textvariable=self._dim_var,
|
|
585
|
+
bg=t.sidebar_bg,
|
|
586
|
+
fg=t.fg_muted,
|
|
587
|
+
font=(FONT_UI, 8),
|
|
588
|
+
).pack(side="right", padx=8)
|
|
589
|
+
|
|
590
|
+
def _select_tool(self, tool_id: str) -> None:
|
|
591
|
+
t = self._tmgr.theme
|
|
592
|
+
for tid, btn in self._tool_btns.items():
|
|
593
|
+
active = tid == tool_id
|
|
594
|
+
btn.config(
|
|
595
|
+
bg=t.accent if active else t.sidebar_bg,
|
|
596
|
+
fg="#ffffff" if active else t.fg,
|
|
597
|
+
relief="sunken" if active else "flat",
|
|
598
|
+
)
|
|
599
|
+
self._canvas.tool = tool_id
|
|
600
|
+
label = next(
|
|
601
|
+
(tip for tid, _, tip in _TOOLS if tid == tool_id), tool_id)
|
|
602
|
+
self._set_status(f"Ferramenta: {label}")
|
|
603
|
+
|
|
604
|
+
def _pick_color(self, primary: bool = True) -> None:
|
|
605
|
+
current = self._canvas.color if primary else self._canvas.color2
|
|
606
|
+
result = colorchooser.askcolor(
|
|
607
|
+
color=current,
|
|
608
|
+
title=(
|
|
609
|
+
_t("paint.pick_color_primary")
|
|
610
|
+
if primary
|
|
611
|
+
else _t("paint.pick_color_secondary")
|
|
612
|
+
),
|
|
613
|
+
)
|
|
614
|
+
if result and result[1]:
|
|
615
|
+
self._set_color(result[1], primary)
|
|
616
|
+
|
|
617
|
+
def _set_color(self, color: str, primary: bool = True) -> None:
|
|
618
|
+
if primary:
|
|
619
|
+
self._canvas.color = color
|
|
620
|
+
self._color1_btn.config(bg=color)
|
|
621
|
+
else:
|
|
622
|
+
self._canvas.color2 = color
|
|
623
|
+
self._color2_btn.config(bg=color)
|
|
624
|
+
|
|
625
|
+
def _swap_colors(self) -> None:
|
|
626
|
+
c1 = self._canvas.color
|
|
627
|
+
c2 = self._canvas.color2
|
|
628
|
+
self._set_color(c2, primary=True)
|
|
629
|
+
self._set_color(c1, primary=False)
|
|
630
|
+
|
|
631
|
+
def _on_color_pick(self, color: str, primary: bool) -> None:
|
|
632
|
+
self._set_color(color, primary)
|
|
633
|
+
self._set_status(
|
|
634
|
+
f"Cor coletada: {color} ({'primária' if primary else 'secundária'})"
|
|
635
|
+
)
|
|
636
|
+
|
|
637
|
+
def _on_fill_toggle(self) -> None:
|
|
638
|
+
self._canvas.fill_shapes = self._fill_var.get()
|
|
639
|
+
|
|
640
|
+
def _on_size_change(self) -> None:
|
|
641
|
+
with contextlib.suppress(ValueError, tk.TclError):
|
|
642
|
+
self._canvas.size = self._size_var.get()
|
|
643
|
+
|
|
644
|
+
def _on_opacity_change(self, *_: Any) -> None:
|
|
645
|
+
pct = self._opacity_var.get()
|
|
646
|
+
self._canvas.opacity = int(pct * 255 / 100)
|
|
647
|
+
self._opacity_label.config(text=f"{pct}%")
|
|
648
|
+
|
|
649
|
+
def _on_tol_change(self) -> None:
|
|
650
|
+
with contextlib.suppress(ValueError, tk.TclError):
|
|
651
|
+
self._canvas.tolerance = self._tol_var.get()
|
|
652
|
+
|
|
653
|
+
def _on_zoom_change(self, z: float) -> None:
|
|
654
|
+
pct = int(round(z * 100))
|
|
655
|
+
self._zoom_label.config(text=f"{pct}%")
|
|
656
|
+
img = self._canvas.image
|
|
657
|
+
if img is not None:
|
|
658
|
+
self._img_info_var.set(f"{img.width}×{img.height} px\n{pct}% zoom")
|
|
659
|
+
|
|
660
|
+
def _zoom_in(self) -> None:
|
|
661
|
+
old = self._canvas.zoom
|
|
662
|
+
self._canvas.set_zoom(next((z for z in _ZOOM_STEPS if z > old * 1.001), _MAX_ZOOM))
|
|
663
|
+
|
|
664
|
+
def _zoom_out(self) -> None:
|
|
665
|
+
old = self._canvas.zoom
|
|
666
|
+
self._canvas.set_zoom(next((z for z in reversed(_ZOOM_STEPS) if z < old * 0.999), _MIN_ZOOM))
|
|
667
|
+
|
|
668
|
+
def _zoom_fit(self) -> None:
|
|
669
|
+
"""Ajusta o zoom para a imagem caber na janela."""
|
|
670
|
+
self._canvas.zoom_fit()
|
|
671
|
+
|
|
672
|
+
def _customize_palette(self, btn: tk.Label, idx: int) -> None:
|
|
673
|
+
current = _PALETTE_COLORS[idx]
|
|
674
|
+
result = colorchooser.askcolor(
|
|
675
|
+
color=current, title=f"Personalizar cor #{idx + 1}"
|
|
676
|
+
)
|
|
677
|
+
if result and result[1]:
|
|
678
|
+
_PALETTE_COLORS[idx] = result[1]
|
|
679
|
+
btn.config(bg=result[1])
|
|
680
|
+
|
|
681
|
+
def _on_new(self) -> None:
|
|
682
|
+
if not self._confirm_discard():
|
|
683
|
+
return
|
|
684
|
+
self._canvas.new_canvas()
|
|
685
|
+
self._current_path = None
|
|
686
|
+
self._set_status(_t("paint.new_done", "Canvas em branco criado."))
|
|
687
|
+
self._on_canvas_change()
|
|
688
|
+
|
|
689
|
+
def _on_open(self) -> None:
|
|
690
|
+
if not self._confirm_discard():
|
|
691
|
+
return
|
|
692
|
+
types = [
|
|
693
|
+
("Imagens", "*.png *.jpg *.jpeg *.bmp *.gif *.webp *.tiff *.tif"),
|
|
694
|
+
("PNG", "*.png"),
|
|
695
|
+
("JPEG", "*.jpg *.jpeg"),
|
|
696
|
+
("BMP", "*.bmp"),
|
|
697
|
+
("GIF", "*.gif"),
|
|
698
|
+
("Todos", "*.*"),
|
|
699
|
+
]
|
|
700
|
+
path = filedialog.askopenfilename(title=_t("paint.open_title"), filetypes=types)
|
|
701
|
+
if path:
|
|
702
|
+
p = Path(path)
|
|
703
|
+
if self._canvas.open_image(p):
|
|
704
|
+
self._current_path = p
|
|
705
|
+
self._set_status(f"Aberto: {p.name}")
|
|
706
|
+
self._on_canvas_change()
|
|
707
|
+
|
|
708
|
+
def open_path(self, p: Path) -> bool:
|
|
709
|
+
"""Abre ``p`` (usado por quem integra o painel)."""
|
|
710
|
+
if self._canvas.open_image(p):
|
|
711
|
+
self._current_path = p
|
|
712
|
+
self._on_canvas_change()
|
|
713
|
+
return True
|
|
714
|
+
return False
|
|
715
|
+
|
|
716
|
+
def _on_save(self) -> None:
|
|
717
|
+
if self._current_path:
|
|
718
|
+
if self._canvas.save_image(self._current_path):
|
|
719
|
+
self._set_status(f"Salvo: {self._current_path.name}")
|
|
720
|
+
self._on_canvas_change()
|
|
721
|
+
else:
|
|
722
|
+
self._on_save_as()
|
|
723
|
+
|
|
724
|
+
def _on_save_as(self) -> None:
|
|
725
|
+
types = [("PNG", "*.png"), ("JPEG", "*.jpg"), ("BMP", "*.bmp"), ("WebP", "*.webp")]
|
|
726
|
+
path = filedialog.asksaveasfilename(title=_t("paint.save_title"), defaultextension=".png", filetypes=types)
|
|
727
|
+
if path:
|
|
728
|
+
p = Path(path)
|
|
729
|
+
if self._canvas.save_image(p):
|
|
730
|
+
self._current_path = p
|
|
731
|
+
self._set_status(f"Salvo: {p.name}")
|
|
732
|
+
self._on_canvas_change()
|
|
733
|
+
|
|
734
|
+
def _on_resize(self) -> None:
|
|
735
|
+
t = self._tmgr.theme
|
|
736
|
+
win = tk.Toplevel(self)
|
|
737
|
+
win.title(_t("paint.resize_title"))
|
|
738
|
+
win.config(bg=t.panel_bg)
|
|
739
|
+
win.resizable(False, False)
|
|
740
|
+
safe_grab_set(win)
|
|
741
|
+
|
|
742
|
+
img = self._canvas.image
|
|
743
|
+
cur_w = img.width if img else _CANVAS_W
|
|
744
|
+
cur_h = img.height if img else _CANVAS_H
|
|
745
|
+
|
|
746
|
+
tk.Label(
|
|
747
|
+
win,
|
|
748
|
+
text=_t("paint.resize_label"),
|
|
749
|
+
bg=t.panel_bg,
|
|
750
|
+
fg=t.fg,
|
|
751
|
+
font=(FONT_UI, 10),
|
|
752
|
+
).pack(padx=16, pady=(12, 4))
|
|
753
|
+
|
|
754
|
+
row = tk.Frame(win, bg=t.panel_bg)
|
|
755
|
+
row.pack(padx=16, pady=4)
|
|
756
|
+
w_var = tk.StringVar(value=str(cur_w))
|
|
757
|
+
h_var = tk.StringVar(value=str(cur_h))
|
|
758
|
+
tk.Entry(
|
|
759
|
+
row,
|
|
760
|
+
textvariable=w_var,
|
|
761
|
+
bg=t.editor_bg,
|
|
762
|
+
fg=t.fg,
|
|
763
|
+
font=(FONT_MONO, 10),
|
|
764
|
+
width=6,
|
|
765
|
+
relief="flat",
|
|
766
|
+
insertbackground=t.cursor,
|
|
767
|
+
).pack(side="left")
|
|
768
|
+
tk.Label(row, text=" × ", bg=t.panel_bg, fg=t.fg).pack(side="left")
|
|
769
|
+
tk.Entry(
|
|
770
|
+
row,
|
|
771
|
+
textvariable=h_var,
|
|
772
|
+
bg=t.editor_bg,
|
|
773
|
+
fg=t.fg,
|
|
774
|
+
font=(FONT_MONO, 10),
|
|
775
|
+
width=6,
|
|
776
|
+
relief="flat",
|
|
777
|
+
insertbackground=t.cursor,
|
|
778
|
+
).pack(side="left")
|
|
779
|
+
|
|
780
|
+
resize_img_var = tk.BooleanVar(value=True)
|
|
781
|
+
tk.Checkbutton(
|
|
782
|
+
win,
|
|
783
|
+
text=_t("paint.resize_img"),
|
|
784
|
+
variable=resize_img_var,
|
|
785
|
+
bg=t.panel_bg,
|
|
786
|
+
fg=t.fg,
|
|
787
|
+
selectcolor=t.editor_bg,
|
|
788
|
+
activebackground=t.panel_bg,
|
|
789
|
+
relief="flat",
|
|
790
|
+
font=(FONT_UI, 9),
|
|
791
|
+
).pack(padx=16, pady=4)
|
|
792
|
+
|
|
793
|
+
presets = tk.Frame(win, bg=t.panel_bg)
|
|
794
|
+
presets.pack(padx=16, pady=(0, 8))
|
|
795
|
+
tk.Label(
|
|
796
|
+
presets,
|
|
797
|
+
text=_t("paint.resize_presets"),
|
|
798
|
+
bg=t.panel_bg,
|
|
799
|
+
fg=t.fg_muted,
|
|
800
|
+
font=(FONT_UI, 8),
|
|
801
|
+
).pack(side="left")
|
|
802
|
+
for pw, ph in [(800, 600), (1024, 768), (1920, 1080), (2560, 1440)]:
|
|
803
|
+
b = tk.Label(
|
|
804
|
+
presets,
|
|
805
|
+
text=f"{pw}×{ph}",
|
|
806
|
+
bg=t.btn_bg,
|
|
807
|
+
fg=t.fg,
|
|
808
|
+
font=(FONT_UI, 7),
|
|
809
|
+
cursor="hand2",
|
|
810
|
+
padx=4,
|
|
811
|
+
pady=1,
|
|
812
|
+
)
|
|
813
|
+
b.pack(side="left", padx=2)
|
|
814
|
+
b.bind(
|
|
815
|
+
"<Button-1>",
|
|
816
|
+
lambda _, _w=pw, _h=ph: (
|
|
817
|
+
w_var.set(str(_w)), h_var.set(str(_h))),
|
|
818
|
+
)
|
|
819
|
+
|
|
820
|
+
def _apply() -> None:
|
|
821
|
+
try:
|
|
822
|
+
nw, nh = max(1, min(20000, int(w_var.get()))), max(1, min(20000, int(h_var.get())))
|
|
823
|
+
except ValueError:
|
|
824
|
+
return
|
|
825
|
+
self._canvas.resize_canvas(nw, nh, resize_img_var.get())
|
|
826
|
+
self._on_canvas_change()
|
|
827
|
+
self._set_status(f"Canvas redimensionado para {nw}×{nh} px.")
|
|
828
|
+
win.destroy()
|
|
829
|
+
|
|
830
|
+
btn_row = tk.Frame(win, bg=t.panel_bg)
|
|
831
|
+
btn_row.pack(fill="x", padx=12, pady=8)
|
|
832
|
+
tk.Button(
|
|
833
|
+
btn_row,
|
|
834
|
+
text=_t("paint.resize_apply"),
|
|
835
|
+
command=_apply,
|
|
836
|
+
bg=t.accent,
|
|
837
|
+
fg="#fff",
|
|
838
|
+
relief="flat",
|
|
839
|
+
font=(FONT_UI, 10),
|
|
840
|
+
).pack(side="right", padx=4)
|
|
841
|
+
tk.Button(
|
|
842
|
+
btn_row,
|
|
843
|
+
text=_t("paint.cancel"),
|
|
844
|
+
command=win.destroy,
|
|
845
|
+
bg=t.sidebar_bg,
|
|
846
|
+
fg=t.fg,
|
|
847
|
+
relief="flat",
|
|
848
|
+
font=(FONT_UI, 10),
|
|
849
|
+
).pack(side="right")
|
|
850
|
+
|
|
851
|
+
win.update_idletasks()
|
|
852
|
+
sw, sh = win.winfo_screenwidth(), win.winfo_screenheight()
|
|
853
|
+
ww, wh = win.winfo_reqwidth(), win.winfo_reqheight()
|
|
854
|
+
win.geometry(f"{ww}x{wh}+{(sw - ww) // 2}+{(sh - wh) // 2}")
|
|
855
|
+
|
|
856
|
+
def _set_status(self, msg: str) -> None:
|
|
857
|
+
with contextlib.suppress(tk.TclError):
|
|
858
|
+
self._status_var.set(msg)
|
|
859
|
+
|
|
860
|
+
def _create_tooltip(self, widget: tk.Widget, text: str) -> None:
|
|
861
|
+
tip: tk.Toplevel | None = None
|
|
862
|
+
|
|
863
|
+
def _show(ev: tk.Event) -> None:
|
|
864
|
+
nonlocal tip
|
|
865
|
+
tip = tk.Toplevel(widget)
|
|
866
|
+
tip.wm_overrideredirect(True)
|
|
867
|
+
tip.wm_geometry(f"+{ev.x_root + 12}+{ev.y_root + 18}")
|
|
868
|
+
tk.Label(
|
|
869
|
+
tip,
|
|
870
|
+
text=text,
|
|
871
|
+
bg="#FFFFCC",
|
|
872
|
+
fg="#333",
|
|
873
|
+
relief="solid",
|
|
874
|
+
bd=1,
|
|
875
|
+
font=(FONT_UI, 8),
|
|
876
|
+
padx=4,
|
|
877
|
+
pady=2,
|
|
878
|
+
).pack()
|
|
879
|
+
|
|
880
|
+
def _hide(_: tk.Event) -> None:
|
|
881
|
+
nonlocal tip
|
|
882
|
+
if tip:
|
|
883
|
+
with contextlib.suppress(tk.TclError):
|
|
884
|
+
tip.destroy()
|
|
885
|
+
tip = None
|
|
886
|
+
|
|
887
|
+
widget.bind("<Enter>", _show, add="+")
|
|
888
|
+
widget.bind("<Leave>", _hide, add="+")
|