Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """ Module pyside """
- import MaxPlus
- from PySide import QtGui, QtCore
- from ctypes import pythonapi, c_void_p, py_object
- class Example(QtGui.QWidget):
- def __init__(self):
- """
- The constructor.
- :return:
- """
- # Calls the __init__() for the base class QtGui.QWidget()
- super(Example, 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:
- """
- self.setGeometry(300, 300, 250, 150)
- self.setWindowTitle('Icon')
- self.show()
- 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(object):
- """
- This class contains Pyside/Qt bindings that are useful for 3ds max
- """
- def __init__(self):
- """
- The constructor.
- """
- 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:
- """
- self.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement