Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- File: baseWindow.py
- Author: Gorka Mendieta
- Implementation of a Base Window using PySide2
- """
- import PySide2.QtCore as qc
- import PySide2.QtWidgets as qw
- import maya.OpenMayaUI as omui
- from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
- from shiboken2 import wrapInstance
- import maya.cmds as mc
- def GetMayaWindow():
- '''Get Main Maya Window'''
- ptr = omui.MQtUtil.mainWindow()
- return wrapInstance(long(ptr), qw.QWidget)
- class BaseWindow(MayaQWidgetDockableMixin, qw.QMainWindow):
- _windowName = 'BaseUI'
- _windowTitle = 'Base UI'
- _windowSize = (300, 600)
- _minSize = (400, 600)
- def __init__(self, parent=GetMayaWindow()):
- """"""
- super(BaseWindow, self).__init__(parent)
- self._dockable = False
- self.widgets = {}
- self.BuildUI()
- def BuildUI(self):
- '''
- :param name:
- :param width:
- :param height:
- :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 = qw.QWidget()
- self.widgets['mainWidget'] = qw.QWidget()
- self.mainLayout = qw.QVBoxLayout()
- self.widgets['mainLayout'] = self.mainLayout
- self.mainWidget.setLayout(self.mainLayout)
- self.setCentralWidget(self.mainWidget)
- self.BuildCustomUI()
- self.BuildMenu()
- self.BuildConnections()
- def BuildCustomUI(self):
- """
- To be overriden
- :return: None
- """
- print ('BaseWindow.BuildCustomUI')
- def BuildMenu(self):
- """
- To be overriden
- :return: None
- """
- print ('BaseWindow.BuildMenu')
- self.windowMenu = self.menuBar().addMenu('Window')
- self.dockableAct = qw.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=False):
- """"""
- self._dockable = dockable
- self.dockableAct.setChecked(self._dockable)
- self.show(dockable=self._dockable)
- def UpdateDockable(self):
- """"""
- self._dockable = self.dockableAct.isChecked()
- self.Show(self._dockable)
- window = BaseWindow()
- window.Show(dockable=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement