klampt.vis.qtbackend module

class klampt.vis.backends.qtbackend.QtBackend[source]

Bases: object

Backend implementation of OpenGL visualization using Qt. Usually hidden from the user.

To use as a standalone program: Set up your GLProgramInterface, call createWindow to construct new windows and setProgram to set the GLProgram used in that window. Then call run() to start the Qt main loop.

createWindow(name, parent=None)[source]
initialize(program_name)[source]
kill()[source]
run()[source]

Starts the main loop

class klampt.vis.backends.qtbackend.QtGLWindow(name='OpenGL window', parent=None)[source]

Bases: PyQt5.QtOpenGL.QGLWidget

A basic OpenGL window using Qt. Should not be used directly, use the functions in QtBackend instead.

name

title of the window (only has an effect before calling run())

Type

str

width, height

width/height of the window in screen units. These are initialized from the GLProgram viewport on run(), but thereafter Qt manages them. After, the user must call resize(w,h) to change the dimensions.

Type

int

devwidth, devheight

width/height of the window in OpenGL device pixel units (Note that these may be different from the screen dimensions due to Retina displays)

Type

int

add_action(hook, short_text, key=None, description=None)[source]

This is called by the user to add actions to the menu bar.

Parameters
  • hook (function) – a python callback function, taking no arguments, called when the action is triggered.

  • short_text (str) – the text shown in the menu bar.

  • key (str, optional) – a shortcut keyboard command (can be ‘k’ or ‘Ctrl+k’).

  • description (str, optional) – if provided, this is a tooltip that shows up when the user hovers their mouse over the menu item.

close()[source]

Qt thread should call close() after this widget should be closed down to stop any existing Qt callbacks.

do_idlesleep(duration)[source]
do_refresh()[source]
do_reshape(w, h)[source]
draw_text(point, text, size=12, color=None)[source]

Renders text at the given point (may be 2d or 3d). Frontend should call this to draw text in either the display or display_screen method.

Parameters
  • point (list of floats) – either a 2d or 3d point at which to draw the text

  • text (str) – the text to draw

  • size (int, optional) – if given, it renders a font in the given size.

  • color (list of 3 floats or list of 4 floats) –

hide()[source]

Hides the window, if already shown

idlesleep(duration=inf)[source]

Externally callable. Sleeps the idle callback for t seconds. If t is not provided, the idle callback is slept forever

idlesleep_signal(*args, **kwargs)
initialize()[source]

Opens a window and initializes. Called internally, and must be in the visualization thread.

initializeGL(self)[source]
keyPressEvent(self, QKeyEvent)[source]
keyReleaseEvent(self, QKeyEvent)[source]
modifiers()[source]

Call this to retrieve modifiers. Called by frontend.

mouseMoveEvent(self, QMouseEvent)[source]
mousePressEvent(self, QMouseEvent)[source]
mouseReleaseEvent(self, QMouseEvent)[source]
paintGL(self)[source]
refresh()[source]

Externally callable. Requests a refresh of the window

refresh_signal(*args, **kwargs)
reshape(w, h)[source]

Externally callable. Reshapes the window

reshape_signal(*args, **kwargs)
resizeEvent(event)[source]

Called internally by Qt when Qt resizes the window

QtGLWindow.resizeGL(self, int, int)[source]
setParent(self, QWidget)[source]

setParent(self, QWidget, Union[Qt.WindowFlags, Qt.WindowType])

setProgram(program)[source]

User will call this to set up the program variable

show()[source]

Restores from a previous hide call

sizeHint(self) → QSize[source]
klampt.vis.backends.qtbackend.toGlutButton(button)[source]
klampt.vis.backends.qtbackend.toModifierList(modifiers)[source]