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/doom_embed.py
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
"""Codis - DOOM embutido no editor (easter egg ``/codis doom``).
|
|
2
|
+
|
|
3
|
+
Responsabilidades deste módulo (a parte genérica de reparentamento de janelas
|
|
4
|
+
vive em :mod:`src.ui.window_embed`):
|
|
5
|
+
|
|
6
|
+
1. Descobrir o executável do motor (gzdoom, chocolate-doom, crispy-doom...).
|
|
7
|
+
2. Descobrir um IWAD (doom.wad, doom2.wad, freedoom...).
|
|
8
|
+
3. Montar a linha de comando adequada à família do motor.
|
|
9
|
+
4. Criar o :class:`~src.ui.window_embed.EmbeddedAppPanel` sobre o editor, ou
|
|
10
|
+
iniciar o jogo em janela externa quando a plataforma não permite embutir.
|
|
11
|
+
|
|
12
|
+
Configuração (``~/.codis/config.json``) e variáveis de ambiente::
|
|
13
|
+
|
|
14
|
+
doom_engine_path / CODIS_DOOM_ENGINE caminho do executável
|
|
15
|
+
doom_iwad_path / CODIS_DOOM_IWAD caminho do IWAD
|
|
16
|
+
doom_extra_args argumentos extras (string estilo shell)
|
|
17
|
+
DOOMWADDIR / DOOMWADPATH diretórios de IWAD (convenção do DOOM)
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import logging
|
|
23
|
+
import os
|
|
24
|
+
import shlex
|
|
25
|
+
import shutil
|
|
26
|
+
import subprocess
|
|
27
|
+
import sys
|
|
28
|
+
import tkinter as tk
|
|
29
|
+
from collections.abc import Callable, Mapping
|
|
30
|
+
from dataclasses import dataclass
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
from typing import Any
|
|
33
|
+
|
|
34
|
+
from src.constants import CONFIG_DIR
|
|
35
|
+
from src.i18n import _t
|
|
36
|
+
from src.ui import window_embed as we
|
|
37
|
+
|
|
38
|
+
logger = logging.getLogger("Codis.Doom")
|
|
39
|
+
|
|
40
|
+
__all__ = [
|
|
41
|
+
"DoomLaunchError",
|
|
42
|
+
"DoomPlan",
|
|
43
|
+
"build_argv",
|
|
44
|
+
"classify_engine",
|
|
45
|
+
"find_engine",
|
|
46
|
+
"find_iwad",
|
|
47
|
+
"resolve_plan",
|
|
48
|
+
"start_embedded",
|
|
49
|
+
"launch_external",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
ENGINE_NAMES: tuple[str, ...] = (
|
|
53
|
+
"gzdoom",
|
|
54
|
+
"uzdoom",
|
|
55
|
+
"crispy-doom",
|
|
56
|
+
"chocolate-doom",
|
|
57
|
+
"dsda-doom",
|
|
58
|
+
"woof",
|
|
59
|
+
"prboom-plus",
|
|
60
|
+
"prboom",
|
|
61
|
+
"zdoom",
|
|
62
|
+
"doom",
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
IWAD_NAMES: tuple[str, ...] = (
|
|
66
|
+
"doom2.wad",
|
|
67
|
+
"doom.wad",
|
|
68
|
+
"freedoom2.wad",
|
|
69
|
+
"freedoom1.wad",
|
|
70
|
+
"plutonia.wad",
|
|
71
|
+
"tnt.wad",
|
|
72
|
+
"doom1.wad",
|
|
73
|
+
"freedm.wad",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
_DOOM_DIR = CONFIG_DIR / "doom"
|
|
77
|
+
_LOG_PATH = _DOOM_DIR / "last_run.log"
|
|
78
|
+
|
|
79
|
+
_BOOT_LINES: tuple[str, ...] = (
|
|
80
|
+
"DOOM v1.9 (c) 1993 id Software, Ltd.\n",
|
|
81
|
+
"V_Init: allocate screens.\n",
|
|
82
|
+
"M_LoadDefaults: Load system defaults.\n",
|
|
83
|
+
"Z_Init: Init zone memory allocation daemon.\n",
|
|
84
|
+
"W_Init: Init WADfiles.\n",
|
|
85
|
+
"R_Init: Init DOOM refresh daemon -\n",
|
|
86
|
+
"..................................................\n",
|
|
87
|
+
"P_Init: Init Playloop state.\n",
|
|
88
|
+
"I_Init: Setting up machine state.\n",
|
|
89
|
+
"D_CheckNetGame: Checking network game status.\n",
|
|
90
|
+
"startskill 2 deathmatch: 0 startmap: 1 startepisode: 1\n",
|
|
91
|
+
"player 1 of 1 (1 nodes)\n",
|
|
92
|
+
"\n",
|
|
93
|
+
"rip and tear, KillovSky\n",
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class DoomLaunchError(RuntimeError):
|
|
98
|
+
"""Falha ao preparar o DOOM; ``kind`` é ``engine``, ``iwad`` ou ``launch``."""
|
|
99
|
+
|
|
100
|
+
def __init__(self, kind: str, message: str) -> None:
|
|
101
|
+
"""Guarda o tipo da falha junto da mensagem já traduzida."""
|
|
102
|
+
super().__init__(message)
|
|
103
|
+
self.kind = kind
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@dataclass(frozen=True)
|
|
107
|
+
class DoomPlan:
|
|
108
|
+
"""Resultado da descoberta: o que será executado."""
|
|
109
|
+
|
|
110
|
+
engine: Path
|
|
111
|
+
family: str
|
|
112
|
+
iwad: Path
|
|
113
|
+
extra_args: tuple[str, ...] = ()
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def classify_engine(path: str | Path) -> str:
|
|
117
|
+
"""Classifica o motor pelo nome do executável.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
``"zdoom"`` (gzdoom/zdoom), ``"chocolate"`` (chocolate/crispy),
|
|
121
|
+
``"boom"`` (prboom/dsda/woof) ou ``"generic"``.
|
|
122
|
+
"""
|
|
123
|
+
stem = Path(path).stem.lower()
|
|
124
|
+
if "zdoom" in stem:
|
|
125
|
+
return "zdoom"
|
|
126
|
+
if "chocolate" in stem or "crispy" in stem:
|
|
127
|
+
return "chocolate"
|
|
128
|
+
if any(tag in stem for tag in ("prboom", "dsda", "woof")):
|
|
129
|
+
return "boom"
|
|
130
|
+
return "generic"
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _engine_dirs(env: Mapping[str, str], home: Path) -> list[Path]:
|
|
134
|
+
"""Diretórios extras (além do PATH) onde procurar o motor."""
|
|
135
|
+
dirs = [_DOOM_DIR, home / ".codis" / "doom", Path(__file__).resolve().parents[2] / "doom"]
|
|
136
|
+
if sys.platform == "win32":
|
|
137
|
+
bases = [env.get("ProgramFiles"), env.get("ProgramFiles(x86)")]
|
|
138
|
+
local = env.get("LOCALAPPDATA")
|
|
139
|
+
if local:
|
|
140
|
+
bases.append(str(Path(local) / "Programs"))
|
|
141
|
+
subs = ("GZDoom", "UZDoom", "Chocolate Doom", "Crispy Doom", "DSDA-Doom", "Woof")
|
|
142
|
+
dirs.extend(Path(base) / sub for base in filter(None, bases) for sub in subs)
|
|
143
|
+
return dirs
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def find_engine(
|
|
147
|
+
configured: str | None = None,
|
|
148
|
+
env: Mapping[str, str] | None = None,
|
|
149
|
+
home: Path | None = None,
|
|
150
|
+
which: Callable[[str], str | None] = shutil.which,
|
|
151
|
+
) -> Path | None:
|
|
152
|
+
"""Localiza o executável do motor.
|
|
153
|
+
|
|
154
|
+
Ordem: caminho configurado -> ``CODIS_DOOM_ENGINE`` -> PATH -> diretórios
|
|
155
|
+
conhecidos. Um caminho configurado inválido é ignorado (cai no próximo).
|
|
156
|
+
"""
|
|
157
|
+
env = os.environ if env is None else env
|
|
158
|
+
home = Path.home() if home is None else home
|
|
159
|
+
for explicit in (configured, env.get("CODIS_DOOM_ENGINE")):
|
|
160
|
+
if explicit and Path(explicit).expanduser().is_file():
|
|
161
|
+
return Path(explicit).expanduser()
|
|
162
|
+
for name in ENGINE_NAMES:
|
|
163
|
+
found = which(name)
|
|
164
|
+
if found:
|
|
165
|
+
return Path(found)
|
|
166
|
+
suffixes = (".exe", "") if sys.platform == "win32" else ("",)
|
|
167
|
+
for directory in _engine_dirs(env, home):
|
|
168
|
+
for name in ENGINE_NAMES:
|
|
169
|
+
for suffix in suffixes:
|
|
170
|
+
candidate = directory / (name + suffix)
|
|
171
|
+
if candidate.is_file():
|
|
172
|
+
return candidate
|
|
173
|
+
return None
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _iwad_dirs(engine_dir: Path, env: Mapping[str, str], home: Path) -> list[Path]:
|
|
177
|
+
dirs: list[Path] = []
|
|
178
|
+
if env.get("DOOMWADDIR"):
|
|
179
|
+
dirs.append(Path(env["DOOMWADDIR"]))
|
|
180
|
+
dirs.extend(Path(p) for p in env.get("DOOMWADPATH", "").split(os.pathsep) if p)
|
|
181
|
+
dirs += [engine_dir, _DOOM_DIR, home / ".codis" / "doom"]
|
|
182
|
+
if sys.platform == "win32":
|
|
183
|
+
pf = [env.get("ProgramFiles(x86)"), env.get("ProgramFiles")]
|
|
184
|
+
for base in filter(None, pf):
|
|
185
|
+
for game in ("Ultimate Doom", "Doom 2", "Final Doom"):
|
|
186
|
+
dirs.append(Path(base) / "Steam" / "steamapps" / "common" / game / "base")
|
|
187
|
+
dirs.append(home / "Documents" / "My Games" / "GZDoom")
|
|
188
|
+
else:
|
|
189
|
+
dirs += [
|
|
190
|
+
home / ".local" / "share" / "games" / "doom",
|
|
191
|
+
home / ".config" / "gzdoom",
|
|
192
|
+
home / ".steam" / "steam" / "steamapps" / "common" / "Ultimate Doom" / "base",
|
|
193
|
+
Path("/usr/share/games/doom"),
|
|
194
|
+
Path("/usr/share/doom"),
|
|
195
|
+
Path("/usr/local/share/doom"),
|
|
196
|
+
Path("/usr/share/games/freedoom"),
|
|
197
|
+
]
|
|
198
|
+
return dirs
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def find_iwad(
|
|
202
|
+
engine_dir: Path,
|
|
203
|
+
configured: str | None = None,
|
|
204
|
+
env: Mapping[str, str] | None = None,
|
|
205
|
+
home: Path | None = None,
|
|
206
|
+
) -> Path | None:
|
|
207
|
+
"""Localiza um IWAD (comparação case-insensitive, vale para Linux)."""
|
|
208
|
+
env = os.environ if env is None else env
|
|
209
|
+
home = Path.home() if home is None else home
|
|
210
|
+
for explicit in (configured, env.get("CODIS_DOOM_IWAD")):
|
|
211
|
+
if explicit and Path(explicit).expanduser().is_file():
|
|
212
|
+
return Path(explicit).expanduser()
|
|
213
|
+
for directory in _iwad_dirs(engine_dir, env, home):
|
|
214
|
+
try:
|
|
215
|
+
names = {p.name.lower(): p for p in directory.iterdir() if p.is_file()}
|
|
216
|
+
except OSError:
|
|
217
|
+
continue
|
|
218
|
+
for wanted in IWAD_NAMES:
|
|
219
|
+
if wanted in names:
|
|
220
|
+
return names[wanted]
|
|
221
|
+
return None
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def build_argv(
|
|
225
|
+
engine: Path,
|
|
226
|
+
family: str,
|
|
227
|
+
iwad: Path,
|
|
228
|
+
width: int,
|
|
229
|
+
height: int,
|
|
230
|
+
extra_args: tuple[str, ...] = (),
|
|
231
|
+
) -> list[str]:
|
|
232
|
+
"""Monta a linha de comando em modo janela para a família do motor.
|
|
233
|
+
|
|
234
|
+
Apenas opções conhecidas por família são usadas; o tamanho real é imposto
|
|
235
|
+
depois pelo reparentamento, então famílias incertas recebem o mínimo.
|
|
236
|
+
"""
|
|
237
|
+
argv = [str(engine), "-iwad", str(iwad)]
|
|
238
|
+
if family == "zdoom":
|
|
239
|
+
argv += ["-width", str(width), "-height", str(height), "+vid_fullscreen", "0"]
|
|
240
|
+
elif family == "chocolate":
|
|
241
|
+
argv += ["-window", "-geometry", f"{width}x{height}"]
|
|
242
|
+
else:
|
|
243
|
+
argv += ["-window"]
|
|
244
|
+
return [*argv, *extra_args]
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def resolve_plan(cfg: Any | None = None) -> DoomPlan:
|
|
248
|
+
"""Descobre motor e IWAD ou levanta :class:`DoomLaunchError`."""
|
|
249
|
+
|
|
250
|
+
def conf(key: str) -> str | None:
|
|
251
|
+
if cfg is None:
|
|
252
|
+
return None
|
|
253
|
+
value = cfg.get(key, None)
|
|
254
|
+
return str(value) if value else None
|
|
255
|
+
|
|
256
|
+
engine = find_engine(conf("doom_engine_path"))
|
|
257
|
+
if engine is None:
|
|
258
|
+
raise DoomLaunchError("engine", _t("doom.err_no_engine"))
|
|
259
|
+
iwad = find_iwad(engine.parent, conf("doom_iwad_path"))
|
|
260
|
+
if iwad is None:
|
|
261
|
+
raise DoomLaunchError("iwad", _t("doom.err_no_iwad", dir=str(_DOOM_DIR)))
|
|
262
|
+
raw_extra = conf("doom_extra_args") or ""
|
|
263
|
+
try:
|
|
264
|
+
extra = tuple(shlex.split(raw_extra, posix=sys.platform != "win32"))
|
|
265
|
+
except ValueError:
|
|
266
|
+
extra = ()
|
|
267
|
+
return DoomPlan(engine, classify_engine(engine), iwad, extra)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def _child_env() -> dict[str, str]:
|
|
271
|
+
"""Ambiente do processo: força X11 no SDL (Linux) e DPI compatível (Windows)."""
|
|
272
|
+
env = os.environ.copy()
|
|
273
|
+
if sys.platform == "win32":
|
|
274
|
+
layers = env.get("__COMPAT_LAYER", "").split()
|
|
275
|
+
if "HIGHDPIAWARE" not in layers:
|
|
276
|
+
env["__COMPAT_LAYER"] = " ".join([*layers, "HIGHDPIAWARE"])
|
|
277
|
+
else:
|
|
278
|
+
env.setdefault("SDL_VIDEODRIVER", "x11")
|
|
279
|
+
return env
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _labels() -> we.EmbedLabels:
|
|
283
|
+
return we.EmbedLabels(
|
|
284
|
+
hint=_t("doom.hint", hotkey=we.EXIT_HOTKEY_TEXT),
|
|
285
|
+
back=_t("doom.btn_back"),
|
|
286
|
+
focus=_t("doom.btn_focus"),
|
|
287
|
+
loading=_t("doom.status_loading"),
|
|
288
|
+
embedded=_t("doom.status_embedded", hotkey=we.EXIT_HOTKEY_TEXT),
|
|
289
|
+
closed=_t("doom.status_closed"),
|
|
290
|
+
err_exited=_t("doom.err_exited"),
|
|
291
|
+
err_timeout=_t("doom.err_timeout"),
|
|
292
|
+
err_launch=_t("doom.err_launch"),
|
|
293
|
+
embed_failed=_t("doom.status_embed_failed"),
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def start_embedded(
|
|
298
|
+
container: tk.Widget,
|
|
299
|
+
plan: DoomPlan,
|
|
300
|
+
*,
|
|
301
|
+
on_status: Callable[[str], None] | None = None,
|
|
302
|
+
on_close: Callable[[], None] | None = None,
|
|
303
|
+
backend: we.WindowBackend | None = None,
|
|
304
|
+
) -> we.EmbeddedAppPanel:
|
|
305
|
+
"""Cria o painel sobre ``container`` e inicia o DOOM dentro dele.
|
|
306
|
+
|
|
307
|
+
Raises:
|
|
308
|
+
DoomLaunchError: ``kind="launch"`` se não houver backend de embutir.
|
|
309
|
+
"""
|
|
310
|
+
backend = backend if backend is not None else we.get_backend()
|
|
311
|
+
if backend is None:
|
|
312
|
+
raise DoomLaunchError("launch", _t("doom.status_external"))
|
|
313
|
+
panel = we.EmbeddedAppPanel(
|
|
314
|
+
container,
|
|
315
|
+
[],
|
|
316
|
+
backend=backend,
|
|
317
|
+
labels=_labels(),
|
|
318
|
+
cwd=str(plan.engine.parent),
|
|
319
|
+
env=_child_env(),
|
|
320
|
+
log_path=_LOG_PATH,
|
|
321
|
+
boot_lines=_BOOT_LINES,
|
|
322
|
+
on_status=on_status,
|
|
323
|
+
on_close=on_close,
|
|
324
|
+
)
|
|
325
|
+
panel.place(x=0, y=0, relwidth=1, relheight=1)
|
|
326
|
+
panel.lift()
|
|
327
|
+
panel.update_idletasks()
|
|
328
|
+
width = max(320, panel.winfo_width())
|
|
329
|
+
height = max(200, panel.winfo_height() - 26)
|
|
330
|
+
panel.set_argv(build_argv(plan.engine, plan.family, plan.iwad, width, height, plan.extra_args))
|
|
331
|
+
panel.start()
|
|
332
|
+
return panel
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def launch_external(plan: DoomPlan) -> subprocess.Popen | None:
|
|
336
|
+
"""Fallback: inicia o DOOM em janela própria (sem embutir)."""
|
|
337
|
+
argv = build_argv(plan.engine, plan.family, plan.iwad, 960, 600, plan.extra_args)
|
|
338
|
+
try:
|
|
339
|
+
return subprocess.Popen(
|
|
340
|
+
argv,
|
|
341
|
+
cwd=str(plan.engine.parent),
|
|
342
|
+
env=_child_env(),
|
|
343
|
+
stdin=subprocess.DEVNULL,
|
|
344
|
+
stdout=subprocess.DEVNULL,
|
|
345
|
+
stderr=subprocess.DEVNULL,
|
|
346
|
+
)
|
|
347
|
+
except OSError as exc:
|
|
348
|
+
logger.warning("Falha ao iniciar DOOM externo: %s", exc)
|
|
349
|
+
raise DoomLaunchError("launch", _t("doom.err_launch").format(reason=exc)) from exc
|
src/ui/dropdown.py
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"""Codis - DropDown: Entry + Listbox substituto do ttk.Combobox.
|
|
2
|
+
|
|
3
|
+
Implementação 100% tk puro - sem ttk - para evitar problemas com temas
|
|
4
|
+
TTK customizados que quebram a abertura do dropdown nativo do Combobox.
|
|
5
|
+
|
|
6
|
+
API compatível com ttk.Combobox:
|
|
7
|
+
widget = DropDown(parent, textvariable=var, values=[...], width=20,
|
|
8
|
+
font=(...), state="readonly")
|
|
9
|
+
widget.bind("<<ComboboxSelected>>", callback)
|
|
10
|
+
widget.config(values=[...])
|
|
11
|
+
widget["values"] = [...]
|
|
12
|
+
widget.pack / grid / place (passa para o frame interno)
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import contextlib
|
|
18
|
+
import tkinter as tk
|
|
19
|
+
import tkinter.font as _tkfont
|
|
20
|
+
from collections.abc import Callable, Sequence
|
|
21
|
+
from typing import Any
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class DropDown(tk.Frame):
|
|
25
|
+
"""Entry + popup Listbox que imita ttk.Combobox sem usar ttk."""
|
|
26
|
+
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
parent: tk.Widget,
|
|
30
|
+
textvariable: tk.StringVar | None = None,
|
|
31
|
+
values: Sequence[str] = (),
|
|
32
|
+
width: int = 16,
|
|
33
|
+
font: Any = None,
|
|
34
|
+
state: str = "readonly",
|
|
35
|
+
bg: str | None = None,
|
|
36
|
+
fg: str | None = None,
|
|
37
|
+
sel_bg: str | None = None,
|
|
38
|
+
sel_fg: str | None = None,
|
|
39
|
+
border_color: str | None = None,
|
|
40
|
+
arrow_fg: str | None = None,
|
|
41
|
+
**kw: Any,
|
|
42
|
+
) -> None:
|
|
43
|
+
bg = bg or self._resolve("input_bg", parent, "#3c3c52")
|
|
44
|
+
fg = fg or self._resolve("fg", parent, "#cdd6f4")
|
|
45
|
+
sel_bg = sel_bg or self._resolve("sel_bg", parent, "#45475a")
|
|
46
|
+
sel_fg = sel_fg or self._resolve("sel_fg", parent, "#cdd6f4")
|
|
47
|
+
border_color = border_color or self._resolve(
|
|
48
|
+
"border", parent, "#555577")
|
|
49
|
+
arrow_fg = arrow_fg or self._resolve("fg_muted", parent, "#888aaa")
|
|
50
|
+
list_bg = self._resolve("floating_bg", parent, "#2a2b3d")
|
|
51
|
+
|
|
52
|
+
super().__init__(
|
|
53
|
+
parent,
|
|
54
|
+
bg=border_color,
|
|
55
|
+
highlightthickness=0,
|
|
56
|
+
bd=0,
|
|
57
|
+
**{
|
|
58
|
+
k: v
|
|
59
|
+
for k, v in kw.items()
|
|
60
|
+
if k not in ("highlightbackground", "highlightcolor")
|
|
61
|
+
},
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
self._var = textvariable or tk.StringVar()
|
|
65
|
+
self._values: list[str] = list(values)
|
|
66
|
+
self._state = state
|
|
67
|
+
self._font = font or ("sans-serif", 9)
|
|
68
|
+
self._fg = fg
|
|
69
|
+
self._bg = bg
|
|
70
|
+
self._sel_bg = sel_bg
|
|
71
|
+
self._sel_fg = sel_fg
|
|
72
|
+
self._list_bg = list_bg
|
|
73
|
+
self._border_color = border_color
|
|
74
|
+
self._popup: tk.Toplevel | None = None
|
|
75
|
+
self._listbox: tk.Listbox | None = None
|
|
76
|
+
self._callbacks: list[Callable] = []
|
|
77
|
+
|
|
78
|
+
inner = tk.Frame(self, bg=bg, bd=0)
|
|
79
|
+
inner.pack(fill="both", expand=True, padx=1, pady=1)
|
|
80
|
+
|
|
81
|
+
self._entry = tk.Entry(
|
|
82
|
+
inner,
|
|
83
|
+
textvariable=self._var,
|
|
84
|
+
font=self._font,
|
|
85
|
+
width=width,
|
|
86
|
+
bg=bg,
|
|
87
|
+
fg=fg,
|
|
88
|
+
insertbackground=fg,
|
|
89
|
+
relief="flat",
|
|
90
|
+
bd=0,
|
|
91
|
+
highlightthickness=0,
|
|
92
|
+
readonlybackground=bg,
|
|
93
|
+
state="readonly" if state == "readonly" else "normal",
|
|
94
|
+
cursor="arrow",
|
|
95
|
+
)
|
|
96
|
+
self._entry.pack(side="left", fill="both", expand=True, padx=(4, 0))
|
|
97
|
+
|
|
98
|
+
self._arrow = tk.Label(
|
|
99
|
+
inner,
|
|
100
|
+
text="▾",
|
|
101
|
+
bg=bg,
|
|
102
|
+
fg=arrow_fg,
|
|
103
|
+
font=(
|
|
104
|
+
self._font[0] if isinstance(
|
|
105
|
+
self._font, (list, tuple)) else self._font,
|
|
106
|
+
9,
|
|
107
|
+
),
|
|
108
|
+
cursor="hand2",
|
|
109
|
+
padx=4,
|
|
110
|
+
pady=0,
|
|
111
|
+
)
|
|
112
|
+
self._arrow.pack(side="right")
|
|
113
|
+
|
|
114
|
+
for widget in (self._entry, self._arrow, inner, self):
|
|
115
|
+
widget.bind("<ButtonPress-1>", self._toggle, add="+")
|
|
116
|
+
self._entry.bind("<FocusOut>", self._on_focus_out, add="+")
|
|
117
|
+
|
|
118
|
+
@staticmethod
|
|
119
|
+
def _resolve(attr: str, widget: tk.Widget, fallback: str) -> str:
|
|
120
|
+
"""Walk up widget parents to find a ThemeManager theme colour."""
|
|
121
|
+
with contextlib.suppress(tk.TclError, AttributeError):
|
|
122
|
+
w = widget
|
|
123
|
+
for _ in range(12):
|
|
124
|
+
tmgr = getattr(w, "_tmgr", None)
|
|
125
|
+
if tmgr is not None:
|
|
126
|
+
return getattr(tmgr.theme, attr, fallback)
|
|
127
|
+
app = getattr(w, "_app", None)
|
|
128
|
+
if app is not None:
|
|
129
|
+
tmgr2 = getattr(app, "_tmgr", None)
|
|
130
|
+
if tmgr2 is not None:
|
|
131
|
+
return getattr(tmgr2.theme, attr, fallback)
|
|
132
|
+
w = w.master
|
|
133
|
+
if w is None:
|
|
134
|
+
break
|
|
135
|
+
return fallback
|
|
136
|
+
|
|
137
|
+
def bind(
|
|
138
|
+
self, sequence: str = "", func: Callable | None = None, add: Any = None
|
|
139
|
+
) -> str:
|
|
140
|
+
"""Delega o bind para o widget interno, repassando sequence e func."""
|
|
141
|
+
if sequence == "<<ComboboxSelected>>":
|
|
142
|
+
if func:
|
|
143
|
+
self._callbacks.append(func)
|
|
144
|
+
return ""
|
|
145
|
+
return super().bind(sequence, func, add)
|
|
146
|
+
|
|
147
|
+
def config(self, **kw: Any) -> None:
|
|
148
|
+
"""Aplica configurações de estilo ao widget interno do dropdown."""
|
|
149
|
+
|
|
150
|
+
if "values" in kw:
|
|
151
|
+
self._values = list(kw.pop("values"))
|
|
152
|
+
if self._listbox:
|
|
153
|
+
self._populate_listbox()
|
|
154
|
+
if kw:
|
|
155
|
+
super().config(**kw)
|
|
156
|
+
|
|
157
|
+
configure = config
|
|
158
|
+
|
|
159
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
160
|
+
"""Define atributo via indexação; 'values' atualiza a lista interna."""
|
|
161
|
+
if key == "values":
|
|
162
|
+
self.config(values=value)
|
|
163
|
+
else:
|
|
164
|
+
super().__setitem__(key, value)
|
|
165
|
+
|
|
166
|
+
def __getitem__(self, key: str) -> Any:
|
|
167
|
+
"""Retorna atributo via indexação; 'values' retorna a lista interna."""
|
|
168
|
+
if key == "values":
|
|
169
|
+
return self._values
|
|
170
|
+
return super().__getitem__(key)
|
|
171
|
+
|
|
172
|
+
def get(self) -> str:
|
|
173
|
+
"""Retorna o valor atualmente selecionado no dropdown."""
|
|
174
|
+
return self._var.get()
|
|
175
|
+
|
|
176
|
+
def set(self, value: str) -> None:
|
|
177
|
+
"""Define o valor exibido no campo de entrada."""
|
|
178
|
+
self._var.set(value)
|
|
179
|
+
|
|
180
|
+
def _toggle(self, _event: Any = None) -> None:
|
|
181
|
+
"""Alterna o estado do componente (ativo/inativo ou visível/oculto)."""
|
|
182
|
+
if self._popup and self._popup.winfo_exists():
|
|
183
|
+
self._close_popup()
|
|
184
|
+
else:
|
|
185
|
+
self._open_popup()
|
|
186
|
+
|
|
187
|
+
def _open_popup(self) -> None:
|
|
188
|
+
"""Cria e exibe a janela popup com a lista de opções."""
|
|
189
|
+
if not self._values:
|
|
190
|
+
return
|
|
191
|
+
self._close_popup()
|
|
192
|
+
|
|
193
|
+
popup = tk.Toplevel(self)
|
|
194
|
+
popup.overrideredirect(True)
|
|
195
|
+
popup.attributes("-topmost", True)
|
|
196
|
+
self._popup = popup
|
|
197
|
+
|
|
198
|
+
self.update_idletasks()
|
|
199
|
+
x = self.winfo_rootx()
|
|
200
|
+
y = self.winfo_rooty() + self.winfo_height()
|
|
201
|
+
w = max(self.winfo_width(), 80)
|
|
202
|
+
rows = min(len(self._values), 10)
|
|
203
|
+
|
|
204
|
+
try:
|
|
205
|
+
fnt = _tkfont.Font(font=self._font)
|
|
206
|
+
row_h = fnt.metrics("linespace") + 6
|
|
207
|
+
except tk.TclError:
|
|
208
|
+
row_h = 20
|
|
209
|
+
h = rows * row_h + 4
|
|
210
|
+
|
|
211
|
+
sw = self.winfo_screenwidth()
|
|
212
|
+
sh = self.winfo_screenheight()
|
|
213
|
+
if x + w > sw:
|
|
214
|
+
x = max(0, sw - w)
|
|
215
|
+
if y + h > sh:
|
|
216
|
+
y = max(0, self.winfo_rooty() - h)
|
|
217
|
+
|
|
218
|
+
popup.geometry(f"{w}x{h}+{x}+{y}")
|
|
219
|
+
popup.config(bg=self._border_color)
|
|
220
|
+
|
|
221
|
+
frame = tk.Frame(popup, bg=self._list_bg, bd=0)
|
|
222
|
+
frame.pack(fill="both", expand=True, padx=1, pady=1)
|
|
223
|
+
|
|
224
|
+
sb = tk.Scrollbar(
|
|
225
|
+
frame,
|
|
226
|
+
orient="vertical",
|
|
227
|
+
bg=self._list_bg,
|
|
228
|
+
troughcolor=self._list_bg,
|
|
229
|
+
activebackground=self._sel_bg,
|
|
230
|
+
highlightthickness=0,
|
|
231
|
+
bd=0,
|
|
232
|
+
width=8,
|
|
233
|
+
)
|
|
234
|
+
sb.pack(side="right", fill="y")
|
|
235
|
+
|
|
236
|
+
lb = tk.Listbox(
|
|
237
|
+
frame,
|
|
238
|
+
font=self._font,
|
|
239
|
+
bg=self._list_bg,
|
|
240
|
+
fg=self._fg,
|
|
241
|
+
selectbackground=self._sel_bg,
|
|
242
|
+
selectforeground=self._sel_fg,
|
|
243
|
+
activestyle="none",
|
|
244
|
+
relief="flat",
|
|
245
|
+
bd=0,
|
|
246
|
+
highlightthickness=0,
|
|
247
|
+
yscrollcommand=sb.set,
|
|
248
|
+
exportselection=False,
|
|
249
|
+
cursor="hand2",
|
|
250
|
+
)
|
|
251
|
+
lb.pack(side="left", fill="both", expand=True)
|
|
252
|
+
sb.config(command=lb.yview)
|
|
253
|
+
self._listbox = lb
|
|
254
|
+
|
|
255
|
+
self._populate_listbox()
|
|
256
|
+
|
|
257
|
+
cur = self._var.get()
|
|
258
|
+
if cur in self._values:
|
|
259
|
+
idx = self._values.index(cur)
|
|
260
|
+
lb.selection_set(idx)
|
|
261
|
+
lb.see(idx)
|
|
262
|
+
|
|
263
|
+
lb.bind("<ButtonRelease-1>", self._on_select)
|
|
264
|
+
lb.bind("<Return>", self._on_select)
|
|
265
|
+
lb.bind("<Escape>", lambda _: self._close_popup())
|
|
266
|
+
popup.bind("<FocusOut>", self._on_popup_focus_out)
|
|
267
|
+
popup.bind("<Escape>", lambda _: self._close_popup())
|
|
268
|
+
|
|
269
|
+
popup.update_idletasks()
|
|
270
|
+
popup.deiconify()
|
|
271
|
+
popup.lift()
|
|
272
|
+
popup.focus_force()
|
|
273
|
+
lb.focus_set()
|
|
274
|
+
|
|
275
|
+
def _populate_listbox(self) -> None:
|
|
276
|
+
"""Preenche a listbox do popup com as opções disponíveis."""
|
|
277
|
+
if not self._listbox:
|
|
278
|
+
return
|
|
279
|
+
self._listbox.delete(0, "end")
|
|
280
|
+
for v in self._values:
|
|
281
|
+
self._listbox.insert("end", v)
|
|
282
|
+
|
|
283
|
+
def _on_select(self, _event: Any = None) -> None:
|
|
284
|
+
lb = self._listbox
|
|
285
|
+
if lb is None:
|
|
286
|
+
return
|
|
287
|
+
sel = lb.curselection()
|
|
288
|
+
if sel:
|
|
289
|
+
value = self._values[sel[0]]
|
|
290
|
+
self._var.set(value)
|
|
291
|
+
self._close_popup()
|
|
292
|
+
|
|
293
|
+
for cb in self._callbacks:
|
|
294
|
+
with contextlib.suppress(TypeError, RuntimeError):
|
|
295
|
+
cb(None)
|
|
296
|
+
|
|
297
|
+
def _close_popup(self) -> None:
|
|
298
|
+
"""Fecha e destrói a janela popup do dropdown."""
|
|
299
|
+
self._listbox = None
|
|
300
|
+
if self._popup and self._popup.winfo_exists():
|
|
301
|
+
self._popup.destroy()
|
|
302
|
+
self._popup = None
|
|
303
|
+
|
|
304
|
+
def _on_focus_out(self, _event: Any = None) -> None:
|
|
305
|
+
self.after(50, self._check_focus)
|
|
306
|
+
|
|
307
|
+
def _on_popup_focus_out(self, _event: Any = None) -> None:
|
|
308
|
+
self.after(50, self._check_focus)
|
|
309
|
+
|
|
310
|
+
def _check_focus(self) -> None:
|
|
311
|
+
"""Fecha o popup se o foco saiu de seus widgets."""
|
|
312
|
+
try:
|
|
313
|
+
focused = self.focus_get()
|
|
314
|
+
except tk.TclError:
|
|
315
|
+
focused = None
|
|
316
|
+
if self._popup and self._popup.winfo_exists():
|
|
317
|
+
with contextlib.suppress(tk.TclError):
|
|
318
|
+
popup_path = str(self._popup)
|
|
319
|
+
if focused and str(focused).startswith(popup_path):
|
|
320
|
+
return
|
|
321
|
+
self._close_popup()
|