Advertisement
gmendieta

Maya dock window with pyside

Mar 7th, 2018
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.72 KB | None | 0 0
  1. """
  2. File: baseWindow.py
  3. Author: Gorka Mendieta
  4. Implementation of a Base Window using PySide
  5. """
  6.  
  7. import PySide.QtGui as qg
  8. import PySide.QtCore as qc
  9.  
  10. from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
  11. from mayalib.ui.pyside.utils import GetMayaWindow
  12.  
  13. import maya.cmds as mc
  14.  
  15. import logging
  16.  
  17. log = logging.getLogger(__name__)
  18. log.setLevel(logging.DEBUG)
  19.  
  20.  
  21. class BaseWindow(MayaQWidgetDockableMixin, qg.QMainWindow):
  22.     _windowName = 'BaseUI'
  23.     _windowTitle = 'Base UI'
  24.     _windowSize = (300, 600)
  25.     _minSize = (400, 600)
  26.     _dockable = True
  27.     _dockArea = 'right'
  28.  
  29.     def __init__(self, parent=GetMayaWindow()):
  30.         """
  31.  
  32.        :param parent:
  33.        """
  34.         qg.QMainWindow.__init__(self, parent)
  35.         # super(BaseWindow, self).__init__(parent)
  36.         self.widgets = {}
  37.         self.BuildUI()
  38.  
  39.     def BuildUI(self):
  40.         """
  41.  
  42.        :return:
  43.        """
  44.         self.widgets = {}
  45.  
  46.         if mc.window(self._windowName, exists=True):
  47.             mc.deleteUI(self._windowName)
  48.  
  49.         self.setObjectName(self._windowName)
  50.         self.setWindowTitle(self._windowTitle)
  51.         self.setMinimumSize(self._minSize[0], self._minSize[1])
  52.         self.resize(self._windowSize[0], self._windowSize[1])
  53.  
  54.         self.mainWidget = qg.QWidget()
  55.  
  56.         self.widgets['mainWidget'] = qg.QWidget()
  57.         self.mainLayout = qg.QVBoxLayout()
  58.         self.widgets['mainLayout'] = self.mainLayout
  59.         self.mainWidget.setLayout(self.mainLayout)
  60.         self.setCentralWidget(self.mainWidget)
  61.  
  62.         self.BuildCustomUI()
  63.         self.BuildMenu()
  64.         self.BuildConnections()
  65.  
  66.     def BuildCustomUI(self):
  67.         """"""
  68.         print ('BaseWindow.BuildCustomUI')
  69.  
  70.     def BuildMenu(self):
  71.         """"""
  72.         print ('BaseWindow.BuildMenu')
  73.         self.windowMenu = self.menuBar().addMenu('Window')
  74.         self.dockableAct = qg.QAction('Dockable Window', self)
  75.         self.dockableAct.setCheckable(True)
  76.         self.dockableAct.triggered.connect(self.UpdateDockable)
  77.         self.windowMenu.addAction(self.dockableAct)
  78.  
  79.     def BuildConnections(self):
  80.         """"""
  81.         print ('BaseWindow.BuildConnections')
  82.  
  83.     def Show(self, dockable=_dockable, dockArea=_dockArea):
  84.         """"""
  85.         self._dockable = dockable
  86.         self._dockArea = dockArea
  87.         self.dockableAct.setChecked(self._dockable)
  88.         self.show(dockable=self._dockable, area=self._dockArea, floating=False)
  89.         self.activateWindow()
  90.         self.raise_()
  91.  
  92.     def UpdateDockable(self):
  93.         """"""
  94.         self._dockable = self.dockableAct.isChecked()
  95.         self.Show(self._dockable, self._dockArea)
  96.  
  97.        
  98. window = BaseWindow()
  99. window.Show(dockable=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement