import os import sys from pathlib import Path def _bootstrap_path() -> None: root = Path(__file__).resolve().parent.parent if getattr(sys, "frozen", False): root = Path(sys._MEIPASS) if hasattr(sys, "_MEIPASS") else root # type: ignore[attr-defined] if str(root) not in sys.path: sys.path.insert(0, str(root)) def _setup_linux_platform() -> None: """Set Qt platform plugin for Linux X11/Wayland compatibility.""" if sys.platform != "linux" or os.environ.get("QT_QPA_PLATFORM"): return if os.environ.get("WAYLAND_DISPLAY"): os.environ["QT_QPA_PLATFORM"] = "wayland;xcb" elif os.environ.get("DISPLAY"): os.environ["QT_QPA_PLATFORM"] = "xcb" _bootstrap_path() _setup_linux_platform() from ameba_control_panel.app import main # noqa: E402 if __name__ == "__main__": if "--profile" in sys.argv: sys.argv.remove("--profile") import cProfile import pstats profiler = cProfile.Profile() profiler.enable() try: main() finally: profiler.disable() stats = pstats.Stats(profiler) stats.sort_stats("cumulative") stats.print_stats(40) stats.dump_stats("profile_output.prof") print("Profile saved to profile_output.prof") else: main()