gmendieta icon

Maya dock window with pyside

gmendieta | PRO | 03/07/18 05:31:22 PM UTC | 0 ⭐ | 541 👁️ | Never ⏰ | []
Python |

2.72 KB

|

None

|

0 👍

/

0 👎

"""
File: baseWindow.py
Author: Gorka Mendieta
Implementation of a Base Window using PySide
"""
 
import PySide.QtGui as qg
import PySide.QtCore as qc
 
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
from mayalib.ui.pyside.utils import GetMayaWindow
 
import maya.cmds as mc
 
import logging
 
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
 
 
class BaseWindow(MayaQWidgetDockableMixin, qg.QMainWindow):
    _windowName = 'BaseUI'
    _windowTitle = 'Base UI'
    _windowSize = (300, 600)
    _minSize = (400, 600)
    _dockable = True
    _dockArea = 'right'
 
    def __init__(self, parent=GetMayaWindow()):
        """
 
        :param parent:
        """
        qg.QMainWindow.__init__(self, parent)
        # super(BaseWindow, self).__init__(parent)
        self.widgets = {}
        self.BuildUI()
 
    def BuildUI(self):
        """
 
        :return:
        """
        self.widgets = {}
 
        if mc.window(self._windowName, exists=True):
            mc.deleteUI(self._windowName)
 
        self.setObjectName(self._windowName)
        self.setWindowTitle(self._windowTitle)
        self.setMinimumSize(self._minSize[0], self._minSize[1])
        self.resize(self._windowSize[0], self._windowSize[1])
 
        self.mainWidget = qg.QWidget()
 
        self.widgets['mainWidget'] = qg.QWidget()
        self.mainLayout = qg.QVBoxLayout()
        self.widgets['mainLayout'] = self.mainLayout
        self.mainWidget.setLayout(self.mainLayout)
        self.setCentralWidget(self.mainWidget)
 
        self.BuildCustomUI()
        self.BuildMenu()
        self.BuildConnections()
 
    def BuildCustomUI(self):
        """"""
        print ('BaseWindow.BuildCustomUI')
 
    def BuildMenu(self):
        """"""
        print ('BaseWindow.BuildMenu')
        self.windowMenu = self.menuBar().addMenu('Window')
        self.dockableAct = qg.QAction('Dockable Window', self)
        self.dockableAct.setCheckable(True)
        self.dockableAct.triggered.connect(self.UpdateDockable)
        self.windowMenu.addAction(self.dockableAct)
 
    def BuildConnections(self):
        """"""
        print ('BaseWindow.BuildConnections')
 
    def Show(self, dockable=_dockable, dockArea=_dockArea):
        """"""
        self._dockable = dockable
        self._dockArea = dockArea
        self.dockableAct.setChecked(self._dockable)
        self.show(dockable=self._dockable, area=self._dockArea, floating=False)
        self.activateWindow()
        self.raise_()
 
    def UpdateDockable(self):
        """"""
        self._dockable = self.dockableAct.isChecked()
        self.Show(self._dockable, self._dockArea)
 
        
window = BaseWindow()
window.Show(dockable=True)

Comments