第一部分:编程环境搭配
1. Anaconda3-4.2.0-Windows-x86.exe,(先安装这个,在c:\Anaconda3)
2. PyQt5-5.6-gpl-Py3.5-Qt5.6.0-x32-2.exe,(再安装这个,会自动在找到目录c:\Anaconda3,使用"import PyQt5"验证一下是否安装成功了)
3. eric6-17.08,(打开命令行,切换到install.py所在路径,输入:python install.py,进行安装。安装完成后需要配置API,然后启用自动补全)
第二部分:软件打包
1. .qrc文件、.ui文件转换成.py
pyuic5 xxx.ui –o xxx.py
2. 打包工具:pyinstaller : pip install pyinstaller (打包成exe)
pyinstaller -F -w xxxxxx.py xxxxx.py ... xxxxxx.py
第三部分:使用vtk
#!/usr/bin/env python
# Contributed by Eric E Monson
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QApplication
import vtk
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
import sys
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(603, 553)
self.centralWidget = QtGui.QWidget(MainWindow)
self.gridlayout = QtGui.QGridLayout(self.centralWidget)
self.vtkWidget = QVTKRenderWindowInteractor(self.centralWidget)
self.gridlayout.addWidget(self.vtkWidget, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralWidget)
class SimpleView(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ren = vtk.vtkRenderer()
self.ui.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
self.iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor()
# Create source
source = vtk.vtkSphereSource()
source.SetCenter(0, 0, 0)
source.SetRadius(5.0)
# Create a mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(source.GetOutputPort())
# Create an actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
self.ren.AddActor(actor)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = SimpleView()
window.show()
window.iren.Initialize() # Need this line to actually show the render inside Qt
sys.exit(app.exec_())
都是网上搬来的内容,都不算原创,忙里偷闲,等有需求的时候再继续,先就这样吧。
参考文献:
- https://zhuanlan.zhihu.com/p/28085650
- https://sourceforge.net/projects/pywin32/files/
- https://blog.csdn.net/wangle_08/article/details/79235719
- https://blog.csdn.net/mccoy39082/article/details/80472730
- http://www.vtk.org/Wiki/VTK/Examples/Python/Widgets/EmbedPyQt2