示例#1
0
 def export_sprite(self, wan: bytes, dir_fn: str):
     with tempfile.TemporaryDirectory() as tmp_path:
         tmp_path = os.path.join(tmp_path, 'tmp.wan')
         with open(tmp_path, 'wb') as f:
             f.write(wan)
         AsyncTaskRunner.instance().run_task(
             self._run_gfxcrunch([tmp_path, dir_fn]))
         self._run_window()
         if self.status != GfxcrunchStatus.SUCCESS:
             raise RuntimeError(_("The gfxcrunch process failed."))
示例#2
0
 def import_sprite(self, dir_fn: str) -> bytes:
     with tempfile.TemporaryDirectory() as tmp_path:
         tmp_path = os.path.join(tmp_path, 'tmp.wan')
         AsyncTaskRunner.instance().run_task(self._run_gfxcrunch([dir_fn, tmp_path]))
         self._run_window()
         if self.status == GfxcrunchStatus.SUCCESS:
             with open(tmp_path, 'rb') as f:
                 return f.read()
         else:
             raise RuntimeError(_("The gfxcrunch process failed."))
示例#3
0
 def open(cls,
          filename,
          main_controller: Optional['MainController'] = None):
     """
     Open a file (in a new thread).
     If the main controller is set, it will be informed about this.
     """
     AsyncTaskRunner().instance().run_task(
         cls._open_impl(filename, main_controller))
示例#4
0
 def run_task(cls, coro: Coroutine):
     """
     This runs the coroutine, depending on the current configuration for async tasks.
     """
     if cls.config_type(
     ).async_task_runner_type == AsyncTaskRunnerType.THREAD_BASED:
         AsyncTaskRunner.instance().run_task(coro)
     elif cls.config_type(
     ).async_task_runner_type == AsyncTaskRunnerType.EVENT_LOOP_BLOCKING:
         Now.instance().run_task(coro)
     elif cls.config_type(
     ).async_task_runner_type == AsyncTaskRunnerType.EVENT_LOOP_BLOCKING_SOON:
         GLib.idle_add(lambda: Now.instance().run_task(coro))
     elif cls.config_type(
     ).async_task_runner_type == AsyncTaskRunnerType.EVENT_LOOP_CONCURRENT:
         asyncio.create_task(coro)
     else:
         raise RuntimeError("Invalid async configuration")
示例#5
0
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()
示例#6
0
 def on_destroy(self, *args):
     logger.debug('Window destroyed. Ending task runner.')
     AsyncTaskRunner.end()
     Gtk.main_quit()
     self._debugger_manager.destroy()
示例#7
0
 def _load_object(self, name, after_load_cb):
     AsyncTaskRunner.instance().run_task(
         self._load_object__impl(name, after_load_cb))
示例#8
0
 def _load_monster_outline(self, md_index, direction_id: int,
                           after_load_cb):
     AsyncTaskRunner.instance().run_task(
         self._load_monster_outline__impl(md_index, direction_id,
                                          after_load_cb))
示例#9
0
 def _load_actor_placeholder(self, actor_id, direction_id: int,
                             after_load_cb):
     AsyncTaskRunner.instance().run_task(
         self._load_actor_placeholder__impl(actor_id, direction_id,
                                            after_load_cb))
示例#10
0
 def _load(self, entry_id, sub_id, after_load_cb, allow_fallback):
     AsyncTaskRunner.instance().run_task(self._load__impl(entry_id, sub_id, after_load_cb, allow_fallback))
示例#11
0
 def save(self, main_controller: Optional['MainController']):
     """Save the rom. The main controller will be informed about this, if given."""
     AsyncTaskRunner().instance().run_task(self._save_impl(main_controller))
示例#12
0
 def _load_item(self, itm: ItemPEntry, after_load_cb):
     AsyncTaskRunner.instance().run_task(
         self._load_item__impl(itm, after_load_cb))
示例#13
0
 def _load_trap(self, trp: int, after_load_cb):
     AsyncTaskRunner.instance().run_task(
         self._load_trap__impl(trp, after_load_cb))