CubeColourDialog
is an alternative implementation of wx.ColourDialog
.
The CubeColourDialog
is an alternative implementation of wx.ColourDialog
, and it
offers different functionalities with respect to the default wxPython one. It
can be used as a replacement of wx.ColourDialog
with exactly the same syntax and
methods.
Some features:
RGB components may be controlled using spin controls or with mouse gestures on a 3D RGB cube, with the 3 components laying on the X, Y, Z axes;
HSB components may be controlled using spin controls or with mouse gestures on a 2D colour wheel;
Brightness has its own vertical slider to play with;
The colour alpha channel can be controlled using another vertical slider, or via spin control;
The colour alpha channel controls can be completely hidden at startup or the
choice to use the alpha channel can be left to the user while playing with the
dialog, via a simple CheckBox
;
The “old colour” and “new colour” are displayed in two small custom panel, which support alpha transparency and texture;
CubeColourDialog
displays also the HTML colour code in hexadecimal format;
When available, a corresponding “Web Safe” colour is generated using a 500 web colours “database” (a dictionary inside the widget source code). Web Safe colours are recognized by all the browsers;
When available, a corresponding “HTML name” for the selected colour is displayed, by using the same 500 web colours “database”;
When available, a corresponding “Microsoft Access Code” for the selected colour is displayed, by using the same 500 web colours “database”.
And much more.
Usage example:
import wx
import wx.lib.agw.cubecolourdialog as CCD
# Our normal wxApp-derived class, as usual
app = wx.App(0)
colourData = wx.ColourData()
dlg = CCD.CubeColourDialog(None, colourData)
if dlg.ShowModal() == wx.ID_OK:
# If the user selected OK, then the dialog's wx.ColourData will
# contain valid information. Fetch the data ...
colourData = dlg.GetColourData()
h, s, v, a = dlg.GetHSVAColour()
# ... then do something with it. The actual colour data will be
# returned as a three-tuple (r, g, b) in this particular case.
colour = colourData.GetColour()
r, g, b, alpha = colour.Red(), colour.Green(), colour.Blue(), colour.Alpha()
print("You selected (RGBA): %d, %d, %d, %d"%(r, g, b, alpha))
print("You selected (HSVA): %d, %d, %d, %d"%(h, s, v, a))
# Once the dialog is destroyed, Mr. wx.ColourData is no longer your
# friend. Don't use it again!
dlg.Destroy()
app.MainLoop()
This class supports the following window styles:
Window Styles |
Hex Value |
Description |
---|---|---|
|
0x1 |
Show the widget used to control colour alpha channels in |
No custom events are available for this class.
CubeColourDialog
is distributed under the wxPython license.
Latest Revision: Andrea Gavana @ 19 Dec 2012, 21.00 GMT
Version 0.5.
Returns the angle between the x-axis and the line connecting the center and |
|
Transforms degrees into radians. |
|
Returns the distance between 2 points. |
|
Draws a checkerboard on a |
|
Internal function. |
|
Calculates the intersection point between 2 lines. |
|
Internal function. |
|
Given the angle with respect to the x-axis, returns the point based on |
|
Transforms radians into degrees. |
|
Restores the old settings for a |
|
Transforms a RGB triplet into an html hex string. |
|
Normalize a value as a function of the radius. |
|
Calculates the slope of the line connecting 2 points. |
|
Normalize a value as a function of the radius. |
Implements the drawing, mouse handling and sizing routines for the alpha |
|
Base class used to hold common code for the Alpha channel control and the |
|
Base class used to hold common code for the HSB colour wheel and the RGB |
|
Implements the drawing, mouse handling and sizing routines for the brightness |
|
This is a subclass of |
|
Simple custom class used to display “old” and “new” colour panels, with alpha |
|
This is the CubeColourDialog main class implementation. |
|
This panel displays a series of custom colours (chosen by the user) just like |
|
Implements the drawing, mouse handling and sizing routines for the HSV |
|
Simple class to store description and constants for a line in 2D space. |
|
Implements the drawing, mouse handling and sizing routines for the RGB |
AngleFromPoint
(pt, center)¶Returns the angle between the x-axis and the line connecting the center and the point pt.
pt – an instance of wx.Point
;
center – a float value representing the center.
deg2rad
(x)¶Transforms degrees into radians.
x – a float representing an angle in degrees.
Distance
(pt1, pt2)¶Returns the distance between 2 points.
DrawCheckerBoard
(dc, rect, checkColour, box=5)¶Draws a checkerboard on a wx.DC
.
dc – an instance of wx.DC
;
rect – the client rectangle on which to draw the checkerboard;
checkColour – the colour used for the dark checkerboards;
box – the checkerboards box sizes.
Note
Used for the Alpha channel control and the colour panels.
FindC
(line)¶Internal function.
Intersection
(line1, line2)¶Calculates the intersection point between 2 lines.
line1 – an instance of LineDescription
;
line2 – another instance of LineDescription
.
PointOnLine
(pt1, pt2, length, maxLen)¶Internal function.
PtFromAngle
(angle, sat, center)¶Given the angle with respect to the x-axis, returns the point based on the saturation value.
angle – a float representing an angle;
sat – a float representing the colour saturation value;
center – a float value representing the center.
rad2deg
(x)¶Transforms radians into degrees.
x – a float representing an angle in radians.
rgb2html
(colour)¶Transforms a RGB triplet into an html hex string.
colour – a tuple of red, green, blue integers.
scaletomax
(x)¶Normalize a value as a function of the radius.
x – a float value to normalize
Slope
(pt1, pt2)¶Calculates the slope of the line connecting 2 points.
toscale
(x)¶Normalize a value as a function of the radius.
x – a float value to normalize