source | issues

pygtkhelpers.ui.objectlist

TreeViews that are object orientated, and mimic Pythonic lists

copyright:2005-2008 by pygtkhelpers Authors
license:LGPL 2 or later (see README/COPYING/LICENSE)
class pygtkhelpers.ui.objectlist.Column(attr=None, type=<type 'str'>, title=None, **kwargs)

A Column for an ObjectList.

A column loosely combines a GUI TreeView column with an attribute of an instance. The column encapsulates the type of the attribute, how it is displayed, whether fields are editable, the column headings, whether sorting can be applied, and other features.

The mapping between columns and attributes is not exactly correct as there is the flexibility to add multiple cells per column.

Parameters:
  • attr – The attribute to display from the object
  • type – The Python type of the data for this attribute
  • title – The header title for the column
  • visible – Whether this column should be displayed
  • width – The width of this column
  • expand – Whether this column should expand to fit available space
  • sorted – Whether this column should be sorted
  • sort_key – The sort key to sort by this column
  • sort_func – The function to sort this column by
  • searchable – Whether this field is searchable
  • search_key – The key used to search this column
  • expander – Whether the expander should be shown before this column
  • resizable – Whether the user can resize the column
  • cells – A list of Cell instances to display in this colum
  • tooltip_attr – An attribute that will display the tooltip for this column
  • tooltip_type – The type of tooltip for this column
  • tooltip_value – The static value of the tooltip for this column
  • tooltip_image_size – The size of an image tooltip
create_treecolumn(objectlist)

Create a gtk.TreeViewColumn for the configuration.

render_tooltip(tooltip, obj)

Render the tooltip for this column for an object

search_by(objectlist)

Search by this column on an ObjectList

Parameters:objectlist – An ObjectList or ObjectTree
class pygtkhelpers.ui.objectlist.ObjectList(columns=(), **kwargs)

An object list

append(item, select=False)

Add an item to the end of the list.

Parameters:
  • item – The item to be added
  • select – Whether the item should be selected after adding
clear()

Clear all the items in the list

extend(iter)

Add a sequence of items to the end of the list

Parameters:iter – The iterable of items to add.
item_after(item)

The item after an item

item_before(item)

The item before an item

Parameters:item – The item to get the previous item relative to
item_visible(item)

Return whether an item is visible

Parameters:item – The item to test visibility
Return type:bool
move_item_down(item)

Move an item down in the list.

Essentially swap it with the item below it.

Parameters:item – The item to be moved.
move_item_up(item)

Move an item up in the list.

Essentially swap it with the item above it.

Parameters:item – The item to be moved.
remove(item)

Remove an item from the list

Parameters:item – The item to remove from the list.
Raises ValueError:
 If the item is not present in the list.
selected_item

The currently selected item

selected_items

List of currently selected items

set_visible_func(visible_func)

Set the function to decide visibility of an item

Parameters:visible_func

A callable that returns a boolean result to decide if an item should be visible, for example:

def is_visible(item):
    return True
sort_by(attr_or_key, direction='asc')

Sort the view by an attribute or key

Parameters:
  • attr_or_key – The attribute or key to sort by
  • direction – Either asc or desc indicating the direction of sorting
update(item)

Manually update an item’s display in the list

Parameters:item – The item to be updated.
class pygtkhelpers.ui.objectlist.ObjectTree(columns=(), **kwargs)

An object tree

append(item, parent=None, select=False)

Add an item to the end of the list.

Parameters:
  • item – The item to be added
  • parent – The parent item to add this as a child of, or None for a top-level node
  • select – Whether the item should be selected after adding
clear()

Clear all the items in the list

collapse_item(item)

Display a node as collapsed

Parameters:item – The item to show collapsed
expand_item(item, open_all=True)

Display a node as expanded

Parameters:
  • item – The item to show expanded
  • open_all – Whether all child nodes should be recursively expanded.
extend(iter, parent=None)

Add a sequence of items to the end of the list

Parameters:
  • iter – The iterable of items to add.
  • parent – The node to add the items as a child of, or None for top-level nodes.
item_after(item)

The item after an item

item_before(item)

The item before an item

Parameters:item – The item to get the previous item relative to
item_expanded(item)

Return whether an item is expanded or collapsed

Parameters:item – The item that is queried for expanded state
item_visible(item)

Return whether an item is visible

Parameters:item – The item to test visibility
Return type:bool
move_item_down(item)

Move an item down in the list.

Essentially swap it with the item below it.

Parameters:item – The item to be moved.
move_item_up(item)

Move an item up in the list.

Essentially swap it with the item above it.

Parameters:item – The item to be moved.
remove(item)

Remove an item from the list

Parameters:item – The item to remove from the list.
Raises ValueError:
 If the item is not present in the list.
selected_item

The currently selected item

selected_items

List of currently selected items

set_visible_func(visible_func)

Set the function to decide visibility of an item

Parameters:visible_func

A callable that returns a boolean result to decide if an item should be visible, for example:

def is_visible(item):
    return True
sort_by(attr_or_key, direction='asc')

Sort the view by an attribute or key

Parameters:
  • attr_or_key – The attribute or key to sort by
  • direction – Either asc or desc indicating the direction of sorting
update(item)

Manually update an item’s display in the list

Parameters:item – The item to be updated.