Last active
August 29, 2015 13:56
-
-
Save RicardoViana/8961047 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ########################################## | |
| # VRAY LIGHT LISTER 0.5.2 # | |
| # # | |
| # by Ricardo Viana # | |
| # Feb 2014 # | |
| # # | |
| ########################################## | |
| import pymel.core as pm | |
| from PySide import QtGui, QtCore | |
| import maya.OpenMayaUI as omui | |
| from shiboken import wrapInstance | |
| def maya_main_window(): | |
| main_window_ptr = omui.MQtUtil.mainWindow() | |
| return wrapInstance (long(main_window_ptr), QtGui.QWidget) | |
| class LightTableModel(QtCore.QAbstractTableModel): | |
| def __init__(self, lights=[[]],headers = [],parent = None): | |
| QtCore.QAbstractTableModel.__init__(self, parent) | |
| self.__lights = lights | |
| self.__headers = headers | |
| self.__checkBoxColumns = set([4,5,6,7,8]) | |
| def rowCount (self , parent): | |
| return len(self.__lights) | |
| def columnCount (self, parent): | |
| return len(self.__lights[0]) | |
| def flags(self, index): | |
| return QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsUserCheckable | |
| def data (self, index, role): | |
| if role == QtCore.Qt.TextAlignmentRole: | |
| row = index.row() | |
| column = index.column() | |
| return QtCore.Qt.AlignCenter | |
| if role == QtCore.Qt.CheckStateRole: | |
| row = index.row() | |
| column = index.column() | |
| value = self.__lights[row][column] | |
| if column in self.__checkBoxColumns: | |
| if value == 1: | |
| return QtCore.Qt.Checked | |
| else: | |
| return QtCore.Qt.Unchecked | |
| if role == QtCore.Qt.DisplayRole: | |
| row = index.row() | |
| column = index.column() | |
| value = self.__lights[row][column] | |
| if column == 0: | |
| return str(value) | |
| else: | |
| return None | |
| elif role == QtCore.Qt.DecorationRole: | |
| row = index.row() | |
| column = index.column() | |
| if column == 1: | |
| color = pm.getAttr(self.__lights[row][0]+".lightColor") | |
| value = QtGui.QColor(color[0]*255,color[1]*255,color[2]*255) | |
| pixmap = QtGui.QPixmap(26,26) | |
| pixmap.fill(value) | |
| icon = QtGui.QIcon(pixmap) | |
| return pixmap | |
| if column == 0: | |
| type = pm.nodeType(self.__lights[row][0]) | |
| if type == "VRayLightDomeShape": | |
| iconPath = "C:/Program Files/Autodesk/Maya2014/vray/icons/render_VRayLightDomeShape.xpm" | |
| elif type == "VRayLightRectShape": | |
| iconPath = "C:/Program Files/Autodesk/Maya2014/vray/icons/render_VRayLightRectShape.xpm" | |
| else: | |
| iconPath = "C:/Program Files/Autodesk/Maya2014/vray/icons/render_VRayLightSphereShape.xpm" | |
| icon = QtGui.QIcon(iconPath) | |
| return icon | |
| elif role == QtCore.Qt.EditRole: | |
| row = index.row() | |
| column = index.column() | |
| if column == 0: | |
| self.name = QtGui.QLineEdit() | |
| pm.select(self.__lights[row][0]) | |
| return self.name | |
| else: | |
| return self.__lights[row][column] | |
| def headerData(self, section, orientation, role): | |
| if role == QtCore.Qt.DisplayRole: | |
| if orientation == QtCore.Qt.Horizontal: | |
| return self.__headers[section] | |
| def setData(self, index, value, role = ""): | |
| if role == QtCore.Qt.CheckStateRole: | |
| row = index.row() | |
| column = index.column() | |
| if value == QtCore.Qt.Checked: | |
| newValue = 1 | |
| display = True | |
| else: | |
| newValue = 0 | |
| display = False | |
| if column == 4: | |
| pm.setAttr(self.__lights[row][0] + ".invisible", newValue) | |
| elif column == 5: | |
| pm.setAttr(self.__lights[row][0] + ".affectDiffuse", newValue) | |
| elif column == 6: | |
| pm.setAttr(self.__lights[row][0] + ".affectSpecular", newValue) | |
| elif column == 7: | |
| pm.setAttr(self.__lights[row][0] + ".affectReflections", newValue) | |
| elif column == 8: | |
| pm.setAttr(self.__lights[row][0] + ".shadows", newValue) | |
| self.__lights[row][column] = display | |
| self.dataChanged.emit(index, index) | |
| if role == QtCore.Qt.EditRole: | |
| row = index.row() | |
| column = index.column() | |
| if column == 0: | |
| selection = pm.ls(sl=True) | |
| pm.rename(selection[0],value) | |
| if column == 2: | |
| pm.setAttr(self.__lights[row][0] + ".intensityMult", value) | |
| elif column == 3: | |
| pm.setAttr(self.__lights[row][0] + ".subdivs", value) | |
| self.__lights[row][column] = value | |
| self.dataChanged.emit(index, index) | |
| return False | |
| class Lister(object): | |
| def __init__(self): | |
| self.showUI() | |
| def showUI(self): | |
| #main window | |
| self.window = QtGui.QWidget(parent = maya_main_window()) | |
| self.window.setWindowFlags (QtCore.Qt.Window) | |
| self.window.setGeometry(400,400,643,300) | |
| self.window.setWindowTitle("VRAY LIGHT DASHBOARD") | |
| # Main Layout | |
| self.mainLayout = QtGui.QVBoxLayout() | |
| self.window.setLayout(self.mainLayout) | |
| #refresh button | |
| self.refresh= QtGui.QPushButton("Refresh") | |
| # Tableview widget | |
| self.labelTable = QtGui.QLabel("VRAY LIGHTS") | |
| self.listWidget = QtGui.QTableView() | |
| self.listWidget.setShowGrid(False) | |
| self.labelTable.setBuddy(self.listWidget) | |
| self.listWidget.setAlternatingRowColors(True) | |
| #add to layout | |
| self.mainLayout.addWidget(self.refresh) | |
| self.mainLayout.addWidget(self.labelTable) | |
| self.mainLayout.addWidget(self.listWidget) | |
| #signals | |
| self.refresh.clicked.connect(self.loadLights) | |
| #calls | |
| self.loadLights() | |
| self.window.show() | |
| def loadLights(self): | |
| """ | |
| load all VRAY lights in the scene into the QListWidget | |
| """ | |
| self.lights = pm.ls(type="VRayLightDomeShape") + pm.ls(type="VRayLightRectShape") + pm.ls(type="VRayLightSphereShape") | |
| attributes = ['lightColor','intensityMult','subdivs','invisible', 'affectDiffuse','affectSpecular','affectReflections','shadows'] | |
| lightsData =[] | |
| for light in self.lights: | |
| list =[] | |
| list.append(light) | |
| for attr in attributes: | |
| entry = light.getAttr(attr) | |
| list.append(entry) | |
| lightsData.append(list) | |
| headers = ['name','color','intensity','subdivs','invisible', 'Diffuse','Specular','Reflections','shadows'] | |
| self.model = LightTableModel(lightsData,headers) | |
| self.listWidget.setModel(self.model) | |
| for row in range(0, len(self.lights)): | |
| self.listWidget.openPersistentEditor(self.model.index(row, 2)) | |
| self.listWidget.openPersistentEditor(self.model.index(row, 3)) | |
| self.listWidget.resizeColumnsToContents() | |
| self.listWidget.setColumnWidth(0,150) | |
| self.listWidget.setColumnWidth(2,75) | |
| self.listWidget.setColumnWidth(3,50) | |
| if __name__ == "__main__": | |
| app = Lister() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment