UI with Color Swatch


#1

I’m building a small tool in MEL and one of the inputs is for color. I’m currently using -colorSliderGrp -l “Tracker Colour” -rgb 1 0 0 trackerColour; but the slider is too long and makes the layout look ugly.

Does anyone know how to implement just the color swatch (without the slider) and if you were to click the swatch the color editor would open.

Thanks!!


#2

my mel is rusty but a option could be to just create your own swatch button using the colorEditor command;

here is how i would do it in python

import pymel.core as pm


windowhandle = "TestWindow"


class UI(object):
	def __init__(self):
		if pm.window(windowhandle, exists=True):
			pm.deleteUI(windowhandle)

		with pm.window(windowhandle, title="TestWindow") as window:
			with pm.columnLayout():
				self.swatchbtn = pm.button(w=32, h=32, l="", c=self.set_color)
			window.show()

	def set_color(self, *args):
		color = pm.colorEditor()
		parsedcolor = [float(i) for i in color.split()]
		self.swatchbtn.setBackgroundColor(parsedcolor[0:-1])


if __name__ == "__main__":
	UI()
 

#3

There is also a UI control called swatchDisplayPort
http://download.autodesk.com/us/maya/2011help/CommandsPython/swatchDisplayPort.html

You can use it to preview shaders/material using the shadingNode -flag, or just skip that one and set a width, height and background color (I think?).