|
|
|
|
@ -6,6 +6,7 @@ import signal |
|
|
|
|
import sys |
|
|
|
|
import pyray as rl |
|
|
|
|
import threading |
|
|
|
|
from contextlib import contextmanager |
|
|
|
|
from collections.abc import Callable |
|
|
|
|
from collections import deque |
|
|
|
|
from dataclasses import dataclass |
|
|
|
|
@ -170,6 +171,7 @@ class GuiApplication: |
|
|
|
|
self._window_close_requested = True |
|
|
|
|
|
|
|
|
|
def init_window(self, title: str, fps: int = _DEFAULT_FPS): |
|
|
|
|
with self._startup_profile_context(): |
|
|
|
|
def _close(sig, frame): |
|
|
|
|
self.close() |
|
|
|
|
sys.exit(0) |
|
|
|
|
@ -202,6 +204,36 @@ class GuiApplication: |
|
|
|
|
if not PC: |
|
|
|
|
self._mouse.start() |
|
|
|
|
|
|
|
|
|
@contextmanager |
|
|
|
|
def _startup_profile_context(self): |
|
|
|
|
if "PROFILE_STARTUP" not in os.environ: |
|
|
|
|
yield |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
import cProfile |
|
|
|
|
import io |
|
|
|
|
import pstats |
|
|
|
|
|
|
|
|
|
profiler = cProfile.Profile() |
|
|
|
|
start_time = time.monotonic() |
|
|
|
|
profiler.enable() |
|
|
|
|
|
|
|
|
|
# do the init |
|
|
|
|
yield |
|
|
|
|
|
|
|
|
|
profiler.disable() |
|
|
|
|
elapsed_ms = (time.monotonic() - start_time) * 1e3 |
|
|
|
|
|
|
|
|
|
stats_stream = io.StringIO() |
|
|
|
|
pstats.Stats(profiler, stream=stats_stream).sort_stats("cumtime").print_stats(25) |
|
|
|
|
print("\n=== Startup profile ===") |
|
|
|
|
print(stats_stream.getvalue().rstrip()) |
|
|
|
|
|
|
|
|
|
green = "\033[92m" |
|
|
|
|
reset = "\033[0m" |
|
|
|
|
print(f"{green}UI window ready in {elapsed_ms:.1f} ms{reset}") |
|
|
|
|
sys.exit(0) |
|
|
|
|
|
|
|
|
|
def set_modal_overlay(self, overlay, callback: Callable | None = None): |
|
|
|
|
if self._modal_overlay.overlay is not None: |
|
|
|
|
if self._modal_overlay.callback is not None: |
|
|
|
|
|