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/collab_panel.py
ADDED
|
@@ -0,0 +1,1009 @@
|
|
|
1
|
+
"""Codis - Painel de Colaboração em Tempo Real.
|
|
2
|
+
|
|
3
|
+
Edição colaborativa estilo Live Share: hospede uma sala (servidor embutido,
|
|
4
|
+
WebSocket) ou entre numa sala de outra pessoa. A interface é só este painel;
|
|
5
|
+
toda a lógica vive em :mod:`src.collab`:
|
|
6
|
+
|
|
7
|
+
* ``ot`` - transformação operacional (convergência provada por fuzz)
|
|
8
|
+
* ``net`` - servidor/cliente WebSocket com ACK e fila de eventos
|
|
9
|
+
* ``session`` - captura de edições locais + integração das remotas
|
|
10
|
+
* ``tk_adapter`` - aplicação incremental no ``tk.Text`` (cursor preservado)
|
|
11
|
+
|
|
12
|
+
Pontos de projeto:
|
|
13
|
+
* A sala só é criada pelo host; senha obrigatória (gerada se em branco).
|
|
14
|
+
* O painel fica **preso ao editor** escolhido ao hospedar/entrar; trocar de
|
|
15
|
+
aba não mistura arquivos. Ao entrar numa sala abre-se uma aba nova.
|
|
16
|
+
* Nenhum callback de rede toca o Tk: tudo passa por uma fila drenada pela
|
|
17
|
+
thread de interface a cada ~50 ms.
|
|
18
|
+
|
|
19
|
+
Dependência opcional: ``pip install websockets``.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import contextlib
|
|
25
|
+
import gc
|
|
26
|
+
import logging
|
|
27
|
+
import secrets
|
|
28
|
+
import socket
|
|
29
|
+
import time
|
|
30
|
+
import tkinter as tk
|
|
31
|
+
from collections.abc import Callable
|
|
32
|
+
from tkinter import messagebox, ttk
|
|
33
|
+
from typing import Any
|
|
34
|
+
|
|
35
|
+
from src.collab.net import (
|
|
36
|
+
DEFAULT_PORT as _DEFAULT_PORT,
|
|
37
|
+
)
|
|
38
|
+
from src.collab.net import (
|
|
39
|
+
HAS_WS as _HAS_WS,
|
|
40
|
+
)
|
|
41
|
+
from src.collab.net import (
|
|
42
|
+
CollabClient,
|
|
43
|
+
CollabServer,
|
|
44
|
+
)
|
|
45
|
+
from src.collab.net import (
|
|
46
|
+
peer_color as _peer_color,
|
|
47
|
+
)
|
|
48
|
+
from src.collab.ot import TextOp
|
|
49
|
+
from src.collab.ot import apply_op as _apply_op
|
|
50
|
+
from src.collab.session import CollabSession
|
|
51
|
+
from src.collab.tk_adapter import TkTextAdapter
|
|
52
|
+
from src.constants import FONT_MONO, FONT_UI
|
|
53
|
+
from src.i18n import _t
|
|
54
|
+
from src.ui.grab_safe import safe_grab_set
|
|
55
|
+
|
|
56
|
+
__all__ = ["CollabClient", "CollabPanel", "CollabServer", "TextOp", "_apply_op"]
|
|
57
|
+
|
|
58
|
+
logger = logging.getLogger("Codis.Collab")
|
|
59
|
+
|
|
60
|
+
_TICK_MS = 50
|
|
61
|
+
_CURSOR_SEND_MS = 150
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _lan_ip() -> str:
|
|
65
|
+
"""IP local usado para sair da máquina (sem enviar nada pela rede)."""
|
|
66
|
+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
67
|
+
try:
|
|
68
|
+
sock.connect(("10.255.255.255", 1))
|
|
69
|
+
return sock.getsockname()[0]
|
|
70
|
+
except OSError:
|
|
71
|
+
return "127.0.0.1"
|
|
72
|
+
finally:
|
|
73
|
+
sock.close()
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class _CursorOverlay:
|
|
77
|
+
"""Caret colorido + etiqueta com o nome de cada participante no editor."""
|
|
78
|
+
|
|
79
|
+
def __init__(self, text_widget: tk.Text) -> None:
|
|
80
|
+
self._tw = text_widget
|
|
81
|
+
self._tags: dict[str, str] = {}
|
|
82
|
+
self._pos: dict[str, tuple[int, int]] = {}
|
|
83
|
+
self._labels: dict[str, tk.Label] = {}
|
|
84
|
+
self._colors: dict[str, str] = {}
|
|
85
|
+
|
|
86
|
+
def update(self, user: str, color: str, line: int, col: int) -> None:
|
|
87
|
+
"""Registra a posição do cursor de ``user`` e o redesenha."""
|
|
88
|
+
self._pos[user] = (line, col)
|
|
89
|
+
self._colors[user] = color
|
|
90
|
+
self._draw(user)
|
|
91
|
+
|
|
92
|
+
def _draw(self, user: str) -> None:
|
|
93
|
+
tw = self._tw
|
|
94
|
+
line, col = self._pos[user]
|
|
95
|
+
tag = self._tags.setdefault(user, "collab_cursor_" + "".join(
|
|
96
|
+
c if c.isalnum() else "_" for c in user))
|
|
97
|
+
with contextlib.suppress(tk.TclError):
|
|
98
|
+
tw.tag_remove(tag, "1.0", "end")
|
|
99
|
+
idx = tw.index(f"{line + 1}.{col}")
|
|
100
|
+
if tw.get(idx) not in ("", "\n"):
|
|
101
|
+
tw.tag_add(tag, idx, f"{idx}+1c")
|
|
102
|
+
tw.tag_config(tag, background=self._colors[user], foreground="#000000")
|
|
103
|
+
tw.tag_raise(tag)
|
|
104
|
+
self._place_label(user)
|
|
105
|
+
|
|
106
|
+
def _place_label(self, user: str) -> None:
|
|
107
|
+
tw = self._tw
|
|
108
|
+
line, col = self._pos[user]
|
|
109
|
+
label = self._labels.get(user)
|
|
110
|
+
try:
|
|
111
|
+
box = tw.bbox(tw.index(f"{line + 1}.{col}"))
|
|
112
|
+
except tk.TclError:
|
|
113
|
+
box = None
|
|
114
|
+
if not box:
|
|
115
|
+
if label is not None:
|
|
116
|
+
label.place_forget()
|
|
117
|
+
return
|
|
118
|
+
if label is None:
|
|
119
|
+
label = tk.Label(tw, text=user, font=(FONT_UI, 7, "bold"), padx=3, pady=0, bd=0)
|
|
120
|
+
self._labels[user] = label
|
|
121
|
+
label.configure(bg=self._colors[user], fg="#000000")
|
|
122
|
+
x, y, _w, h = box
|
|
123
|
+
label.place(x=x, y=max(0, y - h + 2))
|
|
124
|
+
|
|
125
|
+
def refresh(self) -> None:
|
|
126
|
+
"""Reposiciona as etiquetas (rolagem/edição moveram o texto)."""
|
|
127
|
+
for user in list(self._pos):
|
|
128
|
+
self._place_label(user)
|
|
129
|
+
|
|
130
|
+
def remove(self, user: str) -> None:
|
|
131
|
+
"""Remove o cursor de ``user``."""
|
|
132
|
+
self._pos.pop(user, None)
|
|
133
|
+
self._colors.pop(user, None)
|
|
134
|
+
tag = self._tags.pop(user, None)
|
|
135
|
+
label = self._labels.pop(user, None)
|
|
136
|
+
with contextlib.suppress(tk.TclError):
|
|
137
|
+
if tag:
|
|
138
|
+
self._tw.tag_remove(tag, "1.0", "end")
|
|
139
|
+
self._tw.tag_delete(tag)
|
|
140
|
+
if label is not None:
|
|
141
|
+
label.destroy()
|
|
142
|
+
|
|
143
|
+
def clear(self) -> None:
|
|
144
|
+
"""Remove todos os cursores."""
|
|
145
|
+
for user in list(self._pos):
|
|
146
|
+
self.remove(user)
|
|
147
|
+
|
|
148
|
+
@property
|
|
149
|
+
def widget(self) -> tk.Text:
|
|
150
|
+
"""O editor sobre o qual o overlay desenha."""
|
|
151
|
+
return self._tw
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class CollabPanel(tk.Frame):
|
|
155
|
+
"""Painel de colaboração em tempo real do Codis.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
get_editor_widget: devolve o ``tk.Text`` do editor ativo (usado ao
|
|
159
|
+
hospedar e como alvo quando ``new_editor`` não é fornecido).
|
|
160
|
+
new_editor: cria uma aba nova e devolve seu ``tk.Text``; usado ao
|
|
161
|
+
entrar numa sala para não sobrescrever o arquivo aberto.
|
|
162
|
+
"""
|
|
163
|
+
|
|
164
|
+
def __init__(
|
|
165
|
+
self,
|
|
166
|
+
parent: tk.Widget,
|
|
167
|
+
tmgr: Any,
|
|
168
|
+
cfg: Any,
|
|
169
|
+
get_editor_widget: Callable[[], tk.Text | None] | None = None,
|
|
170
|
+
new_editor: Callable[[], tk.Text | None] | None = None,
|
|
171
|
+
) -> None:
|
|
172
|
+
t = tmgr.theme
|
|
173
|
+
super().__init__(parent, bg=t.sidebar_bg)
|
|
174
|
+
self._tmgr = tmgr
|
|
175
|
+
self._cfg = cfg
|
|
176
|
+
self._get_editor = get_editor_widget or (lambda: None)
|
|
177
|
+
self._new_editor = new_editor
|
|
178
|
+
|
|
179
|
+
self._server: CollabServer | None = None
|
|
180
|
+
self._client: CollabClient | None = None
|
|
181
|
+
self._session: CollabSession | None = None
|
|
182
|
+
self._adapter: TkTextAdapter | None = None
|
|
183
|
+
self._overlay: _CursorOverlay | None = None
|
|
184
|
+
self._peers: list[dict] = []
|
|
185
|
+
self._chat_history: list[tuple[str, str, str]] = []
|
|
186
|
+
self._hosting = False
|
|
187
|
+
self._room_id = ""
|
|
188
|
+
self._invite = ""
|
|
189
|
+
self._tick_job: str | None = None
|
|
190
|
+
self._last_cursor: tuple[int, int] | None = None
|
|
191
|
+
self._last_cursor_sent = 0.0
|
|
192
|
+
self._last_status_user_ts = 0.0
|
|
193
|
+
self._user: str = (cfg.get("collab_username", "") if cfg else "") or _default_user()
|
|
194
|
+
|
|
195
|
+
self._build_ui(t)
|
|
196
|
+
port_cfg = self._cfg.get("collab_port", _DEFAULT_PORT) if self._cfg else _DEFAULT_PORT
|
|
197
|
+
if isinstance(port_cfg, int) and 1 <= port_cfg <= 65535:
|
|
198
|
+
self._port_var.set(str(port_cfg))
|
|
199
|
+
self._join_port_var.set(str(port_cfg))
|
|
200
|
+
self.bind("<Destroy>", self._on_destroy, add="+")
|
|
201
|
+
|
|
202
|
+
def _on_destroy(self, event: tk.Event) -> None:
|
|
203
|
+
if event.widget is not self:
|
|
204
|
+
return
|
|
205
|
+
self._teardown(notify=False)
|
|
206
|
+
if self._server:
|
|
207
|
+
self._server.stop()
|
|
208
|
+
self._server = None
|
|
209
|
+
gc.collect()
|
|
210
|
+
|
|
211
|
+
def disconnect(self) -> None:
|
|
212
|
+
"""Encerra a sessão (compatível com o gerenciador de processos)."""
|
|
213
|
+
self._on_leave()
|
|
214
|
+
|
|
215
|
+
def _teardown(self, notify: bool = True) -> None:
|
|
216
|
+
self._stop_tick()
|
|
217
|
+
if self._session is not None:
|
|
218
|
+
self._session.close()
|
|
219
|
+
self._session = None
|
|
220
|
+
self._client = None
|
|
221
|
+
self._adapter = None
|
|
222
|
+
if self._overlay is not None:
|
|
223
|
+
self._overlay.clear()
|
|
224
|
+
self._overlay = None
|
|
225
|
+
self._last_cursor = None
|
|
226
|
+
if notify:
|
|
227
|
+
self._peers = []
|
|
228
|
+
self._refresh_peers_ui()
|
|
229
|
+
|
|
230
|
+
def _start_tick(self) -> None:
|
|
231
|
+
self._stop_tick()
|
|
232
|
+
self._tick_job = self.after(_TICK_MS, self._tick)
|
|
233
|
+
|
|
234
|
+
def _stop_tick(self) -> None:
|
|
235
|
+
if self._tick_job is not None:
|
|
236
|
+
with contextlib.suppress(tk.TclError, ValueError):
|
|
237
|
+
self.after_cancel(self._tick_job)
|
|
238
|
+
self._tick_job = None
|
|
239
|
+
|
|
240
|
+
def _tick(self) -> None:
|
|
241
|
+
self._tick_job = None
|
|
242
|
+
session = self._session
|
|
243
|
+
if session is None:
|
|
244
|
+
return
|
|
245
|
+
try:
|
|
246
|
+
if self._adapter is not None and not self._adapter.alive():
|
|
247
|
+
self._set_status(_t("collab.editor_closed",
|
|
248
|
+
"A aba compartilhada foi fechada. Sessão encerrada."),
|
|
249
|
+
online=False)
|
|
250
|
+
self._on_leave(status=False)
|
|
251
|
+
return
|
|
252
|
+
session.tick()
|
|
253
|
+
self._send_cursor_if_changed()
|
|
254
|
+
if self._overlay is not None:
|
|
255
|
+
self._overlay.refresh()
|
|
256
|
+
except tk.TclError:
|
|
257
|
+
return
|
|
258
|
+
except Exception:
|
|
259
|
+
logger.exception("Falha no ciclo de sincronização do colab")
|
|
260
|
+
if self._session is session and self.winfo_exists():
|
|
261
|
+
self._tick_job = self.after(_TICK_MS, self._tick)
|
|
262
|
+
|
|
263
|
+
def _send_cursor_if_changed(self) -> None:
|
|
264
|
+
if not (self._adapter and self._client and self._session and self._session.synced):
|
|
265
|
+
return
|
|
266
|
+
now = time.monotonic()
|
|
267
|
+
if (now - self._last_cursor_sent) * 1000 < _CURSOR_SEND_MS:
|
|
268
|
+
return
|
|
269
|
+
try:
|
|
270
|
+
line_s, col_s = self._adapter.widget.index("insert").split(".", 1)
|
|
271
|
+
cur = (int(line_s) - 1, int(col_s))
|
|
272
|
+
except (tk.TclError, ValueError):
|
|
273
|
+
return
|
|
274
|
+
if cur != self._last_cursor:
|
|
275
|
+
self._last_cursor = cur
|
|
276
|
+
self._last_cursor_sent = now
|
|
277
|
+
self._client.send({"type": "cursor", "line": cur[0], "col": cur[1]})
|
|
278
|
+
|
|
279
|
+
def _on_session_event(self, ev: dict) -> None:
|
|
280
|
+
kind = ev.get("type")
|
|
281
|
+
if kind == "connected":
|
|
282
|
+
self._set_status(_t("collab.connected", "Conectado. Sincronizando…"), online=True)
|
|
283
|
+
elif kind == "synced":
|
|
284
|
+
self._on_synced(ev)
|
|
285
|
+
elif kind == "remote_op":
|
|
286
|
+
self._on_remote_edit(str(ev.get("user", "?")))
|
|
287
|
+
elif kind == "cursor":
|
|
288
|
+
self._on_cursor(ev)
|
|
289
|
+
elif kind == "chat":
|
|
290
|
+
self._chat_history.append((str(ev.get("ts", "")), str(ev.get("user", "?")),
|
|
291
|
+
str(ev.get("msg", ""))))
|
|
292
|
+
self._refresh_chat()
|
|
293
|
+
elif kind == "peers":
|
|
294
|
+
self._on_peers(ev.get("users", []))
|
|
295
|
+
elif kind == "error":
|
|
296
|
+
self._on_error(str(ev.get("msg", "erro")))
|
|
297
|
+
elif kind == "closed":
|
|
298
|
+
self._on_closed(str(ev.get("msg", "")), bool(ev.get("clean", True)))
|
|
299
|
+
|
|
300
|
+
def _on_synced(self, ev: dict) -> None:
|
|
301
|
+
count = len(self._peers)
|
|
302
|
+
text = _t("collab.synced", "Sincronizado - sala {rid}", rid=self._room_id)
|
|
303
|
+
if count:
|
|
304
|
+
text += f" · {count}"
|
|
305
|
+
if ev.get("resync"):
|
|
306
|
+
text = _t("collab.resynced",
|
|
307
|
+
"Documento ressincronizado com o servidor (edições pendentes descartadas).")
|
|
308
|
+
self._set_status(text, online=True)
|
|
309
|
+
|
|
310
|
+
def _on_remote_edit(self, user: str) -> None:
|
|
311
|
+
now = time.monotonic()
|
|
312
|
+
if now - self._last_status_user_ts > 0.5:
|
|
313
|
+
self._last_status_user_ts = now
|
|
314
|
+
self._set_status(_t("collab.editing", "{user} está editando...", user=user),
|
|
315
|
+
online=True)
|
|
316
|
+
|
|
317
|
+
def _on_cursor(self, ev: dict) -> None:
|
|
318
|
+
if self._adapter is None or not self._adapter.alive():
|
|
319
|
+
return
|
|
320
|
+
user = str(ev.get("user", "?"))
|
|
321
|
+
if user == self._user or not (self._cfg.get("collab_show_cursors", True) if self._cfg else True):
|
|
322
|
+
return
|
|
323
|
+
if self._overlay is None or self._overlay.widget is not self._adapter.widget:
|
|
324
|
+
self._overlay = _CursorOverlay(self._adapter.widget)
|
|
325
|
+
with contextlib.suppress(TypeError, ValueError):
|
|
326
|
+
self._overlay.update(user, str(ev.get("color", "#ffffff")),
|
|
327
|
+
int(ev.get("line", 0)), int(ev.get("col", 0)))
|
|
328
|
+
|
|
329
|
+
def _on_peers(self, users: list) -> None:
|
|
330
|
+
previous = {p.get("user") for p in self._peers}
|
|
331
|
+
self._peers = [u for u in users if isinstance(u, dict)]
|
|
332
|
+
current = {p.get("user") for p in self._peers}
|
|
333
|
+
stamp = time.strftime("%H:%M:%S")
|
|
334
|
+
for name in sorted(current - previous - {self._user}):
|
|
335
|
+
self._chat_history.append((stamp, "->", f"{name} entrou"))
|
|
336
|
+
for name in sorted(previous - current - {self._user}):
|
|
337
|
+
self._chat_history.append((stamp, "<-", f"{name} saiu"))
|
|
338
|
+
if self._overlay is not None:
|
|
339
|
+
self._overlay.remove(str(name))
|
|
340
|
+
if (current - previous) or (previous - current):
|
|
341
|
+
self._refresh_chat()
|
|
342
|
+
self._refresh_peers_ui()
|
|
343
|
+
|
|
344
|
+
def _on_error(self, msg: str) -> None:
|
|
345
|
+
messagebox.showerror(_t("collab.connect_err", "Erro de conexão"), msg, parent=self)
|
|
346
|
+
self._teardown()
|
|
347
|
+
self._set_status(msg, online=False)
|
|
348
|
+
self._reset_buttons()
|
|
349
|
+
|
|
350
|
+
def _on_closed(self, msg: str, clean: bool) -> None:
|
|
351
|
+
if self._session is None:
|
|
352
|
+
return
|
|
353
|
+
self._teardown()
|
|
354
|
+
self._set_status(
|
|
355
|
+
msg or _t("collab.left", "Sessão encerrada."), online=False)
|
|
356
|
+
self._reset_buttons()
|
|
357
|
+
if not clean and self._hosting:
|
|
358
|
+
self._hosting = False
|
|
359
|
+
self._host_btn.config(state="normal")
|
|
360
|
+
self._stop_btn.config(state="disabled")
|
|
361
|
+
|
|
362
|
+
def _reset_buttons(self) -> None:
|
|
363
|
+
self._join_btn.config(state="normal")
|
|
364
|
+
self._leave_btn.config(state="disabled")
|
|
365
|
+
|
|
366
|
+
def _current_editor(self) -> tk.Text | None:
|
|
367
|
+
try:
|
|
368
|
+
editor = self._get_editor()
|
|
369
|
+
except Exception:
|
|
370
|
+
logger.debug("get_editor_widget falhou", exc_info=True)
|
|
371
|
+
return None
|
|
372
|
+
return editor if isinstance(editor, tk.Text) else None
|
|
373
|
+
|
|
374
|
+
def _on_host(self) -> None:
|
|
375
|
+
if not _HAS_WS:
|
|
376
|
+
self._show_ws_warning()
|
|
377
|
+
return
|
|
378
|
+
editor = self._current_editor()
|
|
379
|
+
if editor is None:
|
|
380
|
+
messagebox.showwarning(
|
|
381
|
+
_t("collab.title", "Colaboração"),
|
|
382
|
+
_t("collab.no_editor", "Abra um arquivo (ou crie uma aba) para compartilhar."),
|
|
383
|
+
parent=self)
|
|
384
|
+
return
|
|
385
|
+
user = self._user_var.get().strip() or "Host"
|
|
386
|
+
self._user = user
|
|
387
|
+
try:
|
|
388
|
+
port = int(self._port_var.get())
|
|
389
|
+
if not 1 <= port <= 65535:
|
|
390
|
+
raise ValueError
|
|
391
|
+
except ValueError:
|
|
392
|
+
messagebox.showwarning(_t("collab.title", "Colaboração"),
|
|
393
|
+
_t("collab.bad_port", "Porta inválida (1-65535)."), parent=self)
|
|
394
|
+
return
|
|
395
|
+
password = self._host_pass_var.get().strip()
|
|
396
|
+
if not password:
|
|
397
|
+
password = secrets.token_urlsafe(6)
|
|
398
|
+
self._host_pass_var.set(password)
|
|
399
|
+
|
|
400
|
+
max_peers = self._cfg.get("collab_max_peers", 8) if self._cfg else 8
|
|
401
|
+
server = CollabServer(
|
|
402
|
+
host="0.0.0.0", port=port,
|
|
403
|
+
max_peers=max_peers if isinstance(max_peers, int) else 8)
|
|
404
|
+
ok, msg = server.start()
|
|
405
|
+
if not ok:
|
|
406
|
+
messagebox.showerror(_t("collab.host_err", "Erro ao hospedar"), msg, parent=self)
|
|
407
|
+
return
|
|
408
|
+
self._server = server
|
|
409
|
+
adapter = TkTextAdapter(editor)
|
|
410
|
+
self._room_id = server.create_room(password=password, initial_content=adapter.get_text())
|
|
411
|
+
self._hosting = True
|
|
412
|
+
ip = _lan_ip()
|
|
413
|
+
self._invite = (f"Codis Colab\nHost: {ip}\nPorta: {port}\n"
|
|
414
|
+
f"Sala: {self._room_id}\nSenha: {password}")
|
|
415
|
+
self._room_info_var.set(
|
|
416
|
+
_t("collab.room_info", "Sala: {rid} Porta: {port}\nHost: {ip} Senha: {pwd}",
|
|
417
|
+
rid=self._room_id, port=port, ip=ip, pwd=password))
|
|
418
|
+
self._host_btn.config(state="disabled")
|
|
419
|
+
self._stop_btn.config(state="normal")
|
|
420
|
+
self._set_status(_t("collab.hosting", "Hospedando sala {rid}", rid=self._room_id),
|
|
421
|
+
online=True)
|
|
422
|
+
self._start_session("127.0.0.1", port, self._room_id, user, password, adapter)
|
|
423
|
+
|
|
424
|
+
def _on_stop_host(self) -> None:
|
|
425
|
+
self._teardown()
|
|
426
|
+
if self._server:
|
|
427
|
+
self._server.stop()
|
|
428
|
+
self._server = None
|
|
429
|
+
self._hosting = False
|
|
430
|
+
self._room_id = ""
|
|
431
|
+
self._invite = ""
|
|
432
|
+
self._room_info_var.set("")
|
|
433
|
+
self._host_btn.config(state="normal")
|
|
434
|
+
self._stop_btn.config(state="disabled")
|
|
435
|
+
self._reset_buttons()
|
|
436
|
+
self._set_status(_t("collab.left", "Sessão encerrada."), online=False)
|
|
437
|
+
|
|
438
|
+
def _on_join(self) -> None:
|
|
439
|
+
if not _HAS_WS:
|
|
440
|
+
self._show_ws_warning()
|
|
441
|
+
return
|
|
442
|
+
user = self._user_var.get().strip() or "Guest"
|
|
443
|
+
self._user = user
|
|
444
|
+
host = self._join_host_var.get().strip() or "127.0.0.1"
|
|
445
|
+
try:
|
|
446
|
+
port = int(self._join_port_var.get())
|
|
447
|
+
if not 1 <= port <= 65535:
|
|
448
|
+
raise ValueError
|
|
449
|
+
except ValueError:
|
|
450
|
+
messagebox.showwarning(_t("collab.title", "Colaboração"),
|
|
451
|
+
_t("collab.bad_port", "Porta inválida (1-65535)."), parent=self)
|
|
452
|
+
return
|
|
453
|
+
room = self._join_room_var.get().strip()
|
|
454
|
+
if not room:
|
|
455
|
+
messagebox.showwarning(_t("collab.missing_title", "Campo obrigatório"),
|
|
456
|
+
_t("collab.missing_room", "Informe o ID da sala."), parent=self)
|
|
457
|
+
return
|
|
458
|
+
editor = self._new_editor() if self._new_editor else self._current_editor()
|
|
459
|
+
if editor is None:
|
|
460
|
+
messagebox.showwarning(
|
|
461
|
+
_t("collab.title", "Colaboração"),
|
|
462
|
+
_t("collab.no_editor", "Abra um arquivo (ou crie uma aba) para compartilhar."),
|
|
463
|
+
parent=self)
|
|
464
|
+
return
|
|
465
|
+
if not self._new_editor and editor.get("1.0", "end-1c").strip():
|
|
466
|
+
if not messagebox.askyesno(
|
|
467
|
+
_t("collab.title", "Colaboração"),
|
|
468
|
+
_t("collab.replace_warn",
|
|
469
|
+
"Entrar na sala substituirá o conteúdo da aba atual.\nContinuar?"),
|
|
470
|
+
parent=self,
|
|
471
|
+
):
|
|
472
|
+
return
|
|
473
|
+
self._start_session(host, port, room, user, self._join_pass_var.get(),
|
|
474
|
+
TkTextAdapter(editor))
|
|
475
|
+
|
|
476
|
+
def _start_session(self, host: str, port: int, room: str, user: str, password: str,
|
|
477
|
+
adapter: TkTextAdapter) -> None:
|
|
478
|
+
self._teardown(notify=False)
|
|
479
|
+
self._room_id = room
|
|
480
|
+
self._adapter = adapter
|
|
481
|
+
self._client = CollabClient(host, port, room, user, password)
|
|
482
|
+
self._session = CollabSession(self._client, adapter, self._on_session_event)
|
|
483
|
+
self._client.connect()
|
|
484
|
+
self._join_btn.config(state="disabled")
|
|
485
|
+
self._leave_btn.config(state="normal")
|
|
486
|
+
self._set_status(_t("collab.connecting", "Conectando a {host}:{port} sala {room}...",
|
|
487
|
+
host=host, port=port, room=room))
|
|
488
|
+
self._start_tick()
|
|
489
|
+
|
|
490
|
+
def _on_leave(self, status: bool = True) -> None:
|
|
491
|
+
"""Sai da sala; se for o host, também encerra o servidor."""
|
|
492
|
+
if self._hosting:
|
|
493
|
+
self._on_stop_host()
|
|
494
|
+
return
|
|
495
|
+
self._teardown()
|
|
496
|
+
self._reset_buttons()
|
|
497
|
+
if status:
|
|
498
|
+
self._set_status(_t("collab.left", "Sessão encerrada."), online=False)
|
|
499
|
+
|
|
500
|
+
def _on_chat_send(self, _event: tk.Event | None = None) -> None:
|
|
501
|
+
msg = self._chat_var.get().strip()
|
|
502
|
+
if not msg or not self._client or not self._client.connected:
|
|
503
|
+
return
|
|
504
|
+
self._client.send({"type": "chat", "msg": msg})
|
|
505
|
+
self._chat_var.set("")
|
|
506
|
+
|
|
507
|
+
def _build_ui(self, t: Any) -> None:
|
|
508
|
+
hdr = tk.Frame(self, bg=t.activity_bg, height=48)
|
|
509
|
+
hdr.pack(fill="x")
|
|
510
|
+
hdr.pack_propagate(False)
|
|
511
|
+
tk.Label(
|
|
512
|
+
hdr, text="🤝", bg=t.activity_bg, fg=t.accent, font=(FONT_UI, 16)
|
|
513
|
+
).pack(side="left", padx=(14, 4), pady=8)
|
|
514
|
+
tk.Label(
|
|
515
|
+
hdr,
|
|
516
|
+
text=_t("collab.title", "Colaboração"),
|
|
517
|
+
bg=t.activity_bg,
|
|
518
|
+
fg=t.fg,
|
|
519
|
+
font=(FONT_UI, 13, "bold"),
|
|
520
|
+
).pack(side="left", pady=8)
|
|
521
|
+
self._status_badge = tk.Label(
|
|
522
|
+
hdr,
|
|
523
|
+
text=_t("collab.status_offline", "● offline"),
|
|
524
|
+
bg=t.activity_bg,
|
|
525
|
+
fg=t.fg_muted,
|
|
526
|
+
font=(FONT_UI, 8),
|
|
527
|
+
)
|
|
528
|
+
self._status_badge.pack(side="right", padx=12, pady=8)
|
|
529
|
+
tk.Frame(self, bg=t.border, height=1).pack(fill="x")
|
|
530
|
+
|
|
531
|
+
id_row = tk.Frame(self, bg=t.panel_bg)
|
|
532
|
+
id_row.pack(fill="x", padx=10, pady=(10, 4))
|
|
533
|
+
tk.Label(
|
|
534
|
+
id_row,
|
|
535
|
+
text=_t("collab.your_name", "Seu nome:"),
|
|
536
|
+
bg=t.panel_bg,
|
|
537
|
+
fg=t.fg_muted,
|
|
538
|
+
font=(FONT_UI, 9),
|
|
539
|
+
).pack(side="left")
|
|
540
|
+
self._user_var = tk.StringVar(value=self._user)
|
|
541
|
+
user_entry = tk.Entry(
|
|
542
|
+
id_row,
|
|
543
|
+
textvariable=self._user_var,
|
|
544
|
+
bg=t.editor_bg,
|
|
545
|
+
fg=t.fg,
|
|
546
|
+
insertbackground=t.cursor,
|
|
547
|
+
relief="flat",
|
|
548
|
+
font=(FONT_MONO, 9),
|
|
549
|
+
width=18,
|
|
550
|
+
bd=4,
|
|
551
|
+
)
|
|
552
|
+
user_entry.pack(side="left", padx=6)
|
|
553
|
+
|
|
554
|
+
host_box = tk.LabelFrame(
|
|
555
|
+
self,
|
|
556
|
+
text=_t("collab.host_section", "🖥 Hospedar Sessão"),
|
|
557
|
+
bg=t.panel_bg,
|
|
558
|
+
fg=t.fg,
|
|
559
|
+
font=(FONT_UI, 9, "bold"),
|
|
560
|
+
padx=8,
|
|
561
|
+
pady=6,
|
|
562
|
+
)
|
|
563
|
+
host_box.pack(fill="x", padx=10, pady=4)
|
|
564
|
+
|
|
565
|
+
h1 = tk.Frame(host_box, bg=t.panel_bg)
|
|
566
|
+
h1.pack(fill="x", pady=2)
|
|
567
|
+
tk.Label(
|
|
568
|
+
h1,
|
|
569
|
+
text=_t("collab.f_port", "Porta:"),
|
|
570
|
+
bg=t.panel_bg,
|
|
571
|
+
fg=t.fg_muted,
|
|
572
|
+
font=(FONT_UI, 9),
|
|
573
|
+
width=10,
|
|
574
|
+
).pack(side="left")
|
|
575
|
+
self._port_var = tk.StringVar(value=str(_DEFAULT_PORT))
|
|
576
|
+
tk.Entry(
|
|
577
|
+
h1,
|
|
578
|
+
textvariable=self._port_var,
|
|
579
|
+
bg=t.editor_bg,
|
|
580
|
+
fg=t.fg,
|
|
581
|
+
insertbackground=t.cursor,
|
|
582
|
+
relief="flat",
|
|
583
|
+
font=(FONT_MONO, 9),
|
|
584
|
+
width=8,
|
|
585
|
+
bd=4,
|
|
586
|
+
).pack(side="left", padx=4)
|
|
587
|
+
|
|
588
|
+
h2 = tk.Frame(host_box, bg=t.panel_bg)
|
|
589
|
+
h2.pack(fill="x", pady=2)
|
|
590
|
+
tk.Label(
|
|
591
|
+
h2,
|
|
592
|
+
text=_t("collab.f_room_pass", "Password:"),
|
|
593
|
+
bg=t.panel_bg,
|
|
594
|
+
fg=t.fg_muted,
|
|
595
|
+
font=(FONT_UI, 9),
|
|
596
|
+
width=10,
|
|
597
|
+
).pack(side="left")
|
|
598
|
+
self._host_pass_var = tk.StringVar()
|
|
599
|
+
tk.Entry(
|
|
600
|
+
h2,
|
|
601
|
+
textvariable=self._host_pass_var,
|
|
602
|
+
bg=t.editor_bg,
|
|
603
|
+
fg=t.fg,
|
|
604
|
+
insertbackground=t.cursor,
|
|
605
|
+
relief="flat",
|
|
606
|
+
show="*",
|
|
607
|
+
font=(FONT_MONO, 9),
|
|
608
|
+
width=18,
|
|
609
|
+
bd=4,
|
|
610
|
+
).pack(side="left", padx=4)
|
|
611
|
+
|
|
612
|
+
hb = tk.Frame(host_box, bg=t.panel_bg)
|
|
613
|
+
hb.pack(fill="x", pady=(4, 0))
|
|
614
|
+
self._host_btn = self._mk_btn(
|
|
615
|
+
hb, _t("collab.host", "🖥 Hospedar"), self._on_host, accent=True
|
|
616
|
+
)
|
|
617
|
+
self._stop_btn = self._mk_btn(
|
|
618
|
+
hb, _t("collab.stop", "■ Parar"), self._on_stop_host
|
|
619
|
+
)
|
|
620
|
+
self._stop_btn.config(state="disabled")
|
|
621
|
+
|
|
622
|
+
self._room_info_var = tk.StringVar()
|
|
623
|
+
self._room_info_lbl = tk.Label(
|
|
624
|
+
host_box,
|
|
625
|
+
textvariable=self._room_info_var,
|
|
626
|
+
bg=t.panel_bg,
|
|
627
|
+
fg=t.t_func,
|
|
628
|
+
font=(FONT_MONO, 9),
|
|
629
|
+
)
|
|
630
|
+
self._room_info_lbl.pack(anchor="w", pady=(4, 0))
|
|
631
|
+
|
|
632
|
+
copy_btn = tk.Label(
|
|
633
|
+
host_box,
|
|
634
|
+
text=_t("collab.copy_invite", "📋 Copiar convite"),
|
|
635
|
+
bg=t.panel_bg,
|
|
636
|
+
fg=t.fg_muted,
|
|
637
|
+
font=(FONT_UI, 8),
|
|
638
|
+
cursor="hand2",
|
|
639
|
+
)
|
|
640
|
+
copy_btn.pack(anchor="w")
|
|
641
|
+
copy_btn.bind("<Button-1>", lambda _: self._copy_room_id())
|
|
642
|
+
|
|
643
|
+
join_box = tk.LabelFrame(
|
|
644
|
+
self,
|
|
645
|
+
text=_t("collab.join_section", "🔗 Entrar em Sessão"),
|
|
646
|
+
bg=t.panel_bg,
|
|
647
|
+
fg=t.fg,
|
|
648
|
+
font=(FONT_UI, 9, "bold"),
|
|
649
|
+
padx=8,
|
|
650
|
+
pady=6,
|
|
651
|
+
)
|
|
652
|
+
join_box.pack(fill="x", padx=10, pady=4)
|
|
653
|
+
|
|
654
|
+
j1 = tk.Frame(join_box, bg=t.panel_bg)
|
|
655
|
+
j1.pack(fill="x", pady=2)
|
|
656
|
+
tk.Label(
|
|
657
|
+
j1,
|
|
658
|
+
text=_t("collab.f_host", "Host:"),
|
|
659
|
+
bg=t.panel_bg,
|
|
660
|
+
fg=t.fg_muted,
|
|
661
|
+
font=(FONT_UI, 9),
|
|
662
|
+
width=10,
|
|
663
|
+
).pack(side="left")
|
|
664
|
+
self._join_host_var = tk.StringVar(value="localhost")
|
|
665
|
+
tk.Entry(
|
|
666
|
+
j1,
|
|
667
|
+
textvariable=self._join_host_var,
|
|
668
|
+
bg=t.editor_bg,
|
|
669
|
+
fg=t.fg,
|
|
670
|
+
insertbackground=t.cursor,
|
|
671
|
+
relief="flat",
|
|
672
|
+
font=(FONT_MONO, 9),
|
|
673
|
+
width=20,
|
|
674
|
+
bd=4,
|
|
675
|
+
).pack(side="left", padx=4)
|
|
676
|
+
|
|
677
|
+
j2 = tk.Frame(join_box, bg=t.panel_bg)
|
|
678
|
+
j2.pack(fill="x", pady=2)
|
|
679
|
+
tk.Label(
|
|
680
|
+
j2,
|
|
681
|
+
text=_t("collab.f_port", "Porta:"),
|
|
682
|
+
bg=t.panel_bg,
|
|
683
|
+
fg=t.fg_muted,
|
|
684
|
+
font=(FONT_UI, 9),
|
|
685
|
+
width=10,
|
|
686
|
+
).pack(side="left")
|
|
687
|
+
self._join_port_var = tk.StringVar(value=str(_DEFAULT_PORT))
|
|
688
|
+
tk.Entry(
|
|
689
|
+
j2,
|
|
690
|
+
textvariable=self._join_port_var,
|
|
691
|
+
bg=t.editor_bg,
|
|
692
|
+
fg=t.fg,
|
|
693
|
+
insertbackground=t.cursor,
|
|
694
|
+
relief="flat",
|
|
695
|
+
font=(FONT_MONO, 9),
|
|
696
|
+
width=8,
|
|
697
|
+
bd=4,
|
|
698
|
+
).pack(side="left", padx=4)
|
|
699
|
+
|
|
700
|
+
j3 = tk.Frame(join_box, bg=t.panel_bg)
|
|
701
|
+
j3.pack(fill="x", pady=2)
|
|
702
|
+
tk.Label(
|
|
703
|
+
j3,
|
|
704
|
+
text=_t("collab.f_room", "ID da sala:"),
|
|
705
|
+
bg=t.panel_bg,
|
|
706
|
+
fg=t.fg_muted,
|
|
707
|
+
font=(FONT_UI, 9),
|
|
708
|
+
width=10,
|
|
709
|
+
).pack(side="left")
|
|
710
|
+
self._join_room_var = tk.StringVar()
|
|
711
|
+
tk.Entry(
|
|
712
|
+
j3,
|
|
713
|
+
textvariable=self._join_room_var,
|
|
714
|
+
bg=t.editor_bg,
|
|
715
|
+
fg=t.fg,
|
|
716
|
+
insertbackground=t.cursor,
|
|
717
|
+
relief="flat",
|
|
718
|
+
font=(FONT_MONO, 9),
|
|
719
|
+
width=12,
|
|
720
|
+
bd=4,
|
|
721
|
+
).pack(side="left", padx=4)
|
|
722
|
+
|
|
723
|
+
j4 = tk.Frame(join_box, bg=t.panel_bg)
|
|
724
|
+
j4.pack(fill="x", pady=2)
|
|
725
|
+
tk.Label(
|
|
726
|
+
j4,
|
|
727
|
+
text=_t("collab.f_room_pass", "Senha:"),
|
|
728
|
+
bg=t.panel_bg,
|
|
729
|
+
fg=t.fg_muted,
|
|
730
|
+
font=(FONT_UI, 9),
|
|
731
|
+
width=10,
|
|
732
|
+
).pack(side="left")
|
|
733
|
+
self._join_pass_var = tk.StringVar()
|
|
734
|
+
tk.Entry(
|
|
735
|
+
j4,
|
|
736
|
+
textvariable=self._join_pass_var,
|
|
737
|
+
bg=t.editor_bg,
|
|
738
|
+
fg=t.fg,
|
|
739
|
+
insertbackground=t.cursor,
|
|
740
|
+
relief="flat",
|
|
741
|
+
show="*",
|
|
742
|
+
font=(FONT_MONO, 9),
|
|
743
|
+
width=18,
|
|
744
|
+
bd=4,
|
|
745
|
+
).pack(side="left", padx=4)
|
|
746
|
+
|
|
747
|
+
jb = tk.Frame(join_box, bg=t.panel_bg)
|
|
748
|
+
jb.pack(fill="x", pady=(4, 0))
|
|
749
|
+
self._join_btn = self._mk_btn(
|
|
750
|
+
jb, _t("collab.join", "🔗 Entrar"), self._on_join, accent=True
|
|
751
|
+
)
|
|
752
|
+
self._leave_btn = self._mk_btn(
|
|
753
|
+
jb, _t("collab.leave", "✖ Sair"), self._on_leave)
|
|
754
|
+
self._leave_btn.config(state="disabled")
|
|
755
|
+
|
|
756
|
+
peers_lbl = tk.Label(
|
|
757
|
+
self,
|
|
758
|
+
text=_t("collab.peers", "Participantes"),
|
|
759
|
+
bg=t.sidebar_bg,
|
|
760
|
+
fg=t.fg_muted,
|
|
761
|
+
font=(FONT_UI, 8, "bold"),
|
|
762
|
+
)
|
|
763
|
+
peers_lbl.pack(anchor="w", padx=10, pady=(8, 2))
|
|
764
|
+
|
|
765
|
+
self._peers_frame = tk.Frame(
|
|
766
|
+
self, bg=t.panel_bg, highlightthickness=1, highlightbackground=t.border
|
|
767
|
+
)
|
|
768
|
+
self._peers_frame.pack(fill="x", padx=10, pady=(0, 4))
|
|
769
|
+
self._peers_placeholder = tk.Label(
|
|
770
|
+
self._peers_frame,
|
|
771
|
+
text=_t("collab.no_peers", "Nenhum participante ainda."),
|
|
772
|
+
bg=t.panel_bg,
|
|
773
|
+
fg=t.fg_muted,
|
|
774
|
+
font=(FONT_UI, 8),
|
|
775
|
+
)
|
|
776
|
+
self._peers_placeholder.pack(pady=8)
|
|
777
|
+
|
|
778
|
+
tk.Label(
|
|
779
|
+
self,
|
|
780
|
+
text=_t("collab.chat", "Chat da Sessão"),
|
|
781
|
+
bg=t.sidebar_bg,
|
|
782
|
+
fg=t.fg_muted,
|
|
783
|
+
font=(FONT_UI, 8, "bold"),
|
|
784
|
+
).pack(anchor="w", padx=10, pady=(4, 2))
|
|
785
|
+
|
|
786
|
+
chat_frame = tk.Frame(
|
|
787
|
+
self, bg=t.editor_bg, highlightthickness=1, highlightbackground=t.border
|
|
788
|
+
)
|
|
789
|
+
chat_frame.pack(fill="both", expand=True, padx=10, pady=(0, 4))
|
|
790
|
+
|
|
791
|
+
self._chat_text = tk.Text(
|
|
792
|
+
chat_frame,
|
|
793
|
+
bg=t.editor_bg,
|
|
794
|
+
fg=t.fg,
|
|
795
|
+
font=(FONT_MONO, 9),
|
|
796
|
+
relief="flat",
|
|
797
|
+
bd=4,
|
|
798
|
+
state="disabled",
|
|
799
|
+
wrap="word",
|
|
800
|
+
height=8,
|
|
801
|
+
)
|
|
802
|
+
chat_vsb = ttk.Scrollbar(
|
|
803
|
+
chat_frame, orient="vertical", command=self._chat_text.yview
|
|
804
|
+
)
|
|
805
|
+
self._chat_text.configure(yscrollcommand=chat_vsb.set)
|
|
806
|
+
chat_vsb.pack(side="right", fill="y")
|
|
807
|
+
self._chat_text.pack(fill="both", expand=True)
|
|
808
|
+
self._chat_text.tag_config(
|
|
809
|
+
"ts", foreground=t.fg_muted, font=(FONT_MONO, 7))
|
|
810
|
+
self._chat_text.tag_config(
|
|
811
|
+
"sys", foreground=t.t_func, font=(FONT_MONO, 8, "italic")
|
|
812
|
+
)
|
|
813
|
+
self._chat_text.tag_config(
|
|
814
|
+
"own", foreground=t.accent, font=(FONT_MONO, 9, "bold")
|
|
815
|
+
)
|
|
816
|
+
self._chat_text.tag_config("peer", font=(FONT_MONO, 9, "bold"))
|
|
817
|
+
self._chat_text.tag_config("msg", foreground=t.fg, font=(FONT_MONO, 9))
|
|
818
|
+
|
|
819
|
+
chat_inp = tk.Frame(self, bg=t.panel_bg)
|
|
820
|
+
chat_inp.pack(fill="x", padx=10, pady=(0, 6))
|
|
821
|
+
self._chat_var = tk.StringVar()
|
|
822
|
+
chat_entry = tk.Entry(
|
|
823
|
+
chat_inp,
|
|
824
|
+
textvariable=self._chat_var,
|
|
825
|
+
bg=t.editor_bg,
|
|
826
|
+
fg=t.fg,
|
|
827
|
+
insertbackground=t.cursor,
|
|
828
|
+
relief="flat",
|
|
829
|
+
font=(FONT_MONO, 9),
|
|
830
|
+
bd=6,
|
|
831
|
+
)
|
|
832
|
+
chat_entry.pack(side="left", fill="x", expand=True)
|
|
833
|
+
chat_entry.bind("<Return>", self._on_chat_send)
|
|
834
|
+
send_lbl = tk.Label(
|
|
835
|
+
chat_inp,
|
|
836
|
+
text="↑",
|
|
837
|
+
bg=t.accent,
|
|
838
|
+
fg="#FFF",
|
|
839
|
+
font=(FONT_UI, 10, "bold"),
|
|
840
|
+
padx=8,
|
|
841
|
+
cursor="hand2",
|
|
842
|
+
)
|
|
843
|
+
send_lbl.pack(side="right")
|
|
844
|
+
send_lbl.bind("<Button-1>", self._on_chat_send)
|
|
845
|
+
|
|
846
|
+
sb = tk.Frame(
|
|
847
|
+
self, bg=t.sidebar_bg, highlightthickness=1, highlightbackground=t.border
|
|
848
|
+
)
|
|
849
|
+
sb.pack(fill="x")
|
|
850
|
+
self._status_var = tk.StringVar(
|
|
851
|
+
value=_t("collab.status_idle", "Sem sessão ativa.")
|
|
852
|
+
)
|
|
853
|
+
tk.Label(
|
|
854
|
+
sb,
|
|
855
|
+
textvariable=self._status_var,
|
|
856
|
+
bg=t.sidebar_bg,
|
|
857
|
+
fg=t.fg_muted,
|
|
858
|
+
font=(FONT_UI, 8),
|
|
859
|
+
anchor="w",
|
|
860
|
+
).pack(fill="x", padx=8, pady=4)
|
|
861
|
+
|
|
862
|
+
def _mk_btn(
|
|
863
|
+
self, parent: tk.Frame, text: str, cmd: Callable, accent: bool = False
|
|
864
|
+
) -> tk.Button:
|
|
865
|
+
t = self._tmgr.theme
|
|
866
|
+
bg = t.accent if accent else t.sidebar_bg
|
|
867
|
+
fg = "#FFF" if accent else t.fg
|
|
868
|
+
btn = tk.Button(
|
|
869
|
+
parent,
|
|
870
|
+
text=text,
|
|
871
|
+
command=cmd,
|
|
872
|
+
bg=bg,
|
|
873
|
+
fg=fg,
|
|
874
|
+
relief="flat",
|
|
875
|
+
font=(FONT_UI, 9),
|
|
876
|
+
cursor="hand2",
|
|
877
|
+
padx=8,
|
|
878
|
+
pady=5,
|
|
879
|
+
activebackground=t.btn_hover,
|
|
880
|
+
)
|
|
881
|
+
btn.pack(side="left", padx=2)
|
|
882
|
+
return btn
|
|
883
|
+
|
|
884
|
+
def _set_status(self, msg: str, online: bool | None = None) -> None:
|
|
885
|
+
self._status_var.set(msg)
|
|
886
|
+
if online is not None:
|
|
887
|
+
t = self._tmgr.theme
|
|
888
|
+
if online:
|
|
889
|
+
self._status_badge.config(
|
|
890
|
+
text=_t("collab.status_online", "● online"), fg=t.t_func
|
|
891
|
+
)
|
|
892
|
+
else:
|
|
893
|
+
self._status_badge.config(
|
|
894
|
+
text=_t("collab.status_offline", "● offline"), fg=t.fg_muted
|
|
895
|
+
)
|
|
896
|
+
|
|
897
|
+
def _refresh_chat(self) -> None:
|
|
898
|
+
self._chat_text.config(state="normal")
|
|
899
|
+
self._chat_text.delete("1.0", "end")
|
|
900
|
+
for ts, user, msg in self._chat_history[-200:]:
|
|
901
|
+
self._chat_text.insert("end", f"[{ts}] ", "ts")
|
|
902
|
+
if user in ("ok", "->", "<-", "!!"):
|
|
903
|
+
self._chat_text.insert("end", f"{user} {msg}\n", "sys")
|
|
904
|
+
elif user == self._user:
|
|
905
|
+
self._chat_text.insert("end", f"{user}: ", "own")
|
|
906
|
+
self._chat_text.insert("end", f"{msg}\n", "msg")
|
|
907
|
+
else:
|
|
908
|
+
color = _peer_color(user)
|
|
909
|
+
self._chat_text.tag_config(
|
|
910
|
+
f"peer_{user}", foreground=color, font=(FONT_MONO, 9, "bold")
|
|
911
|
+
)
|
|
912
|
+
self._chat_text.insert("end", f"{user}: ", f"peer_{user}")
|
|
913
|
+
self._chat_text.insert("end", f"{msg}\n", "msg")
|
|
914
|
+
self._chat_text.see("end")
|
|
915
|
+
self._chat_text.config(state="disabled")
|
|
916
|
+
|
|
917
|
+
def _refresh_peers_ui(self) -> None:
|
|
918
|
+
t = self._tmgr.theme
|
|
919
|
+
for w in self._peers_frame.winfo_children():
|
|
920
|
+
w.destroy()
|
|
921
|
+
if not self._peers:
|
|
922
|
+
tk.Label(
|
|
923
|
+
self._peers_frame,
|
|
924
|
+
text=_t("collab.no_peers", "Nenhum participante ainda."),
|
|
925
|
+
bg=t.panel_bg,
|
|
926
|
+
fg=t.fg_muted,
|
|
927
|
+
font=(FONT_UI, 8),
|
|
928
|
+
).pack(pady=6)
|
|
929
|
+
return
|
|
930
|
+
for peer in self._peers:
|
|
931
|
+
user = peer.get("user", "?")
|
|
932
|
+
color = peer.get("color", "#888")
|
|
933
|
+
row = tk.Frame(self._peers_frame, bg=t.panel_bg)
|
|
934
|
+
row.pack(fill="x", padx=6, pady=2)
|
|
935
|
+
dot = tk.Label(row, text="●", bg=t.panel_bg,
|
|
936
|
+
fg=color, font=(FONT_UI, 10))
|
|
937
|
+
dot.pack(side="left")
|
|
938
|
+
you = " " + _t("collab.you",
|
|
939
|
+
"(você)") if user == self._user else ""
|
|
940
|
+
tk.Label(
|
|
941
|
+
row, text=user + you, bg=t.panel_bg, fg=t.fg, font=(FONT_UI, 9)
|
|
942
|
+
).pack(side="left", padx=4)
|
|
943
|
+
|
|
944
|
+
def _copy_room_id(self) -> None:
|
|
945
|
+
"""Copia o convite completo (host, porta, sala e senha)."""
|
|
946
|
+
if not self._room_id:
|
|
947
|
+
return
|
|
948
|
+
text = self._invite or self._room_id
|
|
949
|
+
try:
|
|
950
|
+
self.clipboard_clear()
|
|
951
|
+
self.clipboard_append(text)
|
|
952
|
+
self._set_status(_t("collab.copied_invite", "Convite copiado: sala {rid}", rid=self._room_id))
|
|
953
|
+
except tk.TclError:
|
|
954
|
+
logger.debug("Falha ao copiar o convite", exc_info=True)
|
|
955
|
+
|
|
956
|
+
def _show_ws_warning(self) -> None:
|
|
957
|
+
t = self._tmgr.theme
|
|
958
|
+
win = tk.Toplevel(self)
|
|
959
|
+
win.title(_t("collab.no_ws_title", "websockets não instalado"))
|
|
960
|
+
win.config(bg=t.panel_bg)
|
|
961
|
+
win.resizable(False, False)
|
|
962
|
+
safe_grab_set(win)
|
|
963
|
+
tk.Label(
|
|
964
|
+
win,
|
|
965
|
+
text=_t(
|
|
966
|
+
"collab.no_ws_warning",
|
|
967
|
+
"⚠ Colaboração requer o pacote websockets.\n\n"
|
|
968
|
+
"Instale com:\n pip install websockets\n\n"
|
|
969
|
+
"Depois reinicie o Codis.",
|
|
970
|
+
),
|
|
971
|
+
bg=t.panel_bg,
|
|
972
|
+
fg=t.fg,
|
|
973
|
+
font=(FONT_UI, 10),
|
|
974
|
+
justify="left",
|
|
975
|
+
padx=20,
|
|
976
|
+
pady=16,
|
|
977
|
+
).pack()
|
|
978
|
+
|
|
979
|
+
def _copy_cmd() -> None:
|
|
980
|
+
win.clipboard_clear()
|
|
981
|
+
win.clipboard_append("pip install websockets")
|
|
982
|
+
|
|
983
|
+
tk.Button(
|
|
984
|
+
win,
|
|
985
|
+
text=_t("collab.install_ws", "📋 Copiar comando pip"),
|
|
986
|
+
command=_copy_cmd,
|
|
987
|
+
bg=t.accent,
|
|
988
|
+
fg="#FFF",
|
|
989
|
+
relief="flat",
|
|
990
|
+
font=(FONT_UI, 9),
|
|
991
|
+
padx=12,
|
|
992
|
+
pady=6,
|
|
993
|
+
).pack(pady=(0, 10))
|
|
994
|
+
tk.Button(
|
|
995
|
+
win,
|
|
996
|
+
text=_t("collab.close", "Fechar"),
|
|
997
|
+
command=win.destroy,
|
|
998
|
+
bg=t.sidebar_bg,
|
|
999
|
+
fg=t.fg,
|
|
1000
|
+
relief="flat",
|
|
1001
|
+
font=(FONT_UI, 9),
|
|
1002
|
+
padx=12,
|
|
1003
|
+
).pack(pady=(0, 12))
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
def _default_user() -> str:
|
|
1007
|
+
import os
|
|
1008
|
+
|
|
1009
|
+
return os.environ.get("USER", os.environ.get("USERNAME", "CodisUser"))
|