import maya .cmds as cmds

def override_color(color_index):
	sel = cmds. ls (selection=True)

	shape =cmds.listRelatives (sel, shapes = True )


	for node in shape:	
		cmds. setAttr (node + ".overrideEnabled" ,True) 
		cmds. setAttr (node + ".overrideColor" ,color_index)
	


def display():
	main_window = cmds.window(title= "COLOR", sizeable=False)
	main_layout = cmds.frameLayout()

	columns = 16
	rows = 2
	sell_width = 17.5
	sell_height = 17.5
	color_palette = cmds. palettePort (dimensions = (columns, rows), width = columns*sell_width, height = rows*sell_height,topDown = True,  colorEditable=False)

	for index in range(1, 31):
		color_component = cmds. colorIndex (index,query=True)
		cmds. palettePort (color_palette, edit=True, rgbValue = (index, color_component[0], color_component[1], color_component[2]))
	cmds. palettePort(color_palette, edit = True, rgbValue=(0, 0.6, 0.6, 0.6))

	cmds. button ("Apply",command = "applyColor ()" )



	cmds.showWindow(main_window)

def applyColor ():
	color_index = cmds.palettePort(color_palette, q=True, setCurCell=True)
	override_color(color_index)
	print color_index
	
display()