forked from pyvista/pyvista
/
test_qt_plotting.py
81 lines (59 loc) · 2.05 KB
/
test_qt_plotting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import sys
import pytest
import numpy as np
import vtki
from vtki import QtInteractor
from vtki.plotting import running_xserver
try:
import PyQt5
from PyQt5 import Qt
from PyQt5.Qt import QMainWindow
has_pyqt5 = True
except:
has_pyqt5 = False
class QMainWindow(object):
pass
class MainWindow(QMainWindow):
def __init__(self, parent=None, show=True):
Qt.QMainWindow.__init__(self, parent)
self.frame = Qt.QFrame()
vlayout = Qt.QVBoxLayout()
self.vtk_widget = QtInteractor(self.frame)
vlayout.addWidget(self.vtk_widget)
self.frame.setLayout(vlayout)
self.setCentralWidget(self.frame)
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('File')
exitButton = Qt.QAction('Exit', self)
exitButton.setShortcut('Ctrl+Q')
exitButton.triggered.connect(self.close)
fileMenu.addAction(exitButton)
meshMenu = mainMenu.addMenu('Mesh')
self.add_sphere_action = Qt.QAction('Add Sphere', self)
self.add_sphere_action.triggered.connect(self.add_sphere)
meshMenu.addAction(self.add_sphere_action)
if show:
self.show()
def add_sphere(self):
sphere = vtki.Sphere()
self.vtk_widget.add_mesh(sphere)
self.vtk_widget.reset_camera()
@pytest.mark.skipif(not running_xserver(), reason="Requires X11")
@pytest.mark.skipif(not has_pyqt5, reason="requires pyqt5")
def test_qt_interactor(qtbot):
window = MainWindow(show=False)
qtbot.addWidget(window)
window.add_sphere()
assert np.any(window.vtk_widget.mesh.points)
@pytest.mark.skipif(not running_xserver(), reason="Requires X11")
@pytest.mark.skipif(not has_pyqt5, reason="requires pyqt5")
def test_background_plotting(qtbot):
sphere = vtki.Sphere()
plotter = vtki.BackgroundPlotter(show=False)
plotter.add_mesh(sphere)
assert np.any(plotter.mesh.points)
assert plotter.close()
# if __name__ == '__main__':
# app = Qt.QApplication(sys.argv)
# window = MainWindow()
# sys.exit(app.exec_())