Profile Picture

Python Module: Color Picker Dialog

Posted By jlittle 5 Years Ago
Rated 5 stars based on 1 vote.
Author
Message
jlittle
jlittle
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 1.9K, Visits: 17.1K
I've attached a python module that can be called from any script.
It will present a color dialog and return the selected color or None, if cancelled out.

Included in the zip file is the PickColorDialog.py module and a test program PickColorTest.py detailing how to use it.

Basically there are two ways to reference the module.
Method #1
import PickColorDialog

clr = PickColorDialog.getSelectedColor()
if clr:
print('Selected Color = '+str(clr))
else:
print('No Color Selected')


Method #2
from PickColorDialog import getSelectedColor

clr = getSelectedColor()
if clr:
print('Selected Color = '+str(clr))
else:
print('No Color Selected')


Method #1 is the preferred method because it forces you to precede the function name with the module name (i.e. PickColorDialog.getSelectedColor()).
This prevents the function name from conflicting with an existing function of the same name which could happen using Method #2 (which does not require the preceding module name).
Method #1 allows the function name to appear in multiple modules and would be referenced by <module_name>.<function_name> (i.e. Module1.getSelectedColor(), Module2.getSelectedColor()).

Using modules helps to keep your main script organized and smaller by putting blocks of code into a separate file.
It also allows you to easily reuse blocks of code in other projects and saves time with digging thru old coding looking for a function to cut&paste.

The module also allows you to set the initial color:
# get a current color
currClr = QColor.fromRgb(0,255,0,255)
# create dialog using current color
clr = PickColorDialog.getSelectedColor(currClr)

Jeff


Get my Plugin Manager and TaskNotes plugins for iClone.
Check out EZColors and Other products for CTA/CA. EZColors: the easy way to change Render Styled (RS) colors!
See my CTA Tutorials on the YouTube channel CTAStepByStep

Attachments
PickColorDialog.zip (336 views, 1.00 KB)
Edited
5 Years Ago by jlittle
videodv
videodv
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)

Group: Forum Members
Last Active: Last Year
Posts: 342, Visits: 12.0K
jlittle (1/22/2019)
I've attached a python module that can be called from any script.
It will present a color dialog and return the selected color or None, if cancelled out.

Included in the zip file is the PickColorDialog.py module and a test program PickColorTest.py detailing how to use it.

Basically there are two ways to reference the module.
Method #1
import PickColorDialog

clr = PickColorDialog.getSelectedColor()
if clr:
print('Selected Color = '+str(clr))
else:
print('No Color Selected')


Method #2
from PickColorDialog import getSelectedColor

clr = getSelectedColor()
if clr:
print('Selected Color = '+str(clr))
else:
print('No Color Selected')


Method #1 is the preferred method because it forces you to precede the function name with the module name (i.e. PickColorDialog.getSelectedColor()).
This prevents the function name from conflicting with an existing function of the same name which could happen using Method #2 (which does not require the preceding module name).
Method #1 allows the function name to appear in multiple modules and would be referenced by <module_name>.<function_name> (i.e. Module1.getSelectedColor(), Module2.getSelectedColor()).

Using modules helps to keep your main script organized and smaller by putting blocks of code into a separate file.
It also allows you to easily reuse blocks of code in other projects and saves time with digging thru old coding looking for a function to cut&paste.

The module also allows you to set the initial color:
# get a current color
currClr = QColor.fromRgb(0,255,0,255)
# create dialog using current color
clr = PickColorDialog.getSelectedColor(currClr)

Jeff


Thanks for this jlittle theres some good code in here

Chris.




Reading This Topic