Maya model panel resize events

37 views
Skip to first unread message

Kupnu4000

unread,
Apr 21, 2015, 11:42:19 PM4/21/15
to python_in...@googlegroups.com
Hi! i'm writing a custom toolbox and i want it to be snapped to the left side of perspective model panel. To do that i need to track events when model panel is scaled or moved, but as fas as i know, Maya widgets don't emit any events when scaled or moved.

from PySide import QtCore, QtGui
from maya import OpenMayaUI as omui
from shiboken import wrapInstance

class TestWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent = self.getMayaWindow())

        self.setWindowFlags(QtCore.Qt.
Tool | QtCore.Qt.FramelessWindowHint)
        self.setFixedSize(100, 100)

        panelPtr = omui.MQtUtil.findControl('modelPanel4')
        panel = wrapInstance(long(panelPtr), QtGui.QWidget)
       
        position =  panel.mapToGlobal(panel.pos())
        self.move(position.x(), position.y() + panel.geometry().height() / 2 - self.geometry().height() / 2)

        mainLayout = QtGui.QVBoxLayout(self)
       
        button = QtGui.QPushButton('CLOSE')
        button.setFixedSize(80, 80)
        button.clicked.connect(self.deleteLater)
       
        mainLayout.addWidget(button)

    def getMayaWindow(self):
        omui.MQtUtil.mainWindow()   
        ptr = omui.MQtUtil.mainWindow()
        return wrapInstance(long(ptr), QtGui.QWidget)

w = TestWidget()
w.show()

This script should run as intended when Maya model panel is set to "Single Perspective View" (one model panel, not four). The TestWidget appears on the left center of model panel. I need it always to be there relative to model panel.

Any help would be appreciated!
Reply all
Reply to author
Forward
0 new messages