Advertisement
Guest User

ktools_UI.py _shelf

a guest
Jul 31st, 2015
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.91 KB | None | 0 0
  1. import maya.OpenMayaUI as omui
  2. import maya.cmds as cmds
  3. import System.QTutils as QTutils
  4. reload(QTutils)
  5. from PySide import QtCore as qc
  6. from PySide import QtGui as qg
  7. from shiboken import wrapInstance
  8. import os
  9. from functools import partial
  10. import System.utils as utils
  11. reload(utils)
  12. import System.pluginFactory as pFactory
  13. reload(pFactory)
  14.  
  15. def maya_main_window():
  16.     main_window_ptr = omui.MQtUtil.mainWindow()
  17.     return wrapInstance(long(main_window_ptr), qg.QWidget)
  18.  
  19. class Ktools_UI(qg.QDialog):
  20.     def __init__(self, parent=maya_main_window()):
  21.         super(Ktools_UI, self).__init__(parent)
  22.    
  23.         self.setWindowTitle("_shelf")
  24.         self.setWindowFlags(qc.Qt.Tool)
  25.        
  26.         self.setFixedWidth(200)
  27.         self.setAttribute(qc.Qt.WA_DeleteOnClose) #!
  28.         self.setContentsMargins(0,0,0,0)
  29.         self.create_layout()
  30.  
  31.     def create_layout(self):
  32.     #main layout
  33.         main_layout = qg.QVBoxLayout()
  34.         main_layout.setContentsMargins(0,0,0,0)
  35.         main_layout.setSpacing(0)
  36.         main_layout.setAlignment(qc.Qt.AlignTop)
  37.         header = QTutils.header("_shelf")
  38.         main_layout.layout().addWidget(header)
  39.     #plugins widget
  40.         pluginsWidget = qg.QFrame()
  41.         pluginsWidget.setLayout(qg.QVBoxLayout())
  42.         pluginsWidget.layout().setSpacing(0)
  43.         pluginsWidget.layout().setContentsMargins(9,0,9,0)
  44.        
  45.         systemPath = "System"
  46.         pluginPath = os.environ["K_TOOLS"]
  47.         plugins = os.listdir(pluginPath)
  48.         plugin_list = []
  49.     #create plugins list   
  50.         for plugin in plugins:
  51.             if ((plugin != "__init__.py") and (plugin != systemPath)):
  52.                 plugin_list.append(plugin)
  53.        
  54.         x = len(plugin_list)
  55.        
  56.         windowHeight = 82
  57.         colors = utils.randomColorLine(x, 20)
  58.         style =""
  59.         #create plugin buttons
  60.         for index, plugin in enumerate(plugin_list):
  61.             command = plugin.strip('__') + "_UI"
  62.             uiFile = command + ".py"
  63.             uiPath = pluginPath + "/" + plugin + "/" + uiFile
  64.         #if UI file exists 
  65.             if os.path.isfile(uiPath):
  66.             #button appearance
  67.                 windowHeight += 45
  68.                 pluginLayout = plugin+"_layout"
  69.                 functionButton = plugin+"_functionButton"
  70.                 helpButton = plugin+"_helpButton"              
  71.                 functName = plugin+"_F_css"
  72.                 helpName = plugin+"_H_css"             
  73.                 pluginLayout = qg.QHBoxLayout()
  74.                 functionButton = qg.QPushButton(plugin)
  75.                 helpButton = qg.QPushButton("?")               
  76.                 functionButton.setObjectName(functName)
  77.                 helpButton.setObjectName(helpName)             
  78.                 pluginLayout.layout().addWidget(functionButton)
  79.                 pluginLayout.layout().addWidget(helpButton)            
  80.                 pluginsWidget.layout().addLayout(pluginLayout)
  81.                 if plugin is plugins[0]:
  82.                     Fborders = "border-top-left-radius: 3px;"
  83.                     Hborders = "border-top-right-radius: 3px;"
  84.                 elif plugin is plugins[-1]:
  85.                     Fborders = "border-bottom-left-radius: 3px;"
  86.                     Hborders = "border-bottom-right-radius: 3px;"
  87.                 else:
  88.                     Fborders = "border-radius: 0px;"
  89.                     Hborders = "border-radius: 0px;"   
  90.                 topNormalColor = colors[index] 
  91.                 bottomNormalColor = utils.shadeColor(colors[index], 0.3)       
  92.                 topPressedColor = utils.shadeColor(colors[index], 0.5)
  93.                 bottomPressedColor = utils.shadeColor(colors[index], 0.7)              
  94.                 topHoverColor = utils.shadeColor(colors[index], 1.1)
  95.                 bottomHoverColor = utils.shadeColor(colors[index], 1.2)
  96.                 style += "#%s {height: 45px;width: 160px;background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %s, stop: 1 %s);%s}\
  97.                           #%s:hover {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %s, stop: 1 %s);}\
  98.                           #%s:pressed {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %s, stop: 1 %s);}\
  99.                           #%s {height: 45px;width: 22px;background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %s, stop: 1 %s);%s}\
  100.                           #%s:hover {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %s, stop: 1 %s);}\
  101.                           #%s:pressed {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %s, stop: 1 %s);}\
  102.                 " %(functName,
  103.                     topNormalColor,
  104.                     bottomNormalColor,
  105.                     Fborders,
  106.                     functName,
  107.                     topHoverColor,
  108.                     bottomHoverColor,
  109.                     functName,
  110.                     topPressedColor,
  111.                     bottomPressedColor,
  112.                     helpName,
  113.                     topNormalColor,
  114.                     bottomNormalColor,
  115.                     Hborders,
  116.                     helpName,
  117.                     topHoverColor,
  118.                     bottomHoverColor,
  119.                     helpName,
  120.                     topPressedColor,
  121.                     bottomPressedColor
  122.                     )  
  123.                 #connect buttons
  124.                 functionButton.clicked.connect(partial(self._pluginFactory, command))
  125.                 helpButton.clicked.connect(partial(self.pluginInfo, command))
  126.        
  127.         #finish ui creation
  128.         pluginsWidget.setStyleSheet(style) 
  129.         main_layout.layout().addWidget(pluginsWidget)
  130.         self.setLayout(main_layout)
  131.         self.setFixedHeight(windowHeight)
  132.        
  133.     #plugin factory
  134.     def _pluginFactory(self, plugin, *args):
  135.        
  136.         result = getattr(pFactory, plugin)
  137.         # print result
  138.         ###=<class 'System.pluginFactory.toolBox_UI'>
  139.         if issubclass(result, pFactory.BaseRun):
  140.             return result
  141.             # exec("pFactory.toolBox_UI()")
  142.            
  143.            
  144.            
  145.         # # #########
  146.         # # self.UIPlugins = {}
  147.         # # ##import plugin
  148.         # # folder = "__"+plugin.strip('_UI')
  149.         # # importPlugin = __import__(folder+"."+plugin, {},{},[plugin])
  150.         # # reload(importPlugin)
  151.        
  152.         # # result = getattr(importPlugin, plugin)
  153.         # # ##import toolbox manually just for test
  154.         # # import __toolBox.toolBox_UI as tb
  155.         # # reload(tb)
  156.        
  157.         # # ##manual way
  158.         # # UI = tb.toolBox_UI()
  159.         # # # print "Manual:"
  160.         # # # print UI
  161.         # # ### = <__toolBox.toolBox_UI.toolBox_UI object at 0x000000E8D8F21EC8>
  162.         # # ##result way
  163.         # # self.UIPlugins[plugin+"_UI"] = result
  164.         # # # print "Result:"
  165.         # # # print self.UIPlugins[plugin+"_UI"]
  166.         # # ### = <class '__toolBox.toolBox_UI.toolBox_UI'>
  167.        
  168.        
  169.         # # # if __name__ == "__main__":
  170.             # # # try:
  171.                 # # # self.UIPlugins[plugin+"_UI"].close()
  172.             # # # except:
  173.                 # # # pass
  174.                
  175.         # # # self.UIPlugins[plugin+"_UI"].show()  
  176.         # # ### = TypeError: descriptor 'show' of 'PySide.QtGui.QWidget' object needs an argument
  177.     def pluginInfo(self, plugin):
  178.         print "DD"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement