class Tk::Tile::Treeview

The ttk::treeview widget displays a hierarchical collection of items. Each item has a textual label, an optional image, and an optional list of data values. The data values are displayed in successive columns after the tree label. The order in which data values are displayed may be controlled by setting the -displaycolumns widget option. The tree widget can also display column headings. Columns may be accessed by number or by symbolic names listed in the -columns widget option; see COLUMN IDENTIFIERS. Each item is identified by a unique name. The widget will generate item IDs if they are not supplied by the caller. There is a distinguished root item, named {}. The root item itself is not displayed; its children appear at the top level of the hierarchy. Each item also has a list of tags, which can be used to associate event bindings with individual items and control the appearance of the item. Treeview widgets support horizontal and vertical scrolling with the standard -[xy]scrollcommand options and [xy]view widget commands.

Constants

Item

Public Class Methods

tk_command() click to toggle source
# File lib/ffi-tk/widget/tile/treeview.rb, line 25
def self.tk_command
  'ttk::treeview'
end

Public Instance Methods

bbox(item, column = None) click to toggle source

Returns the bounding box (relative to the treeview widget's window) of the specified item in the form x y width height. If column is specified, returns the bounding box of that cell. If the item is not visible (i.e., if it is a descendant of a closed item or is scrolled offscreen), returns the empty list.

# File lib/ffi-tk/widget/tile/treeview.rb, line 39
def bbox(item, column = None)
  execute(:bbox, item, column)
end
children(item, *new_children) click to toggle source

If newchildren is not specified, returns the list of children belonging to item. If newchildren is specified, replaces item's child list with newchildren. Items in the old child list not present in the new child list are detached from the tree. None of the items in newchildren may be an ancestor of item.

# File lib/ffi-tk/widget/tile/treeview.rb, line 49
def children(item, *new_children)
  if new_children.empty?
    execute(:children, item).to_a.map { |child| Item.new(self, child) }
  else
    execute(:children, item, *new_children.flatten)
  end
end
clear() click to toggle source

Delete all items

# File lib/ffi-tk/widget/tile/treeview.rb, line 30
def clear
  delete(*children(nil))
end
column(column, options = None) click to toggle source

Query or modify the options for the specified column.

If no options is specified, returns an Hash of option/value pairs.

If options is a Symbol/String, returns the value of that option.

Otherwise, the options are updated with the specified values.

The following options may be set on each column:

id: name
  The column name. This is a read-only option. For example
  `list.column('#n')` returns the data column associated with display
  column `#n`.

anchor: name
  Specifies how the text in this column should be aligned with respect
  to the cell.
  One of n, ne, e, se, s, sw, w, nw, or center.

minwidth: width
  The minimum width of the column in pixels.
  The treeview widget will not make the column any smaller than
  minwidth when the widget is resized or the user drags a column
  separator.

stretch: boolean
  Specifies whether or not the column's width should be adjusted when
  the widget is resized.

width: w
  The width of the column in pixels.
  Default is something reasonable, probably 200 or so.

Use column '#0' to configure the tree column.

# File lib/ffi-tk/widget/tile/treeview.rb, line 91
def column(column, options = None)
  common_configure([:column, column], options, stretch: :boolean)
end
delete(*items) click to toggle source

Deletes each of the items in items and all of their descendants. The root item may not be deleted.

@see detach

# File lib/ffi-tk/widget/tile/treeview.rb, line 99
def delete(*items)
  items = items.flatten
  execute_only(:delete, items) if items.any?
end
detach(*items) click to toggle source

Unlinks all of the specified items in items from the tree. The items and all of their descendants are still present and may be reinserted at another point in the tree but will not be displayed. The root item may not be detached.

@see delete

# File lib/ffi-tk/widget/tile/treeview.rb, line 110
def detach(*items)
  execute(:detach, *items.flatten)
end
exist?(item)
Alias for: exists
exists(item) click to toggle source

Returns true if the specified item is present in the tree, false otherwise.

# File lib/ffi-tk/widget/tile/treeview.rb, line 116
def exists(item)
  execute(:exists, item).to_boolean
end
Also aliased as: exist?
focus_item(item = None) click to toggle source

If item is specified, sets the focus item to item. Otherwise, returns the current focus item, or {} if there is none.

# File lib/ffi-tk/widget/tile/treeview.rb, line 123
def focus_item(item = None)
  result = execute(:focus, item)
  Item.new(self, result) if result
end
heading(column, options = None) click to toggle source

Query or modify the heading options for the specified column. Valid options are: -text text The text to display in the column heading. -image imageName Specifies an image to display to the right of the column heading. -anchor anchor Specifies how the heading text should be aligned. One of the standard Tk anchor values. -command script A script to evaluate when the heading label is pressed. Use pathname heading #0 to configure the tree column heading.

# File lib/ffi-tk/widget/tile/treeview.rb, line 135
def heading(column, options = None)
  common_configure([:heading, column], options)
end
identify_column(x, y) click to toggle source

Returns the data column identifier of the cell at position x. The tree column has ID #0.

# File lib/ffi-tk/widget/tile/treeview.rb, line 153
def identify_column(x, y)
  execute(:identify, column, x, y)
end
identify_component(x, y) click to toggle source

Returns a description of the specified component under the point given by x and y, or the empty string if no such component is present at that position. The following subcommands are supported:

# File lib/ffi-tk/widget/tile/treeview.rb, line 142
def identify_component(x, y)
  execute(:identify, component, x, y)
end
identify_row(x, y) click to toggle source

Returns the item ID of the item at position y.

# File lib/ffi-tk/widget/tile/treeview.rb, line 147
def identify_row(x, y)
  execute(:identify, row, x, y)
end
index(item) click to toggle source

Returns the integer index of item within its parent's list of children.

# File lib/ffi-tk/widget/tile/treeview.rb, line 158
def index(item)
  execute(:index, item)
end
insert(parent, index, options = {}) click to toggle source

Creates a new item. parent is the item ID of the parent item, or the empty string {} to create a new top-level item. index is an integer, or the value end, specifying where in the list of parent's children to insert the new item. If index is less than or equal to zero, the new node is inserted at the beginning; if index is greater than or equal to the current number of children, it is inserted at the end. If -id is specified, it is used as the item identifier; id must not already exist in the tree. Otherwise, a new unique identifier is generated.

Returns the item identifier of the newly created item.

# File lib/ffi-tk/widget/tile/treeview.rb, line 175
def insert(parent, index, options = {})
  id = execute(:insert, parent, index, options.to_tcl_options)
  Item.new(self, id)
end
instate(statespec) { || ... } click to toggle source

Test the widget state, execute passed block if state matches statespec.

# File lib/ffi-tk/widget/tile/treeview.rb, line 279
def instate(statespec)
  result = execute(:instate, statespec).to_boolean
  yield if result && block_given?
  result
end
item(item, options = None) click to toggle source

Query or modify the options for the specified item. If no -option is specified, returns a dictionary of option/value pairs. If a single -option is specified, returns the value of that option. Otherwise, the item's options are updated with the specified values. See ITEM OPTIONS for the list of available options.

# File lib/ffi-tk/widget/tile/treeview.rb, line 290
def item(item, options = None)
  common_configure([:item, item], options)
end
move(item, parent, index) click to toggle source

Moves item to position index in parent's list of children. It is illegal to move an item under one of its descendants. If index is less than or equal to zero, item is moved to the beginning; if greater than or equal to the number of children, it is moved to the end.

# File lib/ffi-tk/widget/tile/treeview.rb, line 299
def move(item, parent, index)
  execute(:move, item, parent, index)
end
next(item) click to toggle source

Returns the item's next sibling, or nil if item is the last child of its parent.

# File lib/ffi-tk/widget/tile/treeview.rb, line 305
def next(item)
  id = execute(:next, item)
  Item.new(self, id) if id
end
parent(item) click to toggle source

Returns the parent of item, or nil if item is at the top level of the hierarchy.

# File lib/ffi-tk/widget/tile/treeview.rb, line 312
def parent(item)
  id = execute(:parent, item)
  p item
  p id
  Item.new(self, id) if id
end
prev(item) click to toggle source

Returns the item's previous sibling, or nil if item is the first child of its parent.

# File lib/ffi-tk/widget/tile/treeview.rb, line 321
def prev(item)
  id = execute(:prev, item)
  Item.new(self, id) if id
end
see(item) click to toggle source

Ensure that item is visible: sets all of item's ancestors to -open true, and scrolls the widget if necessary so that item is within the visible portion of the tree.

# File lib/ffi-tk/widget/tile/treeview.rb, line 329
def see(item)
  execute(:see, item)
end
selection() click to toggle source

Returns the list of selected items.

# File lib/ffi-tk/widget/tile/treeview.rb, line 334
def selection
  execute(:selection).to_a.map { |id| Item.new(self, id) }
end
selection_add(*items) click to toggle source

Add items to the selection

# File lib/ffi-tk/widget/tile/treeview.rb, line 344
def selection_add(*items)
  execute(:selection, :add, *items.flatten)
end
selection_remove(*items) click to toggle source

Remove items from the selection

# File lib/ffi-tk/widget/tile/treeview.rb, line 349
def selection_remove(*items)
  execute(:selection, :remove, *items.flatten)
end
selection_set(*items) click to toggle source

items becomes the new selection.

# File lib/ffi-tk/widget/tile/treeview.rb, line 339
def selection_set(*items)
  execute(:selection, :set, *items.flatten)
end
selection_toggle(*items) click to toggle source

Toggle the selection state of each item in items.

# File lib/ffi-tk/widget/tile/treeview.rb, line 354
def selection_toggle(*items)
  execute(:selection, :toggle, *items.flatten)
end
set(item, column = None, value = None) click to toggle source

With one argument, returns a dictionary of column/value pairs for the specified item. With two arguments, returns the current value of the specified column. With three arguments, sets the value of column column in item item to the specified value. See also COLUMN IDENTIFIERS.

# File lib/ffi-tk/widget/tile/treeview.rb, line 364
def set(item, column = None, value = None)
  if None == column
    execute(:set, item)
  elsif None == value
    execute(:set, item, column).to_s
  else
    execute_only(:set, item, column, value)
  end
end
state(state_spec = None) click to toggle source

Modify or query the widget state; see ttk::widget(n).

# File lib/ffi-tk/widget/tile/treeview.rb, line 375
def state(state_spec = None)
  execute(:state, state_spec)
end
tag_bind(tag_name, sequence = None, &script) click to toggle source

Add a Tk binding script for the event sequence sequence to the tag tagName. When an X event is delivered to an item, binding scripts for each of the item's -tags are evaluated in order as per bindtags(n). <KeyPress>, <KeyRelease>, and virtual events are sent to the focus item. <ButtonPress>, <ButtonRelease>, and <Motion> events are sent to the item under the mouse pointer. No other event types are supported. The binding script undergoes %-substitutions before evaluation; see bind(n) for details.

# File lib/ffi-tk/widget/tile/treeview.rb, line 388
def tag_bind(tag_name, sequence = None, &script)
  execute(:tag, :bind, tag_name, sequence, script)
end
tag_configure(tag_name, options = None) click to toggle source

Query or modify the options for the specified tagName. If one or more option/value pairs are specified, sets the value of those options for the specified tag. If a single option is specified, returns the value of that option (or the empty string if the option has not been specified for tagName). With no additional arguments, returns a dictionary of the option settings for tagName. See TAG OPTIONS for the list of available options.

# File lib/ffi-tk/widget/tile/treeview.rb, line 400
def tag_configure(tag_name, options = None)
  common_configure([:tag, :configure, tag_name], options)
end
xview(args) click to toggle source

Standard command for horizontal scrolling; see widget(n).

# File lib/ffi-tk/widget/tile/treeview.rb, line 405
def xview(args)
  execute(:xview, args)
end
yview(args) click to toggle source

Standard command for vertical scrolling; see ttk::widget(n). Each item should have the same number of values as the -columns widget option. If there are fewer values than columns, the remaining values are assumed empty. If there are more values than columns, the extra values are ignored. Specifies the text foreground color. Specifies the cell or item background color. Generated whenever the selection changes. Generated just before setting the focus item to -open true. Generated just after setting the focus item to -open false.

# File lib/ffi-tk/widget/tile/treeview.rb, line 419
def yview(args)
  execute(:yview, args)
end