def run_main(cls, main: Callable, *main_args, **main_kwargs): try: main(*main_args, **main_kwargs) if cls.config_type( ).event_loop_type == AsyncEventLoopType.GLIB_ONLY: Gtk.main() elif cls.config_type().event_loop_type == AsyncEventLoopType.GBULB: gbulb.install(gtk=True) gbulb.get_event_loop().set_exception_handler( async_handle_exeception) from skytemple.core.events.manager import EventManager GLib.idle_add(EventManager.instance().async_init) asyncio.get_event_loop().run_forever() else: raise RuntimeError("Invalid async configuration") except OSError as ex: if hasattr(ex, 'winerror') and ex.winerror == 6: # type: ignore # [WinError 6] The handle is invalid # Originates in gi/_ossighelper.py - Some issues with socket cleanup. We will ignore that. pass else: raise except (SystemExit, KeyboardInterrupt): pass finally: # TODO: Currently always required for Debugger compatibility # (since that ALWAYS uses this async implementation) AsyncTaskRunner.end()
def main(): # TODO: Gtk.Application: https://python-gtk-3-tutorial.readthedocs.io/en/latest/application.html path = os.path.abspath(os.path.dirname(__file__)) # Load settings settings = SkyTempleSettingsStore() if sys.platform.startswith('win'): # Load theming under Windows _load_theme(settings) # Solve issue #12 try: from skytemple_files.common.platform_utils.win import win_set_error_mode win_set_error_mode() except BaseException: # This really shouldn't fail, but it's not important enough to crash over pass if sys.platform.startswith('darwin'): # Load theming under macOS _load_theme(settings) # The search path is wrong if SkyTemple is executed as an .app bundle if getattr(sys, 'frozen', False): path = os.path.dirname(sys.executable) if sys.platform.startswith('linux') and gdk_backend() == GDK_BACKEND_BROADWAY: gtk_settings = Gtk.Settings.get_default() gtk_settings.set_property("gtk-theme-name", 'Arc-Dark') gtk_settings.set_property("gtk-application-prefer-dark-theme", True) itheme: Gtk.IconTheme = Gtk.IconTheme.get_default() itheme.append_search_path(os.path.abspath(icons())) itheme.append_search_path(os.path.abspath(os.path.join(data_dir(), "icons"))) itheme.append_search_path(os.path.abspath(os.path.join(get_debugger_data_dir(), "icons"))) itheme.rescan_if_needed() # Load Builder and Window builder = make_builder(os.path.join(path, "skytemple.glade")) main_window: Window = builder.get_object("main_window") main_window.set_role("SkyTemple") GLib.set_application_name("SkyTemple") GLib.set_prgname("skytemple") # TODO: Deprecated but the only way to set the app title on GNOME...? main_window.set_wmclass("SkyTemple", "SkyTemple") # Load CSS style_provider = Gtk.CssProvider() with open(os.path.join(path, "skytemple.css"), 'rb') as f: css = f.read() style_provider.load_from_data(css) Gtk.StyleContext.add_provider_for_screen( Gdk.Screen.get_default(), style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION ) # Load async task runner thread AsyncTaskRunner.instance() # Init. core events event_manager = EventManager.instance() if settings.get_integration_discord_enabled(): try: from skytemple.core.events.impl.discord import DiscordPresence discord_listener = DiscordPresence() event_manager.register_listener(discord_listener) except BaseException: pass # Load modules Modules.load() # Load main window + controller MainController(builder, main_window, settings) main_window.present() main_window.set_icon_name('skytemple') try: Gtk.main() except (KeyboardInterrupt, SystemExit): AsyncTaskRunner.end()
def on_destroy(self, *args): logger.debug('Window destroyed. Ending task runner.') AsyncTaskRunner.end() Gtk.main_quit() self._debugger_manager.destroy()