WorldView#

class pyenki.viewer.WorldView#

Bases: QOpenGLWidget, HasCamera

A QOpenGLWidget that displays a world.

Basic example:

>>> import pyenki.viewer
>>> # setup a world
>>> world = ...
>>> # setup Qt: needs to be called before creating the first view
>>> pyenki.viewer.init()
>>> viewer = pyenki.WorldView(world=world)
>>> viewer.show()
>>> viewer.start_updating_world(0.1)
>>> # executes the Qt runloop for a while
>>> pyenki.viewer.run(duration=10)

Example of composition of two views of the same world:

>>> import pyenki.viewer
>>> from PySide6.QtWidgets import QHBoxLayout, QWidget
>>> # setup a world
>>> world = ...
>>> viewer_1 = pyenki.WorldView(
        world=world, camera_position=(-20, -20), camera_altitude=20)
>>> viewer_1.point_camera(target_position=(0, 0), target_altitude=5)
>>> viewer_2 = pyenki.WorldView(
        world=world, helpers=False, camera_is_ortho=True, camera_altitude=30)
>>> window = QWidget()
>>> hbox = QHBoxLayout(window)
>>> window.resize(960, 320)
>>> hbox.addWidget(viewer_1.widget)
>>> hbox.addWidget(viewer_2.widget)
>>> window.show()
>>> viewer_1.start_updating_world(0.1)
>>> pyenki.viewer.run(duration=10)
world#

the world to display.

Type:

World | None

walls_height#

the height of the world boundary in cm (readonly).

Type:

float

helpers#

whether to display the helpers widgets.

Type:

bool

image#

the currently rendered image (readonly).

Type:

Image

qt_widget#

a PyQt-compatible widget (readonly).

Type:

QOpenGLWidget

pyside_widget#

a PySide-compatible widget (readonly).

Type:

QOpenGLWidget

__init__(parent: QWidget | None = None, /, world: World | None = None, fps: SupportsFloat = 30.0, update_world: bool = False, time_step: SupportsFloat = 0.0, factor: SupportsFloat = 1.0, helpers: bool = True, walls_height: SupportsFloat = 10.0, **camera_config: Unpack[CameraConfig]) None#

Constructs a new instance.

Parameters:
  • world (World | None) – The world to display.

  • fps (float) – The framerate of the viewer in frames per second.

  • update_world (bool) – Whether to trigger world updates before redrawing.

  • time_step (float) – The simulation time step in seconds.

  • factor (bool) – The real-time factor. If larger than one, the simulation will run faster then real-time.

  • helpers (bool) – Whether to display the helpers widgets.

  • walls_height (float) – the height of the world boundary in cm.

  • **camera_config (CameraConfig) – the camera configuration.

save_image(path: str) None#

Saves an image.

Parameters:

path – The file path

start_updating_world(time_step: SupportsFloat = 0.0, factor: SupportsFloat = 1.0) None#

Starts updating the world in real-time.

Parameters:
  • time_step – The world time step

  • factor – The real time factor

stop_updating_world() None#

Stops updating the world.

property world: World | None#

The type of the None singleton.