Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import maya.OpenMayaUI as omui
- import maya.cmds as cmds
- import System.QTutils as QTutils
- reload(QTutils)
- from PySide import QtCore as qc
- from PySide import QtGui as qg
- from shiboken import wrapInstance
- import os
- from functools import partial
- import System.utils as utils
- reload(utils)
- import System.pluginFactory as pFactory
- reload(pFactory)
- def maya_main_window():
- main_window_ptr = omui.MQtUtil.mainWindow()
- return wrapInstance(long(main_window_ptr), qg.QWidget)
- class Ktools_UI(qg.QDialog):
- def __init__(self, parent=maya_main_window()):
- super(Ktools_UI, self).__init__(parent)
- self.setWindowTitle("_shelf")
- self.setWindowFlags(qc.Qt.Tool)
- self.setFixedWidth(200)
- self.setAttribute(qc.Qt.WA_DeleteOnClose) #!
- self.setContentsMargins(0,0,0,0)
- self.create_layout()
- def create_layout(self):
- #main layout
- main_layout = qg.QVBoxLayout()
- main_layout.setContentsMargins(0,0,0,0)
- main_layout.setSpacing(0)
- main_layout.setAlignment(qc.Qt.AlignTop)
- header = QTutils.header("_shelf")
- main_layout.layout().addWidget(header)
- #plugins widget
- pluginsWidget = qg.QFrame()
- pluginsWidget.setLayout(qg.QVBoxLayout())
- pluginsWidget.layout().setSpacing(0)
- pluginsWidget.layout().setContentsMargins(9,0,9,0)
- systemPath = "System"
- pluginPath = os.environ["K_TOOLS"]
- plugins = os.listdir(pluginPath)
- plugin_list = []
- #create plugins list
- for plugin in plugins:
- if ((plugin != "__init__.py") and (plugin != systemPath)):
- plugin_list.append(plugin)
- x = len(plugin_list)
- windowHeight = 82
- colors = utils.randomColorLine(x, 20)
- style =""
- #create plugin buttons
- for index, plugin in enumerate(plugin_list):
- command = plugin.strip('__') + "_UI"
- uiFile = command + ".py"
- uiPath = pluginPath + "/" + plugin + "/" + uiFile
- #if UI file exists
- if os.path.isfile(uiPath):
- #button appearance
- windowHeight += 45
- pluginLayout = plugin+"_layout"
- functionButton = plugin+"_functionButton"
- helpButton = plugin+"_helpButton"
- functName = plugin+"_F_css"
- helpName = plugin+"_H_css"
- pluginLayout = qg.QHBoxLayout()
- functionButton = qg.QPushButton(plugin)
- helpButton = qg.QPushButton("?")
- functionButton.setObjectName(functName)
- helpButton.setObjectName(helpName)
- pluginLayout.layout().addWidget(functionButton)
- pluginLayout.layout().addWidget(helpButton)
- pluginsWidget.layout().addLayout(pluginLayout)
- if plugin is plugins[0]:
- Fborders = "border-top-left-radius: 3px;"
- Hborders = "border-top-right-radius: 3px;"
- elif plugin is plugins[-1]:
- Fborders = "border-bottom-left-radius: 3px;"
- Hborders = "border-bottom-right-radius: 3px;"
- else:
- Fborders = "border-radius: 0px;"
- Hborders = "border-radius: 0px;"
- topNormalColor = colors[index]
- bottomNormalColor = utils.shadeColor(colors[index], 0.3)
- topPressedColor = utils.shadeColor(colors[index], 0.5)
- bottomPressedColor = utils.shadeColor(colors[index], 0.7)
- topHoverColor = utils.shadeColor(colors[index], 1.1)
- bottomHoverColor = utils.shadeColor(colors[index], 1.2)
- style += "#%s {height: 45px;width: 160px;background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %s, stop: 1 %s);%s}\
- #%s:hover {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %s, stop: 1 %s);}\
- #%s:pressed {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %s, stop: 1 %s);}\
- #%s {height: 45px;width: 22px;background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %s, stop: 1 %s);%s}\
- #%s:hover {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %s, stop: 1 %s);}\
- #%s:pressed {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %s, stop: 1 %s);}\
- " %(functName,
- topNormalColor,
- bottomNormalColor,
- Fborders,
- functName,
- topHoverColor,
- bottomHoverColor,
- functName,
- topPressedColor,
- bottomPressedColor,
- helpName,
- topNormalColor,
- bottomNormalColor,
- Hborders,
- helpName,
- topHoverColor,
- bottomHoverColor,
- helpName,
- topPressedColor,
- bottomPressedColor
- )
- #connect buttons
- functionButton.clicked.connect(partial(self._pluginFactory, command))
- helpButton.clicked.connect(partial(self.pluginInfo, command))
- #finish ui creation
- pluginsWidget.setStyleSheet(style)
- main_layout.layout().addWidget(pluginsWidget)
- self.setLayout(main_layout)
- self.setFixedHeight(windowHeight)
- #plugin factory
- def _pluginFactory(self, plugin, *args):
- result = getattr(pFactory, plugin)
- # print result
- ###=<class 'System.pluginFactory.toolBox_UI'>
- if issubclass(result, pFactory.BaseRun):
- return result
- # exec("pFactory.toolBox_UI()")
- # # #########
- # # self.UIPlugins = {}
- # # ##import plugin
- # # folder = "__"+plugin.strip('_UI')
- # # importPlugin = __import__(folder+"."+plugin, {},{},[plugin])
- # # reload(importPlugin)
- # # result = getattr(importPlugin, plugin)
- # # ##import toolbox manually just for test
- # # import __toolBox.toolBox_UI as tb
- # # reload(tb)
- # # ##manual way
- # # UI = tb.toolBox_UI()
- # # # print "Manual:"
- # # # print UI
- # # ### = <__toolBox.toolBox_UI.toolBox_UI object at 0x000000E8D8F21EC8>
- # # ##result way
- # # self.UIPlugins[plugin+"_UI"] = result
- # # # print "Result:"
- # # # print self.UIPlugins[plugin+"_UI"]
- # # ### = <class '__toolBox.toolBox_UI.toolBox_UI'>
- # # # if __name__ == "__main__":
- # # # try:
- # # # self.UIPlugins[plugin+"_UI"].close()
- # # # except:
- # # # pass
- # # # self.UIPlugins[plugin+"_UI"].show()
- # # ### = TypeError: descriptor 'show' of 'PySide.QtGui.QWidget' object needs an argument
- def pluginInfo(self, plugin):
- print "DD"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement