Advertisement
sanfx

DockedGUI.py

Nov 22nd, 2012
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.58 KB | None | 0 0
  1. import maya.cmds
  2. import maya.mel
  3.  
  4. class BaseGUI(object):
  5.     @classmethod
  6.     def showUI(cls):
  7.         win=cls()
  8.         win.createUI()
  9.    
  10.     def __init__(self):
  11.         self.winName='window_Name'
  12.         self.title='window title'
  13.         self.size=(300,400)
  14.         self.v=maya.mel.eval('getApplicationVersionAsFloat')
  15.         if self.v>= 2011: self.dock=True
  16.         else: self.dock=False      
  17.        
  18.     def createUI(self):
  19.             """
  20.            Creates dockable GUI if maya version above 2011
  21.            else creates flying window
  22.            """
  23.            
  24.             if self.dock:
  25.                     if maya.cmds.dockControl(self.winName+"_dock",q=True,exists=True):
  26.                             maya.cmds.deleteUI(self.winName+"_dock")
  27.             else:
  28.                     if maya.cmds.window(self.winName,q=True, exists=True):
  29.                             maya.cmds.deleteUI(self.winName)
  30.             self.window=maya.cmds.window(self.winName, title = self.title,
  31.                                          widthHeight=self.size,retain=False)                            
  32.             self.tabLayout=maya.cmds.tabLayout('tabLayout',parent=self.winName,
  33.                                     innerMarginWidth=5,scr=True,
  34.                                     innerMarginHeight=5,cr=True)  
  35.  
  36.            
  37.             ###All  controls to be placed in mainLayout###
  38.             self.commonLayout()
  39.            
  40.            
  41.             #Edit tabs layout
  42.             self.editTabLayout()
  43.            
  44.             #Show the window
  45.             if self.dock:
  46.                     maya.cmds.dockControl(self.winName+"_dock",w=self.size[0], label=self.title, area="left",
  47.                                       content=self.winName)
  48.             else:
  49.                     maya.cmds.showWindow(self.winName)
  50.    
  51.     def commonLayout(self):
  52.         """ Add control in this method for by overriding in your py module"""
  53.         self.mainLayout=maya.cmds.columnLayout("mainLayout",parent="tabLayout",adj=True)
  54.         ## add more laytouts update editTabLayout accordingly..
  55.         self.secondTab=maya.cmds.columnLayout('secondTab', adjustableColumn=True,parent="tabLayout")
  56.  
  57.    
  58.     def editTabLayout(self):
  59.         """You can add more tabs here, in tablayout by overriding this method in your py module"""
  60.         maya.cmds.tabLayout( 'tabLayout', edit=True,scr=True,
  61.                              tabLabel=((self.mainLayout,'Label 1'),
  62.                                        (self.secondTab, 'Label 2')
  63.                                        )
  64.                              )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement