Python shiboken2.wrapInstance() Examples
The following are 30
code examples of shiboken2.wrapInstance().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
shiboken2
, or try the search function
.
Example #1
Source File: pyqt.py From mgear_core with MIT License | 8 votes |
def qt_import(shi=False, cui=False): """ import pyside/pyQt Returns: multi: QtGui, QtCore, QtWidgets, wrapInstance """ lookup = ["PySide2", "PySide", "PyQt4"] preferredBinding = os.environ.get("MGEAR_PYTHON_QT_BINDING", None) if preferredBinding is not None and preferredBinding in lookup: lookup.remove(preferredBinding) lookup.insert(0, preferredBinding) for binding in lookup: try: return _qt_import(binding, shi, cui) except Exception: pass raise _qt_import("ThisBindingSurelyDoesNotExist", False, False)
Example #2
Source File: lightManager.py From PythonForMayaSamples with GNU General Public License v3.0 | 7 votes |
def getDock(name='LightingManagerDock'): """ This function creates a dock with the given name. It's an example of how we can mix Maya's UI elements with Qt elements Args: name: The name of the dock to create Returns: QtWidget.QWidget: The dock's widget """ # First lets delete any conflicting docks deleteDock(name) # Then we create a workspaceControl dock using Maya's UI tools # This gives us back the name of the dock created ctrl = pm.workspaceControl(name, dockToMainWindow=('right', 1), label="Lighting Manager") # We can use the OpenMayaUI API to get the actual Qt widget associated with the name qtCtrl = omui.MQtUtil_findControl(ctrl) # Finally we use wrapInstance to convert it to something Python can understand, in this case a QWidget ptr = wrapInstance(long(qtCtrl), QtWidgets.QWidget) # And we return that QWidget back to whoever wants it. return ptr
Example #3
Source File: __init__.py From anima with MIT License | 7 votes |
def get_maya_main_window(): """Get the main Maya window as a QtGui.QMainWindow instance @return: QtGui.QMainWindow instance of the top level Maya windows ref: https://stackoverflow.com/questions/22331337/how-to-get-maya-main-window-pointer-using-pyside """ from anima.ui.lib import QtWidgets, QtCore from maya import OpenMayaUI ptr = OpenMayaUI.MQtUtil.mainWindow() if ptr is not None: from anima.ui.lib import IS_PYSIDE, IS_PYSIDE2, IS_PYQT4, IS_QTPY if IS_PYSIDE(): import shiboken return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget) elif IS_PYSIDE2(): import shiboken2 return shiboken2.wrapInstance(long(ptr), QtWidgets.QWidget) elif IS_PYQT4(): import sip return sip.wrapinstance(long(ptr), QtCore.QObject)
Example #4
Source File: AEsporeNodeTemplate.py From spore with MIT License | 7 votes |
def get_nav_layout(): def find_first_frame_layout(layout): """ recursivley get all child layout until we find the first framelayout """ children = cmds.layout(layout, ca=True, q=True) for child in children: if child.startswith('frameLayout'): return child else: return find_first_frame_layout(child) nav_layout = find_first_frame_layout('AttrEdsporeNodeFormLayout') return wrapInstance(long(omui.MQtUtil.findControl(nav_layout)), QWidget)
Example #5
Source File: ui.py From maya-retarget-blendshape with GNU General Public License v3.0 | 7 votes |
def mayaWindow(): """ Get Maya's main window. :rtype: QMainWindow """ window = OpenMayaUI.MQtUtil.mainWindow() window = shiboken.wrapInstance(long(window), QMainWindow) return window # ----------------------------------------------------------------------------
Example #6
Source File: utils.py From maya-timeline-marker with GNU General Public License v3.0 | 7 votes |
def mayaToQT(name): """ Maya -> QWidget :param str name: Maya name of an ui object :return: QWidget of parsed Maya name :rtype: QWidget """ ptr = OpenMayaUI.MQtUtil.findControl(name) if ptr is None: ptr = OpenMayaUI.MQtUtil.findLayout(name) if ptr is None: ptr = OpenMayaUI.MQtUtil.findMenuItem(name) if ptr is not None: return shiboken.wrapInstance(long(ptr), QWidget) # ----------------------------------------------------------------------------
Example #7
Source File: functions.py From medic with MIT License | 7 votes |
def getMayaMainWindow(): if hasattr(Qt, "IsPySide2"): if Qt.IsPySide2: import shiboken2 as shiboken else: import shiboken # Qt version less than 1.0.0 elif hasattr(Qt, "__version_info__"): if Qt.__version_info__[0] >= 2: import shiboken2 as shiboken else: import shiboken else: try: import shiboken2 as shiboken except: import shiboken return shiboken.wrapInstance(long(OpenMayaUI.MQtUtil_mainWindow()), QtWidgets.QMainWindow)
Example #8
Source File: pyside_test.py From pivy with ISC License | 7 votes |
def testAdresses(self): q = QtCore.QObject() ptr = wrapper.getCppPointer(q) print("CppPointer to an instance of PySide.QtCore.QObject = 0x%016X" % ptr[0]) # None of the following is expected to raise an # OverflowError on 64-bit systems # largest 32-bit address wrapper.wrapInstance(0xFFFFFFFF, QtCore.QObject) # a regular, slightly smaller 32-bit address wrapper.wrapInstance(0xFFFFFFF, QtCore.QObject) # an actual 64-bit address (> 4 GB, the first non 32-bit address) wrapper.wrapInstance(0x100000000, QtCore.QObject) # largest 64-bit address wrapper.wrapInstance(0xFFFFFFFFFFFFFFFF, QtCore.QObject)
Example #9
Source File: MyWindow.py From MayaDev with MIT License | 6 votes |
def getMayaMainWindow(): mayaMainWindow = OpenMayaUI.MQtUtil.mainWindow() return wrapInstance(long(mayaMainWindow), QtWidgets.QMainWindow)
Example #10
Source File: utils.py From maya-command-search with GNU General Public License v3.0 | 6 votes |
def mayaToQT(name): """ Maya -> QWidget :param str name: Maya name of an ui object :return: QWidget of parsed Maya name :rtype: QWidget """ ptr = OpenMayaUI.MQtUtil.findControl(name) if ptr is None: ptr = OpenMayaUI.MQtUtil.findLayout(name) if ptr is None: ptr = OpenMayaUI.MQtUtil.findMenuItem(name) if ptr is not None: return shiboken.wrapInstance(long(ptr), QWidget)
Example #11
Source File: Qt.py From NukeToolSet with MIT License | 6 votes |
def _pyside2(): """Initialise PySide2 These functions serve to test the existence of a binding along with set it up in such a way that it aligns with the final step; adding members from the original binding to Qt.py """ import PySide2 as module _setup(module, ["QtUiTools"]) Qt.__binding_version__ = module.__version__ try: import shiboken2 Qt.QtCompat.wrapInstance = ( lambda ptr, base=None: _wrapinstance( shiboken2.wrapInstance, ptr, base) ) Qt.QtCompat.getCppPointer = lambda object: \ shiboken2.getCppPointer(object)[0] except ImportError: pass # Optional if hasattr(Qt, "_QtUiTools"): Qt.QtCompat.loadUi = _loadUi if hasattr(Qt, "_QtCore"): Qt.__qt_version__ = Qt._QtCore.qVersion() Qt.QtCompat.translate = Qt._QtCore.QCoreApplication.translate if hasattr(Qt, "_QtWidgets"): Qt.QtCompat.setSectionResizeMode = \ Qt._QtWidgets.QHeaderView.setSectionResizeMode _reassign_misplaced_members("pyside2")
Example #12
Source File: Qt.py From NukeToolSet with MIT License | 6 votes |
def _pyqt5(): """Initialise PyQt5""" import PyQt5 as module _setup(module, ["uic"]) try: import sip Qt.QtCompat.wrapInstance = ( lambda ptr, base=None: _wrapinstance( sip.wrapinstance, ptr, base) ) Qt.QtCompat.getCppPointer = lambda object: \ sip.unwrapinstance(object) except ImportError: pass # Optional if hasattr(Qt, "_uic"): Qt.QtCompat.loadUi = _loadUi if hasattr(Qt, "_QtCore"): Qt.__binding_version__ = Qt._QtCore.PYQT_VERSION_STR Qt.__qt_version__ = Qt._QtCore.QT_VERSION_STR Qt.QtCompat.translate = Qt._QtCore.QCoreApplication.translate if hasattr(Qt, "_QtWidgets"): Qt.QtCompat.setSectionResizeMode = \ Qt._QtWidgets.QHeaderView.setSectionResizeMode _reassign_misplaced_members("pyqt5")
Example #13
Source File: Qt.py From dm2skin with The Unlicense | 6 votes |
def _pyside2(): """Initialise PySide2 These functions serve to test the existence of a binding along with set it up in such a way that it aligns with the final step; adding members from the original binding to Qt.py """ import PySide2 as module _setup(module, ["QtUiTools"]) Qt.__binding_version__ = module.__version__ try: import shiboken2 Qt.QtCompat.wrapInstance = ( lambda ptr, base=None: _wrapinstance( shiboken2.wrapInstance, ptr, base) ) Qt.QtCompat.getCppPointer = lambda object: \ shiboken2.getCppPointer(object)[0] except ImportError: pass # Optional if hasattr(Qt, "_QtUiTools"): Qt.QtCompat.loadUi = _loadUi if hasattr(Qt, "_QtCore"): Qt.__qt_version__ = Qt._QtCore.qVersion() Qt.QtCompat.translate = Qt._QtCore.QCoreApplication.translate if hasattr(Qt, "_QtWidgets"): Qt.QtCompat.setSectionResizeMode = \ Qt._QtWidgets.QHeaderView.setSectionResizeMode _reassign_misplaced_members("pyside2")
Example #14
Source File: Qt.py From dm2skin with The Unlicense | 6 votes |
def _pyqt5(): """Initialise PyQt5""" import PyQt5 as module _setup(module, ["uic"]) try: import sip Qt.QtCompat.wrapInstance = ( lambda ptr, base=None: _wrapinstance( sip.wrapinstance, ptr, base) ) Qt.QtCompat.getCppPointer = lambda object: \ sip.unwrapinstance(object) except ImportError: pass # Optional if hasattr(Qt, "_uic"): Qt.QtCompat.loadUi = _loadUi if hasattr(Qt, "_QtCore"): Qt.__binding_version__ = Qt._QtCore.PYQT_VERSION_STR Qt.__qt_version__ = Qt._QtCore.QT_VERSION_STR Qt.QtCompat.translate = Qt._QtCore.QCoreApplication.translate if hasattr(Qt, "_QtWidgets"): Qt.QtCompat.setSectionResizeMode = \ Qt._QtWidgets.QHeaderView.setSectionResizeMode _reassign_misplaced_members("pyqt5")
Example #15
Source File: Rush.py From rush with MIT License | 6 votes |
def getMayaWindow(): """ Get main window pointer """ ptr = OpenMayaUI.MQtUtil.mainWindow() return shiboken2.wrapInstance(long(ptr), QtWidgets.QMainWindow)
Example #16
Source File: _compat.py From mGui with MIT License | 6 votes |
def _pyside2_as_qt_object(widget): from PySide2.QtCore import QObject from PySide2.QtWidgets import QWidget from PySide2 import QtWidgets from shiboken2 import wrapInstance if hasattr(widget, '__qt_object__'): return widget.__qt_object__ ptr = _find_widget_ptr(widget) qobject = wrapInstance(long(ptr), QObject) meta = qobject.metaObject() _class = meta.className() _super = meta.superClass().className() qclass = getattr(QtWidgets, _class, getattr(QtWidgets, _super, QWidget)) return wrapInstance(long(ptr), qclass)
Example #17
Source File: _compat.py From mGui with MIT License | 6 votes |
def _pyside_as_qt_object(widget): from PySide.QtCore import QObject from PySide.QtGui import QWidget from PySide import QtGui from shiboken import wrapInstance if hasattr(widget, '__qt_object__'): return widget.__qt_object__ ptr = _find_widget_ptr(widget) qobject = wrapInstance(long(ptr), QObject) meta = qobject.metaObject() _class = meta.className() _super = meta.superClass().className() qclass = getattr(QtGui, _class, getattr(QtGui, _super, QWidget)) return wrapInstance(long(ptr), qclass)
Example #18
Source File: uExport.py From uExport with zlib License | 6 votes |
def getMayaWindow(): ptr = openMayaUI.MQtUtil.mainWindow() if ptr is not None: return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget)
Example #19
Source File: applications.py From hotbox_designer with BSD 3-Clause Clear License | 6 votes |
def get_main_window(): import maya.OpenMayaUI as omui import shiboken2 main_window = omui.MQtUtil.mainWindow() if main_window is not None: return shiboken2.wrapInstance(long(main_window), QtWidgets.QWidget)
Example #20
Source File: ui.py From maya-spline-ik with GNU General Public License v3.0 | 6 votes |
def mayaWindow(): """ Get Maya's main window. :rtype: QMainWindow """ window = OpenMayaUI.MQtUtil.mainWindow() window = shiboken.wrapInstance(long(window), QMainWindow) return window # ----------------------------------------------------------------------------
Example #21
Source File: setup.py From DeformationLearningSolver with BSD 3-Clause "New" or "Revised" License | 6 votes |
def getMayaWindow(): ptr = omui.MQtUtil.mainWindow() if ptr: return wrapInstance(long(ptr), QWidget) #----------------------------------------------------------------------
Example #22
Source File: lib.py From MayaDev with MIT License | 6 votes |
def getMayaMainWindow(): from PySide2 import QtWidgets from maya import OpenMayaUI from shiboken2 import wrapInstance mayaMainWindow = OpenMayaUI.MQtUtil.mainWindow() return wrapInstance(long(mayaMainWindow), QtWidgets.QMainWindow)
Example #23
Source File: ui.py From maya-channel-box-plus with GNU General Public License v3.0 | 6 votes |
def mayaToQT(name): """ Maya -> QWidget :param str name: Maya name of an ui object :return: QWidget of parsed Maya name :rtype: QWidget """ ptr = OpenMayaUI.MQtUtil.findControl( name ) if ptr is None: ptr = OpenMayaUI.MQtUtil.findLayout( name ) if ptr is None: ptr = OpenMayaUI.MQtUtil.findMenuItem( name ) if ptr is not None: return shiboken.wrapInstance( long( ptr ), QWidget )
Example #24
Source File: pyqt.py From mgear_core with MIT License | 6 votes |
def maya_main_window(): """Get Maya's main window Returns: QMainWindow: main window. """ main_window_ptr = omui.MQtUtil.mainWindow() return QtCompat.wrapInstance(long(main_window_ptr), QtWidgets.QWidget)
Example #25
Source File: pyqt.py From mgear_core with MIT License | 6 votes |
def _qt_import(binding, shi=False, cui=False): QtGui = None QtCore = None QtWidgets = None wrapInstance = None if binding == "PySide2": from PySide2 import QtGui, QtCore, QtWidgets import shiboken2 as shiboken from shiboken2 import wrapInstance from pyside2uic import compileUi elif binding == "PySide": from PySide import QtGui, QtCore import PySide.QtGui as QtWidgets import shiboken from shiboken import wrapInstance from pysideuic import compileUi elif binding == "PyQt4": from PyQt4 import QtGui from PyQt4 import QtCore import PyQt4.QtGui as QtWidgets from sip import wrapinstance as wrapInstance from PyQt4.uic import compileUi print("Warning: 'shiboken' is not supported in 'PyQt4' Qt binding") shiboken = None else: raise Exception("Unsupported python Qt binding '%s'" % binding) rv = [QtGui, QtCore, QtWidgets, wrapInstance] if shi: rv.append(shiboken) if cui: rv.append(compileUi) return rv
Example #26
Source File: qt.py From SISideBar with MIT License | 6 votes |
def get_maya_window(): try: return shiboken.wrapInstance(long(OpenMayaUI.MQtUtil.mainWindow()), QWidget) except: return None
Example #27
Source File: window_utils.py From spore with MIT License | 6 votes |
def get_layout(layout): """ return a layout wraped as QObject """ ptr = omui.MQtUtil.findLayout(layout) return shiboken2.wrapInstance(long(ptr), QWidget) #.layout()
Example #28
Source File: window_utils.py From spore with MIT License | 6 votes |
def maya_main_window(): """ return maya's main window wrapped in a QWidget """ pointer_main_window = omui.MQtUtil.mainWindow() if pointer_main_window: return shiboken2.wrapInstance(long(pointer_main_window), QWidget)
Example #29
Source File: window_utils.py From spore with MIT License | 6 votes |
def active_view_wdg(): """ return the active 3d view wrapped in a QWidget """ view = active_view() active_view_widget = shiboken2.wrapInstance(long(view.widget()), QWidget) return active_view_widget
Example #30
Source File: utils.py From maya-command-search with GNU General Public License v3.0 | 6 votes |
def mayaWindow(): """ Get Maya's main window. :rtype: QMainWindow """ window = OpenMayaUI.MQtUtil.mainWindow() window = shiboken.wrapInstance(long(window), QMainWindow) return window