def test_implicit_wrapInstance(): """.wrapInstance doesn't need the `base` argument""" from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: button = QtWidgets.QPushButton("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer)) assert isinstance(widget, QtWidgets.QWidget), widget assert widget.objectName() == button.objectName() if binding("PySide"): assert widget != button elif binding("PySide2") and _pyside2_commit_date() is None: assert widget != button elif binding("PySide2") and \ _pyside2_commit_date() <= datetime.datetime( 2017, 8, 25): assert widget == button else: assert widget == button finally: app.exit()
def _get_graphEditor(self): try: widget = omui.MQtUtil.findControl('graphEditor1GraphEdImpl') return QtCompat.wrapInstance(long(widget), QtWidgets.QWidget) except TypeError: cmds.error('No GraphEditor found!') return None
def getMainWindow(windowID=None, wrapInstance=True): """Get pointer to main Maya window. The pointer type is a QWidget, so wrap to that (though it can be wrapped to other things too). """ if wrapInstance: if windowID is not None: # ID is possibly a Maya widget if '|' in str(windowID): qtObj = pm.uitypes.toQtObject(windowID) if qtObj is not None: return qtObj # ID is an existing window pointer = omUI.MQtUtil.findControl(windowID) else: pointer = omUI.MQtUtil.mainWindow() if pointer is not None: return QtCompat.wrapInstance(int(pointer), QtWidgets.QWidget) # Fallback to searching widgets if isinstance(windowID, QtWidgets.QWidget): return windowID search = windowID or 'MayaWindow' for obj in QtWidgets.QApplication.topLevelWidgets(): if obj.objectName() == search: return obj
def test_implicit_wrapInstance_for_base_types(): """Tests .wrapInstance implicit cast of `Foo` pointer to `Foo` object Testing is based upon the following parameters: 1. The `base` argument has a default value. 2. `Foo` is a standard Qt class. """ from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: button = QtWidgets.QPushButton("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer)) assert widget.objectName() == button.objectName() assert type(widget) is QtWidgets.QPushButton, widget if binding("PySide"): assert widget != button elif binding("PySide2") and _pyside2_commit_date() is None: assert widget != button elif binding("PySide2") and \ _pyside2_commit_date() <= datetime.datetime( 2017, 8, 25): assert widget == button else: assert widget == button finally: app.exit()
def test_wrapInstance(): """Tests .wrapInstance cast of pointer to explicit class Note: sip.wrapInstance will ignore the explicit class if there is a more suitable type available. """ from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: button = QtWidgets.QPushButton("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer), QtWidgets.QWidget) assert widget.objectName() == button.objectName() if binding("PyQt4") or binding("PyQt5"): # Even when we explicitly pass QWidget we will get QPushButton assert type(widget) is QtWidgets.QPushButton, widget else: assert type(widget) is QtWidgets.QWidget, widget # IMPORTANT: this differs across sip and shiboken. if binding("PySide") or binding("PySide2"): assert widget != button else: assert widget == button finally: app.exit()
def test_implicit_wrapInstance(): """.wrapInstance doesn't need the `base` argument""" from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: button = QtWidgets.QPushButton("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer)) assert isinstance(widget, QtWidgets.QWidget), widget assert widget.objectName() == button.objectName() if binding("PySide"): assert widget != button elif binding("PySide2") and _pyside2_commit_date() is None: assert widget != button elif binding("PySide2") and \ _pyside2_commit_date() <= datetime.datetime( 2017, 8, 25): assert widget == button else: assert widget == button finally: app.exit()
def _notificationsON(overrideText=None): # if cmds.autoKeyframe(state=True, query=True): # Just checking... # print "AutoKey is on. No notifications needed." # return global _Notifications if _Notifications: return # Bounce if they are already on # Get the panels panels = cmds.getPanel(type='modelPanel') for panel in panels: try: # Get the m3dview apiPanel = apiui.M3dView.getM3dViewFromModelPanel(panel) # Wrap it try: widget = QtCompat.wrapInstance(apiPanel.widget(), QtWidgets.QWidget) except: print "Something went wrong with the wrapper." pass # Instance a dknotification on it notification = Notification(widget) if overrideText: notification.buttonText = overrideText # Show it notification.activate() # Store it _Notifications[panel] = [apiPanel, notification] except: print "%s does not have an M3dView." % panel pass
def get_maya_main_window(): """ Find Maya's main Window """ window = OpenMayaUI.MQtUtil.mainWindow() window = QtCompat.wrapInstance(long(window), QtWidgets.QMainWindow) return window
def get_top_window(): top_window = None try: from maya import OpenMayaUI as omui maya_main_window_ptr = omui.MQtUtil().mainWindow() top_window = QtCompat.wrapInstance(long(maya_main_window_ptr), QtWidgets.QWidget) except ImportError, e: pass
def mayaToQT(name): # Maya -> QWidget ptr = omui.MQtUtil.findControl(name) if ptr is None: ptr = omui.MQtUtil.findLayout(name) if ptr is None: ptr = omui.MQtUtil.findMenuItem(name) if ptr is not None: return QtCompat.wrapInstance(long(ptr), QtWidgets.QWidget)
def toQt(mayaName, QtClass): """ Given the name of a Maya UI element of any type, return the corresponding QWidget or QAction. If the object does not exist, returns None """ ptr = OpenMayaUI.MQtUtil.findControl(mayaName) if ptr is None: ptr = OpenMayaUI.MQtUtil.findLayout(mayaName) if ptr is None: ptr = OpenMayaUI.MQtUtil.findMenuItem(mayaName) if ptr is not None: return QtCompat.wrapInstance(long(ptr), QtClass)
def GetMayaPoint(mayaName): """ Convert a Maya ui path to a Qt object @param mayaName: Maya UI Path to convert (Ex: "scriptEditorPanel1Window|TearOffPane|scriptEditorPanel1|testButton" ) @return: PyQt representation of that object """ ptr = OpenMayaUI.MQtUtil.findControl(mayaName) if ptr is None: ptr = OpenMayaUI.MQtUtil.findLayout(mayaName) if ptr is None: ptr = OpenMayaUI.MQtUtil.findMenuItem(mayaName) if ptr is None: ptr = OpenMayaUI.MQtUtil.findMenu(mayaName) if ptr is not None: return QtCompat.wrapInstance(int(ptr), QtCore.QObject)
def test_implicit_wrapInstance_for_derived_types(): """Tests .wrapInstance implicit cast of `Foo` pointer to `Bar` object Testing is based upon the following parameters: 1. The `base` argument has a default value. 2. `Bar` is a standard Qt class. 3. `Foo` is a strict subclass of `Bar`, separated by one or more levels of inheritance. 4. `Foo` is not a standard Qt class. Note: For sip usage, implicit cast of `Foo` pointer always results in a `Foo` object. """ from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: class A(QtWidgets.QPushButton): pass class B(A): pass button = B("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer)) assert widget.objectName() == button.objectName() if binding("PyQt4") or binding("PyQt5"): assert type(widget) is B, widget else: assert type(widget) is QtWidgets.QPushButton, widget if binding("PySide") or binding("PySide2"): assert widget != button else: assert widget == button finally: app.exit()
def BuiltInMaya(qt_widget): window = cmds.window() layout = cmds.formLayout(parent = window) qtobj = QtCompat.wrapInstance(int(OpenMayaUI.MQtUtil.findLayout(layout)), QtWidgets.QWidget) qtobj.layout().addWidget(qt_widget) child = cmds.formLayout(layout, q = True, childArray =True) cmds.formLayout(layout, edit=True, attachForm=[(child[0], 'right', 0), (child[0], 'left', 0),(child[0], 'top', 0),(child[0], 'bottom', 0)]) # cmds.setParent('..') return window # # ----------------------------------------------- # from . import menuinterface # from . import contentinterface # from . import projectinterface # from . import userinterface # def content_interface(): # from . import contentinterface # _ptr = OpenMayaUI.MQtUtil.findControl("zfused_maya_content_interface") # _interface = QtCompat.wrapInstance(int(_ptr), contentinterface.contentguide.ContentGuide) # return _interface
def test_wrapInstance(): """.wrapInstance and .getCppPointer is identical across all bindings""" from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: button = QtWidgets.QPushButton("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer), QtWidgets.QWidget) assert isinstance(widget, QtWidgets.QWidget), widget assert widget.objectName() == button.objectName() # IMPORTANT: this differs across sip and shiboken. if binding("PySide") or binding("PySide2"): assert widget != button else: assert widget == button finally: app.exit()
def test_wrapInstance(): """.wrapInstance and .getCppPointer is identical across all bindings""" from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: button = QtWidgets.QPushButton("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer), QtWidgets.QWidget) assert isinstance(widget, QtWidgets.QWidget), widget assert widget.objectName() == button.objectName() # IMPORTANT: this differs across sip and shiboken. if binding("PySide") or binding("PySide2"): assert widget != button else: assert widget == button finally: app.exit()
def GetMayaMainWindowPoint(): ptr = OpenMayaUI.MQtUtil.mainWindow() return QtCompat.wrapInstance(int(ptr), QtWidgets.QWidget)
def GetMayaLayoutPoint(layoutName): ptr = OpenMayaUI.MQtUtil.findLayout(layoutName) return QtCompat.wrapInstance(int(ptr), QtWidgets.QWidget)
def getMayaWindow(): ptr = OpenMayaUI.MQtUtil.mainWindow() if ptr: return QtCompat.wrapInstance(long(ptr))
def maya_main_window(): main_window_ptr = mui.MQtUtil.mainWindow() return QtCompat.wrapInstance(long(main_window_ptr), QtWidgets.QWidget)
def getMayaWindow(): """ pointer to the maya main window """ ptr = OpenMayaUI.MQtUtil.mainWindow() if ptr: return QtCompat.wrapInstance((long(ptr)))