issue_905.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import sys
  2. from PyQt5 import Qt
  3. from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
  4. from vedo import Plotter, Cone, printc, settings
  5. class MainWindow(Qt.QMainWindow):
  6. def __init__(self, parent=None):
  7. Qt.QMainWindow.__init__(self, parent)
  8. self.frame = Qt.QFrame()
  9. self.layout = Qt.QVBoxLayout()
  10. self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
  11. # Create renderer and add the vedo objects and callbacks
  12. self.plt = Plotter(qt_widget=self.vtkWidget)
  13. self.plt += Cone().rotate_x(20)
  14. self.button = self.plt.add_button(
  15. self.buttonfunc,
  16. pos=(0.7, 0.05), # x,y fraction from bottom left corner
  17. states=["click to green"], # text for each state
  18. c=["w"], # font color for each state
  19. bc=["dg"], # background color for each state
  20. font="courier", # font type
  21. size=25, # font size
  22. bold=True, # bold font
  23. italic=False, # non-italic font style
  24. )
  25. self.plt.show() # <--- show the vedo rendering
  26. # Set-up the rest of the Qt window
  27. button = Qt.QPushButton("My Button makes the cone red")
  28. button.setToolTip("This is an example button")
  29. button.clicked.connect(self.onClick)
  30. self.layout.addWidget(self.vtkWidget)
  31. self.layout.addWidget(button)
  32. self.frame.setLayout(self.layout)
  33. self.setCentralWidget(self.frame)
  34. self.show() # <--- show the Qt Window
  35. def buttonfunc(self, obj, ename):
  36. print("btn is clicked...")
  37. self.plt.objects[0].color("green5").rotate_z(40)
  38. @Qt.pyqtSlot()
  39. def onClick(self):
  40. printc("..calling onClick")
  41. self.plt.objects[0].color("red5").rotate_z(40)
  42. self.plt.render()
  43. if __name__ == "__main__":
  44. if settings.dry_run_mode:
  45. sys.exit()
  46. app = Qt.QApplication(sys.argv)
  47. window = MainWindow()
  48. app.exec_()