def close(self) -> None: """Quit application.""" if self._closed: return if hasattr(self, "render_timer"): self.render_timer.stop() BasePlotter.close(self) QVTKRenderWindowInteractor.close(self)
def disable(self) -> None: """Wrap ``BasePlotter.disable``.""" self.setDisabled(True) return BasePlotter.disable(self)
def enable(self) -> None: """Wrap ``BasePlotter.enable``.""" self.setEnabled(True) return BasePlotter.enable(self)
def _render(self, *args: Any, **kwargs: Any) -> BasePlotter.render: """Wrap ``BasePlotter.render``.""" return BasePlotter.render(self, *args, **kwargs)
def __init__( self, 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: Union[float, bool] = 5.0, **kwargs: Any, ) -> None: # pylint: disable=too-many-branches """Initialize Qt interactor.""" LOG.debug("QtInteractor init start") self.url: QtCore.QUrl = None # Cannot use super() here because # QVTKRenderWindowInteractor silently swallows all kwargs # because they use **kwargs in their constructor... qvtk_kwargs = dict(parent=parent) for key in ("stereo", "iren", "rw", "wflags"): if key in kwargs: qvtk_kwargs[key] = kwargs.pop(key) with _no_base_plotter_init(): QVTKRenderWindowInteractor.__init__(self, **qvtk_kwargs) BasePlotter.__init__(self, **kwargs) # backward compat for when we had this as a separate class self.interactor = self if multi_samples is None: multi_samples = global_theme.multi_samples self.setAcceptDrops(True) # Create and start the interactive renderer self.ren_win = self.GetRenderWindow() self.ren_win.SetMultiSamples(multi_samples) if line_smoothing: self.ren_win.LineSmoothingOn() if point_smoothing: self.ren_win.PointSmoothingOn() if polygon_smoothing: self.ren_win.PolygonSmoothingOn() for renderer in self.renderers: renderer.view_isometric() self.ren_win.AddRenderer(renderer) self.render_signal.connect(self._render) self.key_press_event_signal.connect(super().key_press_event) self.background_color = global_theme.background if self.title: self.setWindowTitle(title) if off_screen is None: off_screen = pyvista.OFF_SCREEN self._setup_interactor(off_screen) if off_screen: self.ren_win.SetOffScreenRendering(1) else: self._setup_key_press() # Make the render timer but only activate if using auto update self.render_timer = QTimer(parent=parent) if float(auto_update) > 0.0: # Can be False as well # Spawn a thread that updates the render window. # Sometimes directly modifiying object data doesn't trigger # Modified() and upstream objects won't be updated. This # ensures the render window stays updated without consuming too # many resources. twait = int((auto_update ** -1) * 1000.0) self.render_timer.timeout.connect(self.render) self.render_timer.start(twait) if global_theme.depth_peeling["enabled"]: if self.enable_depth_peeling(): for renderer in self.renderers: renderer.enable_depth_peeling() self._first_time = False # Crucial! LOG.debug("QtInteractor init stop")
def __init__(self, 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: Union[float, bool] = 5.0, **kwargs: Any) -> None: # pylint: disable=too-many-branches """Initialize Qt interactor.""" LOG.debug("QtInteractor init start") self.url: QtCore.QUrl = None self.default_camera_tool_bar = None self.saved_camera_positions: Optional[List[ BasePlotter.camera_position]] = None self.saved_cameras_tool_bar: QToolBar = None self.main_menu: QMenuBar = None self._menu_close_action = None self._edl_action = None self._parallel_projection_action = None self._view_action = None # Cannot use super() here because # QVTKRenderWindowInteractor silently swallows all kwargs # because they use **kwargs in their constructor... qvtk_kwargs = dict(parent=parent) for key in ("stereo", "iren", "rw", "wflags"): if key in kwargs: qvtk_kwargs[key] = kwargs.pop(key) with _no_base_plotter_init(): QVTKRenderWindowInteractor.__init__(self, **qvtk_kwargs) BasePlotter.__init__(self, **kwargs) # backward compat for when we had this as a separate class self.interactor = self if multi_samples is None: multi_samples = rcParams["multi_samples"] self.setAcceptDrops(True) # Create and start the interactive renderer self.ren_win = self.GetRenderWindow() self.ren_win.SetMultiSamples(multi_samples) if line_smoothing: self.ren_win.LineSmoothingOn() if point_smoothing: self.ren_win.PointSmoothingOn() if polygon_smoothing: self.ren_win.PolygonSmoothingOn() for renderer in self.renderers: self.ren_win.AddRenderer(renderer) self.render_signal.connect(self._render) self.key_press_event_signal.connect( super(QtInteractor, self).key_press_event) self.background_color = rcParams["background"] if self.title: self.setWindowTitle(title) if off_screen is None: off_screen = pyvista.OFF_SCREEN if off_screen: self.ren_win.SetOffScreenRendering(1) else: self.iren = self.ren_win.GetInteractor() self.iren.RemoveObservers("MouseMoveEvent") # slows window update? # Enter trackball camera mode istyle = vtk.vtkInteractorStyleTrackballCamera() self.SetInteractorStyle(istyle) self.iren.Initialize() self._observers: Dict[None, None] = { } # Map of events to observers of self.iren self._add_observer("KeyPressEvent", self.key_press_event) # Make the render timer but only activate if using auto update self.render_timer = QTimer(parent=parent) if float(auto_update) > 0.0: # Can be False as well # Spawn a thread that updates the render window. # Sometimes directly modifiying object data doesn't trigger # Modified() and upstream objects won't be updated. This # ensures the render window stays updated without consuming too # many resources. twait = (auto_update**-1) * 1000.0 self.render_timer.timeout.connect(self.render) self.render_timer.start(twait) if rcParams["depth_peeling"]["enabled"]: if self.enable_depth_peeling(): for renderer in self.renderers: renderer.enable_depth_peeling() self._first_time = False # Crucial! self.view_isometric() LOG.debug("QtInteractor init stop")
def __init__(self, parent=None, title=None, off_screen=None, multi_samples=None, line_smoothing=False, point_smoothing=False, polygon_smoothing=False, splitting_position=None, auto_update=5.0, **kwargs): """Initialize Qt interactor.""" log.debug('QtInteractor init start') # Cannot use super() here because # QVTKRenderWindowInteractor silently swallows all kwargs # because they use **kwargs in their constructor... qvtk_kwargs = dict(parent=parent) for key in ('stereo', 'iren', 'rw', 'wflags'): if key in kwargs: qvtk_kwargs[key] = kwargs.pop(key) with _no_BasePlotter_init(): QVTKRenderWindowInteractor.__init__(self, **qvtk_kwargs) BasePlotter.__init__(self, **kwargs) # backward compat for when we had this as a separate class self.interactor = self if multi_samples is None: multi_samples = rcParams['multi_samples'] self.setAcceptDrops(True) # Create and start the interactive renderer self.ren_win = self.GetRenderWindow() self.ren_win.SetMultiSamples(multi_samples) if line_smoothing: self.ren_win.LineSmoothingOn() if point_smoothing: self.ren_win.PointSmoothingOn() if polygon_smoothing: self.ren_win.PolygonSmoothingOn() for renderer in self.renderers: self.ren_win.AddRenderer(renderer) self.render_signal.connect(self._render) self.key_press_event_signal.connect(super(QtInteractor, self).key_press_event) self.background_color = rcParams['background'] if self.title: self.setWindowTitle(title) if off_screen is None: off_screen = pyvista.OFF_SCREEN if off_screen: self.ren_win.SetOffScreenRendering(1) else: self.iren = self.ren_win.GetInteractor() self.iren.RemoveObservers('MouseMoveEvent') # slows window update? # Enter trackball camera mode istyle = vtk.vtkInteractorStyleTrackballCamera() self.SetInteractorStyle(istyle) self.iren.Initialize() self._observers = {} # Map of events to observers of self.iren self._add_observer("KeyPressEvent", self.key_press_event) # Make the render timer but only activate if using auto update self.render_timer = QTimer(parent=parent) if float(auto_update) > 0.0: # Can be False as well # Spawn a thread that updates the render window. # Sometimes directly modifiying object data doesn't trigger # Modified() and upstream objects won't be updated. This # ensures the render window stays updated without consuming too # many resources. twait = (auto_update**-1) * 1000.0 self.render_timer.timeout.connect(self.render) self.render_timer.start(twait) if rcParams["depth_peeling"]["enabled"]: if self.enable_depth_peeling(): for renderer in self.renderers: renderer.enable_depth_peeling() self._first_time = False # Crucial! self.view_isometric() log.debug('QtInteractor init stop')