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/k_ui/__init__.py
ADDED
|
@@ -0,0 +1,1305 @@
|
|
|
1
|
+
"""
|
|
2
|
+
K-UI - Pacote de engine cósmica Codis
|
|
3
|
+
=====================================
|
|
4
|
+
Estrutura do pacote:
|
|
5
|
+
_colors.py - paletas e utilitários de cor/widget
|
|
6
|
+
_perf.py - perfis de performance (quantum/ultra/balanced/...)
|
|
7
|
+
_easter.py - KUEasterEggs: detecção inteligente de sequências
|
|
8
|
+
_tooltip.py - KHoverTooltip: painel de aprendizado contextual
|
|
9
|
+
_bgrenderer.py - BgRenderer: nebulosa/aurora em thread PIL
|
|
10
|
+
_engine.py - KEngine + KWelcome
|
|
11
|
+
_dock.py - KDock: dono único da sidebar (docked/flutuante)
|
|
12
|
+
_tkutil.py - bind/unbind seguros
|
|
13
|
+
_widgets.py - KGlassPane, KTopBar, KTabBar, KStatusBar,
|
|
14
|
+
KPortal, KFloatWindow, KToast
|
|
15
|
+
__init__.py - KUI: controlador principal + re-exports públicos
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import contextlib
|
|
21
|
+
import logging
|
|
22
|
+
import math
|
|
23
|
+
import random
|
|
24
|
+
import time
|
|
25
|
+
import tkinter as tk
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
|
|
28
|
+
from src.theme.base import Theme
|
|
29
|
+
|
|
30
|
+
from ._bgrenderer import _PIL, BgRenderer
|
|
31
|
+
from ._colors import _hex2rgb, _hue, _lc_q, _lerp, _pal, _safe_del, _wlift, _wlower
|
|
32
|
+
from ._dock import KDock
|
|
33
|
+
from ._easter import KUEasterEggs
|
|
34
|
+
from ._engine import KEngine, KWelcome
|
|
35
|
+
from ._perf import _DEFAULT_PERF, _PERF
|
|
36
|
+
from ._tkutil import unbind_one
|
|
37
|
+
from ._tooltip import KHoverTooltip
|
|
38
|
+
from ._widgets import (
|
|
39
|
+
KFloatWindow,
|
|
40
|
+
KGlassPane,
|
|
41
|
+
KPortal,
|
|
42
|
+
KStatusBar,
|
|
43
|
+
KTabBar,
|
|
44
|
+
KToast,
|
|
45
|
+
KTopBar,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
from src.i18n import _t as _i18n_t
|
|
50
|
+
except ImportError:
|
|
51
|
+
|
|
52
|
+
def _i18n_t(key: str, **_kw) -> str:
|
|
53
|
+
|
|
54
|
+
return key.split(".")[-1]
|
|
55
|
+
|
|
56
|
+
logger = logging.getLogger("Codis.KUI")
|
|
57
|
+
_TAU = math.tau
|
|
58
|
+
|
|
59
|
+
__all__ = [
|
|
60
|
+
"KUI",
|
|
61
|
+
"build_kui_theme",
|
|
62
|
+
"KDock",
|
|
63
|
+
"KEngine",
|
|
64
|
+
"KWelcome",
|
|
65
|
+
"KGlassPane",
|
|
66
|
+
"KTopBar",
|
|
67
|
+
"KTabBar",
|
|
68
|
+
"KStatusBar",
|
|
69
|
+
"KPortal",
|
|
70
|
+
"KFloatWindow",
|
|
71
|
+
"KToast",
|
|
72
|
+
"KHoverTooltip",
|
|
73
|
+
"BgRenderer",
|
|
74
|
+
"KUEasterEggs",
|
|
75
|
+
"_pal",
|
|
76
|
+
"_lc_q",
|
|
77
|
+
"_lerp",
|
|
78
|
+
"_hue",
|
|
79
|
+
"_safe_del",
|
|
80
|
+
"_wlift",
|
|
81
|
+
"_wlower",
|
|
82
|
+
"_hex2rgb",
|
|
83
|
+
"_PIL",
|
|
84
|
+
"_PERF",
|
|
85
|
+
"_DEFAULT_PERF",
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class KUI:
|
|
90
|
+
"""Controlador principal do K-UI.
|
|
91
|
+
|
|
92
|
+
- KGlassPane: editor flutua sobre cosmos com borda luminosa
|
|
93
|
+
- BgRenderer: nebulosa/aurora em thread PIL
|
|
94
|
+
- apply_theme() reconstrói todos os elementos visuais
|
|
95
|
+
- _show_welcome interceptado para usar KWelcome cosmica
|
|
96
|
+
- FPS real reportado na statusbar
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
def __init__(
|
|
100
|
+
self,
|
|
101
|
+
root,
|
|
102
|
+
tmgr,
|
|
103
|
+
get_editor,
|
|
104
|
+
commands,
|
|
105
|
+
_ribbon_actions,
|
|
106
|
+
hide_sidebar_cb=None,
|
|
107
|
+
show_sidebar_cb=None,
|
|
108
|
+
_hide_activity_cb=None,
|
|
109
|
+
_show_activity_cb=None,
|
|
110
|
+
hide_bottom_cb=None,
|
|
111
|
+
show_bottom_cb=None,
|
|
112
|
+
tabbar_widget=None,
|
|
113
|
+
breadcrumb_widget=None,
|
|
114
|
+
statusbar_widget=None,
|
|
115
|
+
menubar_ref=None,
|
|
116
|
+
content_frame=None,
|
|
117
|
+
editor_container=None,
|
|
118
|
+
h_paned=None,
|
|
119
|
+
v_paned=None,
|
|
120
|
+
sidebar_dock=None,
|
|
121
|
+
is_sidebar_visible=None,
|
|
122
|
+
show_welcome_cb=None,
|
|
123
|
+
hide_classic_welcome_cb=None,
|
|
124
|
+
actbar_widget=None,
|
|
125
|
+
panel_factories=None,
|
|
126
|
+
perf_profile=_DEFAULT_PERF,
|
|
127
|
+
detach_manager=None,
|
|
128
|
+
):
|
|
129
|
+
"""
|
|
130
|
+
Args:
|
|
131
|
+
root: Janela raiz Tkinter.
|
|
132
|
+
config: Instância de ConfigManager.
|
|
133
|
+
editor_getter: Callable que retorna o EditorPane ativo.
|
|
134
|
+
dark: True para modo escuro.
|
|
135
|
+
detach_manager: ``PanelDetachManager`` compartilhado com o
|
|
136
|
+
``CodisApp``. Quando fornecido, ``detach_panel``/
|
|
137
|
+
``reattach_panel`` delegam a ele em vez de manter estado
|
|
138
|
+
próprio - isso permite que painéis destacados sobrevivam
|
|
139
|
+
a alternâncias do modo K-UI ligado/desligado, e que o
|
|
140
|
+
modo clássico também consiga destacar painéis. Se omitido,
|
|
141
|
+
o estado fica em ``_detached``.
|
|
142
|
+
"""
|
|
143
|
+
self._root = root
|
|
144
|
+
self._tmgr = tmgr
|
|
145
|
+
self._get_ed = get_editor
|
|
146
|
+
self._commands = commands
|
|
147
|
+
self._hide_sb = hide_sidebar_cb
|
|
148
|
+
self._show_sb = show_sidebar_cb
|
|
149
|
+
self._tabbar = tabbar_widget
|
|
150
|
+
self._breadcrumb = breadcrumb_widget
|
|
151
|
+
self._menubar = menubar_ref
|
|
152
|
+
self._cf = content_frame
|
|
153
|
+
self._ec = editor_container
|
|
154
|
+
self._hpaned = h_paned
|
|
155
|
+
self._vpaned = v_paned
|
|
156
|
+
self._dock = sidebar_dock
|
|
157
|
+
self._is_sb_visible = is_sidebar_visible or (lambda: False)
|
|
158
|
+
self._show_welcome_cb = show_welcome_cb
|
|
159
|
+
self._hide_classic_welcome_cb = hide_classic_welcome_cb
|
|
160
|
+
self._actbar = actbar_widget
|
|
161
|
+
self._factories = panel_factories or {}
|
|
162
|
+
self._profile = perf_profile
|
|
163
|
+
self._enabled = False
|
|
164
|
+
self._dark = True
|
|
165
|
+
self._has_ws = False
|
|
166
|
+
self._engine = None
|
|
167
|
+
self._topbar = None
|
|
168
|
+
self._tabbar_w = None
|
|
169
|
+
self._stbar = None
|
|
170
|
+
self._portal = None
|
|
171
|
+
self._welcome = None
|
|
172
|
+
self._detached = {}
|
|
173
|
+
self._detach_manager = detach_manager
|
|
174
|
+
self._glass_pane: KGlassPane | None = None
|
|
175
|
+
|
|
176
|
+
self._easter: KUEasterEggs | None = None
|
|
177
|
+
self._diag_errors = 0
|
|
178
|
+
self._diag_warnings = 0
|
|
179
|
+
self._open_files = []
|
|
180
|
+
self._kpm_window = []
|
|
181
|
+
self._char_window = []
|
|
182
|
+
self._metric_job = None
|
|
183
|
+
self._last_tab_action = None
|
|
184
|
+
self._fps_report_job = None
|
|
185
|
+
|
|
186
|
+
self._minimize_btn: tk.Label | None = None
|
|
187
|
+
|
|
188
|
+
self._root_bind_ids: dict[str, list[str]] = {}
|
|
189
|
+
self._planet_active: bool = False
|
|
190
|
+
self._activity_job: str | None = None
|
|
191
|
+
|
|
192
|
+
def _paint_frames_void(self) -> None:
|
|
193
|
+
"""Pinta os frames de layout com a cor void para integração visual.
|
|
194
|
+
|
|
195
|
+
Exclui recursivamente a activity sep_bar e o tree_parent (sidebar_stack)
|
|
196
|
+
para não sobrescrever as cores de tema de PainelIA e demais painéis.
|
|
197
|
+
"""
|
|
198
|
+
p = _pal(self._dark)
|
|
199
|
+
void = p["void"]
|
|
200
|
+
_SKIP = (
|
|
201
|
+
tk.Text,
|
|
202
|
+
tk.Listbox,
|
|
203
|
+
tk.Entry,
|
|
204
|
+
tk.Scrollbar,
|
|
205
|
+
tk.Button,
|
|
206
|
+
tk.PanedWindow,
|
|
207
|
+
tk.Canvas,
|
|
208
|
+
)
|
|
209
|
+
_skip: set[str] = set()
|
|
210
|
+
|
|
211
|
+
def _collect(w: tk.Misc) -> None:
|
|
212
|
+
_skip.add(str(w))
|
|
213
|
+
for ch in w.winfo_children():
|
|
214
|
+
_collect(ch)
|
|
215
|
+
|
|
216
|
+
if self._actbar and self._actbar.winfo_exists():
|
|
217
|
+
_collect(self._actbar)
|
|
218
|
+
|
|
219
|
+
if self._dock is not None and self._dock.widget.winfo_exists():
|
|
220
|
+
_collect(self._dock.widget)
|
|
221
|
+
|
|
222
|
+
def _paint(w: tk.Misc, depth: int = 0) -> None:
|
|
223
|
+
if depth > 16 or str(w) in _skip:
|
|
224
|
+
return
|
|
225
|
+
with contextlib.suppress(tk.TclError):
|
|
226
|
+
if not isinstance(w, _SKIP):
|
|
227
|
+
w.configure(bg=void)
|
|
228
|
+
for ch in w.winfo_children():
|
|
229
|
+
_paint(ch, depth + 1)
|
|
230
|
+
|
|
231
|
+
_paint(self._root)
|
|
232
|
+
for pw in (self._hpaned, self._vpaned):
|
|
233
|
+
if pw:
|
|
234
|
+
with contextlib.suppress(tk.TclError):
|
|
235
|
+
pw.config(bg=void, sashwidth=4,
|
|
236
|
+
sashrelief="flat", sashpad=0)
|
|
237
|
+
chain: list[tk.Misc | None] = [self._cf, self._ec]
|
|
238
|
+
if self._ec:
|
|
239
|
+
with contextlib.suppress(tk.TclError):
|
|
240
|
+
ea = self._ec.nametowidget(self._ec.winfo_parent())
|
|
241
|
+
if ea and not isinstance(ea, (tk.PanedWindow, tk.Tk)):
|
|
242
|
+
chain.append(ea)
|
|
243
|
+
for w in chain:
|
|
244
|
+
if w:
|
|
245
|
+
with contextlib.suppress(tk.TclError):
|
|
246
|
+
w.configure(bg=void)
|
|
247
|
+
for ch in w.winfo_children():
|
|
248
|
+
with contextlib.suppress(tk.TclError):
|
|
249
|
+
if not isinstance(
|
|
250
|
+
ch, (tk.Text, tk.Canvas, tk.Listbox,
|
|
251
|
+
tk.Entry, tk.Scrollbar)
|
|
252
|
+
):
|
|
253
|
+
ch.configure(bg=void)
|
|
254
|
+
|
|
255
|
+
def _make_engine(self):
|
|
256
|
+
"""Instancia e configura o KEngine com o perfil atual."""
|
|
257
|
+
engine_parent = self._cf or self._ec or self._root
|
|
258
|
+
self._engine = KEngine(engine_parent, self._dark, self._profile)
|
|
259
|
+
self._engine.place(x=0, y=0, relwidth=1.0, relheight=1.0)
|
|
260
|
+
_wlower(self._engine)
|
|
261
|
+
|
|
262
|
+
self._engine.set_planet_click_cb(self._on_solar_planet_click)
|
|
263
|
+
|
|
264
|
+
def _setup_glass_pane(self) -> None:
|
|
265
|
+
"""Conecta o KGlassPane ao editor_container.
|
|
266
|
+
|
|
267
|
+
Nenhum Frame com place() é criado no _cf; o glass pane é aplicado
|
|
268
|
+
diretamente no _ec:
|
|
269
|
+
- highlightbackground animado (borda luminosa 2px)
|
|
270
|
+
- faixa espectral 2px dentro do _ec via place()
|
|
271
|
+
Isso não interfere com o layout do cosmos nem do editor.
|
|
272
|
+
TÁTICA #6: margens dinâmicas obtidas das alturas reais das barras.
|
|
273
|
+
"""
|
|
274
|
+
if not self._ec:
|
|
275
|
+
return
|
|
276
|
+
|
|
277
|
+
if self._glass_pane:
|
|
278
|
+
self._glass_pane.destroy()
|
|
279
|
+
self._glass_pane = None
|
|
280
|
+
self._glass_pane = KGlassPane(self._dark)
|
|
281
|
+
|
|
282
|
+
def _attach():
|
|
283
|
+
if self._glass_pane and self._ec and self._ec.winfo_exists():
|
|
284
|
+
self._glass_pane.attach(self._ec)
|
|
285
|
+
|
|
286
|
+
self._root.after(100, _attach)
|
|
287
|
+
|
|
288
|
+
def chrome_top(self) -> int:
|
|
289
|
+
"""Y logo abaixo da topbar e (se visível) da tabbar K-UI."""
|
|
290
|
+
top = 22
|
|
291
|
+
tb = self._tabbar_w
|
|
292
|
+
if tb is not None:
|
|
293
|
+
with contextlib.suppress(tk.TclError):
|
|
294
|
+
if tb.winfo_exists() and tb.winfo_ismapped():
|
|
295
|
+
top += 36
|
|
296
|
+
return top
|
|
297
|
+
|
|
298
|
+
def raise_chrome(self) -> None:
|
|
299
|
+
"""Re-eleva as barras K-UI acima da sidebar flutuante (z-order único)."""
|
|
300
|
+
for w in (self._topbar, self._tabbar_w, self._stbar,
|
|
301
|
+
self._minimize_btn, self._portal):
|
|
302
|
+
if w is not None:
|
|
303
|
+
with contextlib.suppress(tk.TclError):
|
|
304
|
+
_wlift(w)
|
|
305
|
+
|
|
306
|
+
def update_engine_activity(self) -> None:
|
|
307
|
+
"""Suspende o engine quando o editor ou a welcome o cobrem totalmente."""
|
|
308
|
+
eng = self._engine
|
|
309
|
+
if eng is None:
|
|
310
|
+
return
|
|
311
|
+
covered = False
|
|
312
|
+
if not self._planet_active:
|
|
313
|
+
w = self._welcome
|
|
314
|
+
with contextlib.suppress(tk.TclError):
|
|
315
|
+
if w is not None and w.winfo_exists() and w.winfo_ismapped():
|
|
316
|
+
covered = True
|
|
317
|
+
if not covered:
|
|
318
|
+
ed = self._get_ed()
|
|
319
|
+
with contextlib.suppress(tk.TclError, AttributeError):
|
|
320
|
+
covered = bool(ed is not None and ed.winfo_ismapped())
|
|
321
|
+
with contextlib.suppress(tk.TclError):
|
|
322
|
+
eng.set_suspended(covered)
|
|
323
|
+
|
|
324
|
+
def _deferred_engine_activity(self) -> None:
|
|
325
|
+
self._activity_job = None
|
|
326
|
+
if self._enabled:
|
|
327
|
+
self.update_engine_activity()
|
|
328
|
+
|
|
329
|
+
def sync_layers(self) -> None:
|
|
330
|
+
"""Garante a ordem de camadas: conteúdo < sidebar flutuante < barras.
|
|
331
|
+
|
|
332
|
+
Chamado após cada troca de modo (cosmos/editor/welcome), pois elevar o
|
|
333
|
+
engine ou a welcome não pode nunca encobrir o painel lateral.
|
|
334
|
+
"""
|
|
335
|
+
if self._dock is not None:
|
|
336
|
+
self._dock.raise_panel()
|
|
337
|
+
self.raise_chrome()
|
|
338
|
+
if self._hide_classic_welcome_cb is not None:
|
|
339
|
+
self._hide_classic_welcome_cb()
|
|
340
|
+
self.update_engine_activity()
|
|
341
|
+
if self._activity_job is not None:
|
|
342
|
+
with contextlib.suppress(tk.TclError):
|
|
343
|
+
self._root.after_cancel(self._activity_job)
|
|
344
|
+
with contextlib.suppress(tk.TclError):
|
|
345
|
+
self._activity_job = self._root.after(
|
|
346
|
+
120, self._deferred_engine_activity)
|
|
347
|
+
|
|
348
|
+
def ensure_editor_visible(self) -> None:
|
|
349
|
+
"""Sai do modo cosmos se necessário (ex.: arquivo aberto pela sidebar)."""
|
|
350
|
+
if self._enabled and self._planet_active:
|
|
351
|
+
self.restore_from_planet()
|
|
352
|
+
|
|
353
|
+
def _dock_relayout(self) -> None:
|
|
354
|
+
if self._dock is not None:
|
|
355
|
+
self._dock.relayout()
|
|
356
|
+
|
|
357
|
+
def _place_bars(self) -> None:
|
|
358
|
+
"""Posiciona topbar, statusbar e tabbar após a sidebar/activity sep_bar."""
|
|
359
|
+
try:
|
|
360
|
+
if self._cf and self._cf.winfo_exists():
|
|
361
|
+
x_off = self._cf.winfo_rootx() - self._root.winfo_rootx()
|
|
362
|
+
x_off = max(0, x_off)
|
|
363
|
+
bar_w = self._root.winfo_width() - x_off
|
|
364
|
+
else:
|
|
365
|
+
x_off = 0
|
|
366
|
+
bar_w = self._root.winfo_width() or 1200
|
|
367
|
+
bar_w = max(200, bar_w)
|
|
368
|
+
except tk.TclError:
|
|
369
|
+
x_off = 0
|
|
370
|
+
bar_w = self._root.winfo_width() or 1200
|
|
371
|
+
if self._topbar and self._topbar.winfo_exists():
|
|
372
|
+
self._topbar.place(x=x_off, y=0, width=bar_w, height=22)
|
|
373
|
+
_wlift(self._topbar)
|
|
374
|
+
if self._stbar and self._stbar.winfo_exists():
|
|
375
|
+
self._stbar.place(x=x_off, rely=1.0, anchor="sw",
|
|
376
|
+
width=bar_w, height=24)
|
|
377
|
+
_wlift(self._stbar)
|
|
378
|
+
|
|
379
|
+
def enable(self):
|
|
380
|
+
"""Ativa o componente."""
|
|
381
|
+
if self._enabled:
|
|
382
|
+
return
|
|
383
|
+
self._enabled = True
|
|
384
|
+
t = self._tmgr.theme if self._tmgr else None
|
|
385
|
+
self._dark = getattr(t, "dark", True)
|
|
386
|
+
p = _pal(self._dark)
|
|
387
|
+
for w in (self._tabbar, self._breadcrumb):
|
|
388
|
+
if w:
|
|
389
|
+
with contextlib.suppress(tk.TclError):
|
|
390
|
+
w.pack_forget()
|
|
391
|
+
if self._menubar is not None:
|
|
392
|
+
with contextlib.suppress(tk.TclError):
|
|
393
|
+
self._menubar.pack_forget()
|
|
394
|
+
self._paint_frames_void()
|
|
395
|
+
self._make_engine()
|
|
396
|
+
|
|
397
|
+
if self._engine:
|
|
398
|
+
self._engine.bind("<Button-1>", self._on_engine_click, add=True)
|
|
399
|
+
|
|
400
|
+
self._build_minimize_btn(p)
|
|
401
|
+
|
|
402
|
+
if not _PIL:
|
|
403
|
+
self._root.after(
|
|
404
|
+
1500,
|
|
405
|
+
lambda: self.toast(
|
|
406
|
+
_i18n_t("kui.pillow_warn"), kind="warn", duration_ms=6000
|
|
407
|
+
),
|
|
408
|
+
)
|
|
409
|
+
self._setup_glass_pane()
|
|
410
|
+
|
|
411
|
+
self._topbar = KTopBar(
|
|
412
|
+
self._root, self._open_portal, self._get_ed, self._dark, self._profile
|
|
413
|
+
)
|
|
414
|
+
self._tabbar_w = KTabBar(
|
|
415
|
+
self._root, self._on_tab_select, self._on_tab_close, self._dark
|
|
416
|
+
)
|
|
417
|
+
self._tabbar_w.set_callbacks(
|
|
418
|
+
minimize_planet=self._minimize_tab_to_planet,
|
|
419
|
+
dual_mode=self._open_tab_dual_mode,
|
|
420
|
+
)
|
|
421
|
+
self._stbar = KStatusBar(self._root, self._get_ed, self._dark)
|
|
422
|
+
self._place_bars()
|
|
423
|
+
_wlift(self._topbar)
|
|
424
|
+
_wlift(self._stbar)
|
|
425
|
+
self._refresh_tabs()
|
|
426
|
+
if self._dock is not None:
|
|
427
|
+
self._dock.set_dark(self._dark)
|
|
428
|
+
if self._minimize_btn:
|
|
429
|
+
self._dock.add_exempt(self._minimize_btn)
|
|
430
|
+
self._dock.enter_float(visible=bool(self._is_sb_visible()))
|
|
431
|
+
|
|
432
|
+
self._easter = KUEasterEggs(
|
|
433
|
+
root=self._root,
|
|
434
|
+
get_engine=lambda: self._engine,
|
|
435
|
+
toast=lambda msg, kind, ms: self.toast(
|
|
436
|
+
msg, kind=kind, duration_ms=ms),
|
|
437
|
+
get_planet_active=lambda: self._planet_active,
|
|
438
|
+
spawn_supernova=self._engine_spawn_supernova,
|
|
439
|
+
spawn_meteor_shower=self._engine_spawn_meteor_shower,
|
|
440
|
+
spawn_star_birth=self._engine_spawn_star_birth,
|
|
441
|
+
spawn_nova_burst=self._engine_spawn_nova_burst,
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
_bi: dict[str, list[str]] = {}
|
|
445
|
+
|
|
446
|
+
def _b(ev: str, fn) -> None:
|
|
447
|
+
fid = self._root.bind(ev, fn, add=True)
|
|
448
|
+
_bi.setdefault(ev, []).append(fid)
|
|
449
|
+
|
|
450
|
+
_b("<Control-space>", lambda _: self._open_portal())
|
|
451
|
+
_b("<Control-grave>", lambda _: self._open_portal())
|
|
452
|
+
_b("<Control-e>", lambda _: self._toggle_side())
|
|
453
|
+
_b("<Control-E>", lambda _: self._toggle_side())
|
|
454
|
+
_b("<Key>", self._easter.on_key)
|
|
455
|
+
_b("<Key>", self._track_keystroke)
|
|
456
|
+
_b("<Button-1>", self._on_click_activity)
|
|
457
|
+
_b("<Configure>", lambda _: (self._place_bars(), self._refresh_tabs(),
|
|
458
|
+
self._dock_relayout()))
|
|
459
|
+
self._root_bind_ids = _bi
|
|
460
|
+
self._poll_metrics()
|
|
461
|
+
self._start_fps_report()
|
|
462
|
+
ed = self._get_ed()
|
|
463
|
+
if ed:
|
|
464
|
+
with contextlib.suppress(tk.TclError):
|
|
465
|
+
ed.text.config(
|
|
466
|
+
bg=p["text_bg"],
|
|
467
|
+
fg=p["text_fg"],
|
|
468
|
+
insertbackground=p["text_cur"],
|
|
469
|
+
selectbackground=p["text_sel"],
|
|
470
|
+
)
|
|
471
|
+
|
|
472
|
+
def _build_minimize_btn(self, p: dict) -> None:
|
|
473
|
+
"""Cria (ou recria) o botão ⊙ Cosmos sobre a barra de abas.
|
|
474
|
+
|
|
475
|
+
Parent é sempre self._root para sobreviver mudanças de layout.
|
|
476
|
+
Usa i18n para o texto. Reconstrói automaticamente se sumir.
|
|
477
|
+
"""
|
|
478
|
+
_safe_del(self._minimize_btn)
|
|
479
|
+
self._minimize_btn = None
|
|
480
|
+
label = "⊙ " + _i18n_t("kui.cosmos_mode")
|
|
481
|
+
btn = tk.Label(
|
|
482
|
+
self._root,
|
|
483
|
+
text=label,
|
|
484
|
+
bg=p["void"],
|
|
485
|
+
fg=p["accent"],
|
|
486
|
+
font=("Segoe UI", 8, "bold"),
|
|
487
|
+
cursor="hand2",
|
|
488
|
+
padx=8,
|
|
489
|
+
pady=3,
|
|
490
|
+
relief="flat",
|
|
491
|
+
)
|
|
492
|
+
|
|
493
|
+
btn.place(relx=1.0, y=26, anchor="ne", x=-6)
|
|
494
|
+
btn.bind("<Button-1>", lambda _: self.minimize_to_planet())
|
|
495
|
+
btn.bind(
|
|
496
|
+
"<Enter>",
|
|
497
|
+
lambda _: btn.config(
|
|
498
|
+
fg=p["accent2"], bg=_lc_q(p["void"], p["accent"], 0.15)
|
|
499
|
+
),
|
|
500
|
+
)
|
|
501
|
+
btn.bind("<Leave>", lambda _: btn.config(fg=p["accent"], bg=p["void"]))
|
|
502
|
+
self._minimize_btn = btn
|
|
503
|
+
_wlift(btn)
|
|
504
|
+
|
|
505
|
+
def _on_engine_click(self, _e=None) -> None:
|
|
506
|
+
"""Clique no cosmos: NADA acontece.
|
|
507
|
+
|
|
508
|
+
A restauração é feita apenas via:
|
|
509
|
+
- Clique direto no planeta (gerenciado pelo hover_tip.on_click)
|
|
510
|
+
- Botão ⊙ Restaurar Editor
|
|
511
|
+
Desta forma cliques fora dos planetas não interrompem tooltips.
|
|
512
|
+
"""
|
|
513
|
+
|
|
514
|
+
if self._engine:
|
|
515
|
+
with contextlib.suppress(tk.TclError):
|
|
516
|
+
self._engine.notify_activity()
|
|
517
|
+
|
|
518
|
+
def minimize_to_planet(self) -> None:
|
|
519
|
+
"""Modo planeta: eleva o engine sobre o editor via z-order puro.
|
|
520
|
+
|
|
521
|
+
NÃO oculta o _ec - apenas coloca o canvas cosmos por cima dele.
|
|
522
|
+
Isso evita qualquer problema de re-layout ao restaurar.
|
|
523
|
+
"""
|
|
524
|
+
if not self._enabled or not self._engine:
|
|
525
|
+
return
|
|
526
|
+
self._planet_active = True
|
|
527
|
+
|
|
528
|
+
filepaths = list(self._open_files) if self._open_files else []
|
|
529
|
+
if not filepaths:
|
|
530
|
+
ed = self._get_ed()
|
|
531
|
+
if ed:
|
|
532
|
+
fp = str(
|
|
533
|
+
getattr(ed, "filepath", None) or getattr(
|
|
534
|
+
ed, "path", None) or ""
|
|
535
|
+
)
|
|
536
|
+
if fp:
|
|
537
|
+
filepaths = [fp]
|
|
538
|
+
|
|
539
|
+
self._engine.set_planet_restore_cb(self._on_planet_clicked)
|
|
540
|
+
|
|
541
|
+
self._engine.enter_planet_mode(filepaths)
|
|
542
|
+
|
|
543
|
+
self._engine.place(x=0, y=0, relwidth=1.0, relheight=1.0)
|
|
544
|
+
|
|
545
|
+
_wlift(self._engine)
|
|
546
|
+
with contextlib.suppress(tk.TclError):
|
|
547
|
+
self._engine.focus_set()
|
|
548
|
+
|
|
549
|
+
if self._glass_pane:
|
|
550
|
+
self._glass_pane.destroy()
|
|
551
|
+
self._glass_pane = None
|
|
552
|
+
|
|
553
|
+
if self._welcome and self._welcome.winfo_exists():
|
|
554
|
+
with contextlib.suppress(tk.TclError):
|
|
555
|
+
self._welcome.place_forget()
|
|
556
|
+
|
|
557
|
+
p = _pal(self._dark)
|
|
558
|
+
if not self._minimize_btn or not self._minimize_btn.winfo_exists():
|
|
559
|
+
self._build_minimize_btn(p)
|
|
560
|
+
if self._minimize_btn and self._minimize_btn.winfo_exists():
|
|
561
|
+
self._minimize_btn.config(
|
|
562
|
+
text="⊙ " + _i18n_t("kui.restore_editor"),
|
|
563
|
+
fg=p["ok"],
|
|
564
|
+
bg=_lc_q(p["void"], p["ok"], 0.12),
|
|
565
|
+
)
|
|
566
|
+
self._minimize_btn.unbind("<Button-1>")
|
|
567
|
+
self._minimize_btn.bind(
|
|
568
|
+
"<Button-1>", lambda _: self.restore_from_planet())
|
|
569
|
+
_wlift(self._minimize_btn)
|
|
570
|
+
self.sync_layers()
|
|
571
|
+
|
|
572
|
+
self.toast(
|
|
573
|
+
"⊙ " + _i18n_t("kui.cosmos_mode") + " - " +
|
|
574
|
+
_i18n_t("kui.restore_hint"),
|
|
575
|
+
kind="info",
|
|
576
|
+
duration_ms=3000,
|
|
577
|
+
)
|
|
578
|
+
|
|
579
|
+
def restore_from_planet(self) -> None:
|
|
580
|
+
"""Restaura editor do modo planeta rebaixando o engine (z-order puro).
|
|
581
|
+
|
|
582
|
+
NÃO toca no layout do _ec - apenas abaixa o canvas cosmos.
|
|
583
|
+
"""
|
|
584
|
+
if not self._enabled:
|
|
585
|
+
return
|
|
586
|
+
self._planet_active = False
|
|
587
|
+
|
|
588
|
+
if self._engine:
|
|
589
|
+
self._engine.exit_planet_mode()
|
|
590
|
+
|
|
591
|
+
if self._engine:
|
|
592
|
+
_wlower(self._engine)
|
|
593
|
+
|
|
594
|
+
ed_restore = self._get_ed()
|
|
595
|
+
if ed_restore and hasattr(ed_restore, "text"):
|
|
596
|
+
with contextlib.suppress(tk.TclError):
|
|
597
|
+
ed_restore.text.focus_set()
|
|
598
|
+
|
|
599
|
+
no_editor = self._get_ed() is None
|
|
600
|
+
if no_editor and self._show_welcome_cb is not None:
|
|
601
|
+
with contextlib.suppress(tk.TclError):
|
|
602
|
+
self._show_welcome_cb()
|
|
603
|
+
elif self._welcome and self._welcome.winfo_exists():
|
|
604
|
+
with contextlib.suppress(tk.TclError):
|
|
605
|
+
self._welcome.place_forget()
|
|
606
|
+
|
|
607
|
+
self._setup_glass_pane()
|
|
608
|
+
|
|
609
|
+
for sep_bar in (self._topbar, self._tabbar_w, self._stbar):
|
|
610
|
+
if sep_bar and sep_bar.winfo_exists():
|
|
611
|
+
_wlift(sep_bar)
|
|
612
|
+
self.sync_layers()
|
|
613
|
+
|
|
614
|
+
p = _pal(self._dark)
|
|
615
|
+
if not self._minimize_btn or not self._minimize_btn.winfo_exists():
|
|
616
|
+
self._build_minimize_btn(p)
|
|
617
|
+
if self._minimize_btn and self._minimize_btn.winfo_exists():
|
|
618
|
+
self._minimize_btn.config(
|
|
619
|
+
text="⊙ " + _i18n_t("kui.cosmos_mode"), fg=p["accent"], bg=p["void"]
|
|
620
|
+
)
|
|
621
|
+
self._minimize_btn.unbind("<Button-1>")
|
|
622
|
+
self._minimize_btn.bind(
|
|
623
|
+
"<Button-1>", lambda _: self.minimize_to_planet())
|
|
624
|
+
_wlift(self._minimize_btn)
|
|
625
|
+
|
|
626
|
+
def disable(self):
|
|
627
|
+
"""Desativa o componente."""
|
|
628
|
+
if not self._enabled:
|
|
629
|
+
return
|
|
630
|
+
self._enabled = False
|
|
631
|
+
for w, kw in ((self._tabbar, {"fill": "x"}), (self._breadcrumb, {"fill": "x"})):
|
|
632
|
+
if w:
|
|
633
|
+
with contextlib.suppress(tk.TclError):
|
|
634
|
+
w.pack(**kw)
|
|
635
|
+
if self._menubar is not None:
|
|
636
|
+
with contextlib.suppress(tk.TclError):
|
|
637
|
+
self._menubar.pack_into(self._root)
|
|
638
|
+
t = self._tmgr.theme if self._tmgr else None
|
|
639
|
+
t_bg = getattr(t, "bg", "#1e1e1e") if t else "#1e1e1e"
|
|
640
|
+
t_brd = getattr(t, "border", "#333") if t else "#333"
|
|
641
|
+
for pw in (self._hpaned, self._vpaned):
|
|
642
|
+
if pw:
|
|
643
|
+
with contextlib.suppress(tk.TclError):
|
|
644
|
+
pw.config(bg=t_brd, sashwidth=6, sashrelief="flat")
|
|
645
|
+
for w2 in (self._root, self._cf, self._ec):
|
|
646
|
+
if w2:
|
|
647
|
+
with contextlib.suppress(tk.TclError):
|
|
648
|
+
w2.configure(bg=t_bg)
|
|
649
|
+
for attr in ("_engine", "_topbar", "_tabbar_w", "_stbar"):
|
|
650
|
+
obj = getattr(self, attr, None)
|
|
651
|
+
if obj:
|
|
652
|
+
with contextlib.suppress(tk.TclError):
|
|
653
|
+
obj.stop()
|
|
654
|
+
_safe_del(obj)
|
|
655
|
+
setattr(self, attr, None)
|
|
656
|
+
if self._glass_pane:
|
|
657
|
+
self._glass_pane.destroy()
|
|
658
|
+
self._glass_pane = None
|
|
659
|
+
if self._dock is not None:
|
|
660
|
+
was_open = self._dock.leave_float()
|
|
661
|
+
cb = self._show_sb if was_open else self._hide_sb
|
|
662
|
+
if cb:
|
|
663
|
+
self._root.after_idle(cb)
|
|
664
|
+
_safe_del(self._portal)
|
|
665
|
+
self._portal = None
|
|
666
|
+
_safe_del(self._welcome)
|
|
667
|
+
self._welcome = None
|
|
668
|
+
_safe_del(self._minimize_btn)
|
|
669
|
+
self._minimize_btn = None
|
|
670
|
+
if self._detach_manager is None:
|
|
671
|
+
for win in list(self._detached.values()):
|
|
672
|
+
_safe_del(win)
|
|
673
|
+
self._detached.clear()
|
|
674
|
+
|
|
675
|
+
for ev, fids in self._root_bind_ids.items():
|
|
676
|
+
for fid in fids:
|
|
677
|
+
unbind_one(self._root, ev, fid)
|
|
678
|
+
self._root_bind_ids.clear()
|
|
679
|
+
self._easter = None
|
|
680
|
+
if self._metric_job:
|
|
681
|
+
with contextlib.suppress(tk.TclError):
|
|
682
|
+
self._root.after_cancel(self._metric_job)
|
|
683
|
+
self._metric_job = None
|
|
684
|
+
if self._fps_report_job:
|
|
685
|
+
with contextlib.suppress(tk.TclError):
|
|
686
|
+
self._root.after_cancel(self._fps_report_job)
|
|
687
|
+
self._fps_report_job = None
|
|
688
|
+
|
|
689
|
+
def apply_theme(self, t):
|
|
690
|
+
if not self._enabled:
|
|
691
|
+
return
|
|
692
|
+
self._dark = getattr(t, "dark", True)
|
|
693
|
+
p = _pal(self._dark)
|
|
694
|
+
self._paint_frames_void()
|
|
695
|
+
if self._engine:
|
|
696
|
+
self._engine.stop()
|
|
697
|
+
_safe_del(self._engine)
|
|
698
|
+
self._engine = None
|
|
699
|
+
if self._glass_pane:
|
|
700
|
+
self._glass_pane.destroy()
|
|
701
|
+
self._glass_pane = None
|
|
702
|
+
self._make_engine()
|
|
703
|
+
self._setup_glass_pane()
|
|
704
|
+
|
|
705
|
+
if self._engine:
|
|
706
|
+
self._engine.bind("<Button-1>", self._on_engine_click, add=True)
|
|
707
|
+
self._engine.set_planet_click_cb(self._on_solar_planet_click)
|
|
708
|
+
self._engine.set_planet_restore_cb(self._on_planet_clicked)
|
|
709
|
+
|
|
710
|
+
self._build_minimize_btn(p)
|
|
711
|
+
|
|
712
|
+
if self._planet_active and self._engine:
|
|
713
|
+
filepath = getattr(self._engine, "_planet_file", "")
|
|
714
|
+
self._engine.enter_planet_mode(filepath)
|
|
715
|
+
for sep_bar in (self._topbar, self._tabbar_w, self._stbar):
|
|
716
|
+
if sep_bar:
|
|
717
|
+
_wlift(sep_bar)
|
|
718
|
+
if self._minimize_btn:
|
|
719
|
+
_wlift(self._minimize_btn)
|
|
720
|
+
ed = self._get_ed()
|
|
721
|
+
if ed:
|
|
722
|
+
with contextlib.suppress(tk.TclError):
|
|
723
|
+
ed.text.config(
|
|
724
|
+
bg=p["text_bg"],
|
|
725
|
+
fg=p["text_fg"],
|
|
726
|
+
insertbackground=p["text_cur"],
|
|
727
|
+
selectbackground=p["text_sel"],
|
|
728
|
+
)
|
|
729
|
+
if self._welcome:
|
|
730
|
+
self._welcome.stop()
|
|
731
|
+
_safe_del(self._welcome)
|
|
732
|
+
self._welcome = None
|
|
733
|
+
|
|
734
|
+
def _start_fps_report(self):
|
|
735
|
+
"""Inicia o timer periódico de reporte de FPS para a barra de status."""
|
|
736
|
+
|
|
737
|
+
def _report():
|
|
738
|
+
if not self._enabled:
|
|
739
|
+
return
|
|
740
|
+
if self._engine and self._stbar:
|
|
741
|
+
with contextlib.suppress(tk.TclError):
|
|
742
|
+
ft = self._engine._frame_times
|
|
743
|
+
if ft:
|
|
744
|
+
avg_ms = sum(ft) / len(ft)
|
|
745
|
+
fps = min(999, 1000.0 / max(0.1, avg_ms))
|
|
746
|
+
self._stbar.set_fps(fps)
|
|
747
|
+
self._fps_report_job = self._root.after(2000, _report)
|
|
748
|
+
|
|
749
|
+
self._fps_report_job = self._root.after(2000, _report)
|
|
750
|
+
|
|
751
|
+
def _open_portal(self, _=None):
|
|
752
|
+
if not self._enabled:
|
|
753
|
+
return
|
|
754
|
+
_safe_del(self._portal)
|
|
755
|
+
self._portal = KPortal(self._root, self._commands, self._dark)
|
|
756
|
+
|
|
757
|
+
def toggle_sidebar(self) -> None:
|
|
758
|
+
"""Alterna a visibilidade da barra lateral (API pública)."""
|
|
759
|
+
self._toggle_side()
|
|
760
|
+
|
|
761
|
+
def _toggle_side(self, _=None):
|
|
762
|
+
if not self._enabled or self._dock is None:
|
|
763
|
+
return
|
|
764
|
+
cb = self._hide_sb if self._dock.visible else self._show_sb
|
|
765
|
+
if cb:
|
|
766
|
+
cb()
|
|
767
|
+
|
|
768
|
+
def _on_click_activity(self, _=None):
|
|
769
|
+
if self._engine:
|
|
770
|
+
with contextlib.suppress(tk.TclError):
|
|
771
|
+
self._engine.notify_activity()
|
|
772
|
+
|
|
773
|
+
def _refresh_tabs(self):
|
|
774
|
+
"""Sincroniza a barra de abas K-UI com as abas abertas no editor."""
|
|
775
|
+
if not self._tabbar_w or not self._tabbar_w.winfo_exists():
|
|
776
|
+
return
|
|
777
|
+
tabs = []
|
|
778
|
+
ed = self._get_ed()
|
|
779
|
+
if self._open_files:
|
|
780
|
+
active_path = ""
|
|
781
|
+
if ed:
|
|
782
|
+
active_path = str(
|
|
783
|
+
getattr(ed, "filepath", None) or getattr(
|
|
784
|
+
ed, "path", None) or ""
|
|
785
|
+
)
|
|
786
|
+
for fpath in self._open_files:
|
|
787
|
+
tabs.append(
|
|
788
|
+
{
|
|
789
|
+
"name": Path(fpath).name if fpath else "Sem título",
|
|
790
|
+
"modified": False,
|
|
791
|
+
"active": (fpath == active_path),
|
|
792
|
+
}
|
|
793
|
+
)
|
|
794
|
+
elif ed:
|
|
795
|
+
path = getattr(ed, "filepath", None) or getattr(ed, "path", None)
|
|
796
|
+
name = Path(path).name if path else "Sem título"
|
|
797
|
+
modified = (
|
|
798
|
+
getattr(ed, "modified", False)
|
|
799
|
+
or getattr(ed, "is_modified", lambda: False)()
|
|
800
|
+
)
|
|
801
|
+
tabs = [{"name": name, "modified": modified, "active": True}]
|
|
802
|
+
self._tabbar_w.set_tabs(tabs)
|
|
803
|
+
self._place_bars()
|
|
804
|
+
if tabs:
|
|
805
|
+
try:
|
|
806
|
+
x_off = 0
|
|
807
|
+
if self._cf and self._cf.winfo_exists():
|
|
808
|
+
x_off = max(0, self._cf.winfo_rootx() -
|
|
809
|
+
self._root.winfo_rootx())
|
|
810
|
+
bar_w = max(200, self._root.winfo_width() - x_off)
|
|
811
|
+
except tk.TclError:
|
|
812
|
+
x_off = 0
|
|
813
|
+
bar_w = max(200, self._root.winfo_width() or 1200)
|
|
814
|
+
self._tabbar_w.place(x=x_off, y=22, width=bar_w, height=36)
|
|
815
|
+
_wlift(self._tabbar_w)
|
|
816
|
+
else:
|
|
817
|
+
self._tabbar_w.place_forget()
|
|
818
|
+
|
|
819
|
+
def _on_planet_clicked(self, filepath: str) -> None:
|
|
820
|
+
"""Chamado quando o usuário clica num planeta minimizado.
|
|
821
|
+
|
|
822
|
+
Restaura o editor e gera evento para o app abrir o arquivo.
|
|
823
|
+
"""
|
|
824
|
+
if not self._enabled:
|
|
825
|
+
return
|
|
826
|
+
|
|
827
|
+
self.restore_from_planet()
|
|
828
|
+
|
|
829
|
+
if filepath:
|
|
830
|
+
self._last_tab_action = "open_planet", filepath
|
|
831
|
+
with contextlib.suppress(tk.TclError):
|
|
832
|
+
self._root.event_generate("<<KUIPlanetRestore>>", when="tail")
|
|
833
|
+
|
|
834
|
+
def _on_solar_planet_click(self, filepath: str) -> None:
|
|
835
|
+
"""Abre o arquivo associado a um planeta do sistema solar clicado."""
|
|
836
|
+
if not self._enabled or not filepath:
|
|
837
|
+
return
|
|
838
|
+
self._last_tab_action = "solar_planet", filepath
|
|
839
|
+
with contextlib.suppress(tk.TclError):
|
|
840
|
+
self._root.event_generate("<<KUISolarPlanetClick>>", when="tail")
|
|
841
|
+
|
|
842
|
+
def _on_tab_select(self, idx):
|
|
843
|
+
if not (0 <= idx < len(self._open_files)):
|
|
844
|
+
return
|
|
845
|
+
self._last_tab_action = "select", idx
|
|
846
|
+
with contextlib.suppress(tk.TclError):
|
|
847
|
+
self._root.event_generate("<<KUITabSelect>>", when="tail")
|
|
848
|
+
|
|
849
|
+
def _on_tab_close(self, idx):
|
|
850
|
+
"""Fecha aba: gera evento se há lista de arquivos, senão busca comando."""
|
|
851
|
+
if 0 <= idx < len(self._open_files):
|
|
852
|
+
self._last_tab_action = "close", idx
|
|
853
|
+
with contextlib.suppress(tk.TclError):
|
|
854
|
+
self._root.event_generate("<<KUITabClose>>", when="tail")
|
|
855
|
+
return
|
|
856
|
+
|
|
857
|
+
for _, label, cb in self._commands:
|
|
858
|
+
if any(
|
|
859
|
+
k in label.lower()
|
|
860
|
+
for k in ("fechar aba", "fechar editor", "file.close")
|
|
861
|
+
):
|
|
862
|
+
with contextlib.suppress(tk.TclError):
|
|
863
|
+
cb()
|
|
864
|
+
return
|
|
865
|
+
|
|
866
|
+
self._last_tab_action = ("close", max(0, idx))
|
|
867
|
+
with contextlib.suppress(tk.TclError):
|
|
868
|
+
self._root.event_generate("<<KUITabClose>>", when="tail")
|
|
869
|
+
|
|
870
|
+
def _minimize_tab_to_planet(self, _idx: int) -> None:
|
|
871
|
+
"""Ativa o modo planeta (``_idx`` não é usado)."""
|
|
872
|
+
if not self._enabled or not self._engine:
|
|
873
|
+
return
|
|
874
|
+
|
|
875
|
+
self.minimize_to_planet()
|
|
876
|
+
|
|
877
|
+
def _open_tab_dual_mode(self, idx: int) -> None:
|
|
878
|
+
"""Registra par de arquivos para modo dual e notifica o app.
|
|
879
|
+
|
|
880
|
+
O app deve ouvir <<KUITabDual>> e ler last_tab_action = ("dual", idx).
|
|
881
|
+
"""
|
|
882
|
+
if not self._enabled:
|
|
883
|
+
return
|
|
884
|
+
if 0 <= idx < len(self._open_files):
|
|
885
|
+
self._last_tab_action = "dual", idx
|
|
886
|
+
with contextlib.suppress(tk.TclError):
|
|
887
|
+
self._root.event_generate("<<KUITabDual>>", when="tail")
|
|
888
|
+
filepath = self._open_files[idx]
|
|
889
|
+
name = Path(filepath).name if filepath else f"aba {idx + 1}"
|
|
890
|
+
self.toast(
|
|
891
|
+
f"⊞ {_i18n_t('kui.dual_mode')}: {name}", kind="info", duration_ms=2500
|
|
892
|
+
)
|
|
893
|
+
else:
|
|
894
|
+
self._last_tab_action = "dual", 0
|
|
895
|
+
with contextlib.suppress(tk.TclError):
|
|
896
|
+
self._root.event_generate("<<KUITabDual>>", when="tail")
|
|
897
|
+
|
|
898
|
+
def _engine_spawn_supernova(self) -> None:
|
|
899
|
+
"""Spawn visual de supernova: muitos meteoros radiais + nascimento estelar."""
|
|
900
|
+
if not self._engine:
|
|
901
|
+
return
|
|
902
|
+
eng = self._engine
|
|
903
|
+
W = eng.winfo_width() or 1200
|
|
904
|
+
H = eng.winfo_height() or 800
|
|
905
|
+
cx2 = W // 2
|
|
906
|
+
cy2 = H // 2
|
|
907
|
+
for _ in range(30):
|
|
908
|
+
ang = random.uniform(0, _TAU)
|
|
909
|
+
spd = random.uniform(6, 14)
|
|
910
|
+
eng._meteors.append(
|
|
911
|
+
{
|
|
912
|
+
"x": float(cx2 + random.uniform(-20, 20)),
|
|
913
|
+
"y": float(cy2 + random.uniform(-20, 20)),
|
|
914
|
+
"dx": spd * math.cos(ang),
|
|
915
|
+
"dy": spd * math.sin(ang),
|
|
916
|
+
"length": random.randint(60, 130),
|
|
917
|
+
"alive": True,
|
|
918
|
+
"vx_extra": 0.0,
|
|
919
|
+
"vy_extra": 0.0,
|
|
920
|
+
"col": random.choice(
|
|
921
|
+
["accent", "accent2", "aur_a",
|
|
922
|
+
"plasma", "quantum", "star3"]
|
|
923
|
+
),
|
|
924
|
+
}
|
|
925
|
+
)
|
|
926
|
+
eng._star_birth.append(
|
|
927
|
+
{
|
|
928
|
+
"x": float(cx2),
|
|
929
|
+
"y": float(cy2),
|
|
930
|
+
"r": random.uniform(12, 24),
|
|
931
|
+
"phase": 0.0,
|
|
932
|
+
"max_phase": 220,
|
|
933
|
+
"col": "star",
|
|
934
|
+
"cloud_r": random.uniform(100, 160),
|
|
935
|
+
}
|
|
936
|
+
)
|
|
937
|
+
|
|
938
|
+
def _engine_spawn_meteor_shower(self) -> None:
|
|
939
|
+
"""Chuva de meteoros comemorativa."""
|
|
940
|
+
if not self._engine:
|
|
941
|
+
return
|
|
942
|
+
eng = self._engine
|
|
943
|
+
W = eng.winfo_width() or 1200
|
|
944
|
+
for _ in range(20):
|
|
945
|
+
ang = math.radians(random.uniform(30, 60))
|
|
946
|
+
spd = random.uniform(8, 16)
|
|
947
|
+
eng._meteors.append(
|
|
948
|
+
{
|
|
949
|
+
"x": float(random.uniform(W * 0.03, W * 0.87)),
|
|
950
|
+
"y": -18.0,
|
|
951
|
+
"dx": math.cos(ang) * spd,
|
|
952
|
+
"dy": math.sin(ang) * spd,
|
|
953
|
+
"length": random.randint(55, 120),
|
|
954
|
+
"alive": True,
|
|
955
|
+
"vx_extra": 0.0,
|
|
956
|
+
"vy_extra": 0.0,
|
|
957
|
+
"col": random.choice(["accent", "aur_a", "star3", "accent2"]),
|
|
958
|
+
}
|
|
959
|
+
)
|
|
960
|
+
|
|
961
|
+
def _engine_spawn_star_birth(self) -> None:
|
|
962
|
+
"""Força nascimento estelar no centro."""
|
|
963
|
+
if not self._engine:
|
|
964
|
+
return
|
|
965
|
+
eng = self._engine
|
|
966
|
+
W = eng.winfo_width() or 1200
|
|
967
|
+
H = eng.winfo_height() or 800
|
|
968
|
+
eng._star_birth.append(
|
|
969
|
+
{
|
|
970
|
+
"x": float(W // 2 + random.randint(-100, 100)),
|
|
971
|
+
"y": float(H // 2 + random.randint(-80, 80)),
|
|
972
|
+
"r": random.uniform(10, 22),
|
|
973
|
+
"phase": 0.0,
|
|
974
|
+
"max_phase": 300,
|
|
975
|
+
"col": random.choice(["star", "accent2", "aur_a"]),
|
|
976
|
+
"cloud_r": random.uniform(80, 140),
|
|
977
|
+
}
|
|
978
|
+
)
|
|
979
|
+
|
|
980
|
+
def _engine_spawn_nova_burst(self) -> None:
|
|
981
|
+
"""Nova burst: anel expansivo de meteoros + star birth + kp burst denso."""
|
|
982
|
+
if not self._engine:
|
|
983
|
+
return
|
|
984
|
+
eng = self._engine
|
|
985
|
+
W = eng.winfo_width() or 1200
|
|
986
|
+
H = eng.winfo_height() or 800
|
|
987
|
+
cx2 = W // 2
|
|
988
|
+
cy2 = H // 2
|
|
989
|
+
|
|
990
|
+
for i in range(16):
|
|
991
|
+
ang = i * (_TAU / 16)
|
|
992
|
+
spd = random.uniform(4, 10)
|
|
993
|
+
eng._meteors.append(
|
|
994
|
+
{
|
|
995
|
+
"x": float(cx2),
|
|
996
|
+
"y": float(cy2),
|
|
997
|
+
"dx": spd * math.cos(ang),
|
|
998
|
+
"dy": spd * math.sin(ang),
|
|
999
|
+
"length": random.randint(50, 100),
|
|
1000
|
+
"alive": True,
|
|
1001
|
+
"vx_extra": 0.0,
|
|
1002
|
+
"vy_extra": 0.0,
|
|
1003
|
+
"col": random.choice(["warn", "accent2", "plasma", "star3"]),
|
|
1004
|
+
}
|
|
1005
|
+
)
|
|
1006
|
+
eng._star_birth.append(
|
|
1007
|
+
{
|
|
1008
|
+
"x": float(cx2),
|
|
1009
|
+
"y": float(cy2),
|
|
1010
|
+
"r": random.uniform(8, 18),
|
|
1011
|
+
"phase": 0.0,
|
|
1012
|
+
"max_phase": 180,
|
|
1013
|
+
"col": "accent2",
|
|
1014
|
+
"cloud_r": random.uniform(70, 120),
|
|
1015
|
+
}
|
|
1016
|
+
)
|
|
1017
|
+
ck = ["accent2", "quantum", "aur_a", "plasma"]
|
|
1018
|
+
for _ in range(30):
|
|
1019
|
+
eng._kp_burst.append(
|
|
1020
|
+
{
|
|
1021
|
+
"x": float(cx2 + random.uniform(-40, 40)),
|
|
1022
|
+
"y": float(cy2 + random.uniform(-40, 40)),
|
|
1023
|
+
"vx": random.uniform(-4.0, 4.0),
|
|
1024
|
+
"vy": random.uniform(-4.0, 4.0),
|
|
1025
|
+
"r": random.uniform(1.0, 3.5),
|
|
1026
|
+
"ph": random.uniform(0, _TAU),
|
|
1027
|
+
"life": random.uniform(0.55, 1.0),
|
|
1028
|
+
"col": random.choice(ck),
|
|
1029
|
+
}
|
|
1030
|
+
)
|
|
1031
|
+
|
|
1032
|
+
def _track_keystroke(self, e):
|
|
1033
|
+
"""Rastreia teclas para métricas de KPM e notifica o engine."""
|
|
1034
|
+
char = getattr(e, "char", "") or ""
|
|
1035
|
+
if not char:
|
|
1036
|
+
return
|
|
1037
|
+
now = time.time()
|
|
1038
|
+
self._kpm_window.append(now)
|
|
1039
|
+
if char.isprintable():
|
|
1040
|
+
self._char_window.append(now)
|
|
1041
|
+
cutoff = now - 60.0
|
|
1042
|
+
self._kpm_window = [t for t in self._kpm_window if t >= cutoff]
|
|
1043
|
+
self._char_window = [t for t in self._char_window if t >= cutoff]
|
|
1044
|
+
if self._engine:
|
|
1045
|
+
with contextlib.suppress(tk.TclError):
|
|
1046
|
+
self._engine.notify_keystroke()
|
|
1047
|
+
|
|
1048
|
+
def _poll_metrics(self):
|
|
1049
|
+
"""Consulta métricas de uso (FPS, memória) e atualiza os indicadores."""
|
|
1050
|
+
if not self._enabled or not self._engine:
|
|
1051
|
+
return
|
|
1052
|
+
self.update_engine_activity()
|
|
1053
|
+
with contextlib.suppress(tk.TclError):
|
|
1054
|
+
ed = self._get_ed()
|
|
1055
|
+
size_kb = 0.0
|
|
1056
|
+
if ed:
|
|
1057
|
+
path = getattr(ed, "filepath", None) or getattr(
|
|
1058
|
+
ed, "path", None)
|
|
1059
|
+
if path:
|
|
1060
|
+
with contextlib.suppress(OSError):
|
|
1061
|
+
size_kb = Path(path).stat().st_size / 1024.0
|
|
1062
|
+
now = time.time()
|
|
1063
|
+
cutoff = now - 60.0
|
|
1064
|
+
self._kpm_window = [t for t in self._kpm_window if t >= cutoff]
|
|
1065
|
+
self._char_window = [t for t in self._char_window if t >= cutoff]
|
|
1066
|
+
self._engine.set_reactive_metrics(
|
|
1067
|
+
file_size_kb=size_kb,
|
|
1068
|
+
errors=self._diag_errors,
|
|
1069
|
+
warnings=self._diag_warnings,
|
|
1070
|
+
keys_per_minute=float(len(self._kpm_window)),
|
|
1071
|
+
open_files=self._open_files,
|
|
1072
|
+
chars_per_min=len(self._char_window),
|
|
1073
|
+
)
|
|
1074
|
+
self._metric_job = self._root.after(5000, self._poll_metrics)
|
|
1075
|
+
|
|
1076
|
+
def set_vim_mode(self, mode, cmd=""):
|
|
1077
|
+
if self._stbar and self._stbar.winfo_exists():
|
|
1078
|
+
self._stbar.set_vim_mode(mode, cmd)
|
|
1079
|
+
|
|
1080
|
+
def notify_diagnostics(self, errors, warnings):
|
|
1081
|
+
self._diag_errors = max(0, errors)
|
|
1082
|
+
self._diag_warnings = max(0, warnings)
|
|
1083
|
+
if self._topbar:
|
|
1084
|
+
with contextlib.suppress(tk.TclError):
|
|
1085
|
+
self._topbar.set_diagnostics(errors, warnings)
|
|
1086
|
+
|
|
1087
|
+
_COSMOS_EVENTS = {"file_save": "save", "file_open": "open", "file_close": "close"}
|
|
1088
|
+
|
|
1089
|
+
def on_app_event(self, event, data=None):
|
|
1090
|
+
"""Traduz eventos do editor (salvar/abrir/fechar) em acontecimentos no cosmos."""
|
|
1091
|
+
kind = self._COSMOS_EVENTS.get(event)
|
|
1092
|
+
if kind and self._enabled and self._engine is not None:
|
|
1093
|
+
self._engine.cosmos_event(kind)
|
|
1094
|
+
|
|
1095
|
+
def notify_open_files(self, paths):
|
|
1096
|
+
self._open_files = list(paths)
|
|
1097
|
+
self._refresh_tabs()
|
|
1098
|
+
self._root.after_idle(self.sync_layers)
|
|
1099
|
+
|
|
1100
|
+
def toast(self, message, kind="info", duration_ms=3000):
|
|
1101
|
+
"""Exibe uma notificação toast temporária na interface KUI."""
|
|
1102
|
+
if not self._enabled:
|
|
1103
|
+
return
|
|
1104
|
+
with contextlib.suppress(tk.TclError):
|
|
1105
|
+
KToast(self._root, message, kind, duration_ms, self._dark)
|
|
1106
|
+
|
|
1107
|
+
def detach_panel(self, panel_key):
|
|
1108
|
+
"""Destaca o painel em janela flutuante; se já destacado, traz ao foco.
|
|
1109
|
+
|
|
1110
|
+
Args:
|
|
1111
|
+
panel_key: Chave do painel registrado em ``_factories``.
|
|
1112
|
+
"""
|
|
1113
|
+
if self._detach_manager is not None:
|
|
1114
|
+
self._detach_manager.detach(panel_key)
|
|
1115
|
+
return
|
|
1116
|
+
|
|
1117
|
+
if panel_key in self._detached:
|
|
1118
|
+
with contextlib.suppress(tk.TclError):
|
|
1119
|
+
self._detached[panel_key].lift()
|
|
1120
|
+
return
|
|
1121
|
+
factory = self._factories.get(panel_key)
|
|
1122
|
+
if not factory:
|
|
1123
|
+
logger.warning("detach_panel: sem factory para %r", panel_key)
|
|
1124
|
+
return
|
|
1125
|
+
|
|
1126
|
+
def _on_close(k=panel_key):
|
|
1127
|
+
self._detached.pop(k, None)
|
|
1128
|
+
|
|
1129
|
+
self._detached[panel_key] = KFloatWindow(
|
|
1130
|
+
self._root,
|
|
1131
|
+
panel_key.replace("_", " ").title(),
|
|
1132
|
+
factory,
|
|
1133
|
+
_on_close,
|
|
1134
|
+
self._dark,
|
|
1135
|
+
)
|
|
1136
|
+
|
|
1137
|
+
def reattach_panel(self, panel_key):
|
|
1138
|
+
if self._detach_manager is not None:
|
|
1139
|
+
self._detach_manager.reattach(panel_key)
|
|
1140
|
+
return
|
|
1141
|
+
|
|
1142
|
+
win = self._detached.pop(panel_key, None)
|
|
1143
|
+
if win:
|
|
1144
|
+
_safe_del(win)
|
|
1145
|
+
|
|
1146
|
+
def notify_workspace_opened(self):
|
|
1147
|
+
"""Marca o KUI como tendo um workspace aberto."""
|
|
1148
|
+
self._has_ws = True
|
|
1149
|
+
|
|
1150
|
+
def show_welcome(
|
|
1151
|
+
self,
|
|
1152
|
+
on_new=None,
|
|
1153
|
+
on_open=None,
|
|
1154
|
+
on_folder=None,
|
|
1155
|
+
on_recent=None,
|
|
1156
|
+
recent_files=None,
|
|
1157
|
+
):
|
|
1158
|
+
if not self._enabled:
|
|
1159
|
+
return
|
|
1160
|
+
_safe_del(self._welcome)
|
|
1161
|
+
container = self._ec or self._cf or self._root
|
|
1162
|
+
with contextlib.suppress(tk.TclError):
|
|
1163
|
+
self._welcome = KWelcome(
|
|
1164
|
+
container,
|
|
1165
|
+
dark=self._dark,
|
|
1166
|
+
profile=self._profile,
|
|
1167
|
+
on_new=on_new,
|
|
1168
|
+
on_open=on_open,
|
|
1169
|
+
on_folder=on_folder,
|
|
1170
|
+
on_recent=on_recent,
|
|
1171
|
+
recent=recent_files,
|
|
1172
|
+
)
|
|
1173
|
+
self._welcome.place(x=0, y=0, relwidth=1.0, relheight=1.0)
|
|
1174
|
+
self.sync_layers()
|
|
1175
|
+
|
|
1176
|
+
def hide_welcome(self):
|
|
1177
|
+
"""Oculta a tela de boas-vindas cósmica e exibe o canvas de edição."""
|
|
1178
|
+
if self._welcome:
|
|
1179
|
+
with contextlib.suppress(tk.TclError):
|
|
1180
|
+
self._welcome.place_forget()
|
|
1181
|
+
self._welcome.stop()
|
|
1182
|
+
_safe_del(self._welcome)
|
|
1183
|
+
self._welcome = None
|
|
1184
|
+
self.sync_layers()
|
|
1185
|
+
|
|
1186
|
+
def set_perf_profile(self, profile):
|
|
1187
|
+
self._profile = profile
|
|
1188
|
+
if self._engine:
|
|
1189
|
+
with contextlib.suppress(tk.TclError):
|
|
1190
|
+
self._engine.set_profile(profile)
|
|
1191
|
+
if self._topbar:
|
|
1192
|
+
with contextlib.suppress(tk.TclError):
|
|
1193
|
+
self._topbar.set_profile(profile)
|
|
1194
|
+
if self._welcome and isinstance(self._welcome, KEngine):
|
|
1195
|
+
with contextlib.suppress(tk.TclError):
|
|
1196
|
+
self._welcome.set_profile(profile)
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
def build_kui_theme() -> Theme:
|
|
1200
|
+
"""Constrói e retorna o tema padrão K-UI (Obsidian/Electric-Indigo) do K-UI."""
|
|
1201
|
+
return Theme(
|
|
1202
|
+
name="kui",
|
|
1203
|
+
dark=True,
|
|
1204
|
+
bg="#020209",
|
|
1205
|
+
editor_bg="#03030c",
|
|
1206
|
+
sidebar_bg="#010108",
|
|
1207
|
+
tabbar_bg="#010108",
|
|
1208
|
+
panel_bg="#020209",
|
|
1209
|
+
activity_bg="#010105",
|
|
1210
|
+
overlay_bg="#000000",
|
|
1211
|
+
fg="#e8eaf6",
|
|
1212
|
+
fg_muted="#546e7a",
|
|
1213
|
+
fg_dim="#18183a",
|
|
1214
|
+
border="#0a0a28",
|
|
1215
|
+
border_focus="#7c4dff",
|
|
1216
|
+
gutter_bg="#03030c",
|
|
1217
|
+
gutter_fg="#1e2030",
|
|
1218
|
+
gutter_active_fg="#e8eaf6",
|
|
1219
|
+
line_hl="#07072a",
|
|
1220
|
+
line_hl2="#09093a",
|
|
1221
|
+
sel_bg="#18186a",
|
|
1222
|
+
sel_fg="#e8eaf6",
|
|
1223
|
+
cursor="#7c4dff",
|
|
1224
|
+
ruler_color="#0a0a28",
|
|
1225
|
+
indent_guide="#0a0a28",
|
|
1226
|
+
whitespace="#18183a",
|
|
1227
|
+
input_bg="#07072a",
|
|
1228
|
+
input_border="#7c4dff",
|
|
1229
|
+
btn_bg="#0a0a28",
|
|
1230
|
+
btn_fg="#e8eaf6",
|
|
1231
|
+
btn_hover="#18184e",
|
|
1232
|
+
btn_active="#282880",
|
|
1233
|
+
btn_primary="#7c4dff",
|
|
1234
|
+
btn_primary_fg="#020209",
|
|
1235
|
+
tab_act_bg="#03030c",
|
|
1236
|
+
tab_act_fg="#e8eaf6",
|
|
1237
|
+
tab_act_border="#7c4dff",
|
|
1238
|
+
tab_in_bg="#010108",
|
|
1239
|
+
tab_in_fg="#546e7a",
|
|
1240
|
+
tab_hover_bg="#0a0a20",
|
|
1241
|
+
tab_modified="#ff6d00",
|
|
1242
|
+
err_fg="#ff5252",
|
|
1243
|
+
warn_fg="#ff9100",
|
|
1244
|
+
info_fg="#00e5ff",
|
|
1245
|
+
hint_fg="#69ff47",
|
|
1246
|
+
ok_fg="#69ff47",
|
|
1247
|
+
err_bg="#1a0010",
|
|
1248
|
+
warn_bg="#1a0800",
|
|
1249
|
+
info_bg="#00101a",
|
|
1250
|
+
status_bg="#010105",
|
|
1251
|
+
status_fg="#e8eaf6",
|
|
1252
|
+
status_err_bg="#ff5252",
|
|
1253
|
+
status_err_fg="#020209",
|
|
1254
|
+
status_warn_bg="#ff9100",
|
|
1255
|
+
status_warn_fg="#020209",
|
|
1256
|
+
scroll_bg="#03030c",
|
|
1257
|
+
scroll_thumb="#0a0a28",
|
|
1258
|
+
scroll_hover="#18184e",
|
|
1259
|
+
diff_add_bg="#001a0a",
|
|
1260
|
+
diff_add_fg="#69ff47",
|
|
1261
|
+
diff_del_bg="#1a0008",
|
|
1262
|
+
diff_del_fg="#ff5252",
|
|
1263
|
+
diff_change_bg="#0a0a00",
|
|
1264
|
+
diff_change_fg="#ff9100",
|
|
1265
|
+
diff_hunk_bg="#03030c",
|
|
1266
|
+
diff_hunk_fg="#546e7a",
|
|
1267
|
+
minimap_bg="#010108",
|
|
1268
|
+
minimap_viewport="#0a0a28",
|
|
1269
|
+
minimap_err="#ff5252",
|
|
1270
|
+
minimap_warn="#ff9100",
|
|
1271
|
+
minimap_find="#ffd740",
|
|
1272
|
+
breadcrumb_bg="#03030c",
|
|
1273
|
+
breadcrumb_fg="#546e7a",
|
|
1274
|
+
breadcrumb_active_fg="#e8eaf6",
|
|
1275
|
+
t_keyword="#ea80fc",
|
|
1276
|
+
t_string="#69ff47",
|
|
1277
|
+
t_number="#ffd740",
|
|
1278
|
+
t_comment="#2e3d50",
|
|
1279
|
+
t_func="#40c4ff",
|
|
1280
|
+
t_class="#ffe57f",
|
|
1281
|
+
t_builtin="#18ffff",
|
|
1282
|
+
t_decorator="#ff4081",
|
|
1283
|
+
t_type="#ffe57f",
|
|
1284
|
+
t_operator="#e8eaf6",
|
|
1285
|
+
t_variable="#e8eaf6",
|
|
1286
|
+
t_tag="#ff4081",
|
|
1287
|
+
t_attr="#40c4ff",
|
|
1288
|
+
t_heading="#ea80fc",
|
|
1289
|
+
t_regex="#ff80ab",
|
|
1290
|
+
t_constant="#ffd740",
|
|
1291
|
+
t_escape="#ff4081",
|
|
1292
|
+
t_embedded="#40c4ff",
|
|
1293
|
+
t_invalid="#ff5252",
|
|
1294
|
+
t_namespace="#ea80fc",
|
|
1295
|
+
corner_radius=14,
|
|
1296
|
+
use_blur=False,
|
|
1297
|
+
blur_alpha=0.92,
|
|
1298
|
+
shadow_color="#000000",
|
|
1299
|
+
floating_bg="#06061c",
|
|
1300
|
+
floating_border="#18186a",
|
|
1301
|
+
floating_shadow="#000000",
|
|
1302
|
+
activity_icon_active="#e8eaf6",
|
|
1303
|
+
activity_icon_inactive="#1e2030",
|
|
1304
|
+
activity_active_indicator="#7c4dff",
|
|
1305
|
+
)
|