API Reference#
Background Plotter#
Attributes
Return render window size. |
Methods
|
Add a function that can update the scene in the background. |
Add the editor. |
|
Add the main menu bar. |
|
Add the toolbars. |
|
Clear all camera positions. |
|
|
Close the plotter. |
Reset all of the key press events to their defaults. |
|
Save camera position to saved camera menu for recall. |
|
|
Open scale axes dialog. |
|
Set the icon image. |
Update the app icon if the user is not trying to resize the window. |
- class pyvistaqt.BackgroundPlotter(show: bool = True, app: QApplication | None = None, window_size: Tuple[int, int] | None = None, off_screen: bool | None = None, allow_quit_keypress: bool = True, toolbar: bool = True, menu_bar: bool = True, editor: bool = True, update_app_icon: bool | None = None, app_window_class: Type[MainWindow] | None = None, **kwargs: Any)#
Bases:
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 runningshow()
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 (bool) – If True, display the default camera toolbar. Defaults to True.
menu_bar (bool) – If True, display the default main menu. Defaults to True.
editor (bool) – If True, display the VTK object editor. 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. If None, the logo of PyVista will be used. If False, no icon will be set. Defaults to None.
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 toTrue
, update rate will be 1 second.app_window_class (None, class, optional) – A subclass of MainWindow to use when creating the app window.
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: int | None = 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 the main menu bar.
- 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.
- set_icon(img: ndarray | str) None #
Set the icon image.
- Parameters:
img (numpy.ndarray, 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)
.
- staticMetaObject = PySide6.QtCore.QMetaObject("BackgroundPlotter" inherits "QtInteractor": )#
MultiPlotter#
Attributes
Methods
- class pyvistaqt.MultiPlotter(app: QApplication | None = None, nrows: int = 1, ncols: int = 1, show: bool = True, window_size: Tuple[int, int] | None = None, title: str | None = None, off_screen: bool | None = None, **kwargs: Any)#
Bases:
object
Qt interactive plotter.
Multi plotter for pyvista that allows to maintain an interactive window with multiple plotters without blocking the main python thread.
- Parameters:
app (optional) – Creates a QApplication if left as None.
nrows (int) – Number of rows. Defaults to 1.
ncols (int) – Number of columns. Defaults to 1.
show (bool) – Show the plotting window. If
False
, show this window by runningshow()
window_size (tuple, optional) – Window size in pixels. Defaults to
[1024, 768]
off_screen (bool, optional) – Renders off screen when True. Useful for automated screenshots or debug testing.
Examples
>>> import pyvista as pv >>> from pyvistaqt import MultiPlotter >>> plotter = MultiPlotter() >>> _ = plotter[0, 0].add_mesh(pv.Sphere())
QtInteractor#
Attributes
Methods
|
Quit application. |
|
Disable this renderer's camera from being interactive. |
|
Event is called when something is dropped onto the vtk window. |
|
Event is called after dragEnterEvent. |
|
Enable this renderer's camera to be interactive. |
|
Handle gesture events. |
|
Call key_press_event using a signal. |
|
Link the views' cameras across two plotters. |
|
Override the |
- class pyvistaqt.QtInteractor(parent: 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: float | bool = 5.0, **kwargs: Any)#
Bases:
QVTKRenderWindowInteractor
,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 – Number of updates per second. Useful for automatically updating the render window when actors are change without being automatically
Modified
.
- disable()#
Disable this renderer’s camera from being interactive.
- dragEnterEvent(event: 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.
- enable()#
Enable this renderer’s camera to be interactive.
- gesture_event(event: QGestureEvent) bool #
Handle gesture events.
- key_press_event_signal#
- link_views_across_plotters(other_plotter: Any, view: int = 0, other_views: Any = None) None #
Link the views’ cameras across two plotters.
- Parameters:
other_plotter (BackgroundPlotter) – The plotter whose views will be linked.
view (int) – Link the views in other_plotter to the this view index.
other_views (int | list of int) – Link these views from other_plotter to the reference view. The default is None, in which case all views from other_plotter will be linked to the reference view.
Note
For linking views belonging to a single plotter, please use pyvista’s Plotter.link_views method.
- render_signal#
- staticMetaObject = PySide6.QtCore.QMetaObject("QtInteractor" inherits "QVTKRenderWindowInteractor": Methods: #33 type=Signal, signature=render_signal() #34 type=Signal, signature=key_press_event_signal(PyObject,QString), parameters=PyObject, QString )#
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__
.