def wrapinstance(ptr, base=None): """ Wraps given object in a Qt object :param ptr: :param base: QObject, base QWidget class we want to wrap given object :return: """ if ptr is None: return None ptr = long(ptr) if 'shiboken' in globals(): if base is None: qObj = shiboken.wrapInstance(long(ptr), QtCore.QObject) meta_obj = qObj.metaObject() cls = meta_obj.className() super_cls = meta_obj.superClass().className() if hasattr(QtGui, cls): base = getattr(QtGui, cls) elif hasattr(QtGui, super_cls): base = getattr(QtGui, super_cls) else: base = QtWidgets.QWidget try: return shiboken.wrapInstance(long(ptr), base) except Exception: from PySide.shiboken import wrapInstance return wrapInstance(long(ptr), base) elif 'sip' in globals(): base = QtCore.QObject return shiboken.wrapinstance(long(ptr), base) else: logger.error('Failed to wrap object {} ...'.format(ptr)) return None
def wrapinstance(ptr, base=None): if ptr is None: return None ptr = long(ptr) if 'shiboken' in globals(): if base is None: qObj = shiboken.wrapInstance(long(ptr), QObject) meta_obj = qObj.metaObject() cls = meta_obj.className() super_cls = meta_obj.superClass().className() if hasattr(QtGui, cls): base = getattr(QtGui, cls) elif hasattr(QtGui, super_cls): base = getattr(QtGui, super_cls) else: base = QWidget try: return shiboken.wrapInstance(long(ptr), base) except Exception: from PySide.shiboken import wrapInstance return wrapInstance(long(ptr), base) elif 'sip' in globals(): base = QObject return shiboken.wrapinstance(long(ptr), base) else: print('Failed to wrap object ...') return None
def ExampleDialog_Execute(): """a simple example dialog showing basic functionality of the pyqt for softimage plugin""" from PySide import shiboken sianchor = Application.getQtSoftimageAnchor() sianchor = shiboken.wrapInstance( long(sianchor), QWidget ) dialog = ExampleDialog( sianchor ) dialog.show()
def ExampleSignalSlot_Execute(): """a simple example showing softimage events triggering pyqt signals""" from PySide import shiboken sianchor = Application.getQtSoftimageAnchor() sianchor = shiboken.wrapInstance( long(sianchor), QWidget ) dialog = ExampleSignalSlot( sianchor ) dialog.show()
def ExampleMenu_Execute(): """a simple example showing the use of a qmenu""" from PySide import shiboken sianchor = Application.getQtSoftimageAnchor() sianchor = shiboken.wrapInstance( long(sianchor), QWidget ) menu = ExampleMenu( sianchor ) # notice the use of QCursor and exec_ call menu.exec_(QCursor.pos())
def getMayaWindow(): try: ptr = mui.MQtUtil.mainWindow() if not ptr == None: return shiboken.wrapInstance(long(ptr), QtGui.QMainWindow) except AttributeError: return None
def _qtObject( address, type ) : global __qtModuleName if "PyQt" in __qtModuleName : import sip return sip.wrapinstance( address, type ) else : try : import PySide.shiboken as shiboken except ImportError : import shiboken return shiboken.wrapInstance( address, type )
def _qtObject(address, type): global __qtModuleName if "PyQt" in __qtModuleName: import sip return sip.wrapinstance(address, type) else: try: import PySide.shiboken as shiboken except ImportError: import shiboken return shiboken.wrapInstance(address, type)
def wrapinstance(ptr, base=None): """convert a pointer to a Qt class instance (PySide/PyQt compatible)""" if ptr is None: return None ptr = long(ptr) #Ensure type if isPySide(): from PySide import shiboken if base is None: qObj = shiboken.wrapInstance(ptr, QtCore.QObject) metaObj = qObj.metaObject() cls = metaObj.className() superCls = metaObj.superClass().className() if hasattr(QtGui, cls): base = getattr(QtGui, cls) elif hasattr(QtGui, superCls): base = getattr(QtGui, superCls) else: base = QtGui.QWidget return shiboken.wrapInstance(ptr, base) elif isPyQt4(): import sip return sip.wrapinstance(ptr, base) else: return None
def WidgetCreate(self, pWidgetParent): # # IN parameter pWidgetparent is the memory address of the parent Qt widget. # here we should PySide.shiboken.wrapInstance() function to convert it to PySide.QtWidget object. # and use it the as the parent for native Qt widgets created via Python. # Similiar approach is available in the sip python module for PyQt # # Only a single widget is allowed to be the *direct* child of the IN parent widget. # self.mNativeQtWidget = ReferencingSample.MainForm(shiboken.wrapInstance(pWidgetParent, QtGui.QWidget)) # # return the memory address of the *single direct* child QWidget. # return shiboken.getCppPointer(self.mNativeQtWidget)[0]
def WidgetCreate(self, pWidgetParent): # # IN parameter pWidgetparent is the memory address of the parent Qt widget. # here we should PySide.shiboken.wrapInstance() function to convert it to PySide.QtWidget object. # and use it the as the parent for native Qt widgets created via Python. # Similiar approach is available in the sip python module for PyQt # # Only a single widget is allowed to be the *direct* child of the IN parent widget. # self.mNativeQtWidget = ReferencingSample.MainForm( shiboken.wrapInstance(pWidgetParent, QtGui.QWidget)) # # return the memory address of the *single direct* child QWidget. # return shiboken.getCppPointer(self.mNativeQtWidget)[0]
def getMayaWindow(): ptr = OpenMayaUI.MQtUtil.mainWindow() return shiboken.wrapInstance(long(ptr), QtGui.QWidget)
def WidgetCreate(self, widgetParent): global the_window self.widget = VRayWindow(shiboken.wrapInstance(widgetParent, QtGui.QWidget)) the_window = self.widget return shiboken.getCppPointer(self.widget)[0]
def WidgetCreate(self, pWidgetParent): self.mNativeQtWidget = Ui_TabWidget(shiboken.wrapInstance(pWidgetParent, QtGui.QWidget)) return shiboken.getCppPointer(self.mNativeQtWidget)[0]
def mainwindow(): import pysidehooks_impl from PySide import QtGui, shiboken return shiboken.wrapInstance(pysidehooks_impl.mainwindow(), QtGui.QMainWindow)