demosys.context.pyqt.Window

demosys.context.pyqt.Window

Window using PyQt5.

This is the recommended window if you want your project to work on most platforms out of the box without any binary dependecies.

demosys.context.pyqt.Keys

Namespace creating pyqt specific key constants

Methods

Window.__init__()

Creates a pyqt application and window overriding the built in event loop. Sets up keyboard and mouse events and creates a monderngl.Context.

Window.keyPressEvent(event)

Pyqt specific key press callback function. Translates and forwards events to keyboard_event().

Window.keyReleaseEvent(event)

Pyqt specific key release callback function. Translates and forwards events to keyboard_event().

Window.mouseMoveEvent(event)

Pyqt specific mouse event callback Translates and forwards events to cursor_event().

Window.swap_buffers()

Swaps buffers, increments the frame counter and pulls events

Window.use()

Make the window’s framebuffer the current render target

Window.should_close() → bool

Checks if the internal close state is set

Window.close()

Set the internal close state

Window.terminate()

Quits the running qt application

Window.resize(width, height)

Pyqt specific resize callback.

Other Inherited Methods

Window.draw(current_time, frame_time)

Draws a frame. Internally it calls the configured timeline’s draw method.

Parameters:
  • current_time (float) – The current time (preferrably always from the configured timer class)
  • frame_time (float) – The duration of the previous frame in seconds
Window.clear()

Clear the window buffer

Window.clear_values(red=0.0, green=0.0, blue=0.0, alpha=0.0, depth=1.0)

Sets the clear values for the window buffer.

Parameters:
  • red (float) – red compoent
  • green (float) – green compoent
  • blue (float) – blue compoent
  • alpha (float) – alpha compoent
  • depth (float) – depth value
Window.keyboard_event(key, action, modifier)

Handles the standard keyboard events such as camera movements, taking a screenshot, closing the window etc.

Can be overriden add new keyboard events. Ensure this method is also called if you want to keep the standard features.

Parameters:
  • key – The key that was pressed or released
  • action – The key action. Can be ACTION_PRESS or ACTION_RELEASE
  • modifier – Modifiers such as holding shift or ctrl
Window.cursor_event(x, y, dx, dy)

The standard mouse movement event method. Can be overriden to add new functionality. By default this feeds the system camera with new values.

Parameters:
  • x – The current mouse x position
  • y – The current mouse y position
  • dx – Delta x postion (x position difference from the previous event)
  • dy – Delta y postion (y position difference from the previous event)
Window.print_context_info()

Prints moderngl context info.

Window.set_default_viewport()

Calculates the viewport based on the configured aspect ratio in settings. Will add black borders if the window do not match the viewport.

Attributes

Window.size

(width, height) tuple containing the window size.

Note that for certain displays we rely on buffer_size() to get the actual window buffer size. This is fairly common for retina and 4k displays where the UI scale is > 1.0

Window.buffer_size

(width, heigh) buffer size of the window.

This is the actual buffer size of the window taking UI scale into account. A 1920 x 1080 window running in an environment with UI scale 2.0 would have a 3840 x 2160 window buffer.

Window.keys = <class 'demosys.context.pyqt.keys.Keys'>