App

class compas_view2.app.App(version='120', width=800, height=500, viewmode='shaded', controller_class=None, show_grid=True, config=None)[source]

Bases: object

Viewer app.

The app has a (main) window with a central OpenGL widget (i.e. the “view”), and a menubar, toolbar, and statusbar. The menubar provides access to all supported “actions”. The toolbar is meant to be a “quicknav” to a selected set of actions. The app supports rotate/pan/zoom, and object selection via picking or box selections.

Currently the app uses OpenGL 2.2 and GLSL 120 with a “compatibility” profile. Support for OpenGL 3.3 and GLSL 330 with a “core” profile is under development.

Parameters
  • version (‘120’ | ‘330’, optional) – The version of the GLSL used by the shaders. Default is '120' with a compatibility profile. The option '330' is not yet available.

  • width (int, optional) – The width of the app window at startup. Default is 800.

  • height (int, optional) – The height of the app window at startup. Default is 500.

  • viewmode (‘shaded’ | ‘ghosted’ | ‘wireframe’ | ‘lighted’, optional) – The display mode of the OpenGL view. Default is 'shaded'. In 'ghosted' mode, all objects have a default opacity of 0.7.

  • show_grid (bool, optional) – Show the XY plane. Default is True.

  • controller_class (compas_view2.app.Controller, optional) – A custom controller corresponding to a custom config file. Default is None, in which case the default controller is used, matching the default config file.

  • config (dict | filepath, optional) – A configuration dict for the UI, or a path to a JSON file containing such a dict. Default is None, in which case the default configuration is used.

Attributes
  • window (PySide2.QtWidgets.QMainWindow) – The main window of the application. This window contains the view and any other UI components such as the menu, toolbar, statusbar, …

  • view (compas_view2.View) – Instance of OpenGL view. This view is the central widget of the main window.

  • controller (compas_view2.app.Controller) – The action controller of the app.

Notes

The app can currently only be used “as-is”. This means that there is no formal mechanism for adding actions to the controller or to add functionality to the shader, other than by extending the core classes. In the future, such mechanism will be provided by allowing the user to overwrite the configuration file and add actions to the controller, without having to modify the package source code.

Currently the app has no scene graph. All added COMPAS objects are wrapped in a viewer object and stored in a dictionary, mapping the object’s ID (id(object)) to the instance.

Examples

>>> from compas_view2 import app
>>> viewer = app.App()
>>> viewer.show()

Methods

about()

Display the about message as defined in the config file.

add(data, **kwargs)

Add a COMPAS object.

critical(message)

Display a critical warning.

fps(_fps)

Update fps info in the status bar.

info(message)

Display info.

on([interval, timeout])

question(message)

Ask a question.

resize(width, height)

Resize the main window programmatically.

run()

Show the viewer window.

show()

Show the viewer window.

status(message)

Display a message in the status bar.

warning(message)

Display a warning.