App#

App manages the pygame window and the active worlds. Most beginner projects do not need to create an App directly because world.run() starts the default application loop.

Use App only when you intentionally manage more than one world or need direct control over the application lifecycle.

API Reference#

class miniworlds.base.app.App(title, world)[Quellcode]#

Main application class for Miniworlds. Created automatically when world.run() is called for the first time.

Verursacht:

NoRunError – If run() is not called from the main module.

__init__(title, world)[Quellcode]#

Initializes the App and all its managers.

Parameter:
  • title – Title for the window.

  • world – The initial world object to be run.

add_display_to_repaint_areas()[Quellcode]#

Adds the full screen area to the repaint queue.

add_running_world(world)[Quellcode]#
Rückgabetyp:

None

static check_for_run_method()[Quellcode]#

Verifies that .run() is called in the user’s main module. Prints a warning if it’s not found (except in emscripten or notebooks).

display_repaint()[Quellcode]#

Repaints the regions marked as dirty (called every frame).

display_update()[Quellcode]#

Repaints the full display if it was marked dirty.

Bemerkung

This could be merged with display_repaint and update_surface.

classmethod get_path()[Quellcode]#
Rückgabetyp:

str | None

classmethod get_platform()[Quellcode]#
Rückgabetyp:

PlatformAdapter

classmethod get_running_app()[Quellcode]#
Rückgabetyp:

Optional[App]

classmethod get_running_world()[Quellcode]#
Rückgabetyp:

Optional[World]

classmethod get_window()[Quellcode]#
Rückgabetyp:

Optional[Window]

init: bool = False#
init_app()[Quellcode]#

Initializes global resources (e.g., image cache).

path: str | None = ''#
prepare_mainloop()[Quellcode]#

Prepares all world objects for drawing.

quit(exit_code=0)[Quellcode]#

Signals the mainloop to exit.

Parameter:

exit_code – Exit code to use when quitting.

register_path(path)[Quellcode]#

Registers the app path for relative resource access.

Parameter:

path – Path to the project directory.

classmethod register_run_check()[Quellcode]#

Registers an exit hook that warns when a world was created but run() was never called.

The source-based check in check_for_run_method() cannot detect run() calls that are commented out or never reached. This hook runs after the program ends and reports if no mainloop ever started, so students learn why no window appeared.

Rückgabetyp:

None

remove_running_world(world)[Quellcode]#
Rückgabetyp:

None

static reset(unittest=False, file=None)[Quellcode]#

Resets all app globals.

Parameter:
  • unittest – Whether the reset is being called in a unit test context.

  • file – Optional file path to use for setting the base path.

resize()[Quellcode]#

Resizes the window surface and updates all layout-related components.

async run(image, fullscreen=False, fit_desktop=False, replit=False)[Quellcode]#

Starts the app and enters the mainloop.

Parameter:
  • image – The background image to display.

  • fullscreen – Whether to start in fullscreen mode.

  • fit_desktop – Whether to adapt the window to desktop size.

  • replit – Whether running in replit environment.

running_app: Optional[App] = None#
running_world: Optional[World] = None#
running_worlds: List[World] = []#
set_running_world(world)[Quellcode]#
Rückgabetyp:

None

async start_mainloop()[Quellcode]#

Starts the main event loop.

window: Optional[Window] = None#