Choose Palette

class choose_palette.Slider(x, y, width, height, active, type_, from_, to, resolution, **kwargs)[source]

Initializes a new Slider object for the graphical user interface choose_palette.gui. A Slider is a combination of a Tk.Frame including a Tk.Label, Tk.Slider, and a Tk.Entry element with all necessary interactions.

Parameters:
  • x (int) – x-position on the Tk interface
  • y (int) – y-position on the Tk interface
  • width (int) – width of the Slider object (Tk.Frame taking up Tk.Scale, Tk.Label, and Tk.Entry)
  • height (int) – height of the Slider object (Tk.Frame taking up Tk.Scale, Tk.Label, and Tk.Entry)
  • type (str) – name of the Slider
  • from (numeric) – lower value of the Slider (see isValidInt(), isValidFloat())
  • to (numeric) – upper value of the Slider (see isValidInt(), isValidFloat())
  • resolution (numeric) – resolution of the slider, the increments when moving the Slider
  • kwargs – Unused
OnTrace(*args, **kwargs)[source]

Triggered when Slider.trace() is triggered. The method is loading the current value and sets the Tk.Scale and Tk.Entry element to the new value.

disable()[source]

Disables the Slider.

enable()[source]

Enables the Slider.

get()[source]
Returns:Returns the current value of the slider. The return value depends on the slider config (int or float).
Return type:int or float
isValidFloat(x, from_ = -999., to = 999.)[source]

Helper function to check whether x is a valid float in the range [from_,to].

Parameters:
  • x (float) – Value to be validated
  • from (float) – Lower limit of the valid range
  • to (float) – Upper limit of the valid range
Returns:

Returns True if x is a valid float within [from_, to] and False otherwise.

Return type:

bool

isValidInt(x, from_ = -999, to = 999)[source]

Helper function to check whether x is a valid integer in the range [from_,to].

Parameters:
  • x (int) – Value to be validated
  • from (int) – Lower limit of the valid range
  • to (int) – Upper limit of the valid range
Returns:

Returns True if x is a valid float within [from_, to] and False otherwise.

Return type:

bool

is_active()[source]

Returns True if the Slider is active and False if currently inactive.

name()[source]
Returns:Returns the name of the Slider.
Return type:str
trace(mode, *args, **kwargs)[source]

Trace method of the Slider object.

Parameters:
  • mode (str) – default is w (call observer when variable is written)
  • args – arguments passed to Tkinter.<vartype>.trace(), at least one argument (a callback function) should be provided
  • kwargs – arguments passed to Tkinter.<vartype>.trace(), unused
choose_palette.choose_palette(**kwargs)[source]

Graphical user interface to choose HCL based color palettes. Returns an object of palettes.diverging_hcl, palettes.qualitative_hcl, or palettes.sequential_hcl with user-defined default settings.

Parameters:kwargs – See choose_palette.gui.
Returns:The object allows to get colors in different ways, the default is a list with hex colors. See palettes.hclpalette or, more specifically, the manual of the depending palette (palettes.diverging_hcl, palettes.qualitative_hcl, or palettes.sequential_hcl).
Return type:palettes.hclpalette object
class choose_palette.currentpalettecanvas(parent, x, y, width, height)[source]

Draws the current palette (the palette as specified on the GUI), will be displayed in the lower part of the GUI.

Parameters:
  • parent (Tk) – the Tk object (interface)
  • x (numeric) – x position on the interface
  • y (numeric) – y position on the interface
  • width (numeric) – width of the palette on the interface
  • height (numeric) – height of the palette on the interface
class choose_palette.defaultpalettecanvas(palframe, sliders, pal, n, xpos, figwidth, figheight)[source]

Sets up a Tk.Canvas element containing the colors of the default HCL color palettes which will be placed in the top part of the GUI.

Parameters:
  • palframe (Tk.Frame) – the bounding Tk.Frame which takes up the palettes.
  • sliders (list) – list of Slider objects. When a user selets a new default palette the sliders will be set to the specification given the selected palette (and enabled/disabled corresponding to the palette specification)
  • pal (defaultpalette) – the default color palette
  • n (int) – number of colors to be drawn
  • xpos (numeric) – x position within Tk.Canvas (palframe input)
  • figwidth (numeric) – width of the Tk.Canvas element (palframe input)
  • figheight (numeric) – width of the Tk.Canvas element (palframe input)
class choose_palette.gui(**kwargs)[source]

choose_palette(**kwargs)

Graphical user interface to choose custom HCL-basec color palettes.

Parameters:kwargs – Optional, can be used to change the defaults when starting the GUI. Currently a parameter called palette is allowed to specify the initial color palette. If not set, palette = "Blue-Red" is used.

Example

>>> colorspace.choose_palette()
OnChange(*args, **kwargs)[source]

Triggered any time the slider values or control arguments change. Draws new current palette (see _draw_currentpalette()).

OnPaltypeChange(*args, **kwargs)[source]

The callback function of the drop down element. Triggered every time the drop down element changes.

control()[source]
Returns:Returns a dictionary with the current control options (see _add_control()).
Return type:dict
get_colors()[source]
Returns:Returns a list of hex colors and nan given the current settings on the GUI. numpy.nan will be returned if fixup is set to False but some colors lie outside the RGB color space.
Return type:list
master()[source]
Returns:Returns the Tk GUI object.
Return type:Tk
method()[source]
Returns:Returns the name of the object which has to be called to get the colors. The name of the object is defined in the palconfig config files. For “Diverging” palettes this will be palettes.diverging_hcl, for “Qualitative” palettes.qualitative_hcl, and for “Sequential” palettes palettes.sequential_hcl.
Return type:str
palettes()[source]
Returns:Returns the default palettes available.
Return type:palettes.hclpalettes
palframe()[source]
Returns:Returns the palette frame (Tk.Frame object, see _add_palframe()).
Return type:Tk.Frame
settings(*args, **kwargs)[source]

Used to load/store current palette settings (gui settings).

Parameters:
  • args – strings to load one/several parameters.
  • kwargs – named arguments, used to store values.
Returns:

Returns a dictionary with the current slider settings.

Return type:

dict

sliders()[source]
Returns:List of Slider objects.
Return type:list