class PaletteView(GridView)

A PaletteView is a specialised subclass of GridView designed for implementing tool palettes and other such components. Instead of row and column numbers, the cells in a PaletteView are identified by a single integer index, called an item number, with items being numbered from left to right, top to bottom.

The PaletteView also has a notion of one or more items being selected, and provides support for highlighting selected items in a variety of ways.

PaletteView inherits from ScrollableView and can therefore be made scrollable if needed, although it does not show any scroll bars by default.

The extent of a PaletteView is managed through the num_items, items_per_row and cell_size properties. The num_rows and num_columns properties inherited from GridView, and the extent property inherited from ScrollableView, should not be changed directly.

Constructor

PaletteView(num_items, items_per_row, cell_size)
Creates a palette view with the specified initial property values.

Properties

num_items
Total number of items in the palette. The items will be laid out with items_per_row items in each row, using as many rows as necessary. If num_items is not an even multiple of items_per_row, some cells in the last row will be left empty.

items_per_row
The number of items in each row of the palette's extent.

highlight_style
The style in which to highlight selected items. Possible values are:

  • 'fill' - the cell is filled with the highlight_color before calling draw_item().
  • 'frame' - a rectangle is drawn around the cell as specified by highlight_color and highlight_thickness before calling draw_item().
  • '' or None - no automatic highlighting is performed.

highlight_color
Color to use for highlighting of selected items.

highlight_thickness
When using the 'frame' highlight style, the pen width to use for drawing the highlight rectangle.

Abstract Methods

draw_item(canvas, item_number, item_rect)
Should draw the specified item in the given rectangle. Any automatic highlighting specified by the highlight_style property has already been applied.

click_item(item_number, event)
Called when a mouse_down event occurs in an item.

item_is_selected(item_number)
Should return true if the indicated item is to be regarded as selected.

draw_item_and_highlight(canvas, item_number, item_rect, highlight)
This method can optionally be overridden instead of draw_item() to gain more control over how items are highlighted. Your implementation should draw the specified item, and apply highlighting if highlight is true. If you override this method, draw_item() is not called and no automatic highlighting is performed.

Methods

item_rect(item_number)
Returns the rectangle corresponding to the given item number. If the item number is out of bounds (less than 0 or greater than num_items - 1), returns None.

item_no_of_cell(row_number, column_number)
Returns the item number corresponding to the specified cell, or None if the cell does not correspond to a valid item.

cell_of_item_no(item_number)
Returns the row and column numbers of the cell corresponding to the given item number. If the item number is out of bounds (less than 0 or greater than num_items - 1), returns None.