Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/marcomusy/vtkplotter
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Jun 22, 2019
2 parents 11135bd + 78c088a commit 6fbcdbf
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
34 changes: 34 additions & 0 deletions examples/basic/qt_window.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
from PyQt5 import Qt
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor

from vtkplotter import Plotter, Cone

# settings.usingQt = True <-- not needed anymore, automatically triggered by passing a qtWidget to Plotter


class MainWindow(Qt.QMainWindow):
def __init__(self, parent=None):

Qt.QMainWindow.__init__(self, parent)
self.frame = Qt.QFrame()
self.vl = Qt.QVBoxLayout()
self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
self.vl.addWidget(self.vtkWidget)

vp = Plotter(qtWidget=self.vtkWidget, axes=4, verbose=False)

vp += Cone()
vp.show() # to create renderer and add the actors

# set-up the rest of the Qt window
self.frame.setLayout(self.vl)
self.setCentralWidget(self.frame)

self.show() # <--- show the Qt Window


if __name__ == "__main__":
app = Qt.QApplication(sys.argv)
window = MainWindow()
app.exec_()
26 changes: 25 additions & 1 deletion vtkplotter/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class Plotter:
:param list shape: shape of the grid of renderers in format (rows, columns).
Ignored if N is specified.
:param int N: number of desired renderers arranged in a grid automatically.
:param list pos: (x,y) position in pixels of top-left corneer of the rendering window
:param list pos: (x,y) position in pixels of top-left corner of the rendering window
on the screen
:param size: size of the rendering window. If 'auto', guess it based on screensize.
:param screensize: physical size of the monitor screen
Expand Down Expand Up @@ -377,6 +377,13 @@ class Plotter:
:param bool interactive: if True will stop after show() to allow interaction w/ window
:param bool offscreen: if True will not show the rendering window
:param bool depthpeeling: depth-peel volumes along with the translucent geometry
:param QVTKRenderWindowInteractor qtWidget:
render in a Qt-Widget using an QVTKRenderWindowInteractor.
Overrides offscreen to True
Overides interactive to False
Sets setting.usingQt to True
See Also: example qt_windows.py
|multiwindows|
"""
Expand All @@ -398,11 +405,18 @@ def __init__(
interactive=None,
offscreen=False,
depthpeeling=False,
qtWidget = None
):

settings.plotter_instance = self
settings.plotter_instances.append(self)

if qtWidget is not None:
# overrides the interactive and offscreen properties
interactive = False
offscreen = True
settings.usingQt = True

if interactive is None:
if N or shape != (1, 1):
interactive = False
Expand Down Expand Up @@ -433,6 +447,7 @@ def __init__(
self.backgrcol = bg
self.offscreen = offscreen
self.showFrame = True
self.qtWidget = qtWidget # (QVTKRenderWindowInteractor)

# mostly internal stuff:
self.justremoved = None
Expand Down Expand Up @@ -586,6 +601,11 @@ def __init__(
for r in self.renderers:
self.window.AddRenderer(r)

if self.qtWidget is not None:
self.interactor = self.qtWidget.GetRenderWindow().GetInteractor()
self.window.SetOffScreenRendering(True)
return

if offscreen:
self.window.SetOffScreenRendering(True)
self.interactive = False
Expand Down Expand Up @@ -1356,6 +1376,9 @@ def scan(wannabeacts):
colors.printc("~times Error in show(): wrong renderer index", at, c=1)
return

if self.qtWidget is not None:
self.qtWidget.GetRenderWindow().AddRenderer(self.renderer)

if not self.camera:
if isinstance(camera, vtk.vtkCamera):
self.camera = camera
Expand Down Expand Up @@ -1394,6 +1417,7 @@ def scan(wannabeacts):
if hasattr(c, 'renderedAt'):
c.renderedAt.discard(at)


if self.axes is not None and not settings.notebookBackend:
addons.addAxes()

Expand Down

0 comments on commit 6fbcdbf

Please sign in to comment.