demoPySideQWidget.py

demoPySideQWidget.py
1 
2 '''
3  Demonstrates how to create a QWidget with PySide2 and attach it to the 3dsmax main window.
4 '''
5 
6 from PySide2 import QtCore
7 from PySide2 import QtWidgets
8 import MaxPlus
9 
10 
11 class _GCProtector(object):
12  widgets = []
13 
14 
15 def make_cylinder():
16  obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Cylinder)
17  obj.ParameterBlock.Radius.Value = 10.0
18  obj.ParameterBlock.Height.Value = 30.0
19  node = MaxPlus.Factory.CreateNode(obj)
22  return
23 
24 app = QtWidgets.qApp
25 if not app:
26  app = QtWidgets.QApplication([])
27 
28 
29 def main():
31 
32  w = QtWidgets.QWidget(MaxPlus.GetQMaxMainWindow(), QtCore.Qt.Dialog)
33  _GCProtector.widgets.append(w)
34  w.resize(250, 100)
35  w.setWindowTitle('PySide Qt Window')
36 
37  main_layout = QtWidgets.QVBoxLayout()
38  label = QtWidgets.QLabel("Click button to create a cylinder in the scene")
39  main_layout.addWidget(label)
40 
41  cylinder_btn = QtWidgets.QPushButton("Cylinder")
42  cylinder_btn.clicked.connect(make_cylinder)
43  main_layout.addWidget(cylinder_btn)
44 
45  textEdit = QtWidgets.QLineEdit()
46  textEdit.setText("Edit box")
47  main_layout.addWidget(textEdit)
48 
49  w.setLayout(main_layout)
50  w.show()
51 
52 
53 if __name__ == '__main__':
54  main()