Esempio n. 1
0
 def destroy(self):
     """Free resources."""
     if self._was_opened_once:
         emu_instance = EmulatorThread.instance()
         if emu_instance is not None:
             emu_instance.end()
         EmulatorThread.destroy_lib()
Esempio n. 2
0
def main():
    try:
        if sys.platform.startswith('win'):
            # Load theming under Windows
            _windows_load_theme()

        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(get_debugger_data_dir(), "icons")))
        itheme.rescan_if_needed()

        # Load Builder and Window
        builder = get_debugger_builder()
        main_window: Window = builder.get_object("main_window")
        main_window.set_role("SkyTemple Script Engine Debugger")
        GLib.set_application_name("SkyTemple Script Engine Debugger")
        GLib.set_prgname("skytemple_ssb_debugger")
        # TODO: Deprecated but the only way to set the app title on GNOME...?
        main_window.set_wmclass("SkyTemple Script Engine Debugger",
                                "SkyTemple Script Engine Debugger")

        # Load main window + controller
        MainController(builder, main_window,
                       StandaloneDebuggerControlContext(main_window))

        Gtk.main()
    finally:
        if EmulatorThread.instance():
            EmulatorThread.instance().stop()
 def newFunction(*args, **kw):
     if THREAD_DEBUG:
         print(f'{current_thread()}: Trying to acquire {lock} ({f})')
         traceback.print_stack(file=sys.stdout)
     if current_thread() == EmulatorThread.instance()._thread_instance:
         while not lock.acquire(False):
             EmulatorThread.instance().run_one_pending_task()
         retval = f(*args, **kw)
         lock.release()
     else:
         with lock:
             retval = f(*args, **kw)
     if THREAD_DEBUG:
         print(f'{current_thread()}: Done with {lock}')
     return retval
def threadsafe_now_or_gtk_nonblocking(cb: Callable) -> None:
    """If on GTK thread: Run now blocking. Else delegate to threadsafe_gtk_nonblocking."""
    from skytemple_ssb_debugger.emulator_thread import EmulatorThread
    if current_thread() != EmulatorThread.instance()._thread_instance:
        cb()
    else:
        threadsafe_gtk_nonblocking(cb)
def threadsafe_gtk_nonblocking(cb: Callable) -> None:
    """Non-blocking call on the GTK thread. Must be called from emulator thread. No return value available."""
    if THREAD_DEBUG:
        from skytemple_ssb_debugger.emulator_thread import EmulatorThread
        if current_thread() != EmulatorThread.instance()._thread_instance:
            raise RuntimeError("Wrong threadsafe_gtk_nonblocking call.")

    def resolve_callback():
        cb()
        return False

    GLib.idle_add(resolve_callback)
Esempio n. 6
0
 def on_quit(self):
     Gtk.main_quit()
     emu_instance = EmulatorThread.instance()
     if emu_instance is not None:
         emu_instance.end()
     EmulatorThread.destroy_lib()
 def wrapper(*args, **kwargs):
     if current_thread() == EmulatorThread.instance()._thread_instance:
         return f(*args, **kwargs)
     return threadsafe_emu(EmulatorThread.instance(), lambda: f(*args, **kwargs))