Advertisement
Guest User

Untitled

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