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/web_preview.py
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
"""Codis - Preview Web avançado (navegador real embutido, sem API key).
|
|
2
|
+
|
|
3
|
+
Abre a página (HTML/CSS/JS, Markdown ou SVG) num **Chromium de verdade**
|
|
4
|
+
(Edge/Chrome/Brave já instalados) cuja janela é incorporada ao editor, e
|
|
5
|
+
liga a ele:
|
|
6
|
+
|
|
7
|
+
* servidor local com *live reload* e buffers **não salvos** (:mod:`webdev`);
|
|
8
|
+
* barra de navegação (voltar/avançar/recarregar/URL) e emulação de
|
|
9
|
+
dispositivo (desktop/tablet/mobile) via DevTools Protocol;
|
|
10
|
+
* **console do navegador dentro do Codis** - erros de JS, ``console.log``,
|
|
11
|
+
recursos que falharam, com clique para abrir ``arquivo:linha`` no editor;
|
|
12
|
+
* divisão do editor (35/50/70/100 %) e F12 do próprio navegador (DevTools).
|
|
13
|
+
|
|
14
|
+
Sem Chromium (ou sem suporte a incorporar, como macOS/Wayland) o painel serve
|
|
15
|
+
a página e abre no navegador padrão, mantendo o live reload.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import contextlib
|
|
21
|
+
import logging
|
|
22
|
+
import os
|
|
23
|
+
import queue
|
|
24
|
+
import shutil
|
|
25
|
+
import sys
|
|
26
|
+
import tkinter as tk
|
|
27
|
+
import webbrowser
|
|
28
|
+
from collections.abc import Callable
|
|
29
|
+
from pathlib import Path
|
|
30
|
+
from typing import Any
|
|
31
|
+
|
|
32
|
+
from src.constants import CONFIG_DIR, FONT_MONO, FONT_UI
|
|
33
|
+
from src.i18n import _t
|
|
34
|
+
from src.ui import webdev
|
|
35
|
+
from src.ui import window_embed as we
|
|
36
|
+
|
|
37
|
+
logger = logging.getLogger("Codis.WebPreview")
|
|
38
|
+
|
|
39
|
+
__all__ = ["WebPreviewPanel", "markdown_page"]
|
|
40
|
+
|
|
41
|
+
_PROFILE_ROOT = CONFIG_DIR / "webpreview"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def markdown_page(text: str, title: str, tmgr: Any) -> str:
|
|
45
|
+
"""Markdown -> página HTML completa com o tema do Codis."""
|
|
46
|
+
from src.ui import render_panel as rp
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
import markdown as mdlib # type: ignore[import-untyped]
|
|
50
|
+
|
|
51
|
+
body = mdlib.markdown(
|
|
52
|
+
text, extensions=["fenced_code", "tables", "toc", "attr_list", "def_list", "footnotes"]
|
|
53
|
+
)
|
|
54
|
+
except ImportError:
|
|
55
|
+
body = rp.markdown_to_html(text)
|
|
56
|
+
return rp._TEMPLATE.format(
|
|
57
|
+
title=title, body=body, extra_head="", extra_scripts="", **rp._theme_vars(tmgr)
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class WebPreviewPanel(tk.Frame):
|
|
62
|
+
"""Painel de preview com navegador embutido; coloque-o com ``place``.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
parent: container do editor.
|
|
66
|
+
tmgr: gerenciador de temas.
|
|
67
|
+
cfg: configuração (``web_browser_path``, ``web_extra_args``).
|
|
68
|
+
root_dir: pasta servida (workspace ou pasta do arquivo).
|
|
69
|
+
open_at: ``(caminho, linha)`` chamado ao clicar num erro do console.
|
|
70
|
+
on_status: mensagens para a status bar.
|
|
71
|
+
on_close: chamado uma vez ao encerrar.
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
_LEVEL_FG = {"error": "#f38ba8", "warn": "#f9e2af", "info": "#89b4fa", "debug": "#9399b2", "log": ""}
|
|
75
|
+
|
|
76
|
+
def __init__(
|
|
77
|
+
self,
|
|
78
|
+
parent: tk.Widget,
|
|
79
|
+
tmgr: Any,
|
|
80
|
+
cfg: Any,
|
|
81
|
+
*,
|
|
82
|
+
root_dir: Path,
|
|
83
|
+
open_at: Callable[[str, int], None] | None = None,
|
|
84
|
+
on_status: Callable[[str], None] | None = None,
|
|
85
|
+
on_close: Callable[[], None] | None = None,
|
|
86
|
+
) -> None:
|
|
87
|
+
"""Monta a interface; chame :meth:`open_path` para carregar uma página."""
|
|
88
|
+
self._t = tmgr.theme
|
|
89
|
+
super().__init__(parent, bg=self._t.panel_bg, highlightthickness=1,
|
|
90
|
+
highlightbackground=self._t.border)
|
|
91
|
+
self._tmgr, self._cfg = tmgr, cfg
|
|
92
|
+
self._open_at, self._status, self._on_close = open_at, on_status, on_close
|
|
93
|
+
self._server = webdev.DevServer(
|
|
94
|
+
root_dir, md_renderer=lambda text, title: markdown_page(text, title, self._tmgr))
|
|
95
|
+
self._embed: we.EmbeddedAppPanel | None = None
|
|
96
|
+
self._cdp: webdev.CdpClient | None = None
|
|
97
|
+
self._profile: Path | None = None
|
|
98
|
+
self._events: queue.Queue[Any] = queue.Queue()
|
|
99
|
+
self._pump_job: str | None = None
|
|
100
|
+
self._closed = False
|
|
101
|
+
self._counts = {"error": 0, "warn": 0}
|
|
102
|
+
self._console_open = False
|
|
103
|
+
self._url_var = tk.StringVar()
|
|
104
|
+
self._current: Path | None = None
|
|
105
|
+
self._build()
|
|
106
|
+
self.bind("<Destroy>", self._on_destroy, add="+")
|
|
107
|
+
|
|
108
|
+
def _btn(self, parent: tk.Widget, text: str, cmd: Callable[[], None], tip: str = "") -> tk.Label:
|
|
109
|
+
t = self._t
|
|
110
|
+
b = tk.Label(parent, text=text, bg=t.input_bg, fg=t.fg, font=(FONT_UI, 10), cursor="hand2", padx=7, pady=2)
|
|
111
|
+
b.pack(side="left", padx=1)
|
|
112
|
+
b.bind("<Button-1>", lambda _e: cmd())
|
|
113
|
+
b.bind("<Enter>", lambda _e: b.config(bg=t.sel_bg))
|
|
114
|
+
b.bind("<Leave>", lambda _e: b.config(bg=t.input_bg))
|
|
115
|
+
return b
|
|
116
|
+
|
|
117
|
+
def _build(self) -> None:
|
|
118
|
+
t = self._t
|
|
119
|
+
bar = tk.Frame(self, bg=t.panel_bg)
|
|
120
|
+
bar.pack(fill="x", padx=4, pady=4)
|
|
121
|
+
self._btn(bar, "◀", lambda: self._cdp_do("back"))
|
|
122
|
+
self._btn(bar, "▶", lambda: self._cdp_do("forward"))
|
|
123
|
+
self._btn(bar, "↻", self.reload)
|
|
124
|
+
url = tk.Entry(bar, textvariable=self._url_var, bg=t.input_bg, fg=t.fg, relief="flat",
|
|
125
|
+
insertbackground=t.fg, font=(FONT_UI, 9))
|
|
126
|
+
url.pack(side="left", fill="x", expand=True, padx=6, ipady=3)
|
|
127
|
+
url.bind("<Return>", lambda _e: self._go(self._url_var.get()))
|
|
128
|
+
|
|
129
|
+
self._device_btn = tk.Menubutton(bar, text="📱", bg=t.input_bg, fg=t.fg, relief="flat",
|
|
130
|
+
font=(FONT_UI, 10), padx=6)
|
|
131
|
+
menu = tk.Menu(self._device_btn, tearoff=0, bg=t.floating_bg, fg=t.fg)
|
|
132
|
+
for name, preset in webdev.DEVICE_PRESETS.items():
|
|
133
|
+
menu.add_command(label=name, command=lambda p=preset, n=name: self._emulate(p, n))
|
|
134
|
+
self._device_btn.config(menu=menu)
|
|
135
|
+
self._device_btn.pack(side="left", padx=1)
|
|
136
|
+
|
|
137
|
+
self._console_btn = self._btn(bar, "⌨ 0", self.toggle_console)
|
|
138
|
+
self._btn(bar, "🌍", self.open_external)
|
|
139
|
+
for frac, label in ((0.35, "⅓"), (0.5, "½"), (0.7, "⅔"), (1.0, "⛶")):
|
|
140
|
+
self._btn(bar, label, lambda f=frac: self.set_split(f))
|
|
141
|
+
self._btn(bar, "✕", self.close)
|
|
142
|
+
|
|
143
|
+
self._stage = tk.Frame(self, bg=t.editor_bg)
|
|
144
|
+
self._stage.pack(fill="both", expand=True)
|
|
145
|
+
self._msg = tk.Label(self._stage, bg=t.editor_bg, fg=t.fg_muted, font=(FONT_UI, 10),
|
|
146
|
+
wraplength=420, justify="center")
|
|
147
|
+
|
|
148
|
+
self._console_frame = tk.Frame(self, bg=t.panel_bg, height=150)
|
|
149
|
+
self._console_frame.pack_propagate(False)
|
|
150
|
+
head = tk.Frame(self._console_frame, bg=t.panel_bg)
|
|
151
|
+
head.pack(fill="x")
|
|
152
|
+
tk.Label(head, text=_t("webpreview.console", "Console do navegador"), bg=t.panel_bg,
|
|
153
|
+
fg=t.fg_muted, font=(FONT_UI, 8, "bold")).pack(side="left", padx=6)
|
|
154
|
+
clear = tk.Label(head, text=_t("webpreview.clear", "limpar"), bg=t.panel_bg, fg=t.accent,
|
|
155
|
+
font=(FONT_UI, 8), cursor="hand2")
|
|
156
|
+
clear.pack(side="right", padx=6)
|
|
157
|
+
clear.bind("<Button-1>", lambda _e: self._clear_console())
|
|
158
|
+
self._console = tk.Text(self._console_frame, bg=t.editor_bg, fg=t.fg, font=(FONT_MONO, 9),
|
|
159
|
+
relief="flat", wrap="word", state="disabled", height=6)
|
|
160
|
+
sb = tk.Scrollbar(self._console_frame, command=self._console.yview)
|
|
161
|
+
self._console.configure(yscrollcommand=sb.set)
|
|
162
|
+
sb.pack(side="right", fill="y")
|
|
163
|
+
self._console.pack(fill="both", expand=True)
|
|
164
|
+
for lvl, fg in self._LEVEL_FG.items():
|
|
165
|
+
self._console.tag_configure(lvl, foreground=fg or t.fg)
|
|
166
|
+
self._console.tag_configure("link", underline=True)
|
|
167
|
+
self._console.tag_bind("link", "<Button-1>", self._click_console)
|
|
168
|
+
self._console.tag_bind("link", "<Enter>", lambda _e: self._console.config(cursor="hand2"))
|
|
169
|
+
self._console.tag_bind("link", "<Leave>", lambda _e: self._console.config(cursor=""))
|
|
170
|
+
self._links: dict[str, tuple[str, int]] = {}
|
|
171
|
+
|
|
172
|
+
def open_path(self, path: Path) -> bool:
|
|
173
|
+
"""Mostra ``path`` (HTML/MD/SVG). Inicia o navegador na primeira chamada.
|
|
174
|
+
|
|
175
|
+
Returns:
|
|
176
|
+
``True`` se há navegador embutido; ``False`` se caiu para o navegador externo.
|
|
177
|
+
"""
|
|
178
|
+
self._current = path
|
|
179
|
+
self._server.start()
|
|
180
|
+
url = self._server.url_for(path)
|
|
181
|
+
if url is None:
|
|
182
|
+
self._notify(_t("webpreview.outside", "Arquivo fora da pasta servida."))
|
|
183
|
+
return False
|
|
184
|
+
self._url_var.set(url)
|
|
185
|
+
if self._embed is not None and self._cdp is not None and self._cdp.connected:
|
|
186
|
+
self._cdp.navigate(url)
|
|
187
|
+
return True
|
|
188
|
+
if self._embed is not None:
|
|
189
|
+
return True
|
|
190
|
+
return self._launch(url)
|
|
191
|
+
|
|
192
|
+
def set_buffer(self, path: Path, text: str | None) -> None:
|
|
193
|
+
"""Entrega o texto não salvo do editor ao servidor (live reload sem salvar)."""
|
|
194
|
+
if webdev.is_previewable(path) or path.suffix.lower() in (".css", ".js", ".mjs", ".json"):
|
|
195
|
+
self._server.set_overlay(path, text)
|
|
196
|
+
|
|
197
|
+
def reload(self) -> None:
|
|
198
|
+
"""Recarrega a página (ignora cache)."""
|
|
199
|
+
if self._cdp is not None and self._cdp.connected:
|
|
200
|
+
self._cdp.reload()
|
|
201
|
+
elif self._current is not None:
|
|
202
|
+
self.open_path(self._current)
|
|
203
|
+
|
|
204
|
+
def open_external(self) -> None:
|
|
205
|
+
"""Abre a mesma URL no navegador padrão do sistema."""
|
|
206
|
+
url = self._url_var.get().strip() or (self._server.url_for(self._current) if self._current else None)
|
|
207
|
+
if url:
|
|
208
|
+
webbrowser.open(url)
|
|
209
|
+
|
|
210
|
+
def _go(self, text: str) -> None:
|
|
211
|
+
text = text.strip()
|
|
212
|
+
if not text:
|
|
213
|
+
return
|
|
214
|
+
p = Path(text.strip('"')).expanduser()
|
|
215
|
+
if "://" not in text and p.is_file():
|
|
216
|
+
self.open_path(p)
|
|
217
|
+
return
|
|
218
|
+
if "://" not in text:
|
|
219
|
+
text = "http://" + text
|
|
220
|
+
if self._cdp is not None and self._cdp.connected:
|
|
221
|
+
self._cdp.navigate(text)
|
|
222
|
+
|
|
223
|
+
def _cdp_do(self, what: str) -> None:
|
|
224
|
+
if self._cdp is not None and self._cdp.connected:
|
|
225
|
+
getattr(self._cdp, what)()
|
|
226
|
+
|
|
227
|
+
def _emulate(self, preset: tuple[int, int, float, bool] | None, name: str) -> None:
|
|
228
|
+
if self._cdp is not None and self._cdp.connected:
|
|
229
|
+
self._cdp.emulate(preset)
|
|
230
|
+
self._device_btn.config(text="📱" if preset is None else "📱•")
|
|
231
|
+
self._notify(name)
|
|
232
|
+
|
|
233
|
+
def _launch(self, url: str) -> bool:
|
|
234
|
+
browser = webdev.find_browser(self._cfg.get("web_browser_path", None) if self._cfg else None)
|
|
235
|
+
backend = we.get_backend() if browser else None
|
|
236
|
+
if browser is None or backend is None:
|
|
237
|
+
reason = (_t("webpreview.no_browser", "Nenhum navegador Chromium (Edge/Chrome/Brave) encontrado.")
|
|
238
|
+
if browser is None else
|
|
239
|
+
_t("webpreview.no_embed", "Este ambiente não permite incorporar janelas."))
|
|
240
|
+
self._show_message(reason + "\n" + _t("webpreview.external_fallback", "Abrindo no navegador padrão (com live reload)."))
|
|
241
|
+
webbrowser.open(url)
|
|
242
|
+
return False
|
|
243
|
+
|
|
244
|
+
self._profile = _PROFILE_ROOT / f"p{os.getpid()}"
|
|
245
|
+
shutil.rmtree(self._profile, ignore_errors=True)
|
|
246
|
+
self._profile.mkdir(parents=True, exist_ok=True)
|
|
247
|
+
argv = [
|
|
248
|
+
str(browser), f"--app={url}", f"--user-data-dir={self._profile}",
|
|
249
|
+
"--remote-debugging-port=0", "--no-first-run", "--no-default-browser-check",
|
|
250
|
+
"--disable-sync", "--disable-session-crashed-bubble", "--hide-crash-restore-bubble",
|
|
251
|
+
"--disable-features=Translate", "--window-size=900,700",
|
|
252
|
+
]
|
|
253
|
+
if sys.platform.startswith("linux") and hasattr(os, "geteuid") and os.geteuid() == 0:
|
|
254
|
+
argv.append("--no-sandbox")
|
|
255
|
+
extra = (self._cfg.get("web_extra_args", "") if self._cfg else "") or ""
|
|
256
|
+
if extra:
|
|
257
|
+
import shlex
|
|
258
|
+
|
|
259
|
+
with contextlib.suppress(ValueError):
|
|
260
|
+
argv += shlex.split(extra, posix=sys.platform != "win32")
|
|
261
|
+
|
|
262
|
+
self._embed = we.EmbeddedAppPanel(
|
|
263
|
+
self._stage, argv, backend=backend,
|
|
264
|
+
labels=we.EmbedLabels(
|
|
265
|
+
hint="", back="", focus="",
|
|
266
|
+
loading=_t("webpreview.loading", "Abrindo o navegador..."),
|
|
267
|
+
embedded=_t("webpreview.embedded", "Preview pronto. F12 abre o DevTools."),
|
|
268
|
+
closed=_t("webpreview.closed", "Preview fechado."),
|
|
269
|
+
err_exited=_t("webpreview.err_exited", "O navegador encerrou ao iniciar (código {code}). {log}"),
|
|
270
|
+
err_timeout=_t("webpreview.err_timeout", "O navegador não abriu a janela em {seconds} s."),
|
|
271
|
+
err_launch=_t("webpreview.err_launch", "Falha ao iniciar o navegador: {reason}"),
|
|
272
|
+
embed_failed=_t("webpreview.err_embed", "Não foi possível incorporar o navegador: {reason}"),
|
|
273
|
+
),
|
|
274
|
+
theme=we.EmbedTheme(bg=self._t.editor_bg, boot_fg=self._t.fg_muted),
|
|
275
|
+
cwd=str(self._profile), env=os.environ.copy(), window_timeout=30.0, show_bar=False,
|
|
276
|
+
on_status=self._notify, on_close=self.close,
|
|
277
|
+
)
|
|
278
|
+
self._embed.pack(fill="both", expand=True)
|
|
279
|
+
self._embed.start()
|
|
280
|
+
self._cdp = webdev.CdpClient(self._profile, self._events_put_console, self._events_put_nav)
|
|
281
|
+
self._cdp.connect_async()
|
|
282
|
+
self._pump()
|
|
283
|
+
return True
|
|
284
|
+
|
|
285
|
+
def _events_put_console(self, entry: webdev.ConsoleEntry) -> None:
|
|
286
|
+
self._events.put(("console", entry))
|
|
287
|
+
|
|
288
|
+
def _events_put_nav(self, url: str) -> None:
|
|
289
|
+
self._events.put(("nav", url))
|
|
290
|
+
|
|
291
|
+
def _pump(self) -> None:
|
|
292
|
+
self._pump_job = None
|
|
293
|
+
if self._closed:
|
|
294
|
+
return
|
|
295
|
+
with contextlib.suppress(queue.Empty):
|
|
296
|
+
while True:
|
|
297
|
+
kind, payload = self._events.get_nowait()
|
|
298
|
+
if kind == "console":
|
|
299
|
+
self._add_console(payload)
|
|
300
|
+
elif kind == "nav" and payload and not payload.startswith(("about:", "chrome-error:")):
|
|
301
|
+
self._url_var.set(payload)
|
|
302
|
+
with contextlib.suppress(tk.TclError):
|
|
303
|
+
self._pump_job = self.after(150, self._pump)
|
|
304
|
+
|
|
305
|
+
def toggle_console(self) -> None:
|
|
306
|
+
"""Mostra/esconde o console do navegador."""
|
|
307
|
+
self._console_open = not self._console_open
|
|
308
|
+
if self._console_open:
|
|
309
|
+
self._console_frame.pack(fill="x", side="bottom", before=self._stage)
|
|
310
|
+
else:
|
|
311
|
+
self._console_frame.pack_forget()
|
|
312
|
+
|
|
313
|
+
def _add_console(self, e: webdev.ConsoleEntry) -> None:
|
|
314
|
+
if e.level in self._counts:
|
|
315
|
+
self._counts[e.level] += 1
|
|
316
|
+
self._console_btn.config(text=f"⌨ ✖{self._counts['error']} ⚠{self._counts['warn']}")
|
|
317
|
+
c = self._console
|
|
318
|
+
c.config(state="normal")
|
|
319
|
+
c.insert("end", f"[{e.level}] ", e.level)
|
|
320
|
+
c.insert("end", e.text + "\n", e.level)
|
|
321
|
+
local = self._server.path_for_url(e.url) if e.url else None
|
|
322
|
+
if local is not None and e.line:
|
|
323
|
+
tag = f"lnk{len(self._links)}"
|
|
324
|
+
self._links[tag] = (str(local), e.line)
|
|
325
|
+
c.insert("end", f" {local.name}:{e.line}\n", ("link", tag))
|
|
326
|
+
c.see("end")
|
|
327
|
+
c.config(state="disabled")
|
|
328
|
+
if e.level == "error" and not self._console_open:
|
|
329
|
+
self.toggle_console()
|
|
330
|
+
|
|
331
|
+
def _click_console(self, event: tk.Event) -> None:
|
|
332
|
+
idx = self._console.index(f"@{event.x},{event.y}")
|
|
333
|
+
for tag in self._console.tag_names(idx):
|
|
334
|
+
if tag in self._links and self._open_at:
|
|
335
|
+
self._open_at(*self._links[tag])
|
|
336
|
+
return
|
|
337
|
+
|
|
338
|
+
def _clear_console(self) -> None:
|
|
339
|
+
self._console.config(state="normal")
|
|
340
|
+
self._console.delete("1.0", "end")
|
|
341
|
+
self._console.config(state="disabled")
|
|
342
|
+
self._counts = {"error": 0, "warn": 0}
|
|
343
|
+
self._links.clear()
|
|
344
|
+
self._console_btn.config(text="⌨ 0")
|
|
345
|
+
|
|
346
|
+
def set_split(self, frac: float) -> None:
|
|
347
|
+
"""Ocupa ``frac`` da largura do editor (a partir da direita)."""
|
|
348
|
+
frac = max(0.2, min(1.0, frac))
|
|
349
|
+
self.place(relx=1.0 - frac, rely=0.0, relwidth=frac, relheight=1.0)
|
|
350
|
+
self.lift()
|
|
351
|
+
|
|
352
|
+
def _show_message(self, text: str) -> None:
|
|
353
|
+
self._msg.config(text=text)
|
|
354
|
+
self._msg.place(relx=0.5, rely=0.5, anchor="center")
|
|
355
|
+
|
|
356
|
+
def _notify(self, msg: str) -> None:
|
|
357
|
+
if self._status is not None:
|
|
358
|
+
with contextlib.suppress(Exception):
|
|
359
|
+
self._status(msg)
|
|
360
|
+
|
|
361
|
+
def close(self) -> None:
|
|
362
|
+
"""Fecha navegador, servidor e painel (idempotente)."""
|
|
363
|
+
if self._closed:
|
|
364
|
+
return
|
|
365
|
+
self._closed = True
|
|
366
|
+
if self._pump_job is not None:
|
|
367
|
+
with contextlib.suppress(tk.TclError, ValueError):
|
|
368
|
+
self.after_cancel(self._pump_job)
|
|
369
|
+
if self._cdp is not None:
|
|
370
|
+
self._cdp.close()
|
|
371
|
+
embed, self._embed = self._embed, None
|
|
372
|
+
if embed is not None:
|
|
373
|
+
with contextlib.suppress(Exception):
|
|
374
|
+
embed.close()
|
|
375
|
+
self._server.stop()
|
|
376
|
+
top: tk.Misc | None = None
|
|
377
|
+
with contextlib.suppress(tk.TclError):
|
|
378
|
+
top = self.winfo_toplevel()
|
|
379
|
+
if self._profile is not None:
|
|
380
|
+
prof = self._profile
|
|
381
|
+
shutil.rmtree(prof, ignore_errors=True)
|
|
382
|
+
if top is not None:
|
|
383
|
+
with contextlib.suppress(tk.TclError):
|
|
384
|
+
top.after(3000, lambda: shutil.rmtree(prof, ignore_errors=True))
|
|
385
|
+
cb, self._on_close = self._on_close, None
|
|
386
|
+
with contextlib.suppress(tk.TclError):
|
|
387
|
+
self.destroy()
|
|
388
|
+
if cb is not None:
|
|
389
|
+
with contextlib.suppress(Exception):
|
|
390
|
+
cb()
|
|
391
|
+
|
|
392
|
+
def _on_destroy(self, event: tk.Event) -> None:
|
|
393
|
+
if event.widget is self and not self._closed:
|
|
394
|
+
self._closed = True
|
|
395
|
+
if self._cdp is not None:
|
|
396
|
+
self._cdp.close()
|
|
397
|
+
self._server.stop()
|