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/key_remapper.py
ADDED
|
@@ -0,0 +1,856 @@
|
|
|
1
|
+
"""Codis - Key Remapper.
|
|
2
|
+
|
|
3
|
+
Permite ao usuário remapear qualquer atalho de teclado da aplicação.
|
|
4
|
+
Os atalhos customizados são persistidos na configuração e aplicados
|
|
5
|
+
em toda a sessão.
|
|
6
|
+
|
|
7
|
+
Arquitetura
|
|
8
|
+
-----------
|
|
9
|
+
- ``KeyRemapperStore`` : lê/grava ``keybindings.json`` separado do config.json
|
|
10
|
+
- ``KeyRemapperDialog`` : janela de edição com lista pesquisável e captura interativa
|
|
11
|
+
- ``KeyRemapperManager`` : aplica os bindings no root do Tk e é usado pelo CodisApp
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import contextlib
|
|
17
|
+
import json
|
|
18
|
+
import logging
|
|
19
|
+
import tkinter as tk
|
|
20
|
+
from collections.abc import Callable
|
|
21
|
+
from tkinter import messagebox
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
from src.constants import CONFIG_DIR, FONT_MONO, FONT_UI
|
|
25
|
+
from src.i18n import _t
|
|
26
|
+
from src.ui.grab_safe import safe_grab_set
|
|
27
|
+
|
|
28
|
+
logger = logging.getLogger("Codis")
|
|
29
|
+
|
|
30
|
+
_KEYBINDINGS_FILE = CONFIG_DIR / "keybindings.json"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _get_default_bindings() -> list[dict[str, str]]:
|
|
34
|
+
"""Returns the default binding list with localised labels."""
|
|
35
|
+
return [
|
|
36
|
+
{
|
|
37
|
+
"id": "file.new",
|
|
38
|
+
"label": _t("keyremap.cmd.file_new"),
|
|
39
|
+
"default": "<Control-n>",
|
|
40
|
+
"current": "",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"id": "file.open",
|
|
44
|
+
"label": _t("keyremap.cmd.file_open"),
|
|
45
|
+
"default": "<Control-o>",
|
|
46
|
+
"current": "",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"id": "file.save",
|
|
50
|
+
"label": _t("keyremap.cmd.file_save"),
|
|
51
|
+
"default": "<Control-s>",
|
|
52
|
+
"current": "",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"id": "file.save_as",
|
|
56
|
+
"label": _t("keyremap.cmd.file_save_as"),
|
|
57
|
+
"default": "<Control-S>",
|
|
58
|
+
"current": "",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"id": "file.save_all",
|
|
62
|
+
"label": _t("keyremap.cmd.file_save_all"),
|
|
63
|
+
"default": "",
|
|
64
|
+
"current": "",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"id": "file.close_tab",
|
|
68
|
+
"label": _t("keyremap.cmd.file_close_tab"),
|
|
69
|
+
"default": "<Control-w>",
|
|
70
|
+
"current": "",
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"id": "file.exit",
|
|
74
|
+
"label": _t("keyremap.cmd.file_exit"),
|
|
75
|
+
"default": "<Alt-F4>",
|
|
76
|
+
"current": "",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"id": "edit.undo",
|
|
80
|
+
"label": _t("keyremap.cmd.edit_undo"),
|
|
81
|
+
"default": "<Control-z>",
|
|
82
|
+
"current": "",
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"id": "edit.redo",
|
|
86
|
+
"label": _t("keyremap.cmd.edit_redo"),
|
|
87
|
+
"default": "<Control-y>",
|
|
88
|
+
"current": "",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"id": "edit.cut",
|
|
92
|
+
"label": _t("keyremap.cmd.edit_cut"),
|
|
93
|
+
"default": "<Control-x>",
|
|
94
|
+
"current": "",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"id": "edit.copy",
|
|
98
|
+
"label": _t("keyremap.cmd.edit_copy"),
|
|
99
|
+
"default": "<Control-c>",
|
|
100
|
+
"current": "",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"id": "edit.paste",
|
|
104
|
+
"label": _t("keyremap.cmd.edit_paste"),
|
|
105
|
+
"default": "<Control-v>",
|
|
106
|
+
"current": "",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"id": "edit.select_all",
|
|
110
|
+
"label": _t("keyremap.cmd.edit_select_all"),
|
|
111
|
+
"default": "<Control-a>",
|
|
112
|
+
"current": "",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"id": "edit.find",
|
|
116
|
+
"label": _t("keyremap.cmd.edit_find"),
|
|
117
|
+
"default": "<Control-f>",
|
|
118
|
+
"current": "",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"id": "edit.replace",
|
|
122
|
+
"label": _t("keyremap.cmd.edit_replace"),
|
|
123
|
+
"default": "<Control-h>",
|
|
124
|
+
"current": "",
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"id": "edit.find_files",
|
|
128
|
+
"label": _t("keyremap.cmd.edit_find_files"),
|
|
129
|
+
"default": "<Control-F>",
|
|
130
|
+
"current": "",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"id": "edit.comment",
|
|
134
|
+
"label": _t("keyremap.cmd.edit_comment"),
|
|
135
|
+
"default": "<Control-slash>",
|
|
136
|
+
"current": "",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"id": "edit.duplicate",
|
|
140
|
+
"label": _t("keyremap.cmd.edit_duplicate"),
|
|
141
|
+
"default": "<Control-d>",
|
|
142
|
+
"current": "",
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"id": "edit.delete_line",
|
|
146
|
+
"label": _t("keyremap.cmd.edit_delete_line"),
|
|
147
|
+
"default": "<Control-K>",
|
|
148
|
+
"current": "",
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"id": "edit.move_up",
|
|
152
|
+
"label": _t("keyremap.cmd.edit_move_up"),
|
|
153
|
+
"default": "<Alt-Up>",
|
|
154
|
+
"current": "",
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"id": "edit.move_down",
|
|
158
|
+
"label": _t("keyremap.cmd.edit_move_down"),
|
|
159
|
+
"default": "<Alt-Down>",
|
|
160
|
+
"current": "",
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"id": "edit.paste_history",
|
|
164
|
+
"label": _t("keyremap.cmd.edit_paste_history"),
|
|
165
|
+
"default": "<Control-Shift-V>",
|
|
166
|
+
"current": "",
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"id": "view.command_palette",
|
|
170
|
+
"label": _t("keyremap.cmd.view_palette"),
|
|
171
|
+
"default": "<Control-P>",
|
|
172
|
+
"current": "",
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"id": "view.quick_open",
|
|
176
|
+
"label": _t("keyremap.cmd.view_quick_open"),
|
|
177
|
+
"default": "<Control-p>",
|
|
178
|
+
"current": "",
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"id": "view.terminal",
|
|
182
|
+
"label": _t("keyremap.cmd.view_terminal"),
|
|
183
|
+
"default": "<Control-grave>",
|
|
184
|
+
"current": "",
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"id": "view.problems",
|
|
188
|
+
"label": _t("keyremap.cmd.view_problems"),
|
|
189
|
+
"default": "<Control-Shift-M>",
|
|
190
|
+
"current": "",
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"id": "view.zoom_in",
|
|
194
|
+
"label": _t("keyremap.cmd.view_zoom_in"),
|
|
195
|
+
"default": "<Control-equal>",
|
|
196
|
+
"current": "",
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"id": "view.zoom_out",
|
|
200
|
+
"label": _t("keyremap.cmd.view_zoom_out"),
|
|
201
|
+
"default": "<Control-minus>",
|
|
202
|
+
"current": "",
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"id": "view.zoom_reset",
|
|
206
|
+
"label": _t("keyremap.cmd.view_zoom_reset"),
|
|
207
|
+
"default": "<Control-0>",
|
|
208
|
+
"current": "",
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"id": "view.fullscreen",
|
|
212
|
+
"label": _t("keyremap.cmd.view_fullscreen"),
|
|
213
|
+
"default": "<F11>",
|
|
214
|
+
"current": "",
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"id": "view.split",
|
|
218
|
+
"label": _t("keyremap.cmd.view_split"),
|
|
219
|
+
"default": "",
|
|
220
|
+
"current": "",
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"id": "view.settings",
|
|
224
|
+
"label": _t("keyremap.cmd.view_settings"),
|
|
225
|
+
"default": "<Control-comma>",
|
|
226
|
+
"current": "",
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"id": "view.color_picker",
|
|
230
|
+
"label": _t("keyremap.cmd.view_color_picker"),
|
|
231
|
+
"default": "<Control-Shift-C>",
|
|
232
|
+
"current": "",
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"id": "view.regex",
|
|
236
|
+
"label": _t("keyremap.cmd.view_regex"),
|
|
237
|
+
"default": "<Control-Shift-R>",
|
|
238
|
+
"current": "",
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
"id": "view.ia",
|
|
242
|
+
"label": _t("keyremap.cmd.view_ia"),
|
|
243
|
+
"default": "<Control-Shift-A>",
|
|
244
|
+
"current": "",
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
"id": "view.scratchpad",
|
|
248
|
+
"label": _t("keyremap.cmd.view_scratchpad"),
|
|
249
|
+
"default": "<Control-Shift-N>",
|
|
250
|
+
"current": "",
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
"id": "view.snippets",
|
|
254
|
+
"label": _t("keyremap.cmd.view_snippets"),
|
|
255
|
+
"default": "<Control-Shift-J>",
|
|
256
|
+
"current": "",
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"id": "go.line",
|
|
260
|
+
"label": _t("keyremap.cmd.go_line"),
|
|
261
|
+
"default": "<Control-g>",
|
|
262
|
+
"current": "",
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
"id": "go.next_tab",
|
|
266
|
+
"label": _t("keyremap.cmd.go_next_tab"),
|
|
267
|
+
"default": "<Control-Tab>",
|
|
268
|
+
"current": "",
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
"id": "go.prev_tab",
|
|
272
|
+
"label": _t("keyremap.cmd.go_prev_tab"),
|
|
273
|
+
"default": "<Control-Shift-Tab>",
|
|
274
|
+
"current": "",
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
"id": "go.next_problem",
|
|
278
|
+
"label": _t("keyremap.cmd.go_next_problem"),
|
|
279
|
+
"default": "<F8>",
|
|
280
|
+
"current": "",
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"id": "go.prev_problem",
|
|
284
|
+
"label": _t("keyremap.cmd.go_prev_problem"),
|
|
285
|
+
"default": "<Shift-F8>",
|
|
286
|
+
"current": "",
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
"id": "run.run_file",
|
|
290
|
+
"label": _t("keyremap.cmd.run_file"),
|
|
291
|
+
"default": "<F5>",
|
|
292
|
+
"current": "",
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
"id": "run.format",
|
|
296
|
+
"label": _t("keyremap.cmd.run_format"),
|
|
297
|
+
"default": "<Shift-Alt-f>",
|
|
298
|
+
"current": "",
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
"id": "tools.bookmark_add",
|
|
302
|
+
"label": _t("keyremap.cmd.tools_bookmark_add"),
|
|
303
|
+
"default": "<Control-F2>",
|
|
304
|
+
"current": "",
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
"id": "tools.bookmark_next",
|
|
308
|
+
"label": _t("keyremap.cmd.tools_bookmark_next"),
|
|
309
|
+
"default": "<F2>",
|
|
310
|
+
"current": "",
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
"id": "tools.zen_mode",
|
|
314
|
+
"label": _t("keyremap.cmd.tools_zen_mode"),
|
|
315
|
+
"default": "<Control-Alt-z>",
|
|
316
|
+
"current": "",
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
"id": "tools.vim_mode",
|
|
320
|
+
"label": _t("keyremap.cmd.tools_vim_mode"),
|
|
321
|
+
"default": "<Control-Alt-v>",
|
|
322
|
+
"current": "",
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
"id": "tools.kui",
|
|
326
|
+
"label": _t("keyremap.cmd.tools_kui"),
|
|
327
|
+
"default": "<Control-Alt-n>",
|
|
328
|
+
"current": "",
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
"id": "tools.pomodoro",
|
|
332
|
+
"label": _t("keyremap.cmd.tools_pomodoro"),
|
|
333
|
+
"default": "<Control-Alt-p>",
|
|
334
|
+
"current": "",
|
|
335
|
+
},
|
|
336
|
+
]
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
class KeyRemapperStore:
|
|
340
|
+
"""Persiste e lê o arquivo keybindings.json."""
|
|
341
|
+
|
|
342
|
+
def __init__(self) -> None:
|
|
343
|
+
self._bindings: list[dict[str, str]] = []
|
|
344
|
+
self._load()
|
|
345
|
+
|
|
346
|
+
def _load(self) -> None:
|
|
347
|
+
self._bindings = [dict(b) for b in _get_default_bindings()]
|
|
348
|
+
if not _KEYBINDINGS_FILE.exists():
|
|
349
|
+
return
|
|
350
|
+
try:
|
|
351
|
+
raw: Any = json.loads(
|
|
352
|
+
_KEYBINDINGS_FILE.read_text(encoding="utf-8"))
|
|
353
|
+
overrides: dict[str, str] = raw if isinstance(raw, dict) else {}
|
|
354
|
+
for b in self._bindings:
|
|
355
|
+
if b["id"] in overrides:
|
|
356
|
+
b["current"] = overrides[b["id"]]
|
|
357
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
358
|
+
logger.warning("keybindings.json corrompido: %s", exc)
|
|
359
|
+
|
|
360
|
+
def save(self) -> None:
|
|
361
|
+
"""Persiste o mapa de atalhos atual no arquivo de configuração."""
|
|
362
|
+
try:
|
|
363
|
+
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
|
364
|
+
overrides = {b["id"]: b["current"]
|
|
365
|
+
for b in self._bindings if b["current"]}
|
|
366
|
+
_KEYBINDINGS_FILE.write_text(
|
|
367
|
+
json.dumps(overrides, indent=2, ensure_ascii=False),
|
|
368
|
+
encoding="utf-8",
|
|
369
|
+
)
|
|
370
|
+
except OSError as exc:
|
|
371
|
+
logger.warning("Falha ao salvar keybindings.json: %s", exc)
|
|
372
|
+
|
|
373
|
+
def set(self, binding_id: str, key: str) -> None:
|
|
374
|
+
"""Define ou redefine o atalho de uma ação."""
|
|
375
|
+
for b in self._bindings:
|
|
376
|
+
if b["id"] == binding_id:
|
|
377
|
+
b["current"] = key
|
|
378
|
+
return
|
|
379
|
+
|
|
380
|
+
def reset(self, binding_id: str) -> None:
|
|
381
|
+
"""Restaura o atalho de uma ação para o valor padrão."""
|
|
382
|
+
self.set(binding_id, "")
|
|
383
|
+
|
|
384
|
+
def reset_all(self) -> None:
|
|
385
|
+
"""Restaura todos os atalhos para os valores padrão."""
|
|
386
|
+
for b in self._bindings:
|
|
387
|
+
b["current"] = ""
|
|
388
|
+
|
|
389
|
+
@property
|
|
390
|
+
def bindings(self) -> list[dict[str, str]]:
|
|
391
|
+
"""Retorna uma cópia do dicionário de atalhos atual."""
|
|
392
|
+
return self._bindings
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
class KeyRemapperManager:
|
|
396
|
+
"""Aplica os keybindings no widget raiz do Tkinter."""
|
|
397
|
+
|
|
398
|
+
def __init__(self, root: tk.Tk, store: KeyRemapperStore) -> None:
|
|
399
|
+
self._root = root
|
|
400
|
+
self._store = store
|
|
401
|
+
self._handlers: dict[str, Callable] = {}
|
|
402
|
+
self._applied_keys: list[str] = []
|
|
403
|
+
|
|
404
|
+
def register(self, binding_id: str, handler: Callable) -> None:
|
|
405
|
+
"""Registra uma ação com seu atalho padrão."""
|
|
406
|
+
self._handlers[binding_id] = handler
|
|
407
|
+
|
|
408
|
+
def apply_all(self) -> None:
|
|
409
|
+
"""Aplica todos os atalhos registrados ao widget root."""
|
|
410
|
+
for key in self._applied_keys:
|
|
411
|
+
with contextlib.suppress(tk.TclError):
|
|
412
|
+
self._root.unbind(key)
|
|
413
|
+
self._applied_keys.clear()
|
|
414
|
+
|
|
415
|
+
for b in self._store.bindings:
|
|
416
|
+
bid = b["id"]
|
|
417
|
+
handler = self._handlers.get(bid)
|
|
418
|
+
if not handler:
|
|
419
|
+
continue
|
|
420
|
+
key = b["current"] or b["default"]
|
|
421
|
+
if not key:
|
|
422
|
+
continue
|
|
423
|
+
with contextlib.suppress(tk.TclError):
|
|
424
|
+
self._root.bind(key, lambda _e, h=handler: h())
|
|
425
|
+
self._applied_keys.append(key)
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
def _tk_key_to_human(tk_key: str) -> str:
|
|
429
|
+
"""Converte string Tk (<Control-s>) para exibição legível (Ctrl+S)."""
|
|
430
|
+
if not tk_key:
|
|
431
|
+
return ""
|
|
432
|
+
s = tk_key.strip("<>")
|
|
433
|
+
parts = s.split("-")
|
|
434
|
+
mapped = []
|
|
435
|
+
for p in parts:
|
|
436
|
+
p_lower = p.lower()
|
|
437
|
+
if p_lower == "control":
|
|
438
|
+
mapped.append("Ctrl")
|
|
439
|
+
elif p_lower == "shift":
|
|
440
|
+
mapped.append("Shift")
|
|
441
|
+
elif p_lower == "alt":
|
|
442
|
+
mapped.append("Alt")
|
|
443
|
+
elif p_lower == "grave":
|
|
444
|
+
mapped.append("`")
|
|
445
|
+
elif p_lower == "slash":
|
|
446
|
+
mapped.append("/")
|
|
447
|
+
elif p_lower == "equal":
|
|
448
|
+
mapped.append("=")
|
|
449
|
+
elif p_lower == "minus":
|
|
450
|
+
mapped.append("-")
|
|
451
|
+
elif p_lower == "comma":
|
|
452
|
+
mapped.append(",")
|
|
453
|
+
else:
|
|
454
|
+
mapped.append(p.upper() if len(p) == 1 else p)
|
|
455
|
+
return "+".join(mapped)
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def _human_to_tk_key(human: str) -> str:
|
|
459
|
+
"""Converte exibição legível (Ctrl+Shift+S) para string Tk (<Control-Shift-S>)."""
|
|
460
|
+
if not human:
|
|
461
|
+
return ""
|
|
462
|
+
parts = human.split("+")
|
|
463
|
+
mapped = []
|
|
464
|
+
for p in parts:
|
|
465
|
+
p_lower = p.lower()
|
|
466
|
+
if p_lower == "ctrl":
|
|
467
|
+
mapped.append("Control")
|
|
468
|
+
elif p_lower == "shift":
|
|
469
|
+
mapped.append("Shift")
|
|
470
|
+
elif p_lower == "alt":
|
|
471
|
+
mapped.append("Alt")
|
|
472
|
+
elif p == "`":
|
|
473
|
+
mapped.append("grave")
|
|
474
|
+
elif p == "/":
|
|
475
|
+
mapped.append("slash")
|
|
476
|
+
elif p == "=":
|
|
477
|
+
mapped.append("equal")
|
|
478
|
+
elif p == "-":
|
|
479
|
+
mapped.append("minus")
|
|
480
|
+
elif p == ",":
|
|
481
|
+
mapped.append("comma")
|
|
482
|
+
else:
|
|
483
|
+
mapped.append(p)
|
|
484
|
+
return "<" + "-".join(mapped) + ">"
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
class KeyRemapperDialog(tk.Toplevel):
|
|
488
|
+
"""Janela de remapeamento de atalhos.
|
|
489
|
+
|
|
490
|
+
Exibe lista pesquisável de todos os comandos. O usuário pode clicar
|
|
491
|
+
em um item e pressionar a nova combinação de teclas para capturá-la
|
|
492
|
+
interativamente, ou digitar manualmente.
|
|
493
|
+
"""
|
|
494
|
+
|
|
495
|
+
def __init__(
|
|
496
|
+
self,
|
|
497
|
+
parent: tk.Widget,
|
|
498
|
+
tmgr: Any,
|
|
499
|
+
store: KeyRemapperStore,
|
|
500
|
+
on_apply: Callable[[], None],
|
|
501
|
+
) -> None:
|
|
502
|
+
t = tmgr.theme
|
|
503
|
+
super().__init__(parent)
|
|
504
|
+
self.title(_t("keyremap.window_title"))
|
|
505
|
+
self.configure(bg=t.floating_bg)
|
|
506
|
+
self.geometry("760x560")
|
|
507
|
+
self.minsize(600, 400)
|
|
508
|
+
self.transient(parent)
|
|
509
|
+
safe_grab_set(self)
|
|
510
|
+
|
|
511
|
+
self._tmgr = tmgr
|
|
512
|
+
self._store = store
|
|
513
|
+
self._on_apply = on_apply
|
|
514
|
+
self._capturing = False
|
|
515
|
+
self._selected_id: str | None = None
|
|
516
|
+
|
|
517
|
+
self._build(t)
|
|
518
|
+
self._populate()
|
|
519
|
+
self._center(parent)
|
|
520
|
+
|
|
521
|
+
def _build(self, t: Any) -> None:
|
|
522
|
+
tk.Frame(self, bg=t.accent, height=2).pack(fill="x")
|
|
523
|
+
|
|
524
|
+
hdr = tk.Frame(self, bg=t.floating_bg)
|
|
525
|
+
hdr.pack(fill="x", padx=14, pady=(10, 4))
|
|
526
|
+
tk.Label(
|
|
527
|
+
hdr,
|
|
528
|
+
text=_t("keyremap.title"),
|
|
529
|
+
bg=t.floating_bg,
|
|
530
|
+
fg=t.t_func,
|
|
531
|
+
font=(FONT_UI, 12, "bold"),
|
|
532
|
+
).pack(side="left")
|
|
533
|
+
|
|
534
|
+
reset_all_btn = tk.Label(
|
|
535
|
+
hdr,
|
|
536
|
+
text=_t("keyremap.restore_all"),
|
|
537
|
+
bg=t.btn_bg,
|
|
538
|
+
fg=t.fg,
|
|
539
|
+
font=(FONT_UI, 8),
|
|
540
|
+
cursor="hand2",
|
|
541
|
+
padx=8,
|
|
542
|
+
pady=3,
|
|
543
|
+
relief="flat",
|
|
544
|
+
)
|
|
545
|
+
reset_all_btn.pack(side="right")
|
|
546
|
+
reset_all_btn.bind("<Button-1>", lambda _: self._reset_all())
|
|
547
|
+
|
|
548
|
+
search_frame = tk.Frame(self, bg=t.floating_bg)
|
|
549
|
+
search_frame.pack(fill="x", padx=14, pady=(0, 4))
|
|
550
|
+
tk.Label(
|
|
551
|
+
search_frame,
|
|
552
|
+
text="🔍",
|
|
553
|
+
bg=t.floating_bg,
|
|
554
|
+
fg=t.fg_muted,
|
|
555
|
+
font=(FONT_UI, 10),
|
|
556
|
+
).pack(side="left")
|
|
557
|
+
self._search_var = tk.StringVar()
|
|
558
|
+
self._search_var.trace_add("write", lambda *_: self._populate())
|
|
559
|
+
tk.Entry(
|
|
560
|
+
search_frame,
|
|
561
|
+
textvariable=self._search_var,
|
|
562
|
+
bg=t.input_bg,
|
|
563
|
+
fg=t.fg,
|
|
564
|
+
insertbackground=t.cursor,
|
|
565
|
+
relief="flat",
|
|
566
|
+
bd=0,
|
|
567
|
+
font=(FONT_UI, 10),
|
|
568
|
+
highlightthickness=1,
|
|
569
|
+
highlightbackground=t.border,
|
|
570
|
+
).pack(side="left", fill="x", expand=True, padx=4, pady=2)
|
|
571
|
+
|
|
572
|
+
cols = tk.Frame(self, bg=t.floating_bg)
|
|
573
|
+
cols.pack(fill="x", padx=14, pady=(0, 2))
|
|
574
|
+
for text, w in (
|
|
575
|
+
(_t("keyremap.col_command"), 30),
|
|
576
|
+
(_t("keyremap.col_default"), 18),
|
|
577
|
+
(_t("keyremap.col_current"), 18),
|
|
578
|
+
):
|
|
579
|
+
tk.Label(
|
|
580
|
+
cols,
|
|
581
|
+
text=text,
|
|
582
|
+
bg=t.floating_bg,
|
|
583
|
+
fg=t.fg_muted,
|
|
584
|
+
font=(FONT_UI, 8, "bold"),
|
|
585
|
+
width=w,
|
|
586
|
+
anchor="w",
|
|
587
|
+
).pack(side="left")
|
|
588
|
+
|
|
589
|
+
list_frame = tk.Frame(self, bg=t.floating_bg)
|
|
590
|
+
list_frame.pack(fill="both", expand=True, padx=14, pady=2)
|
|
591
|
+
|
|
592
|
+
scrollbar = tk.Scrollbar(
|
|
593
|
+
list_frame, orient="vertical", bg=t.scroll_thumb)
|
|
594
|
+
self._listbox = tk.Listbox(
|
|
595
|
+
list_frame,
|
|
596
|
+
bg=t.editor_bg,
|
|
597
|
+
fg=t.fg,
|
|
598
|
+
selectbackground=t.sel_bg,
|
|
599
|
+
selectforeground=t.sel_fg,
|
|
600
|
+
font=(FONT_MONO, 9),
|
|
601
|
+
relief="flat",
|
|
602
|
+
bd=0,
|
|
603
|
+
activestyle="none",
|
|
604
|
+
highlightthickness=0,
|
|
605
|
+
yscrollcommand=scrollbar.set,
|
|
606
|
+
)
|
|
607
|
+
scrollbar.config(command=self._listbox.yview)
|
|
608
|
+
scrollbar.pack(side="right", fill="y")
|
|
609
|
+
self._listbox.pack(side="left", fill="both", expand=True)
|
|
610
|
+
self._listbox.bind("<<ListboxSelect>>", self._on_select)
|
|
611
|
+
|
|
612
|
+
sep = tk.Frame(self, bg=t.border, height=1)
|
|
613
|
+
sep.pack(fill="x", padx=14, pady=4)
|
|
614
|
+
|
|
615
|
+
edit_frame = tk.Frame(self, bg=t.floating_bg)
|
|
616
|
+
edit_frame.pack(fill="x", padx=14, pady=(0, 4))
|
|
617
|
+
|
|
618
|
+
tk.Label(
|
|
619
|
+
edit_frame,
|
|
620
|
+
text=_t("keyremap.new_shortcut"),
|
|
621
|
+
bg=t.floating_bg,
|
|
622
|
+
fg=t.fg_muted,
|
|
623
|
+
font=(FONT_UI, 9),
|
|
624
|
+
).pack(side="left")
|
|
625
|
+
|
|
626
|
+
self._key_var = tk.StringVar()
|
|
627
|
+
self._key_entry = tk.Entry(
|
|
628
|
+
edit_frame,
|
|
629
|
+
textvariable=self._key_var,
|
|
630
|
+
bg=t.input_bg,
|
|
631
|
+
fg=t.fg,
|
|
632
|
+
insertbackground=t.cursor,
|
|
633
|
+
relief="flat",
|
|
634
|
+
bd=0,
|
|
635
|
+
font=(FONT_MONO, 10),
|
|
636
|
+
width=22,
|
|
637
|
+
highlightthickness=1,
|
|
638
|
+
highlightbackground=t.border,
|
|
639
|
+
)
|
|
640
|
+
self._key_entry.pack(side="left", padx=6)
|
|
641
|
+
|
|
642
|
+
self._capture_btn = tk.Label(
|
|
643
|
+
edit_frame,
|
|
644
|
+
text=_t("keyremap.capture_btn"),
|
|
645
|
+
bg=t.btn_bg,
|
|
646
|
+
fg=t.fg,
|
|
647
|
+
font=(FONT_UI, 9),
|
|
648
|
+
cursor="hand2",
|
|
649
|
+
padx=8,
|
|
650
|
+
pady=3,
|
|
651
|
+
relief="flat",
|
|
652
|
+
)
|
|
653
|
+
self._capture_btn.pack(side="left", padx=4)
|
|
654
|
+
self._capture_btn.bind("<Button-1>", lambda _: self._start_capture())
|
|
655
|
+
|
|
656
|
+
self._status_lbl = tk.Label(
|
|
657
|
+
edit_frame,
|
|
658
|
+
text="",
|
|
659
|
+
bg=t.floating_bg,
|
|
660
|
+
fg=t.t_string,
|
|
661
|
+
font=(FONT_UI, 8),
|
|
662
|
+
)
|
|
663
|
+
self._status_lbl.pack(side="left", padx=6)
|
|
664
|
+
|
|
665
|
+
foot = tk.Frame(self, bg=t.floating_bg)
|
|
666
|
+
foot.pack(fill="x", padx=14, pady=(4, 12))
|
|
667
|
+
|
|
668
|
+
tk.Label(
|
|
669
|
+
foot,
|
|
670
|
+
text=_t("keyremap.hint"),
|
|
671
|
+
bg=t.floating_bg,
|
|
672
|
+
fg=t.fg_muted,
|
|
673
|
+
font=(FONT_UI, 8),
|
|
674
|
+
).pack(side="left")
|
|
675
|
+
|
|
676
|
+
for text, cmd, primary in (
|
|
677
|
+
(_t("keyremap.apply"), self._apply_selected, True),
|
|
678
|
+
(_t("keyremap.reset"), self._reset_selected, False),
|
|
679
|
+
(_t("keyremap.close"), self.destroy, False),
|
|
680
|
+
):
|
|
681
|
+
btn = tk.Label(
|
|
682
|
+
foot,
|
|
683
|
+
text=text,
|
|
684
|
+
bg=t.btn_primary if primary else t.btn_bg,
|
|
685
|
+
fg=t.btn_primary_fg if primary else t.fg,
|
|
686
|
+
font=(FONT_UI, 9, "bold" if primary else "normal"),
|
|
687
|
+
cursor="hand2",
|
|
688
|
+
padx=10,
|
|
689
|
+
pady=4,
|
|
690
|
+
relief="flat",
|
|
691
|
+
)
|
|
692
|
+
btn.pack(side="right", padx=3)
|
|
693
|
+
btn.bind("<Button-1>", lambda _, c=cmd: c())
|
|
694
|
+
|
|
695
|
+
def _populate(self) -> None:
|
|
696
|
+
t = self._tmgr.theme
|
|
697
|
+
q = self._search_var.get().lower()
|
|
698
|
+
self._listbox.delete(0, "end")
|
|
699
|
+
self._row_ids: list[str] = []
|
|
700
|
+
|
|
701
|
+
for b in self._store.bindings:
|
|
702
|
+
if q and q not in b["label"].lower() and q not in b["id"].lower():
|
|
703
|
+
continue
|
|
704
|
+
default_human = _tk_key_to_human(b["default"])
|
|
705
|
+
current_human = _tk_key_to_human(
|
|
706
|
+
b["current"]) if b["current"] else ""
|
|
707
|
+
custom_marker = "✎ " if b["current"] else " "
|
|
708
|
+
active = current_human or default_human or "-"
|
|
709
|
+
line = f" {b['label']:<32} {default_human:<18} {custom_marker}{active}"
|
|
710
|
+
self._listbox.insert("end", line)
|
|
711
|
+
self._row_ids.append(b["id"])
|
|
712
|
+
|
|
713
|
+
if b["current"]:
|
|
714
|
+
idx = len(self._row_ids) - 1
|
|
715
|
+
self._listbox.itemconfig(idx, fg=t.t_string)
|
|
716
|
+
|
|
717
|
+
def _on_select(self, _e: Any = None) -> None:
|
|
718
|
+
sel = self._listbox.curselection()
|
|
719
|
+
if not sel:
|
|
720
|
+
return
|
|
721
|
+
idx = sel[0]
|
|
722
|
+
if idx >= len(self._row_ids):
|
|
723
|
+
return
|
|
724
|
+
self._selected_id = self._row_ids[idx]
|
|
725
|
+
for b in self._store.bindings:
|
|
726
|
+
if b["id"] == self._selected_id:
|
|
727
|
+
current = _tk_key_to_human(
|
|
728
|
+
b["current"]) if b["current"] else ""
|
|
729
|
+
self._key_var.set(current)
|
|
730
|
+
self._status_lbl.config(
|
|
731
|
+
text=_t("keyremap.id_hint", id=b["id"]))
|
|
732
|
+
break
|
|
733
|
+
|
|
734
|
+
def _start_capture(self) -> None:
|
|
735
|
+
if not self._selected_id:
|
|
736
|
+
self._status_lbl.config(text=_t("keyremap.no_command"))
|
|
737
|
+
return
|
|
738
|
+
|
|
739
|
+
t = self._tmgr.theme
|
|
740
|
+
self._capturing = True
|
|
741
|
+
self._capture_btn.config(
|
|
742
|
+
text=_t("keyremap.capturing"),
|
|
743
|
+
bg="#c62828",
|
|
744
|
+
fg="white",
|
|
745
|
+
)
|
|
746
|
+
self._status_lbl.config(text="")
|
|
747
|
+
|
|
748
|
+
capture_win = tk.Toplevel(self)
|
|
749
|
+
capture_win.title(_t("keyremap.capture_win"))
|
|
750
|
+
capture_win.configure(bg=t.floating_bg)
|
|
751
|
+
capture_win.geometry("320x120")
|
|
752
|
+
capture_win.transient(self)
|
|
753
|
+
safe_grab_set(capture_win)
|
|
754
|
+
capture_win.resizable(False, False)
|
|
755
|
+
|
|
756
|
+
tk.Label(
|
|
757
|
+
capture_win,
|
|
758
|
+
text=_t("keyremap.capture_hint"),
|
|
759
|
+
bg=t.floating_bg,
|
|
760
|
+
fg=t.fg,
|
|
761
|
+
font=(FONT_UI, 11),
|
|
762
|
+
justify="center",
|
|
763
|
+
).pack(expand=True)
|
|
764
|
+
|
|
765
|
+
def _on_key(event: tk.Event) -> str:
|
|
766
|
+
if event.keysym == "Escape":
|
|
767
|
+
capture_win.destroy()
|
|
768
|
+
self._stop_capture()
|
|
769
|
+
return "break"
|
|
770
|
+
|
|
771
|
+
parts = []
|
|
772
|
+
if event.state & 0x4:
|
|
773
|
+
parts.append("Control")
|
|
774
|
+
if event.state & 0x1:
|
|
775
|
+
parts.append("Shift")
|
|
776
|
+
if event.state & 0x8:
|
|
777
|
+
parts.append("Alt")
|
|
778
|
+
|
|
779
|
+
sym = event.keysym
|
|
780
|
+
if sym in (
|
|
781
|
+
"Control_L",
|
|
782
|
+
"Control_R",
|
|
783
|
+
"Shift_L",
|
|
784
|
+
"Shift_R",
|
|
785
|
+
"Alt_L",
|
|
786
|
+
"Alt_R",
|
|
787
|
+
"Meta_L",
|
|
788
|
+
"Meta_R",
|
|
789
|
+
):
|
|
790
|
+
return "break"
|
|
791
|
+
|
|
792
|
+
parts.append(sym)
|
|
793
|
+
tk_key = "<" + "-".join(parts) + ">"
|
|
794
|
+
human = _tk_key_to_human(tk_key)
|
|
795
|
+
self._key_var.set(human)
|
|
796
|
+
capture_win.destroy()
|
|
797
|
+
self._stop_capture()
|
|
798
|
+
return "break"
|
|
799
|
+
|
|
800
|
+
capture_win.bind("<KeyPress>", _on_key)
|
|
801
|
+
capture_win.focus_force()
|
|
802
|
+
|
|
803
|
+
def _stop_capture(self) -> None:
|
|
804
|
+
t = self._tmgr.theme
|
|
805
|
+
self._capturing = False
|
|
806
|
+
self._capture_btn.config(
|
|
807
|
+
text=_t("keyremap.capture_btn"), bg=t.btn_bg, fg=t.fg)
|
|
808
|
+
|
|
809
|
+
def _apply_selected(self) -> None:
|
|
810
|
+
if not self._selected_id:
|
|
811
|
+
return
|
|
812
|
+
human = self._key_var.get().strip()
|
|
813
|
+
tk_key = _human_to_tk_key(human) if human else ""
|
|
814
|
+
|
|
815
|
+
self._store.set(self._selected_id, tk_key)
|
|
816
|
+
self._store.save()
|
|
817
|
+
self._on_apply()
|
|
818
|
+
self._status_lbl.config(text=_t("keyremap.applied"))
|
|
819
|
+
self._populate()
|
|
820
|
+
|
|
821
|
+
def _reset_selected(self) -> None:
|
|
822
|
+
if not self._selected_id:
|
|
823
|
+
return
|
|
824
|
+
self._store.reset(self._selected_id)
|
|
825
|
+
self._key_var.set("")
|
|
826
|
+
self._store.save()
|
|
827
|
+
self._on_apply()
|
|
828
|
+
self._status_lbl.config(text=_t("keyremap.reset_done"))
|
|
829
|
+
self._populate()
|
|
830
|
+
|
|
831
|
+
def _reset_all(self) -> None:
|
|
832
|
+
if not messagebox.askyesno(
|
|
833
|
+
_t("keyremap.reset_all_title"),
|
|
834
|
+
_t("keyremap.reset_all_confirm"),
|
|
835
|
+
parent=self,
|
|
836
|
+
):
|
|
837
|
+
return
|
|
838
|
+
self._store.reset_all()
|
|
839
|
+
self._key_var.set("")
|
|
840
|
+
self._store.save()
|
|
841
|
+
self._on_apply()
|
|
842
|
+
self._status_lbl.config(text=_t("keyremap.reset_all_done"))
|
|
843
|
+
self._populate()
|
|
844
|
+
|
|
845
|
+
def _center(self, parent: tk.Widget) -> None:
|
|
846
|
+
self.update_idletasks()
|
|
847
|
+
try:
|
|
848
|
+
px = parent.winfo_rootx()
|
|
849
|
+
py = parent.winfo_rooty()
|
|
850
|
+
pw = parent.winfo_width()
|
|
851
|
+
ph = parent.winfo_height()
|
|
852
|
+
except tk.TclError:
|
|
853
|
+
return
|
|
854
|
+
w = self.winfo_width()
|
|
855
|
+
h = self.winfo_height()
|
|
856
|
+
self.geometry(f"+{px + (pw - w) // 2}+{py + (ph - h) // 2}")
|