Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PySide import QtGui, QtCore
- from ctypes import pythonapi, c_void_p, py_object
- class Ui_TestWidget(object):
- def setupUi(self, TestWidget):
- TestWidget.setObjectName("TestWidget")
- TestWidget.resize(396, 205)
- self.pushButton = QtGui.QPushButton(TestWidget)
- self.pushButton.setGeometry(QtCore.QRect(250, 120, 75, 23))
- self.pushButton.setObjectName("pushButton")
- self.radioButton = QtGui.QRadioButton(TestWidget)
- self.radioButton.setGeometry(QtCore.QRect(90, 70, 82, 17))
- self.radioButton.setObjectName("radioButton")
- self.pushButton_2 = QtGui.QPushButton(TestWidget)
- self.pushButton_2.setGeometry(QtCore.QRect(250, 90, 75, 23))
- self.pushButton_2.setObjectName("pushButton_2")
- self.toolButton = QtGui.QToolButton(TestWidget)
- self.toolButton.setGeometry(QtCore.QRect(150, 120, 25, 19))
- self.toolButton.setObjectName("toolButton")
- self.retranslateUi(TestWidget)
- QtCore.QMetaObject.connectSlotsByName(TestWidget)
- def retranslateUi(self, TestWidget):
- TestWidget.setWindowTitle(QtGui.QApplication.translate("TestWidget", "Form", None, QtGui.QApplication.UnicodeUTF8))
- self.pushButton.setText(QtGui.QApplication.translate("TestWidget", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
- self.radioButton.setText(QtGui.QApplication.translate("TestWidget", "RadioButton", None, QtGui.QApplication.UnicodeUTF8))
- self.pushButton_2.setText(QtGui.QApplication.translate("TestWidget", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
- self.toolButton.setText(QtGui.QApplication.translate("TestWidget", "...", None, QtGui.QApplication.UnicodeUTF8))
- class _GCProtector(object):
- """
- This class acts as a holder for a static class var in order to prevent Qt widgets
- from being garbage-collected
- """
- # declare static class var
- widgets = []
- class MaxQt(QtGui.QMainWindow):
- """
- This class contains Pyside/Qt bindings that are useful for 3ds max
- """
- def __init__(self):
- """
- The constructor.
- """
- super(MaxQt, self).__init__()
- if __name__ == '__main__':
- self.drawWidget()
- def drawWidget(self):
- """
- This draws the Qt widget
- """
- # create an instance of the widget
- widget = MaxQtWidget()
- # add to protection from being garbage collected
- _GCProtector.widgets.append(widget)
- # return effective window system identifier of widget (const)
- hwnd = widget.effectiveWinId()
- # use ctypes to get a pointer for the widget
- pythonapi.PyCObject_AsVoidPtr.restype = c_void_p
- pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object]
- ptr = pythonapi.PyCObject_AsVoidPtr(hwnd)
- # now set 3ds max as the parent window of the widget
- MaxPlus.Win32.Set3dsMaxAsParentWindow(ptr)
- class MaxQtWidget(QtGui.QWidget):
- """
- This subclass contains methods for creating a Qt widget
- that has the 3ds max application as its parent.
- """
- def __init__(self):
- """
- The constructor.
- :return:
- """
- # Calls the __init__() for the base class QtGui.QWidget()
- super(MaxQtWidget, self).__init__()
- self.initUI()
- def moveEvent(self, event):
- """
- This acts as an event listener and forces the QWidget to update.
- Thus preventing graphic artifacting when dragging Qt widgets around the viewport.
- :param event:
- :return:
- """
- self.update()
- def initUI(self):
- """
- This creates the UI and shows it.
- :return:
- """
- a = Ui_TestWidget()
- a.setupUi(self)
- self.show()
- a = MaxQt()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement