Profile Picture

Python Module: Color Picker Dialog

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

Distinguished Member (3.3K reputation)Distinguished Member (3.3K reputation)Distinguished Member (3.3K reputation)Distinguished Member (3.3K reputation)Distinguished Member (3.3K reputation)Distinguished Member (3.3K reputation)Distinguished Member (3.3K reputation)Distinguished Member (3.3K reputation)Distinguished Member (3.3K reputation)

Group: Forum Members
Last Active: 2 hours ago
Posts: 1.5K, Visits: 11.5K
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


See my CTA Tutorials on the YouTube channel CTAStepByStep
Check out EZColors for CTA. The easy way to change Render Styled (RS) colors.

Attachments
PickColorDialog.zip (18 views, 1.00 KB)
Edited
Last Month by jlittle
videodv
videodv
Posted Last Month
View Quick Profile
Veteran Member

Veteran Member (666 reputation)Veteran Member (666 reputation)Veteran Member (666 reputation)Veteran Member (666 reputation)Veteran Member (666 reputation)Veteran Member (666 reputation)Veteran Member (666 reputation)Veteran Member (666 reputation)Veteran Member (666 reputation)

Group: Forum Members
Last Active: 17 minutes ago
Posts: 156, Visits: 3.9K
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