User defined colors in UI

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  04 April 2013
User defined colors in UI

Is it possible to use the user-defined colors in the ui elements, like for instance color a button or something like the color-slider?
I could of course copy the rgb values into the rgb of the button, but I would like the connection to remain dynamic.

Basically I am looking for a way to have the user choose between the user colors within my own UI.
Any ideas?
Steam Punk Challenge
  04 April 2013
I don't know about colouring the Maya UI elements natively off the top of my head, but...

Are you stuck with using the Maya provided UI elements, or can you inject a little Qt in there and force what you want?
  04 April 2013
Turns out, you can do it with the native UI elements:

import maya.cmds as cmds
import random


for _ in xrange(10):
    colour = [random.random() for _ in xrange(3)]
    cmds.button(label=', '.join('%.3f' % x for x in colour), backgroundColor=colour)



EDIT: I think I missed the point of the question; could you elaborate?

Last edited by mikeboers : 04 April 2013 at 05:20 PM. Reason: I think I missed the point.
  04 April 2013
Thanks a lot for your answer.

The colors I am talking about, are the ones from settings/preferences --> colors --> user defined.
It is the colors maya color the skinned joints for instance.

I want to use them as a color override, instead of the overrideColor thing.
It is a list 1-8.

It would just be nice to create a sweet little ui where I can choose the color I want, instead of going by the numbers 1-8.
Steam Punk Challenge
  04 April 2013
Originally Posted by doffer: It would just be nice to create a sweet little ui where I can choose the color I want, instead of going by the numbers 1-8.

I'm still a little confused here.

You want to a UI element for the user to pick from the 8 user defined colours, that at least displays the colour instead of just being a number?
  04 April 2013
and then through a button, color a selected object with that color or something like that.
But it is displaying those colors in the UI i'm not sure of how to do.
Except copying the rgb value.

An alternative would be to make a optionMenu and use descriptive text instead, have that run from 0-7 and plus it with 1 ( to get the list from 1-8), but the most intuitive would be to have the actual color displayed somehow.
Steam Punk Challenge
  04 April 2013
Alright. It is kinda ugly (need to get the spacings right), but what about:

from maya import cmds



cmds.text(label='User Colour:')
canvas = cmds.canvas(width=100, height=16)
field = cmds.intSlider(minValue=1, maxValue=8, value=1)

def update_canvas(index=1):
    colour = cmds.displayRGBColor('userDefined%d' % index, query=True)
    cmds.canvas(canvas, edit=True, rgbValue=colour)
cmds.intSlider(field, edit=True, dragCommand=update_canvas)


Last edited by mikeboers : 04 April 2013 at 05:57 PM. Reason: Cleaner code.
  04 April 2013
That was exactly what I was after.
A bunch of stuff in your code I didn't know about.
I'll try and break it down to see what happens.

Thanks a lot for your help!
Steam Punk Challenge
  04 April 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 01:46 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.