ProgressBar

class pygamelib.gfx.ui.ProgressBar(value=0, maximum=100, width=20, progress_marker='▬', empty_marker=' ', config=None)

Bases: object

A simple horizontal progress bar widget.

__init__(value=0, maximum=100, width=20, progress_marker='▬', empty_marker=' ', config=None)
Parameters:
  • value (int) – The initial value parameter. It represents the progression.

  • maximum (int) – The maximum value held by the progress bar. Any value over the maximum is ignored.

  • width (int) – The width of the progress bar widget (in number of screen cells).

  • progress_marker (pygamelib.gfx.core.Sprixel) – The progress marker is displayed on progression. It is the sprixel that fills the bar. Please see below.

  • empty_marker (pygamelib.gfx.core.Sprixel) – The empty marker is displayed instead of the progress marker when the bar should be empty (when the value is too low to fill the bar for example). Please see below.

  • config (UiConfig) – The configuration object.

Here is a representation of were the progress and empty markers are used.

Progress marker
   |
[=====--------------]
           |
        Empty marker

Example:

# Create a default progress bar with the default configuration
progress_bar = ProgressBar(config=UiConfig.instance())
# Place the progress bar in the middle of the screen
screen.place(
    progress_bar, screen.vcenter, screen.hcenter - int(progress_bar.width)
)
for progress in range(progress_bar.maximum + 1):
    # Do something useful
    progress_bar.value = progress
    screen.update()

Methods

__init__([value, maximum, width, ...])

param value:

The initial value parameter. It represents the progression.

render_to_buffer(buffer, row, column, ...)

Render the object from the display buffer to the frame buffer.

Attributes

config

Get and set the config object (UiConfig).

empty_marker

Get and set the empty marker, preferrably a Sprixel but could be a str.

maximum

Get and set the maximum possible progress, it has to be an int.

progress_marker

Get and set the progress marker, preferrably a Sprixel but could be a str.

value

Get and set the current progress value, it has to be an int.

property config

Get and set the config object (UiConfig).

property empty_marker

Get and set the empty marker, preferrably a Sprixel but could be a str.

property maximum

Get and set the maximum possible progress, it has to be an int.

property progress_marker

Get and set the progress marker, preferrably a Sprixel but could be a str.

render_to_buffer(buffer, row, column, buffer_height, buffer_width)

Render the object from the display buffer to the frame 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.

property value

Get and set the current progress value, it has to be an int.