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/lazy_panel.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Painéis construídos só na primeira vez que são usados.
|
|
2
|
+
|
|
3
|
+
A sidebar do Codis tem ~20 painéis (centenas de widgets Tk). Como a criação
|
|
4
|
+
de widgets é lenta (sobretudo no Windows), os painéis raramente usados são
|
|
5
|
+
instanciados sob demanda.
|
|
6
|
+
|
|
7
|
+
``LazyPanel`` é um proxy transparente: qualquer acesso a atributo (``pack``,
|
|
8
|
+
``refresh``, ``winfo_exists``...) constrói o painel real e repassa. Chamadas
|
|
9
|
+
"informativas" feitas enquanto ele não existe (tema, arquivo ativo,
|
|
10
|
+
workspace...) não forçam a construção: o tema é lido do ``tmgr`` no
|
|
11
|
+
``__init__`` do painel real, e as demais são *reproduzidas* na construção.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import logging
|
|
17
|
+
from collections.abc import Callable
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
logger = logging.getLogger("Codis.Lazy")
|
|
21
|
+
|
|
22
|
+
_DROP = frozenset({"apply_theme", "notify_file_saved"})
|
|
23
|
+
_REPLAY = frozenset({"notify_active_file", "notify_active_lang", "set_workspace", "refresh"})
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class LazyPanel:
|
|
27
|
+
"""Proxy que adia a criação do widget real até o primeiro uso."""
|
|
28
|
+
|
|
29
|
+
def __init__(self, factory: Callable[[], Any], name: str = "") -> None:
|
|
30
|
+
object.__setattr__(self, "_lp_factory", factory)
|
|
31
|
+
object.__setattr__(self, "_lp_real", None)
|
|
32
|
+
object.__setattr__(self, "_lp_name", name)
|
|
33
|
+
object.__setattr__(self, "_lp_pending", {})
|
|
34
|
+
|
|
35
|
+
def build(self) -> Any:
|
|
36
|
+
"""Cria (uma vez) e devolve o widget real."""
|
|
37
|
+
real = object.__getattribute__(self, "_lp_real")
|
|
38
|
+
if real is not None:
|
|
39
|
+
return real
|
|
40
|
+
factory = object.__getattribute__(self, "_lp_factory")
|
|
41
|
+
real = factory()
|
|
42
|
+
object.__setattr__(self, "_lp_real", real)
|
|
43
|
+
pending = object.__getattribute__(self, "_lp_pending")
|
|
44
|
+
object.__setattr__(self, "_lp_pending", {})
|
|
45
|
+
for meth, (args, kw) in pending.items():
|
|
46
|
+
fn = getattr(real, meth, None)
|
|
47
|
+
if callable(fn):
|
|
48
|
+
try:
|
|
49
|
+
fn(*args, **kw)
|
|
50
|
+
except Exception as exc:
|
|
51
|
+
logger.debug("replay %s.%s falhou: %s", object.__getattribute__(self, "_lp_name"), meth, exc)
|
|
52
|
+
return real
|
|
53
|
+
|
|
54
|
+
def __getattr__(self, item: str) -> Any:
|
|
55
|
+
real = object.__getattribute__(self, "_lp_real")
|
|
56
|
+
if real is None:
|
|
57
|
+
if item in _DROP:
|
|
58
|
+
return lambda *a, **k: None
|
|
59
|
+
if item in _REPLAY:
|
|
60
|
+
pending = object.__getattribute__(self, "_lp_pending")
|
|
61
|
+
|
|
62
|
+
def _remember(*a: Any, **k: Any) -> None:
|
|
63
|
+
pending[item] = (a, k)
|
|
64
|
+
|
|
65
|
+
return _remember
|
|
66
|
+
real = self.build()
|
|
67
|
+
return getattr(real, item)
|
|
68
|
+
|
|
69
|
+
def __setattr__(self, key: str, value: Any) -> None:
|
|
70
|
+
setattr(self.build(), key, value)
|
|
71
|
+
|
|
72
|
+
def __bool__(self) -> bool:
|
|
73
|
+
return True
|
src/ui/macro_recorder.py
ADDED
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
"""Codis - Macro Recorder.
|
|
2
|
+
|
|
3
|
+
Grava e reproduz sequências de teclas e ações do editor,
|
|
4
|
+
com gerenciamento de múltiplas macros salvas.
|
|
5
|
+
|
|
6
|
+
Features
|
|
7
|
+
--------
|
|
8
|
+
- Gravar / Parar / Reproduzir via toolbar flutuante
|
|
9
|
+
- Suporte a texto digitado, atalhos, navegação de cursor
|
|
10
|
+
- Múltiplas macros nomeadas com persistência em JSON
|
|
11
|
+
- Reprodução com delay configurável (para visualizar)
|
|
12
|
+
- Importar / exportar macros como JSON
|
|
13
|
+
- Atalho padrão: Ctrl+Shift+M (start/stop), Ctrl+Alt+M (play)
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import contextlib
|
|
19
|
+
import json
|
|
20
|
+
import logging
|
|
21
|
+
import threading
|
|
22
|
+
import time
|
|
23
|
+
import tkinter as tk
|
|
24
|
+
from collections.abc import Callable
|
|
25
|
+
from dataclasses import asdict, dataclass, field
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
from tkinter import filedialog, messagebox, simpledialog
|
|
28
|
+
from typing import Any
|
|
29
|
+
|
|
30
|
+
from src.constants import CONFIG_DIR, FONT_MONO, FONT_UI
|
|
31
|
+
from src.i18n import _t
|
|
32
|
+
|
|
33
|
+
logger = logging.getLogger("Codis.Macro")
|
|
34
|
+
|
|
35
|
+
_MACROS_FILE = CONFIG_DIR / "macros.json"
|
|
36
|
+
|
|
37
|
+
_EV_INSERT = "insert"
|
|
38
|
+
_EV_DELETE = "delete"
|
|
39
|
+
_EV_KEY = "key"
|
|
40
|
+
_EV_CURSOR = "cursor"
|
|
41
|
+
_EV_WAIT = "wait"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass
|
|
45
|
+
class MacroEvent:
|
|
46
|
+
type: str
|
|
47
|
+
data: str = ""
|
|
48
|
+
index: str = ""
|
|
49
|
+
delay: int = 0
|
|
50
|
+
|
|
51
|
+
def to_dict(self) -> dict:
|
|
52
|
+
"""Serializa o evento de macro em dicionário."""
|
|
53
|
+
return asdict(self)
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
def from_dict(cls, d: dict) -> MacroEvent:
|
|
57
|
+
"""Desserializa um evento de macro a partir de dicionário."""
|
|
58
|
+
return cls(**{k: v for k, v in d.items() if k in cls.__dataclass_fields__}) # type: ignore[attr-defined] # pylint: disable=no-member
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass
|
|
62
|
+
class Macro:
|
|
63
|
+
name: str
|
|
64
|
+
events: list[MacroEvent] = field(default_factory=list)
|
|
65
|
+
created: str = ""
|
|
66
|
+
|
|
67
|
+
def to_dict(self) -> dict:
|
|
68
|
+
"""Serializa a macro completa em dicionário."""
|
|
69
|
+
return {
|
|
70
|
+
"name": self.name,
|
|
71
|
+
"created": self.created,
|
|
72
|
+
"events": [e.to_dict() for e in self.events],
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def from_dict(cls, d: dict) -> Macro:
|
|
77
|
+
"""Desserializa uma macro a partir de dicionário."""
|
|
78
|
+
events = [MacroEvent.from_dict(e) for e in d.get("events", [])]
|
|
79
|
+
return cls(
|
|
80
|
+
name=d.get("name", "Macro"), events=events, created=d.get("created", "")
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class MacroStore:
|
|
85
|
+
"""Persiste macros em macros.json."""
|
|
86
|
+
|
|
87
|
+
def __init__(self) -> None:
|
|
88
|
+
self._macros: dict[str, Macro] = {}
|
|
89
|
+
self._load()
|
|
90
|
+
|
|
91
|
+
def _load(self) -> None:
|
|
92
|
+
if not _MACROS_FILE.exists():
|
|
93
|
+
return
|
|
94
|
+
try:
|
|
95
|
+
raw = json.loads(_MACROS_FILE.read_text(encoding="utf-8"))
|
|
96
|
+
for m in raw.get("macros", []):
|
|
97
|
+
mac = Macro.from_dict(m)
|
|
98
|
+
self._macros[mac.name] = mac
|
|
99
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
100
|
+
logger.warning("macros.json corrompido: %s", exc)
|
|
101
|
+
|
|
102
|
+
def save(self) -> None:
|
|
103
|
+
"""Persiste as macros no arquivo de configuração."""
|
|
104
|
+
try:
|
|
105
|
+
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
|
106
|
+
data = {"macros": [m.to_dict() for m in self._macros.values()]}
|
|
107
|
+
_MACROS_FILE.write_text(
|
|
108
|
+
json.dumps(data, indent=2, ensure_ascii=False), encoding="utf-8"
|
|
109
|
+
)
|
|
110
|
+
except OSError as exc:
|
|
111
|
+
logger.warning("Falha ao salvar macros.json: %s", exc)
|
|
112
|
+
|
|
113
|
+
def add(self, macro: Macro) -> None:
|
|
114
|
+
"""Adiciona ou substitui uma macro na store."""
|
|
115
|
+
self._macros[macro.name] = macro
|
|
116
|
+
self.save()
|
|
117
|
+
|
|
118
|
+
def remove(self, name: str) -> None:
|
|
119
|
+
"""Remove uma macro da store pelo nome."""
|
|
120
|
+
self._macros.pop(name, None)
|
|
121
|
+
self.save()
|
|
122
|
+
|
|
123
|
+
def get(self, name: str) -> Macro | None:
|
|
124
|
+
"""Retorna a macro com o nome fornecido, ou ``None``."""
|
|
125
|
+
return self._macros.get(name)
|
|
126
|
+
|
|
127
|
+
def names(self) -> list[str]:
|
|
128
|
+
"""Retorna a lista de nomes de macros disponíveis."""
|
|
129
|
+
return list(self._macros.keys())
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def macros(self) -> dict[str, Macro]:
|
|
133
|
+
"""Retorna a lista de todas as macros armazenadas."""
|
|
134
|
+
return self._macros
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class MacroRecorder:
|
|
138
|
+
"""Componente de gravação e reprodução de macros.
|
|
139
|
+
|
|
140
|
+
Conecte-o ao widget Text ativo via `attach(text_widget)`.
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
def __init__(self, store: MacroStore) -> None:
|
|
144
|
+
self._store = store
|
|
145
|
+
self._recording = False
|
|
146
|
+
self._playing = False
|
|
147
|
+
self._events: list[MacroEvent] = []
|
|
148
|
+
self._text: tk.Text | None = None
|
|
149
|
+
self._last_ts: float = 0.0
|
|
150
|
+
self._bindings: list[tuple[tk.Widget, str, str]] = []
|
|
151
|
+
self._on_state_change: Callable[[], None] | None = None
|
|
152
|
+
|
|
153
|
+
def attach(self, text_widget: tk.Text) -> None:
|
|
154
|
+
"""Conecta o gravador a um widget Text. Chame ao trocar de aba."""
|
|
155
|
+
self._detach()
|
|
156
|
+
self._text = text_widget
|
|
157
|
+
if self._recording:
|
|
158
|
+
self._bind_text(text_widget)
|
|
159
|
+
|
|
160
|
+
def _detach(self) -> None:
|
|
161
|
+
for widget, seq, fid in self._bindings:
|
|
162
|
+
with contextlib.suppress(tk.TclError):
|
|
163
|
+
widget.unbind(seq, fid)
|
|
164
|
+
self._bindings.clear()
|
|
165
|
+
self._text = None
|
|
166
|
+
|
|
167
|
+
def start_recording(self) -> None:
|
|
168
|
+
"""Inicia a gravação de uma nova macro com o nome fornecido."""
|
|
169
|
+
if self._recording:
|
|
170
|
+
return
|
|
171
|
+
self._recording = True
|
|
172
|
+
self._events = []
|
|
173
|
+
self._last_ts = time.monotonic()
|
|
174
|
+
if self._text:
|
|
175
|
+
self._bind_text(self._text)
|
|
176
|
+
self._notify()
|
|
177
|
+
logger.info("Macro: gravação iniciada")
|
|
178
|
+
|
|
179
|
+
def stop_recording(self, name: str | None = None) -> Macro | None:
|
|
180
|
+
"""Encerra a gravação e salva a macro na store."""
|
|
181
|
+
if not self._recording:
|
|
182
|
+
return None
|
|
183
|
+
self._recording = False
|
|
184
|
+
self._detach()
|
|
185
|
+
self._notify()
|
|
186
|
+
|
|
187
|
+
if not self._events:
|
|
188
|
+
return None
|
|
189
|
+
|
|
190
|
+
import datetime
|
|
191
|
+
|
|
192
|
+
macro = Macro(
|
|
193
|
+
name=name or f"Macro {len(self._store.names()) + 1}",
|
|
194
|
+
events=self._events[:],
|
|
195
|
+
created=datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),
|
|
196
|
+
)
|
|
197
|
+
self._store.add(macro)
|
|
198
|
+
logger.info("Macro: %d eventos gravados → '%s'",
|
|
199
|
+
len(self._events), macro.name)
|
|
200
|
+
return macro
|
|
201
|
+
|
|
202
|
+
def play(
|
|
203
|
+
self,
|
|
204
|
+
name: str,
|
|
205
|
+
speed: float = 1.0,
|
|
206
|
+
on_done: Callable[[], None] | None = None,
|
|
207
|
+
) -> None:
|
|
208
|
+
"""Reproduz a macro em thread de background."""
|
|
209
|
+
macro = self._store.get(name)
|
|
210
|
+
if not macro or self._playing:
|
|
211
|
+
return
|
|
212
|
+
self._playing = True
|
|
213
|
+
self._notify()
|
|
214
|
+
|
|
215
|
+
def _run() -> None:
|
|
216
|
+
try:
|
|
217
|
+
self._replay(macro, speed)
|
|
218
|
+
finally:
|
|
219
|
+
self._playing = False
|
|
220
|
+
self._notify()
|
|
221
|
+
if on_done and self._text:
|
|
222
|
+
self._text.after(0, on_done)
|
|
223
|
+
|
|
224
|
+
threading.Thread(target=_run, daemon=True).start()
|
|
225
|
+
|
|
226
|
+
@property
|
|
227
|
+
def is_recording(self) -> bool:
|
|
228
|
+
"""Retorna ``True`` se uma macro está sendo gravada."""
|
|
229
|
+
return self._recording
|
|
230
|
+
|
|
231
|
+
@property
|
|
232
|
+
def is_playing(self) -> bool:
|
|
233
|
+
"""Retorna ``True`` se uma macro está sendo reproduzida."""
|
|
234
|
+
return self._playing
|
|
235
|
+
|
|
236
|
+
def on_state_change(self, cb: Callable[[], None]) -> None:
|
|
237
|
+
"""Registra callback chamado quando o estado de gravação/reprodução muda."""
|
|
238
|
+
self._on_state_change = cb
|
|
239
|
+
|
|
240
|
+
def _notify(self) -> None:
|
|
241
|
+
if self._on_state_change and self._text:
|
|
242
|
+
self._text.after(0, self._on_state_change)
|
|
243
|
+
|
|
244
|
+
def _bind_text(self, w: tk.Text) -> None:
|
|
245
|
+
def _bind(seq: str, cb: Callable) -> None:
|
|
246
|
+
fid = w.bind(seq, cb, "+")
|
|
247
|
+
self._bindings.append((w, seq, fid))
|
|
248
|
+
|
|
249
|
+
_bind("<Key>", self._on_key)
|
|
250
|
+
|
|
251
|
+
def _on_key(self, event: tk.Event) -> None:
|
|
252
|
+
if not self._recording:
|
|
253
|
+
return
|
|
254
|
+
now = time.monotonic()
|
|
255
|
+
delay = int((now - self._last_ts) * 1000)
|
|
256
|
+
self._last_ts = now
|
|
257
|
+
|
|
258
|
+
char = event.char
|
|
259
|
+
if char and char.isprintable():
|
|
260
|
+
idx = self._text.index("insert") if self._text else "insert"
|
|
261
|
+
self._events.append(
|
|
262
|
+
MacroEvent(_EV_INSERT, data=char, index=idx, delay=delay)
|
|
263
|
+
)
|
|
264
|
+
return
|
|
265
|
+
|
|
266
|
+
sym = event.keysym
|
|
267
|
+
if sym in (
|
|
268
|
+
"Control_L",
|
|
269
|
+
"Control_R",
|
|
270
|
+
"Shift_L",
|
|
271
|
+
"Shift_R",
|
|
272
|
+
"Alt_L",
|
|
273
|
+
"Alt_R",
|
|
274
|
+
"Super_L",
|
|
275
|
+
"Super_R",
|
|
276
|
+
):
|
|
277
|
+
return
|
|
278
|
+
|
|
279
|
+
parts = []
|
|
280
|
+
if event.state & 0x4:
|
|
281
|
+
parts.append("Control")
|
|
282
|
+
if event.state & 0x1:
|
|
283
|
+
parts.append("Shift")
|
|
284
|
+
if event.state & 0x8:
|
|
285
|
+
parts.append("Alt")
|
|
286
|
+
parts.append(sym)
|
|
287
|
+
key_str = "<" + "-".join(parts) + ">"
|
|
288
|
+
|
|
289
|
+
idx = self._text.index("insert") if self._text else "insert"
|
|
290
|
+
self._events.append(MacroEvent(
|
|
291
|
+
_EV_KEY, data=key_str, index=idx, delay=delay))
|
|
292
|
+
|
|
293
|
+
def _replay(self, macro: Macro, speed: float) -> None:
|
|
294
|
+
if not self._text:
|
|
295
|
+
return
|
|
296
|
+
for ev in macro.events:
|
|
297
|
+
if not self._playing:
|
|
298
|
+
break
|
|
299
|
+
raw_delay = ev.delay
|
|
300
|
+
delay_s = (raw_delay / 1000.0) / max(speed, 0.1)
|
|
301
|
+
if delay_s > 0.005:
|
|
302
|
+
time.sleep(min(delay_s, 2.0))
|
|
303
|
+
|
|
304
|
+
if ev.type == _EV_INSERT:
|
|
305
|
+
self._text.after(0, lambda c=ev.data: self._do_insert(c))
|
|
306
|
+
elif ev.type == _EV_KEY:
|
|
307
|
+
self._text.after(0, lambda k=ev.data: self._do_key(k))
|
|
308
|
+
|
|
309
|
+
def _do_insert(self, char: str) -> None:
|
|
310
|
+
if self._text:
|
|
311
|
+
with contextlib.suppress(tk.TclError):
|
|
312
|
+
self._text.insert("insert", char)
|
|
313
|
+
|
|
314
|
+
def _do_key(self, key_str: str) -> None:
|
|
315
|
+
if self._text:
|
|
316
|
+
with contextlib.suppress(tk.TclError):
|
|
317
|
+
self._text.event_generate(key_str)
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
class MacroToolbar(tk.Toplevel):
|
|
321
|
+
"""Toolbar flutuante sempre-no-topo para controlar gravação/reprodução."""
|
|
322
|
+
|
|
323
|
+
def __init__(
|
|
324
|
+
self,
|
|
325
|
+
parent: tk.Widget,
|
|
326
|
+
tmgr: Any,
|
|
327
|
+
recorder: MacroRecorder,
|
|
328
|
+
store: MacroStore,
|
|
329
|
+
get_text: Callable[[], tk.Text | None],
|
|
330
|
+
) -> None:
|
|
331
|
+
t = tmgr.theme
|
|
332
|
+
super().__init__(parent)
|
|
333
|
+
self.title(_t("macro.toolbar_title"))
|
|
334
|
+
self.configure(bg=t.floating_bg)
|
|
335
|
+
self.resizable(False, False)
|
|
336
|
+
self.attributes("-topmost", True)
|
|
337
|
+
self.transient(parent)
|
|
338
|
+
|
|
339
|
+
self._tmgr = tmgr
|
|
340
|
+
self._rec = recorder
|
|
341
|
+
self._store = store
|
|
342
|
+
self._get_txt = get_text
|
|
343
|
+
self._speed = tk.DoubleVar(value=1.0)
|
|
344
|
+
|
|
345
|
+
self._build(t)
|
|
346
|
+
recorder.on_state_change(self._update_ui)
|
|
347
|
+
self._update_ui()
|
|
348
|
+
self._place_near_parent(parent)
|
|
349
|
+
|
|
350
|
+
def _build(self, t: Any) -> None:
|
|
351
|
+
tk.Frame(self, bg=t.accent, height=2).pack(fill="x")
|
|
352
|
+
|
|
353
|
+
top = tk.Frame(self, bg=t.floating_bg)
|
|
354
|
+
top.pack(fill="x", padx=6, pady=4)
|
|
355
|
+
|
|
356
|
+
tk.Label(
|
|
357
|
+
top,
|
|
358
|
+
text=_t("macro.title"),
|
|
359
|
+
bg=t.floating_bg,
|
|
360
|
+
fg=t.t_func,
|
|
361
|
+
font=(FONT_UI, 9, "bold"),
|
|
362
|
+
).pack(side="left")
|
|
363
|
+
|
|
364
|
+
tk.Label(
|
|
365
|
+
self,
|
|
366
|
+
text=_t("macro.saved_list"),
|
|
367
|
+
bg=t.floating_bg,
|
|
368
|
+
fg=t.fg_muted,
|
|
369
|
+
font=(FONT_UI, 8),
|
|
370
|
+
).pack(anchor="w", padx=6)
|
|
371
|
+
|
|
372
|
+
list_frame = tk.Frame(self, bg=t.editor_bg)
|
|
373
|
+
list_frame.pack(fill="both", expand=True, padx=6, pady=2)
|
|
374
|
+
|
|
375
|
+
vsb = tk.Scrollbar(list_frame, orient="vertical")
|
|
376
|
+
self._listbox = tk.Listbox(
|
|
377
|
+
list_frame,
|
|
378
|
+
bg=t.editor_bg,
|
|
379
|
+
fg=t.fg,
|
|
380
|
+
selectbackground=t.sel_bg,
|
|
381
|
+
selectforeground=t.sel_fg,
|
|
382
|
+
font=(FONT_MONO, 8),
|
|
383
|
+
relief="flat",
|
|
384
|
+
bd=0,
|
|
385
|
+
activestyle="none",
|
|
386
|
+
height=6,
|
|
387
|
+
highlightthickness=0,
|
|
388
|
+
yscrollcommand=vsb.set,
|
|
389
|
+
)
|
|
390
|
+
vsb.config(command=self._listbox.yview)
|
|
391
|
+
vsb.pack(side="right", fill="y")
|
|
392
|
+
self._listbox.pack(fill="both", expand=True)
|
|
393
|
+
self._populate()
|
|
394
|
+
|
|
395
|
+
sp_row = tk.Frame(self, bg=t.floating_bg)
|
|
396
|
+
sp_row.pack(fill="x", padx=6, pady=2)
|
|
397
|
+
tk.Label(
|
|
398
|
+
sp_row,
|
|
399
|
+
text=_t("macro.speed_label"),
|
|
400
|
+
bg=t.floating_bg,
|
|
401
|
+
fg=t.fg_muted,
|
|
402
|
+
font=(FONT_UI, 8),
|
|
403
|
+
).pack(side="left")
|
|
404
|
+
tk.Scale(
|
|
405
|
+
sp_row,
|
|
406
|
+
from_=0.25,
|
|
407
|
+
to=4.0,
|
|
408
|
+
resolution=0.25,
|
|
409
|
+
orient="horizontal",
|
|
410
|
+
variable=self._speed,
|
|
411
|
+
bg=t.floating_bg,
|
|
412
|
+
fg=t.fg,
|
|
413
|
+
troughcolor=t.editor_bg,
|
|
414
|
+
highlightthickness=0,
|
|
415
|
+
showvalue=True,
|
|
416
|
+
length=120,
|
|
417
|
+
font=(FONT_UI, 7),
|
|
418
|
+
).pack(side="left", padx=4)
|
|
419
|
+
|
|
420
|
+
btn_row = tk.Frame(self, bg=t.floating_bg)
|
|
421
|
+
btn_row.pack(fill="x", padx=6, pady=(4, 6))
|
|
422
|
+
|
|
423
|
+
buttons = [
|
|
424
|
+
(_t("macro.btn_record"), self._btn_record, "#c62828", "white"),
|
|
425
|
+
(_t("macro.btn_stop"), self._btn_stop, t.btn_bg, t.fg),
|
|
426
|
+
(_t("macro.btn_play"), self._btn_play, t.btn_primary, t.btn_primary_fg),
|
|
427
|
+
(_t("macro.btn_remove"), self._btn_remove, t.btn_bg, t.fg),
|
|
428
|
+
]
|
|
429
|
+
self._btns: dict[str, tk.Label] = {}
|
|
430
|
+
for text, cmd, bg, fg in buttons:
|
|
431
|
+
key = text.split()[0]
|
|
432
|
+
btn = tk.Label(
|
|
433
|
+
btn_row,
|
|
434
|
+
text=text,
|
|
435
|
+
bg=bg,
|
|
436
|
+
fg=fg,
|
|
437
|
+
font=(FONT_UI, 8),
|
|
438
|
+
cursor="hand2",
|
|
439
|
+
padx=6,
|
|
440
|
+
pady=3,
|
|
441
|
+
relief="flat",
|
|
442
|
+
)
|
|
443
|
+
btn.pack(side="left", padx=2)
|
|
444
|
+
btn.bind("<Button-1>", lambda _, c=cmd: c())
|
|
445
|
+
self._btns[key] = btn
|
|
446
|
+
|
|
447
|
+
io_row = tk.Frame(self, bg=t.floating_bg)
|
|
448
|
+
io_row.pack(fill="x", padx=6, pady=(0, 6))
|
|
449
|
+
for text, cmd in (
|
|
450
|
+
(_t("macro.btn_export"), self._btn_export),
|
|
451
|
+
(_t("macro.btn_import"), self._btn_import),
|
|
452
|
+
):
|
|
453
|
+
tk.Label(
|
|
454
|
+
io_row,
|
|
455
|
+
text=text,
|
|
456
|
+
bg=t.btn_bg,
|
|
457
|
+
fg=t.fg,
|
|
458
|
+
font=(FONT_UI, 7),
|
|
459
|
+
cursor="hand2",
|
|
460
|
+
padx=4,
|
|
461
|
+
pady=2,
|
|
462
|
+
relief="flat",
|
|
463
|
+
).pack(side="left", padx=2)
|
|
464
|
+
io_row.winfo_children()[-1].bind("<Button-1>",
|
|
465
|
+
lambda _, c=cmd: c())
|
|
466
|
+
|
|
467
|
+
self._status = tk.Label(
|
|
468
|
+
self,
|
|
469
|
+
text="",
|
|
470
|
+
bg=t.floating_bg,
|
|
471
|
+
fg=t.fg_muted,
|
|
472
|
+
font=(FONT_UI, 7),
|
|
473
|
+
)
|
|
474
|
+
self._status.pack(anchor="w", padx=6, pady=(0, 4))
|
|
475
|
+
|
|
476
|
+
def _populate(self) -> None:
|
|
477
|
+
self._listbox.delete(0, "end")
|
|
478
|
+
for name in self._store.names():
|
|
479
|
+
m = self._store.get(name)
|
|
480
|
+
ev_count = len(m.events) if m else 0
|
|
481
|
+
self._listbox.insert(
|
|
482
|
+
"end", f" {name} ({_t('macro.ev_count', n=ev_count)})"
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
def _update_ui(self) -> None:
|
|
486
|
+
t = self._tmgr.theme
|
|
487
|
+
rec = self._rec.is_recording
|
|
488
|
+
play = self._rec.is_playing
|
|
489
|
+
|
|
490
|
+
rec_btn = self._btns.get("⏺")
|
|
491
|
+
if rec_btn:
|
|
492
|
+
rec_btn.config(
|
|
493
|
+
text=_t("macro.btn_stop_rec") if rec else "⏺ Gravar",
|
|
494
|
+
bg="#c62828" if rec else t.btn_bg,
|
|
495
|
+
fg="white" if rec else t.fg,
|
|
496
|
+
)
|
|
497
|
+
|
|
498
|
+
play_btn = self._btns.get("▶")
|
|
499
|
+
if play_btn:
|
|
500
|
+
play_btn.config(state="disabled" if play else "normal")
|
|
501
|
+
|
|
502
|
+
status = ""
|
|
503
|
+
if rec:
|
|
504
|
+
status = _t("macro.recording")
|
|
505
|
+
elif play:
|
|
506
|
+
status = _t("macro.playing")
|
|
507
|
+
self._status.config(text=status)
|
|
508
|
+
|
|
509
|
+
def _btn_record(self) -> None:
|
|
510
|
+
if self._rec.is_recording:
|
|
511
|
+
name = simpledialog.askstring(
|
|
512
|
+
_t("macro.save_title"),
|
|
513
|
+
_t("macro.save_prompt"),
|
|
514
|
+
parent=self,
|
|
515
|
+
initialvalue=_t("macro.save_default",
|
|
516
|
+
n=len(self._store.names()) + 1),
|
|
517
|
+
)
|
|
518
|
+
if name is None:
|
|
519
|
+
return
|
|
520
|
+
macro = self._rec.stop_recording(name)
|
|
521
|
+
if macro:
|
|
522
|
+
self._populate()
|
|
523
|
+
self._status.config(text=f"Salva: {macro.name}")
|
|
524
|
+
else:
|
|
525
|
+
txt = self._get_txt()
|
|
526
|
+
if txt:
|
|
527
|
+
self._rec.attach(txt)
|
|
528
|
+
self._rec.start_recording()
|
|
529
|
+
|
|
530
|
+
def _btn_stop(self) -> None:
|
|
531
|
+
if self._rec.is_recording:
|
|
532
|
+
self._btn_record()
|
|
533
|
+
elif self._rec.is_playing:
|
|
534
|
+
self._rec._playing = False
|
|
535
|
+
|
|
536
|
+
def _btn_play(self) -> None:
|
|
537
|
+
sel = self._listbox.curselection()
|
|
538
|
+
names = self._store.names()
|
|
539
|
+
if not sel or sel[0] >= len(names):
|
|
540
|
+
self._status.config(text=_t("macro.no_select"))
|
|
541
|
+
return
|
|
542
|
+
name = names[sel[0]]
|
|
543
|
+
txt = self._get_txt()
|
|
544
|
+
if txt:
|
|
545
|
+
self._rec.attach(txt)
|
|
546
|
+
self._rec.play(
|
|
547
|
+
name,
|
|
548
|
+
speed=self._speed.get(),
|
|
549
|
+
on_done=lambda: self._status.config(text=_t("macro.play_done")),
|
|
550
|
+
)
|
|
551
|
+
|
|
552
|
+
def _btn_remove(self) -> None:
|
|
553
|
+
sel = self._listbox.curselection()
|
|
554
|
+
names = self._store.names()
|
|
555
|
+
if not sel or sel[0] >= len(names):
|
|
556
|
+
return
|
|
557
|
+
name = names[sel[0]]
|
|
558
|
+
if messagebox.askyesno(
|
|
559
|
+
_t("macro.remove_title"), f"Remover '{name}'?", parent=self
|
|
560
|
+
):
|
|
561
|
+
self._store.remove(name)
|
|
562
|
+
self._populate()
|
|
563
|
+
|
|
564
|
+
def _btn_export(self) -> None:
|
|
565
|
+
path = filedialog.asksaveasfilename(
|
|
566
|
+
parent=self,
|
|
567
|
+
title=_t("macro.export_title"),
|
|
568
|
+
defaultextension=".json",
|
|
569
|
+
filetypes=[("JSON", "*.json")],
|
|
570
|
+
initialfile=_t("macro.export_file"),
|
|
571
|
+
)
|
|
572
|
+
if not path:
|
|
573
|
+
return
|
|
574
|
+
try:
|
|
575
|
+
data = {"macros": [m.to_dict()
|
|
576
|
+
for m in self._store.macros.values()]}
|
|
577
|
+
Path(path).write_text(
|
|
578
|
+
json.dumps(data, indent=2, ensure_ascii=False), encoding="utf-8"
|
|
579
|
+
)
|
|
580
|
+
self._status.config(text=_t("macro.exported"))
|
|
581
|
+
except OSError as exc:
|
|
582
|
+
messagebox.showerror(_t("macro.error_title"),
|
|
583
|
+
str(exc), parent=self)
|
|
584
|
+
|
|
585
|
+
def _btn_import(self) -> None:
|
|
586
|
+
path = filedialog.askopenfilename(
|
|
587
|
+
parent=self,
|
|
588
|
+
title=_t("macro.import_title"),
|
|
589
|
+
filetypes=[("JSON", "*.json")],
|
|
590
|
+
)
|
|
591
|
+
if not path:
|
|
592
|
+
return
|
|
593
|
+
try:
|
|
594
|
+
raw = json.loads(Path(path).read_text(encoding="utf-8"))
|
|
595
|
+
count = 0
|
|
596
|
+
for m in raw.get("macros", []):
|
|
597
|
+
mac = Macro.from_dict(m)
|
|
598
|
+
self._store.add(mac)
|
|
599
|
+
count += 1
|
|
600
|
+
self._populate()
|
|
601
|
+
self._status.config(text=_t("macro.import_done", n=count))
|
|
602
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
603
|
+
messagebox.showerror(_t("macro.import_err"), str(exc), parent=self)
|
|
604
|
+
|
|
605
|
+
def _place_near_parent(self, parent: tk.Widget) -> None:
|
|
606
|
+
self.update_idletasks()
|
|
607
|
+
with contextlib.suppress(tk.TclError):
|
|
608
|
+
x = parent.winfo_rootx() + parent.winfo_width() - self.winfo_width() - 20
|
|
609
|
+
y = parent.winfo_rooty() + 60
|
|
610
|
+
self.geometry(f"+{x}+{y}")
|