Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2015
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.86 KB | None | 0 0
  1.  
  2.  
  3. from PySide import QtGui, QtCore
  4. from ctypes import pythonapi, c_void_p, py_object
  5.  
  6.  
  7. class Ui_TestWidget(object):
  8.     def setupUi(self, TestWidget):
  9.         TestWidget.setObjectName("TestWidget")
  10.         TestWidget.resize(396, 205)
  11.         self.pushButton = QtGui.QPushButton(TestWidget)
  12.         self.pushButton.setGeometry(QtCore.QRect(250, 120, 75, 23))
  13.         self.pushButton.setObjectName("pushButton")
  14.         self.radioButton = QtGui.QRadioButton(TestWidget)
  15.         self.radioButton.setGeometry(QtCore.QRect(90, 70, 82, 17))
  16.         self.radioButton.setObjectName("radioButton")
  17.         self.pushButton_2 = QtGui.QPushButton(TestWidget)
  18.         self.pushButton_2.setGeometry(QtCore.QRect(250, 90, 75, 23))
  19.         self.pushButton_2.setObjectName("pushButton_2")
  20.         self.toolButton = QtGui.QToolButton(TestWidget)
  21.         self.toolButton.setGeometry(QtCore.QRect(150, 120, 25, 19))
  22.         self.toolButton.setObjectName("toolButton")
  23.  
  24.         self.retranslateUi(TestWidget)
  25.         QtCore.QMetaObject.connectSlotsByName(TestWidget)
  26.  
  27.     def retranslateUi(self, TestWidget):
  28.         TestWidget.setWindowTitle(QtGui.QApplication.translate("TestWidget", "Form", None, QtGui.QApplication.UnicodeUTF8))
  29.         self.pushButton.setText(QtGui.QApplication.translate("TestWidget", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
  30.         self.radioButton.setText(QtGui.QApplication.translate("TestWidget", "RadioButton", None, QtGui.QApplication.UnicodeUTF8))
  31.         self.pushButton_2.setText(QtGui.QApplication.translate("TestWidget", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
  32.         self.toolButton.setText(QtGui.QApplication.translate("TestWidget", "...", None, QtGui.QApplication.UnicodeUTF8))
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. class _GCProtector(object):
  40.     """
  41.    This class acts as a holder for a static class var in order to prevent Qt widgets
  42.    from being garbage-collected
  43.    """
  44.  
  45.     # declare static class var
  46.     widgets = []
  47.  
  48.  
  49. class MaxQt(QtGui.QMainWindow):
  50.     """
  51.    This class contains Pyside/Qt bindings that are useful for 3ds max
  52.    """
  53.  
  54.     def __init__(self):
  55.         """
  56.        The constructor.
  57.        """
  58.  
  59.         super(MaxQt, self).__init__()
  60.  
  61.         if __name__ == '__main__':
  62.             self.drawWidget()
  63.  
  64.  
  65.     def drawWidget(self):
  66.         """
  67.        This draws the Qt widget
  68.        """
  69.  
  70.         # create an instance of the widget
  71.         widget = MaxQtWidget()
  72.  
  73.         # add to protection from being garbage collected
  74.         _GCProtector.widgets.append(widget)
  75.  
  76.         # return effective window system identifier of widget (const)
  77.         hwnd = widget.effectiveWinId()
  78.  
  79.         # use ctypes to get a pointer for the widget
  80.         pythonapi.PyCObject_AsVoidPtr.restype  = c_void_p
  81.         pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object]
  82.  
  83.         ptr = pythonapi.PyCObject_AsVoidPtr(hwnd)
  84.  
  85.         # now set 3ds max as the parent window of the widget
  86.         MaxPlus.Win32.Set3dsMaxAsParentWindow(ptr)
  87.  
  88.  
  89. class MaxQtWidget(QtGui.QWidget):
  90.     """
  91.    This subclass contains methods for creating a Qt widget
  92.    that has the 3ds max application as its parent.
  93.    """
  94.  
  95.     def __init__(self):
  96.         """
  97.        The constructor.
  98.        :return:
  99.        """
  100.  
  101.         # Calls the __init__() for the base class QtGui.QWidget()
  102.         super(MaxQtWidget, self).__init__()
  103.  
  104.  
  105.  
  106.         self.initUI()
  107.  
  108.  
  109.     def moveEvent(self, event):
  110.         """
  111.        This acts as an event listener and forces the QWidget to update.
  112.        Thus preventing graphic artifacting when dragging Qt widgets around the viewport.
  113.        :param event:
  114.        :return:
  115.        """
  116.         self.update()
  117.  
  118.  
  119.     def initUI(self):
  120.         """
  121.        This creates the UI and shows it.
  122.        :return:
  123.        """
  124.         a = Ui_TestWidget()
  125.  
  126.         a.setupUi(self)
  127.         self.show()
  128.  
  129.  
  130. a = MaxQt()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement