Example #1
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()
Example #2
0
    def open(self, main_window):
        """Open the debugger (if not already opened) and focus it's UI."""
        if not self.is_opened():
            self._was_opened_once = True
            self._context = SkyTempleMainDebuggerControlContext(self)
            builder = get_debugger_builder()
            self._opened_main_window: Gtk.Window = builder.get_object("main_window")
            self._opened_main_window.set_role("SkyTemple Script Engine Debugger")
            self._opened_main_window.set_title("SkyTemple Script Engine Debugger")

            self._opened_main_controller = DebuggerMainController(
                builder, self._opened_main_window, self._context
            )
            self.handle_project_change()
            self.main_window = main_window

        self._opened_main_window.present()
Example #3
0
    def open(self, main_window):
        """Open the debugger (if not already opened) and focus it's UI."""
        if not self.is_opened():
            self._was_opened_once = True
            self._context = SkyTempleMainDebuggerControlContext(self)

            builder = make_builder(
                os.path.join(get_debugger_package_dir(), "debugger.glade"))
            self._opened_main_window = builder.get_object("main_window")
            self._opened_main_window.set_role(
                "SkyTemple Script Engine Debugger")
            self._opened_main_window.set_title(
                "SkyTemple Script Engine Debugger")

            self._opened_main_controller = DebuggerMainController(
                builder, self._opened_main_window, self._context)
            self.handle_project_change()
            self.main_window = main_window

        assert self._opened_main_window is not None
        self._opened_main_window.present()
Example #4
0
class DebuggerManager:
    def __init__(self):
        self._context: Optional[SkyTempleMainDebuggerControlContext] = None
        self._opened_main_window: Optional[Gtk.Window] = None
        self._opened_main_controller: Optional[DebuggerMainController] = None
        self._was_opened_once = False
        self.main_window = None

    def open(self, main_window):
        """Open the debugger (if not already opened) and focus it's UI."""
        if not self.is_opened():
            self._was_opened_once = True
            self._context = SkyTempleMainDebuggerControlContext(self)

            builder = make_builder(
                os.path.join(get_debugger_package_dir(), "debugger.glade"))
            self._opened_main_window = builder.get_object("main_window")
            self._opened_main_window.set_role(
                "SkyTemple Script Engine Debugger")
            self._opened_main_window.set_title(
                "SkyTemple Script Engine Debugger")

            self._opened_main_controller = DebuggerMainController(
                builder, self._opened_main_window, self._context)
            self.handle_project_change()
            self.main_window = main_window

        assert self._opened_main_window is not None
        self._opened_main_window.present()

    def close(self):
        """
        Close the debugger and focus it's UI (to bring dialog boxes of it into foreground).
        Returns False if the debugger was not closed.
        """
        if not self.is_opened():
            return True
        assert self._opened_main_controller is not None
        return not self._opened_main_controller.on_main_window_delete_event()

    def check_save(self):
        """Checks if unsaved files exist, if so asks the user to save them."""
        if not self.is_opened():
            return True
        assert self._opened_main_controller is not None
        return self._opened_main_controller.editor_notebook.close_all_tabs()

    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()

    def is_opened(self):
        """Returns whether or not the debugger is opened."""
        should_be_opened = self._context is not None
        if should_be_opened:
            if self._opened_main_window not in Gtk.Window.list_toplevels():
                self.on_close()
                return False
        return should_be_opened

    def handle_project_change(self):
        """
        If the debugger is currently open, handles changing the project for it.
        The global singleton instance of RomProject is used.
        """
        project = RomProject.get_current()
        if project is not None and self.is_opened():
            assert self._opened_main_controller is not None
            self._opened_main_controller.load_rom()

    def open_ssb(self, ssb_filename, main_window):
        """Open a SSB file in the debugger and focus it."""
        self.open(main_window)
        assert self._opened_main_controller is not None
        self._opened_main_controller.editor_notebook.open_ssb(ssb_filename)

    def get_context(self) -> Optional[SkyTempleMainDebuggerControlContext]:
        """Returns the managing context for the debugger. Returns None if the debugger is not opened!"""
        return self._context

    def on_script_added(self, ssb_path, mapname, scene_type, scene_name):
        """Inform the debugger about a newly created SSB file."""
        if self.is_opened():
            assert self._opened_main_controller is not None
            self._opened_main_controller.on_script_added(
                ssb_path, mapname, scene_type, scene_name)

    def on_script_removed(self, ssb_path):
        """Inform the debugger about a removed SSB file."""
        if self.is_opened():
            assert self._opened_main_controller is not None
            self._opened_main_controller.on_script_removed(ssb_path)

    # CONTEXT PRIVATE:

    def on_close(self):
        """(Internal, only to be called by the Context). Mark as closed."""
        self._context = None
        self._opened_main_window = None
        self._opened_main_controller = None

    def get_controller(self) -> Optional[DebuggerMainController]:
        return self._opened_main_controller

    def get_window(self) -> Optional[Gtk.Window]:
        return self._opened_main_window