class neoscore.interface.app_interface.AppInterface[source]

Bases: object

The primary interface to the application state.

This holds much of the global application state. An AppInterface must be created near the start of neoscore programs.

__init__(document: Document, repl_refresh_func: Callable[[float], float], background_brush: BrushInterface, auto_viewport_interaction_enabled: bool)[source]
set_refresh_func(refresh_func: Callable[[float], float])[source]

Set a function to run automatically on a timer in the main window.

set_mouse_event_handler(handler: Callable[[MouseEvent], None])[source]

Set a function to run on mouse events.

set_key_event_handler(handler: Callable[[KeyEvent], None])[source]

Set a function to run on keyboard input events.

show(min_size: Optional[Tuple[int, int]] = None, max_size: Optional[Tuple[int, int]] = None, fullscreen: bool = False)[source]

Open a window showing a preview of the document.

  • min_size – An optional (width, height) minimum window size tuple.

  • max_size – An optional (width, height) maximum window size tuple.

  • fullscreen – Whether to show the window in fullscreen mode. This doesn’t mix well with max_window_size.

render_image(rect: Optional[RectDef], dest: str | pathlib.Path | bytearray, dpi: int, quality: int, bg_color: Color, autocrop: bool, preserve_alpha: bool) PropagatingThread[source]

Render the scene, or part of it, to a saved image.

This renders on the main thread but autocrops and saves the image on a spawned thread which is returned to allow efficient rendering of many images in parallel. render_image will block if too many render threads are already running.

  • rect – The part of the document to render, in document coordinates. If None, the entire scene will be rendered.

  • dest – An output file path or a bytearray to save to. If a bytearray is given, the output format will be PNG.

  • dpi – The pixels per inch of the rendered image.

  • quality – The quality of the output image for compressed image formats. Must be either -1 (default compression) or between 0 (most compressed) and 100 (least compressed).

  • bg_color – The background color for the image.

  • autocrop – Whether to crop the output image to tightly fit the contents of the frame. If true, the image will be cropped such that all 4 edges have at least one pixel not of bg_color.

  • preserve_alpha – Whether to preserve the alpha channel. If false, some non-transparent bg_color should be provided.


ImageExportError – If Qt image export fails for unknown reasons.


Destroy the window and all global interface-level data.

register_font(font_file_path: str | pathlib.Path) List[str][source]

Register a font file with the graphics engine.


font_file_path – A path to a font file. Supports TrueType and OpenType formats.


A list of font families found in the font.


FontRegistrationError – If the registration fails for any reason.

property background_brush: BrushInterface

The brush used to paint the scene background

property auto_viewport_interaction_enabled: bool

Whether mouse and scrollbar viewport interaction is enabled

property viewport_center_pos: Point

The interactive viewport’s center position in document space.

property viewport_scale: float

The interactive viewport’s scale (zoom).

Values should be greater than 0, with 1 as the base zoom and larger numbers zooming in.

property viewport_rotation: float

Set the interactive viewport’s rotation angle in degrees.

The viewport is rotated about its center.


Clear the QT Scene. This should be called before each render.