ColorPickerDialog

class pygamelib.gfx.ui.ColorPickerDialog(title: str = None, config: pygamelib.gfx.ui.UiConfig = None)

Bases: pygamelib.gfx.ui.Dialog

The ColorPickerDialog is a dialog wrapper around the ColorPicker widget.

It serves the same purpose: present a way to easily select a custom color to the user.

It does it as an immediately usable dialog.

The show() method returns the Color selected by the user. If the user pressed the ESC key, it returns None.

Key mapping:

  • ESC: Exit from the show() method and return None.
  • ENTER: Exit from the show() method. Returns the currently selected color.
  • UP / DOWN: Increase/decrease the currently selected channel by 1.
  • PAGE_UP / PAGE_DOWN: Increase/decrease the currently selected channel by 10.
  • LEFT / RIGHT: Navigate between color channels.

Like all dialogs, it is automatically destroyed on exit of the show() method. It is also deleted from the screen buffer.

__init__(title: str = None, config: pygamelib.gfx.ui.UiConfig = None) → None

The constructor only take the configuration as parameter.

Parameters:config (UiConfig) – The configuration object.

Example:

color_dialog = ColorPickerDialog(conf)
color_dialog.set_color( core.Color(128, 128, 128) )
screen.place(color_dialog, 10, 10)
new_color = color_dialog.show()

Methods

__init__(title, config) The constructor only take the configuration as parameter.
render_to_buffer(buffer, row, column, …) Render the object into a display buffer (not a screen buffer).
set_color(color) Set the color shown in the dialog.
set_selection(selection) Set the channel selection.
show() Show the dialog and execute the event loop.

Attributes

config Get and set the config object (UiConfig).
user_input Facility to store and retrieve the user input.
config

Get and set the config object (UiConfig).

render_to_buffer(buffer, row: int, column: int, buffer_height: int, buffer_width: int) → None

Render the object into a display buffer (not a screen buffer).

This method is automatically called by pygamelib.engine.Screen.render().

Parameters:
  • buffer (numpy.array) – A screen buffer to render the item into.
  • row (int) – The row to render in.
  • column (int) – The column to render in.
  • height (int) – The total height of the display buffer.
  • width (int) – The total width of the display buffer.
set_color(color: pygamelib.gfx.core.Color) → None

Set the color shown in the dialog.

Parameters:color (Color) – The color to edit.

Example:

color_dialog.set_color( core.Color(128, 128, 128) )
set_selection(selection: int = 0)

Set the channel selection.

Parameters:selection (int) – The number of the channel to select (0 = red, 1 = green and 2 = blue).

Example:

color_dialog.set_selection(1)
show()

Show the dialog and execute the event loop. Until this method returns, all keyboards event are processed by the local event loop. This is also true if called from the main event loop.

This event loop returns the edited Color or None if the user pressed the ESC key.

Returns:The editor color.
Return type:Color

Example:

new_color = color_dialog.show()
title

Get / set the dialog title, it needs to be a str.

user_input

Facility to store and retrieve the user input.