API Reference

Background Plotter

Attributes

ICON_TIME_STEP

window_size

Return render window size.

Methods

add_callback(func[, interval, count])

Add a function that can update the scene in the background.

add_editor()

Add the editor.

close()

Close the plotter.

reset_key_events()

Reset all of the key press events to their defaults.

scale_axes_dialog([show])

Open scale axes dialog.

set_icon(img)

Set the icon image.

update_app_icon()

Update the app icon if the user is not trying to resize the window.

class pyvistaqt.BackgroundPlotter(show: bool = True, app: PyQt5.QtWidgets.QApplication = None, window_size: Optional[Tuple[int, int]] = None, off_screen: bool = None, allow_quit_keypress: bool = True, toolbar: bool = True, menu_bar: bool = True, editor: bool = True, update_app_icon: bool = False, **kwargs: Any)

Bases: pyvistaqt.plotting.QtInteractor

Qt interactive plotter.

Background plotter for pyvista that allows you to maintain an interactive plotting window without blocking the main python thread.

Parameters
  • show – Show the plotting window. If False, show this window by running show()

  • app (optional) – Creates a QApplication if left as None.

  • window_size – Window size in pixels. Defaults to [1024, 768]

  • off_screen – Renders off screen when True. Useful for automated screenshots or debug testing.

  • allow_quit_keypress – Allow user to exit by pressing "q".

  • toolbar – Display the default camera toolbar. Defaults to True.

  • menu_bar – Display the default main menu. Defaults to True.

  • update_app_icon – If True, update_app_icon will be called automatically to update the Qt app icon based on the current rendering output.

  • title (str, optional) – Title of plotting window.

  • multi_samples (int, optional) – The number of multi-samples used to mitigate aliasing. 4 is a good default but 8 will have better results with a potential impact on performance.

  • line_smoothing (bool, optional) – If True, enable line smothing

  • point_smoothing (bool, optional) – If True, enable point smothing

  • polygon_smoothing (bool, optional) – If True, enable polygon smothing

  • auto_update (float, bool, optional) – Automatic update rate in seconds. Useful for automatically updating the render window when actors are change without being automatically Modified. If set to True, update rate will be 1 second.

Examples

>>> import pyvista as pv
>>> from pyvistaqt import BackgroundPlotter
>>> plotter = BackgroundPlotter()
>>> _ = plotter.add_mesh(pv.Sphere())
ICON_TIME_STEP = 5.0
add_callback(func: Callable, interval: int = 1000, count: Optional[int] = None)None

Add a function that can update the scene in the background.

Parameters
  • func – Function to be called with no arguments.

  • interval – Time interval between calls to func in milliseconds.

  • count – Number of times func will be called. If None, func will be called until the main window is closed.

add_editor()None

Add the editor.

close()None

Close the plotter.

This function closes the window which in turn will close the plotter through signal_close.

reset_key_events()None

Reset all of the key press events to their defaults.

Handles closing configuration for q-key.

scale_axes_dialog(show: bool = True) → pyvistaqt.dialog.ScaleAxesDialog

Open scale axes dialog.

set_icon(img: numpy.ndarray)None

Set the icon image.

Parameters

img (shape (w, h, c) | str) – The image. Should be uint8 and square (w == h). Can have 3 or 4 color/alpha channels (c). Can also be a string path that QIcon can load.

Notes

Currently string paths can silently fail, so make sure your path is something that produces a valid QIcon(img).

update_app_icon()None

Update the app icon if the user is not trying to resize the window.

property window_size

Return render window size.

QtInteractor

Attributes

key_press_event_signal

render_signal

Methods

add_menu_bar()

Add the main menu bar.

add_toolbars()

Add the toolbars.

clear_camera_positions()

Clear all camera positions.

close()

Quit application.

disable()

Disable this renderer’s camera from being interactive.

dragEnterEvent(event)

Event is called when something is dropped onto the vtk window.

dropEvent(event)

Event is called after dragEnterEvent.

enable()

Enable this renderer’s camera to be interactive.

gesture_event(event)

Handle gesture events.

key_press_event(obj, event)

Call key_press_event using a signal.

render()

Override the render method to handle threading issues.

save_camera_position()

Save camera position to saved camera menu for recall.

class pyvistaqt.QtInteractor(parent: pyvistaqt.window.MainWindow = None, title: str = None, off_screen: bool = None, multi_samples: int = None, line_smoothing: bool = False, point_smoothing: bool = False, polygon_smoothing: bool = False, auto_update: Union[float, bool] = 5.0, **kwargs: Any)

Bases: vtk.qt.QVTKRenderWindowInteractor.QVTKRenderWindowInteractor, pyvista.plotting.plotting.BasePlotter

Extend QVTKRenderWindowInteractor class.

This adds the methods available to pyvista.Plotter.

Parameters
  • parent – Qt parent.

  • title – Title of plotting window.

  • multi_samples – The number of multi-samples used to mitigate aliasing. 4 is a good default but 8 will have better results with a potential impact on performance.

  • line_smoothing – If True, enable line smothing

  • point_smoothing – If True, enable point smothing

  • polygon_smoothing – If True, enable polygon smothing

  • auto_update – Automatic update rate in seconds. Useful for automatically updating the render window when actors are change without being automatically Modified.

add_menu_bar()None

Add the main menu bar.

add_toolbars()None

Add the toolbars.

clear_camera_positions()None

Clear all camera positions.

close()None

Quit application.

disable()

Disable this renderer’s camera from being interactive.

dragEnterEvent(event: PyQt5.QtGui.QDragEnterEvent)None

Event is called when something is dropped onto the vtk window.

Only triggers event when event contains file paths that exist. User can drop anything in this window and we only want to allow files.

dropEvent(event: PyQt5.QtCore.QEvent)None

Event is called after dragEnterEvent.

enable()

Enable this renderer’s camera to be interactive.

gesture_event(event: PyQt5.QtWidgets.QGestureEvent)bool

Handle gesture events.

key_press_event(obj: Any, event: Any)None

Call key_press_event using a signal.

key_press_event_signal
render()None

Override the render method to handle threading issues.

render_signal
save_camera_position()None

Save camera position to saved camera menu for recall.

Class inheritance

This module contains the QtInteractor and BackgroundPlotter.

Diagram

BackgroundPlotter
+-- QtInteractor
    |-- QVTKRenderWindowInteractor
    |   +-- QWidget
    +-- BasePlotter

MainWindow
+-- QMainWindow

Implementation

BackgroundPlotter.__init__(...)
|-- self.app_window = MainWindow()
|-- self.frame = QFrame(parent=self.app_window)
+-- QtInteractor.__init__(parent=self.frame)
    |-- QVTKRenderWindowInteractor.__init__(parent=parent)
    |   +-- QWidget.__init__(parent, flags)
    |-- BasePlotter.__init__(...)
    +-- self.ren_win = self.GetRenderWindow()

Because QVTKRenderWindowInteractor calls QWidget.__init__, this will actually trigger BasePlotter.__init__ to be called with no arguments. This cannot be solved (at least) because using super() because QVTKRenderWindowInteractor.__init__ does not use super(), and also it might not be fixable because Qt is doing something in QWidget which is probably entirely separate from the Python super() process. We fix this by internally by temporarily monkey-patching BasePlotter.__init__ with a no-op __init__.