先把这个UI篇结束,然后在继续通读Max的Python模块的文档。
这一篇我是在Max2016上测试的,听说从2017之后,开始支持ui文件(Qt designer.exe)的解析.
在Max2016目录里的Python2.7并没有这个designer工具,我是在我自己安装的2.7的环境里找到的,它安静的躺在PySide的文件夹里等我轻轻的双击。
打开之后的界面是这样的
之后。。。我就省略了,这种基础UI布局类的软件都是基本操作。
然后简单的做了一下功能按钮,没有想太多,就按之前DotNet做的那个丑UI做吧
然后保存一下,文件名ExpressiongMirror.ui,于是我们就得到了一个UI文件
在2017版应该提供了直接将这个UI文件变成图形界面的接口。明天找时间重开一篇补充一下这个吧。
这个UI文件的内容我贴一下,其实就是个xml格式的文件
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>245</width>
<height>369</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="ResetXFormToPolyBtn">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>221</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>ResetXFormToPoly</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
<widget class="QPushButton" name="GetSampleBtn">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>221</width>
<height>71</height>
</rect>
</property>
<property name="text">
<string>GetSample</string>
</property>
</widget>
<widget class="QPushButton" name="MirrorVertexBtn">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>221</width>
<height>71</height>
</rect>
</property>
<property name="text">
<string>MirrorVertex</string>
</property>
</widget>
<widget class="QPushButton" name="GetLocalSampleBtn">
<property name="geometry">
<rect>
<x>10</x>
<y>200</y>
<width>221</width>
<height>71</height>
</rect>
</property>
<property name="text">
<string>GetLocalSample</string>
</property>
</widget>
<widget class="QPushButton" name="MirrorLocalVertexBtn">
<property name="geometry">
<rect>
<x>10</x>
<y>280</y>
<width>221</width>
<height>71</height>
</rect>
</property>
<property name="text">
<string>MirrorLocalVertex</string>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>ResetXFormToPolyBtn</sender>
<signal>clicked()</signal>
<receiver>Form</receiver>
<slot>ResetXFormToPolyClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>215</x>
<y>19</y>
</hint>
<hint type="destinationlabel">
<x>240</x>
<y>23</y>
</hint>
</hints>
</connection>
<connection>
<sender>GetSampleBtn</sender>
<signal>clicked()</signal>
<receiver>Form</receiver>
<slot>GetSampleClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>216</x>
<y>77</y>
</hint>
<hint type="destinationlabel">
<x>243</x>
<y>77</y>
</hint>
</hints>
</connection>
<connection>
<sender>MirrorVertexBtn</sender>
<signal>clicked()</signal>
<receiver>Form</receiver>
<slot>MirrorVertexClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>209</x>
<y>153</y>
</hint>
<hint type="destinationlabel">
<x>241</x>
<y>155</y>
</hint>
</hints>
</connection>
<connection>
<sender>GetLocalSampleBtn</sender>
<signal>clicked()</signal>
<receiver>Form</receiver>
<slot>GetLocalSampleClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>211</x>
<y>243</y>
</hint>
<hint type="destinationlabel">
<x>241</x>
<y>243</y>
</hint>
</hints>
</connection>
<connection>
<sender>MirrorLocalVertexBtn</sender>
<signal>clicked()</signal>
<receiver>Form</receiver>
<slot>MirrorLocalVertexClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>216</x>
<y>311</y>
</hint>
<hint type="destinationlabel">
<x>243</x>
<y>313</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>ResetXFormToPolyClicked()</slot>
<slot>GetSampleClicked()</slot>
<slot>MirrorVertexClicked()</slot>
<slot>GetLocalSampleClicked()</slot>
<slot>MirrorLocalVertexClicked()</slot>
</slots>
</ui>
有兴趣的可以看一下文件的内容,反正。。。我不太感兴趣,也不想自己造“解析这个文件为max2016及一下支持py的版本能用的文件“的轮子。
“生命苦短,我用派森”
这就是python的标语,轮子有人造好了,拿来主义,用就好了。(手动贴上那张牛顿图)
找到我自己安装的python2.7和PySide的目录
在PySide的目录上有个Scripts文件夹,里面有个uic.py文件,它就是轮子。
为了省略篇幅,我就直接吧我的ExpressiongMirror.ui复制到这个文件夹下。
然后(。。我的是win平台。。。)按住Shift,右键,选择在此处打开命令窗口.然后,也看到了,路径已经cd好了。
输入python uic.py ExpressiongMirror.ui -o ExpressiongMirror.py,按下伟大的Enter。我们的py文件就生成了,然后我把这UI和PY文件剪切走,还原我的原生态PySide目录。
打开看一下ExpressiongMirror.py文件
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'ExpressiongMirror.ui'
#
# Created: Thu Nov 8 00:12:47 2018
# by: pyside-uic 0.2.15 running on PySide 1.2.4
#
# WARNING! All changes made in this file will be lost!
from PySide import QtCore, QtGui
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(245, 369)
self.ResetXFormToPolyBtn = QtGui.QPushButton(Form)
self.ResetXFormToPolyBtn.setGeometry(QtCore.QRect(10, 10, 221, 23))
self.ResetXFormToPolyBtn.setAutoDefault(False)
self.ResetXFormToPolyBtn.setDefault(False)
self.ResetXFormToPolyBtn.setFlat(False)
self.ResetXFormToPolyBtn.setObjectName("ResetXFormToPolyBtn")
self.GetSampleBtn = QtGui.QPushButton(Form)
self.GetSampleBtn.setGeometry(QtCore.QRect(10, 40, 221, 71))
self.GetSampleBtn.setObjectName("GetSampleBtn")
self.MirrorVertexBtn = QtGui.QPushButton(Form)
self.MirrorVertexBtn.setGeometry(QtCore.QRect(10, 120, 221, 71))
self.MirrorVertexBtn.setObjectName("MirrorVertexBtn")
self.GetLocalSampleBtn = QtGui.QPushButton(Form)
self.GetLocalSampleBtn.setGeometry(QtCore.QRect(10, 200, 221, 71))
self.GetLocalSampleBtn.setObjectName("GetLocalSampleBtn")
self.MirrorLocalVertexBtn = QtGui.QPushButton(Form)
self.MirrorLocalVertexBtn.setGeometry(QtCore.QRect(10, 280, 221, 71))
self.MirrorLocalVertexBtn.setObjectName("MirrorLocalVertexBtn")
self.retranslateUi(Form)
QtCore.QObject.connect(self.ResetXFormToPolyBtn, QtCore.SIGNAL("clicked()"), Form.ResetXFormToPolyClicked)
QtCore.QObject.connect(self.GetSampleBtn, QtCore.SIGNAL("clicked()"), Form.GetSampleClicked)
QtCore.QObject.connect(self.MirrorVertexBtn, QtCore.SIGNAL("clicked()"), Form.MirrorVertexClicked)
QtCore.QObject.connect(self.GetLocalSampleBtn, QtCore.SIGNAL("clicked()"), Form.GetLocalSampleClicked)
QtCore.QObject.connect(self.MirrorLocalVertexBtn, QtCore.SIGNAL("clicked()"), Form.MirrorLocalVertexClicked)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.ResetXFormToPolyBtn.setText(QtGui.QApplication.translate("Form", "ResetXFormToPoly", None, QtGui.QApplication.UnicodeUTF8))
self.GetSampleBtn.setText(QtGui.QApplication.translate("Form", "GetSample", None, QtGui.QApplication.UnicodeUTF8))
self.MirrorVertexBtn.setText(QtGui.QApplication.translate("Form", "MirrorVertex", None, QtGui.QApplication.UnicodeUTF8))
self.GetLocalSampleBtn.setText(QtGui.QApplication.translate("Form", "GetLocalSample", None, QtGui.QApplication.UnicodeUTF8))
self.MirrorLocalVertexBtn.setText(QtGui.QApplication.translate("Form", "MirrorLocalVertex", None, QtGui.QApplication.UnicodeUTF8))
为了简单操作,我就直接在这个py文件里继续写了,根据上篇博客,直接写一个lei继承这个类和QtGui.QWidget。。
注意 我删除了上面的注释
from PySide import QtCore, QtGui
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(245, 369)
self.ResetXFormToPolyBtn = QtGui.QPushButton(Form)
self.ResetXFormToPolyBtn.setGeometry(QtCore.QRect(10, 10, 221, 23))
self.ResetXFormToPolyBtn.setAutoDefault(False)
self.ResetXFormToPolyBtn.setDefault(False)
self.ResetXFormToPolyBtn.setFlat(False)
self.ResetXFormToPolyBtn.setObjectName("ResetXFormToPolyBtn")
self.GetSampleBtn = QtGui.QPushButton(Form)
self.GetSampleBtn.setGeometry(QtCore.QRect(10, 40, 221, 71))
self.GetSampleBtn.setObjectName("GetSampleBtn")
self.MirrorVertexBtn = QtGui.QPushButton(Form)
self.MirrorVertexBtn.setGeometry(QtCore.QRect(10, 120, 221, 71))
self.MirrorVertexBtn.setObjectName("MirrorVertexBtn")
self.GetLocalSampleBtn = QtGui.QPushButton(Form)
self.GetLocalSampleBtn.setGeometry(QtCore.QRect(10, 200, 221, 71))
self.GetLocalSampleBtn.setObjectName("GetLocalSampleBtn")
self.MirrorLocalVertexBtn = QtGui.QPushButton(Form)
self.MirrorLocalVertexBtn.setGeometry(QtCore.QRect(10, 280, 221, 71))
self.MirrorLocalVertexBtn.setObjectName("MirrorLocalVertexBtn")
self.retranslateUi(Form)
QtCore.QObject.connect(self.ResetXFormToPolyBtn, QtCore.SIGNAL("clicked()"), Form.ResetXFormToPolyClicked)
QtCore.QObject.connect(self.GetSampleBtn, QtCore.SIGNAL("clicked()"), Form.GetSampleClicked)
QtCore.QObject.connect(self.MirrorVertexBtn, QtCore.SIGNAL("clicked()"), Form.MirrorVertexClicked)
QtCore.QObject.connect(self.GetLocalSampleBtn, QtCore.SIGNAL("clicked()"), Form.GetLocalSampleClicked)
QtCore.QObject.connect(self.MirrorLocalVertexBtn, QtCore.SIGNAL("clicked()"), Form.MirrorLocalVertexClicked)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
#我忘了修改这个。。。在py里直接修改了
Form.setWindowTitle(QtGui.QApplication.translate("Form", "ExpressiongMirror", None, QtGui.QApplication.UnicodeUTF8))
self.ResetXFormToPolyBtn.setText(QtGui.QApplication.translate("Form", "ResetXFormToPoly", None, QtGui.QApplication.UnicodeUTF8))
self.GetSampleBtn.setText(QtGui.QApplication.translate("Form", "GetSample", None, QtGui.QApplication.UnicodeUTF8))
self.MirrorVertexBtn.setText(QtGui.QApplication.translate("Form", "MirrorVertex", None, QtGui.QApplication.UnicodeUTF8))
self.GetLocalSampleBtn.setText(QtGui.QApplication.translate("Form", "GetLocalSample", None, QtGui.QApplication.UnicodeUTF8))
self.MirrorLocalVertexBtn.setText(QtGui.QApplication.translate("Form", "MirrorLocalVertex", None, QtGui.QApplication.UnicodeUTF8))
# add it by c.p.
class _GCProtector(object):
widgets = []
class MyWindow(QtGui.QWidget, Ui_Form):
def __init__(self):
super(MyWindow, self).__init__()
self.setupUi(self)
def ResetXFormToPolyClicked(self):
print "ResetXFormToPolyClicked"
def GetSampleClicked(self):
print "GetSampleClicked"
def MirrorVertexClicked(self):
print "MirrorVertexClicked"
def GetLocalSampleClicked(self):
print "GetLocalSampleClicked"
def MirrorLocalVertexClicked(self):
print "MirrorLocalVertexClicked"
def main():
app = QtGui.QApplication.instance()
if not app:
app = QtGui.QApplication([])
MaxPlus.FileManager.Reset(True)
form = MyWindow()
_GCProtector.widgets.append(form)
#为了让这个窗口一直浮于max主窗口之上,Max2016
MaxPlus.AttachQWidgetToMax(form)
form.show()
if __name__ == '__main__':
main()
这样,我的py文件修改好了,然后我打开max2016在一个ms文件里这么写道:
fname = "E:\\我的坚果云\\MaxScriptsDev\\ExpressiongMirror.py"
python.ExecuteFile fname
Ctrl+E运行一下。。
于是就有了
到此,工具的UI篇就这么恍恍惚惚的结束了吧