Last active
December 13, 2017 11:32
-
-
Save RicardoViana/9110907 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.6 # | |
| # # | |
| # 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 Delegate(QtGui.QItemDelegate): | |
| def __init__(self, parent=None): | |
| super(Delegate, self).__init__(parent) | |
| def createEditor(self, parent , option, index): | |
| self.container = QtGui.QWidget(parent) | |
| layout = QtGui.QHBoxLayout() | |
| layout.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignCenter) | |
| layout.setContentsMargins(0, 0, 0, 0) | |
| self.container.setLayout(layout) | |
| self.checkBox = QtGui.QCheckBox(parent) | |
| layout.addWidget(self.checkBox) | |
| return self.container | |
| def setEditorData (self, editor, index): | |
| getValue = index.model().data(index,QtCore.Qt.EditRole) | |
| if getValue == True: | |
| self.checkBox.setCheckState(QtCore.Qt.Checked) | |
| self.container.setStyleSheet("background-color:#347545") | |
| else: | |
| self.checkBox.setCheckState(QtCore.Qt.Unchecked) | |
| self.container.setStyleSheet("background-color:#7F2627") | |
| def setModelData(self, editor, model, index): | |
| model.setData(index,self.checkBox.isChecked(),QtCore.Qt.CheckStateRole) | |
| 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.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(50,26) | |
| pixmap.fill(value) | |
| icon = QtGui.QIcon(pixmap) | |
| return pixmap | |
| 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 == True: | |
| newValue = 1 | |
| else: | |
| newValue = 0 | |
| if column == 4: | |
| print "invisible" | |
| print value | |
| print newValue | |
| pm.setAttr(self.__lights[row][0] + ".invisible", newValue) | |
| elif column == 5: | |
| print "diffuse" | |
| print value | |
| print newValue | |
| pm.setAttr(self.__lights[row][0] + ".affectDiffuse", newValue) | |
| elif column == 6: | |
| print "spec" | |
| print value | |
| print newValue | |
| pm.setAttr(self.__lights[row][0] + ".affectSpecular", newValue) | |
| elif column == 7: | |
| print "reflect" | |
| print value | |
| print newValue | |
| pm.setAttr(self.__lights[row][0] + ".affectReflections", newValue) | |
| elif column == 8: | |
| print "shadows" | |
| print value | |
| print newValue | |
| pm.setAttr(self.__lights[row][0] + ".shadows", newValue) | |
| self.__lights[row][column] = value | |
| self.dataChanged.emit(index, index) | |
| if role == QtCore.Qt.EditRole: | |
| row = index.row() | |
| column = index.column() | |
| checkColumns = [4,5,6,7,8] | |
| if column == 0: | |
| selection = pm.ls(sl=True) | |
| pm.rename(selection[0],value) | |
| elif 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) | |
| checkBoxColumns = [4,5,6,7,8] | |
| for col in checkBoxColumns: | |
| self.listWidget.setItemDelegateForColumn(col,Delegate(self.window)) | |
| for row in range(0, len(headers)): | |
| self.listWidget.openPersistentEditor(self.model.index(row, 2)) | |
| self.listWidget.openPersistentEditor(self.model.index(row, 3)) | |
| self.listWidget.openPersistentEditor(self.model.index(row, 8)) | |
| self.listWidget.openPersistentEditor(self.model.index(row, 4)) | |
| self.listWidget.openPersistentEditor(self.model.index(row, 7)) | |
| self.listWidget.openPersistentEditor(self.model.index(row, 6)) | |
| self.listWidget.openPersistentEditor(self.model.index(row, 5)) | |
| 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