class palette_view.PaletteView(GridView)

The PaletteView class is an abstract base class for implementing tool palettes and similar things. A PaletteView displays an array of items which can be selected by clicking, with the selected item being highlighted. There is provision for scrolling, so that the palette can contain more items than are displayed at one time.

The PaletteView does not maintain the items themselves or keep track of which one is selected; these things are responsibilities of the subclass.


PaletteView(cell_size, nrows, ncols, scrolling = False)
Initializes the palette view with the specified cell_size, and a rect sized for displaying nrows rows and ncols columns of items. If scrolling is true, controls will be displayed for scrolling the view.

Theme Properties

Colour to use for highlighting the selected cell.

Width of the border drawn around the selected item when the highlight_style is 'frame'.

Size of the scrolling buttons. (This is a number, not a tuple -- the scroll buttons are square.)
Colour in which to draw the scrolling buttons.


Determines the way in which a selected cell is highlighted. Values are 'frame' to draw a frame around the cell, 'fill' to fill its background with the sel_color, and 'reverse' to swap the foreground and background colours.


Scrolls the view up by one page of items, if possible.

Scrolls the view down by one page of items, if possible.

Scrolls the view so as to make the specified item visible.

Abstract Methods

A minimum implementation needs to supply the following methods.
Should return the total number of items in the palette. If scrolling is enabled, this can be greater than the number of displayed items.

draw_item(surface, item_no, rect)
Should draw the item specified by item_no in the given rect.

click_item(item_no, event)
Called when a mouse-down event occurs in item item_no. Typically the subclass will record the fact that the item is selected so that this can be reported later via item_is_selected().

Should return a boolean indicating whether item number item_no is currently to be considered selected.

Default Methods

Greater control can be exercised over the widget's behaviour by overriding the following methods.
draw_item_and_highlight(surface, item_no, rect, highlight)
Draws the cell for item item_no, together with highlighting if highlight is true. The default implementation calls draw_prehighlight, draw_item and draw_posthighlight.

draw_prehighlight(surface, item_no, rect)
Called for highlighted cells before draw_item, to draw highlighting that is to appear underneath the cell's contents.

draw_posthighlight(surface, item_no, rect)
Called for highlighted cells after draw_item, to draw highlighting that is to appear on top of the cell's contents.