gtk.TreeView — a widget for displaying both trees and lists.
|
|
gtk.Container Signal Prototypes
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( |
A gtk.TreeView
widget is used to display the contents of any model implementing the gtk.TreeModel
interface. The tree models provided standard with GTK+
and PyGTK are:
In addition, PyGTK provides gtk.GenericTreeModel
that allows you to create your own tree model entirely in Python.
The gtk.TreeView uses
columns and cell renderers to actually display the model information.
GTK+ and PyGTK provides the gtk.TreeViewColumn
to manage the display of a column and the following cell renderers:
In addition, PyGTK provides the gtk.GenericCellRenderer
that allows you to create your own cell renderers entirely in Python.
gtk.TreeView(model=None)
| the tree model to display |
Returns : | A new gtk.TreeView
widget. |
Creates a new gtk.TreeView
widget displaying the model specified by model.
def get_model()Returns : | the current gtk.TreeModel, or
None if none is currently being
used. |
The get_model() method returns the
value of the "model" property containing the model the gtk.TreeView is
displaying or None there is no the model.
def set_model(model=None)
| the new tree model to use with the treeview |
The set_model() method sets the "model"
property for the treeview to the value of model. If
the treeview already has a model set, this method will remove it before
setting the new model. If model is
None, it will unset the old model.
def get_selection()Returns : | A gtk.TreeSelection
object. |
The get_selection() method returns the
current gtk.TreeSelection
associated with the treeview.
def get_hadjustment()Returns : | a gtk.Adjustment
object, or None if none is currently being
used. |
The get_hadjustment() method returns
the value of the "hadjustment" property that contains the current horizontal
gtk.Adjustment
object or None (if no horizontal adjustment is being
used).
def set_hadjustment(adjustment)
| the gtk.Adjustment
to set |
The set_hadjustment() method sets the
"hadjustment" property to the value of adjustment
that must be a gtk.Adjustment
object.
def get_vadjustment()Returns : | a gtk.Adjustment
object, or None if none is currently being
used. |
The get_vadjustment() method returns
the value of the "vadjustment" property that contains the horizontal gtk.Adjustment
or None if there is no vertical adjustment.
def set_vadjustment(adjustment)
| the gtk.Adjustment
to set |
The set_vadjustment() method sets the
"vadjustment" property to the value of adjustment.
The new gtk.Adjustment
replaces the current vertical adjustment.
def get_headers_visible()Returns : | True if the headers are
visible. |
The get_headers_visible() method
returns the value of the "headers-visible" property. If "headers-visible" is
True the headers on the treeview are visible.
def set_headers_visible(headers_visible)
| if True the headers are
visible |
The set_headers_visible() method sets
the "headers-visible" property to the value of
headers_visible. If
headers_visible is True the
headers will be displayed.
def columns_autosize()The columns_autosize() method resizes
all columns to their optimal width. Only works after the treeview has been
realized.
def set_headers_clickable(active)
| if True the headers are
clickable |
The set_headers_clickable() method sets
the "headers-clickable" property to the value of
active. If active is
True the column title buttons can be clicked.
def set_rules_hint(setting)
| if True the tree requires
reading across rows |
The set_rules_hint() method sets the
"rules-hint" property to the value of setting. If
setting is True it indicates that
the user interface for your application requires users to read across tree
rows and associate cells with one another. By default, the tree will be
rendered with alternating row colors. Do not use it
just because you prefer the appearance of the ruled tree; that's a question
for the theme. Some themes will draw tree rows in alternating colors even
when rules are turned off, and users who prefer that appearance all the time
can choose those themes. You should call this method only as a
semantic hint to the theme engine that your tree makes
alternating colors useful from a functional standpoint (since it has lots of
columns, generally).
def get_rules_hint()Returns : | True if rules are useful for
the user of this tree |
The get_rules_hint() returns the value
of the "rules-hint" property. See the set_rules_hint()
method for more information on the use of "rules-hint".
def append_column(column)
| the gtk.TreeViewColumn
to add. |
Returns : | the number of columns in
tree_view after appending. |
The append_column() method appends the
specified column to the list of columns and returns
the new number of columns in the treeview.
def remove_column(column)
| the gtk.TreeViewColumn
to remove. |
Returns : | the number of columns in the treeview after the column removal. |
The remove_column() method removes the
specified column from the treeview.
def insert_column(column, position)
| the gtk.TreeViewColumn
to be inserted. |
| the position to insert
column. |
Returns : | the number of columns in the treeview after the insertion. |
The insert_column() method inserts the
specified column into the treeview at the location
specified by position. If
position is -1, then the column is inserted at the
end.
def insert_column_with_attributes(position, title, cell, ...)
| the position to insert the new column in. |
| the title to set the header to. |
| the gtk.CellRenderer. |
| optional keyword-value arguments |
Returns : | the gtk.TreeViewColumn
that was inserted. |
The insert_column_with_attributes()
method creates a new gtk.TreeViewColumn
and inserts it into the treeview at the location specified by
position with the column title specified by
title and using the gtk.CellRenderer
specified by cell. If position
is -1, then the newly created column is inserted at the end. The column is
initialized with the optional attributes passed as keyword-value pairs (e.g.
text=0, foreground=2). See the gtk.TreeViewColumn.add_attribute()
method for more information.
def insert_column_with_data_func(position, title, cell, func, data=None)
| the position to insert, -1 for append |
| the column title |
| a cell renderer for the column |
| the function or method to set attributes of the cell renderer |
| the data to pass with
func |
Returns : | the number of columns in the treeview after the insertion |
The insert_column_with_data_func()
method is a convenience function that inserts a new column into the treeview
at the location specified by position with the
specified title and the cell renderer specified by
cell and using the function or method specified by
func to set cell renderer attributes (normally using
data from the model). The signature of func is:
def celldatafunction(column,cell,model,iter,user_data)
def celldatamethod(self,column,cell,model,iter,user_data)
where column is the gtk.TreeViewColumn
in the treeview, cell is the gtk.CellRenderer
for column, model is the gtk.TreeModel for
the treeview and iter is the gtk.TreeIter
pointing at the row. See the gtk.TreeViewColumn.set_cell_data_func()
and gtk.TreeViewColumn.pack_start()
methods for more detail.
def get_column(n)
| the position of the column, counting from 0. |
Returns : | the gtk.TreeViewColumn,
or None if the position is outside the range of
columns. |
The get_column() method returns the
gtk.TreeViewColumn
at the specified position in the treeview.
def get_columns()Returns : | a list of gtk.TreeViewColumn
s |
The get_columns() method returns a list
of all the gtk.TreeViewColumn
objects currently in the treeview.
def move_column_after(column, base_column)
| the gtk.TreeViewColumn
to be moved. |
| the gtk.TreeViewColumn
column is to be after, or
None. |
The move_column_after() method moves
the gtk.TreeViewColumn
specified by column to be after the treeview column
specified by base_column. If
base_column is None, then
column is placed in the first position.
def set_expander_column(column)
| the column to draw the expander arrow at
orNone. |
The set_expander_column() method sets
the "expander-column" property to the value of column
which must be a gtk.TreeViewColumn
in the treeview. If column is
None, then the expander arrow is always at the first
visible column.
def get_expander_column()Returns : | the expander column. |
The get_expander_column() method
returns the value of the "expander-column" property that contains the
current expander column i.e. the column that has the expander arrow drawn
next to it.
def set_column_drag_function(func, user_data)
| A function to determine which columns are reorderable, or None. |
| User data to be passed to func, or None |
This method is available in PyGTK 2.4 and above.
The set_column_drag_function() method
sets the user function specified by func for
determining where a column may be dropped when dragged. The user function is
called on every column pair in turn at the beginning of a column drag to
determine where a drop can take place. The signature of
func is:
def func(tree_view,column,prev_column,next_column,data)
where tree_view is the gtk.TreeView,
column is the gtk.TreeViewColumn
being dragged, prev_column and next_column are the two gtk.TreeViewColumn
objects bracketing the drop spot, and data is
user_data. If prev_column or
next_column is None, then the drop
is at an edge. If func is None,
the user drag function is removed and the gtk.TreeView
reverts to the default behavior of allowing any reorderable column to be
dropped anywhere.
def scroll_to_point(tree_x, tree_y)
| the X coordinate of new top-left pixel of visible area, or -1 |
| the Y coordinate of new top-left pixel of visible area, or -1 |
The scroll_to_point() method scrolls
the treeview so that the top-left corner of the visible area is at the
location specified by tree_x and
tree_y, where tree_x and
tree_y are specified in tree window coordinates. The
treeview must be realized before this method is called. If it isn't, you
should use the scroll_to_cell()
method instead. If either tree_x or
tree_y are -1, there is no scrolling in that
direction.
def scroll_to_cell(path, column=None, use_align=False, row_align=0.0, col_align=0.0)
| the path of the row to move to |
| the gtk.TreeViewColumn
to move horizontally to, or None. |
| if True use the alignment
arguments |
| the vertical alignment of the row specified by
path. |
| the horizontal alignment of the column
specified by column. |
The scroll_to_cell() method scrolls the
treeview display to the position specified by column
and path. If column is
None, no horizontal scrolling occurs. The alignment
parameters specified by row_align and
col_align determines where
column is placed within the treeview. The values of
col_align and row_align range
from 0.0 to 1.0. The alignment values specify the fraction of display space
that is to the left of or above the cell. If
use_align is False, the alignment
arguments are ignored, and the tree does the minimum amount of work to
scroll the cell onto the screen. This means that the cell will be scrolled
to the edge closest to it's current position. If the cell is currently
visible on the screen, nothing is done. This method only works if the model
is set, and path is a valid row in the model.
def row_activated(path, column)
| the tree path of the row of the cell to be activated. |
| the gtk.TreeViewColumn
of the cell to be activated. |
The row_activated() method activates
the cell determined by path and
column.
def expand_all()The expand_all() method recursively
expands all nodes in the treeview.
def collapse_all()The collapse_all() method recursively
collapses all visible, expanded nodes in the treeview.
def expand_to_path(path)
| a path to a row. |
This method is available in PyGTK 2.2 and above.
The expand_to_row() method expands the
row with the tree path specified by path. This will
also expand all parent rows of path as
necessary.
def expand_row(path, open_all)
| the path to a row |
| if True recursively expand,
otherwise just expand immediate children |
The expand_row() method opens the row
specified by path so its children are visible. If
open_all is True all rows are
expanded, otherwise only the immediate children of
path are expanded.
def collapse_row(path)
| the path to a row |
The collapse_row() method collapses the
row specified by path (hides its child rows, if they
exist).
def map_expanded_rows(func, data)
| A function to be called |
| User data to be passed to the function. |
This method is available in PyGTK 2.2 and above.
The map_expanded_rows() method calls
the function specified by func on all expanded rows
passing data as an argument.
def row_expanded(path)
| the path to a row to test the expansion state. |
Returns : | True if
path is expanded. |
The row_expanded() method returns
True if the node pointed to by
path is expanded.
def set_reorderable(reorderable)
| if True, the tree can be
reordered. |
The set_reorderable() method sets the
"reorderable" property to the value of reorderable.
This method is a convenience method to allow you to reorder models that
support the gtk.TreeDragSource
and the gtk.TreeDragDest
interfaces. Both gtk.TreeStore and
gtk.ListStore
support these. If reorderable is
True, then the user can reorder the model by dragging and
dropping rows. The application can listen to these changes by connecting to
the model's signals.
This function does not give you any degree of control over the order -- any reordering is allowed. If more control is needed, you should probably handle drag and drop manually.
def get_reorderable()Returns : | True if the tree can be
reordered. |
The get_reorderable() method returns
the value of the "reorderable" property that determines if the user can
reorder the tree via drag-and-drop. See the set_reorderable()
method for more information.
def set_cursor(path, focus_column=None, start_editing=False)
| a tree path |
| a gtk.TreeViewColumn,
or None |
| if True the specified cell
should start being edited. |
The set_cursor() method sets the
current keyboard focus to be at the row specified by
path, and selects it. This is useful when you want to
focus the user's attention on a particular row. If
column is not None, then focus is
given to the specified column. Additionally, if
column is specified, and
start_editing is True, then
editing should be started in the specified cell. This method is often
followed by the gtk.Widget.grab_focus()
method to give keyboard focus to the treeview. Please note that editing can
only happen when the widget is realized.
def set_cursor_on_cell(path, focus_column=None, focus_cell=None, start_editing=False)
| a tree path |
| a gtk.TreeViewColumn,
or None |
| a gtk.CellRenderer,
or None |
| True if the specified cell
should start being edited. |
This method is available in PyGTK 2.2 and above.
The set_cursor_on_cell() method sets
the current keyboard focus to be at the node specified by
path, and selects it. This is useful when you want
to focus the user's attention on a particular row. If
focus_column is specified, focus is given to that
column. If focus_column and
focus_cell are specified, and
focus_column contains 2 or more editable or
activatable cells, then focus is given to the cell specified by
focus_cell. Additionally, if
focus_column is specified, and
start_editing is True, editing
should be started in the specified cell. This method is often followed by
the gtk.Widget.grab_focus()
method in order to give keyboard focus to the widget. Please note that
editing can only happen when the widget is realized.
def get_cursor()Returns : | a tuple containing the current cursor path and focus column. |
The get_cursor() method returns a tuple
containing the current path and focus column. If the cursor isn't currently
set, the current path will be None. If no column
currently has focus, the current focus column will be
None.
def get_bin_window()Returns : | a gtk.gdk.Window, or
None |
The get_bin_window() method returns the
window that the treeview renders to or None if the
treeview is not realized yet. This is used primarily to compare to the
event.window attribute to confirm that the event on the
treeview is on the right window.
def get_path_at_pos(x, y)
| The x position to be identified. |
| The y position to be identified. |
Returns : | a tuple containing: a tree path; a gtk.TreeViewColumn
object; the X coordinate relative to the cell; and, the Y
coordinate relative to the cell. If there is no path at the
position None is returned. |
The get_path_at_pos() method returns a
tuple containing:
x, y), relative to widget
coordinatesgtk.TreeViewColumn
at that pointx and y are
relative to the coordinates of an event on the treeview only when
event.window==treeview.get_bin_window(). It is primarily
used for popup menus. This method is only meaningful if the treeview is
realized. This method returns None if there is no path at
the position.
def get_cell_area(path, column)
| a tree path for the row |
| a gtk.TreeViewColumn
for the column |
Returns : | rectangle |
The get_cell_area() method returns the
bounding gtk.gdk.Rectangle
in tree window coordinates for the cell at the row specified by
path and the column specified by
column. If path points to a
path not currently displayed, the y and
height attributes of the rectangle will be 0. The sum
of all cell rects does not cover the entire tree; there are extra pixels in
between rows, for example. The returned rectangle is equivalent to the
cell_area passed to the gtk.CellRenderer.render()
method. This method is only valid if the treeview is realized.
def get_background_area(path, column)
| a tree path for the row, |
| a gtk.TreeViewColumn
for the column |
Returns : | a rectangle |
The get_background_area() method
returns the bounding gtk.gdk.Rectangle
in tree window coordinates for the cell at the row specified by
path and the column specified by
column. If path points to a
node not found in the tree, the y and
height attributes of the rectangle will be 0. The
returned rectangle is equivalent to the
background_area passed to the gtk.CellRenderer.render().
These background areas tile to cover the entire tree window (except for the
area used for header buttons). Contrast with the
cell_area, returned by the get_cell_area()
method, that returns only the cell itself, excluding the surrounding borders
and the tree expander area.
def get_visible_rect()Returns : | a rectangle |
The get_visible_rect() method returns
the bounding gtk.gdk.Rectangle
for the currently visible region of the treeview widget, in tree
coordinates. Convert to widget coordinates with the tree_to_widget_coords().
Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
scrollable area of the tree.
def widget_to_tree_coords(wx, wy)
| the widget X coordinate |
| the widget Y coordinate |
Returns : | a tuple containing the tree X and Y coordinates |
The widget_to_tree_coords() method
returns a tuple containing the tree X and Y coordinates for the widget
coordinates specified by wx and
wy. The tree coordinates cover the full scrollable
area of the tree.
def tree_to_widget_coords(tx, ty)
| tree X coordinate |
| tree Y coordinate |
Returns : | a tuple containing the widget X and Y coordinates |
The tree_to_widget_coords() method
returns a tuple containing the widget coordinates for the tree coordinates
specified by tx and ty.