def get_all_mesh():
all_mesh = cmds.listRelatives(cmds.ls(type = 'mesh'), parent=True)
# Result: [u'pCube1', u'pSphere1', u'pPlane1'] #
return all_mesh
def get_color(node_name):
# checks if the node_name exists in the json file
with open('/Desktop/colors.json') as data_file:
data = json.load(data_file)
items = set()
for index, name in enumerate(data):
# if the name is in the json, it will states the color
if node_name in name:
for item in (data[name]):
#print "{0} - {1}".format(name, item)
items.add(item)
return items
class testTableView(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setWindowTitle('Color Test')
self.setModal(False)
self.all_mesh = get_all_mesh()
# Build the GUI
self.init_ui()
self.populate_data()
def init_ui(self):
# Table setup
self.mesh_table = QtGui.QTableWidget()
self.mesh_table.setRowCount(len(self.all_mesh))
self.mesh_table.setColumnCount(3)
self.mesh_table.setHorizontalHeaderLabels(['Mesh Found', 'Color for Mesh'])
self.md_insert_color_btn = QtGui.QPushButton('Apply color')
# Layout
self.layout = QtGui.QVBoxLayout()
self.layout.addWidget(self.mesh_table)
self.layout.addWidget(self.md_insert_color_btn)
self.setLayout(self.layout)
def populate_data(self):
geo_name = self.all_mesh
for row_index, geo_item in enumerate(geo_name):
new_item = QtGui.QTableWidgetItem(geo_item)
# Add in each and every mesh found in scene and append them into rows
self.mesh_table.setItem(row_index, 0, new_item)
geo_exclude_num = ''.join(i for i in geo_item if not i.isdigit())
color_list = get_color(geo_exclude_num)
# Insert in the color
combobox = QtGui.QComboBox()
#color_list = get_color()
combobox.addItems(list(color_list))
self.mesh_table.setCellWidget(row_index, 1, combobox)
# To opent the dialog window
dialog = testTableView()
dialog.show()--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/eeb630dc-5e5e-4b0c-b2da-4129effac47f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def __init__(self, parent=None):
...
self.init_ui() self.populate_data() self.connect_signals()def connect_signals(self):
self.combobox.currentIndexChanged.connect(self.append_color)
def append_color(self):
for row in xrange(self.mesh_table.rowCount()):
color_sel = self.mesh_table.cellWidget(row, 1).currentText()
print color_selfrom PyQt4 import QtGui, QtCore
import sys
def get_geos():
all_mesh = cmds.listRelatives(cmds.ls(type = 'mesh'), parent=True)
return all_mesh
class test(QtGui.QWidget):
# Our main window will be a QListView
list = QtGui.QTableView()
list.setWindowTitle('Example List')
list.setMinimumSize(600, 400)
# Create an empty model for the list's data
model = QtGui.QStandardItemModel(list)
all_geos = get_geos()
for geo in all_geos:
# create an item with a caption
item = QtGui.QStandardItem(geo)
# Add the item to the model
model.appendRow(item)
# Apply the model to the list view
list.setModel(model)
# Show the window and run the app
list.show()Okay, currentIndexChanged works, I have placed it wrongly instead of it being under the connect_signals functions, I should have placed it under the populate_data function..
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/a657289c-96a2-4b9c-80bd-605028c94af7%40googlegroups.com.