Class: Tk::Tile::Treeview

Inherits:
Widget show all
Includes:
Cget, Configure, TileWidget
Defined in:
lib/ffi-tk/widget/tile/treeview.rb

Overview

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.

Defined Under Namespace

Classes: Item

Constant Summary

Constants included from Cget

Cget::CGET_MAP

Constants included from WM

WM::WM_ATTRIBUTES_HINTS

Instance Attribute Summary

Attributes inherited from Widget

#tk_parent, #tk_pathname

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TileWidget

#grid, #style, #ttk_state

Methods included from Grid

anchor, bbox, columnconfigure, configure, forget, #grid_anchor, #grid_bbox, #grid_columnconfigure, #grid_configure, #grid_forget, #grid_info, #grid_location, #grid_propagate, #grid_remove, #grid_rowconfigure, #grid_size, #grid_slave, #grid_slaves, info, location, propagate, remove, rowconfigure, size, slave, slaves

Methods included from Cget

#cget, option_hash_to_tcl, option_to_ruby, type_to_ruby

Methods included from Configure

#configure

Methods inherited from Widget

#execute, #execute_only, #focus, #focus_next, #focus_prev, #initialize, #lower, #raise, #to_tcl

Methods included from Pack

configure, forget, info, pack, #pack, #pack_configure, #pack_forget, #pack_info, #pack_propagate, #pack_slaves, propagate, slaves

Methods included from Destroy

destroy, #destroy

Methods included from Bind

bind, #bind

Methods included from Bindtags

bindtags, #bindtags

Methods included from WM

aspect, attributes, client, colormapwindows, command, deiconify, focusmodel, forget, frame, geometry, grid, group, iconbitmap, iconbitmap_default, iconify, iconmask, iconname, iconphoto, iconphoto_default, iconposition, iconwindow, manage, maxsize, minsize, overrideredirect, positionfrom, protocol, resizable, sizefrom, stackorder, state, title, transient, withdraw, #wm_aspect, #wm_aspect=, #wm_attributes, #wm_client, #wm_client=, #wm_colormapwindows, #wm_colormapwindows=, #wm_command, #wm_command=, #wm_deiconify, #wm_focusmodel, #wm_focusmodel=, #wm_forget, #wm_frame, #wm_geometry, #wm_geometry=, #wm_grid, #wm_grid=, #wm_group, #wm_group=, #wm_iconbitmap, #wm_iconbitmap=, #wm_iconbitmap_default, #wm_iconbitmap_default=, #wm_iconify, #wm_iconmask, #wm_iconmask=, #wm_iconname, #wm_iconname=, #wm_iconphoto, #wm_iconphoto=, #wm_iconphoto_default, #wm_iconphoto_default=, #wm_iconposition, #wm_iconposition=, #wm_iconwindow, #wm_iconwindow=, #wm_manage, #wm_maxsize, #wm_minsize, #wm_overrideredirect, #wm_overrideredirect=, #wm_positionfrom, #wm_positionfrom=, #wm_protocol, #wm_resizable, #wm_sizefrom, #wm_sizefrom=, #wm_stackorder, #wm_state, #wm_state=, #wm_title, #wm_title=, #wm_transient, #wm_transient=, #wm_withdraw

Methods included from Winfo

atom, atomname, cells, children, class_name, colormapfull, containing, depth, exists, fpixels, geometry, height, id, interps, ismapped, manager, name, parent, pathname, pixels, pointerx, pointerxy, pointery, reqheight, reqwidth, rgb, rootx, rooty, screen, screencells, screendepth, screenheight, screenmmheight, screenmmwidth, screenvisual, screenwidth, server, toplevel, viewable, visual, visualid, visualsavailable, vrootheight, vrootwidth, vrootx, vrooty, width, #winfo_atom, #winfo_atomname, #winfo_cells, #winfo_children, #winfo_class, #winfo_colormapfull, #winfo_containing, #winfo_depth, #winfo_exists, #winfo_fpixels, #winfo_geometry, #winfo_height, #winfo_id, #winfo_interps, #winfo_ismapped, #winfo_manager, #winfo_name, #winfo_parent, #winfo_pathname, #winfo_pixels, #winfo_pointerx, #winfo_pointerxy, #winfo_pointery, #winfo_reqheight, #winfo_reqwidth, #winfo_rgb, #winfo_rootx, #winfo_rooty, #winfo_screen, #winfo_screencells, #winfo_screendepth, #winfo_screenheight, #winfo_screenmmheight, #winfo_screenmmwidth, #winfo_screenvisual, #winfo_screenwidth, #winfo_server, #winfo_toplevel, #winfo_viewable, #winfo_visual, #winfo_visualid, #winfo_visualsavailable, #winfo_vrootheight, #winfo_vrootwidth, #winfo_vrootx, #winfo_vrooty, #winfo_width, #winfo_x, #winfo_y, x, y

Methods included from Clipboard

append, clear, #clipboard_append, #clipboard_clear, #clipboard_get, #clipboard_set, get

Methods included from Place

configure, forget, info, place, #place, #place_configure, #place_forget, #place_info, #place_slaves, slaves

Methods included from Tk::TkCmd

appname, caret, inactive, scaling, #tk_appname, #tk_appname=, #tk_caret, #tk_inactive, #tk_scaling, #tk_scaling=, #tk_useinputmethods, #tk_useinputmethods=, #tk_windowingsystem, useinputmethods, windowingsystem

Constructor Details

This class inherits a constructor from Tk::Widget

Class Method Details

.tk_commandObject



24
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 24

def self.tk_command; 'ttk::treeview'; end

Instance Method Details

#bbox(item, column = None) ⇒ Object

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.



36
37
38
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 36

def bbox(item, column = None)
  execute(:bbox, item, column)
end

#children(item, *new_children) ⇒ Object

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.



46
47
48
49
50
51
52
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 46

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

#clearObject

Delete all items



27
28
29
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 27

def clear
  delete(*children(nil))
end

#column(column, options = None) ⇒ Object

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.



88
89
90
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 88

def column(column, options = None)
  common_configure([:column, column], options, stretch: :boolean)
end

#delete(*items) ⇒ Object

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

See Also:



96
97
98
99
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 96

def delete(*items)
  items = items.flatten
  execute_only(:delete, items) if items.any?
end

#detach(*items) ⇒ Object

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 Also:



107
108
109
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 107

def detach(*items)
  execute(:detach, *items.flatten)
end

#exists(item) ⇒ Object Also known as: exist?

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



113
114
115
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 113

def exists(item)
  execute(:exists, item).to_boolean
end

#focus_item(item = None) ⇒ Object

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



120
121
122
123
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 120

def focus_item(item = None)
  result = execute(:focus, item)
  Item.new(self, result) if result
end

#heading(column, options = None) ⇒ Object

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.



132
133
134
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 132

def heading(column, options = None)
  common_configure([:heading, column], options)
end

#identify_column(x, y) ⇒ Object

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



150
151
152
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 150

def identify_column(x, y)
  execute(:identify, column, x, y)
end

#identify_component(x, y) ⇒ Object

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:



139
140
141
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 139

def identify_component(x, y)
  execute(:identify, component, x, y)
end

#identify_row(x, y) ⇒ Object

Returns the item ID of the item at position y.



144
145
146
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 144

def identify_row(x, y)
  execute(:identify, row, x, y)
end

#index(item) ⇒ Object

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



155
156
157
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 155

def index(item)
  execute(:index, item)
end

#insert(parent, index, options = {}) ⇒ Object

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.



172
173
174
175
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 172

def insert(parent, index, options = {})
  id = execute(:insert, parent, index, options.to_tcl_options)
  Item.new(self, id)
end

#instate(statespec) ⇒ Object

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



271
272
273
274
275
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 271

def instate(statespec)
  result = execute(:instate, statespec).to_boolean
  yield if result && block_given?
  result
end

#item(item, options = None) ⇒ Object

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.



282
283
284
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 282

def item(item, options = None)
  common_configure([:item, item], options)
end

#move(item, parent, index) ⇒ Object

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.



291
292
293
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 291

def move(item, parent, index)
  execute(:move, item, parent, index)
end

#next(item) ⇒ Object

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



297
298
299
300
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 297

def next(item)
  id = execute(:next, item)
  Item.new(self, id) if id
end

#parent(item) ⇒ Object

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



304
305
306
307
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 304

def parent(item)
  id = execute(:parent, item)
  Item.new(self, id) if id
end

#prev(item) ⇒ Object

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



311
312
313
314
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 311

def prev(item)
  id = execute(:prev, item)
  Item.new(self, id) if id
end

#see(item) ⇒ Object

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.



319
320
321
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 319

def see(item)
  execute(:see, item)
end

#selectionObject

Returns the list of selected items.



324
325
326
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 324

def selection
  execute(:selection).to_a
end

#selection_add(*items) ⇒ Object

Add items to the selection



334
335
336
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 334

def selection_add(*items)
  execute(:selection, :add, *items.flatten)
end

#selection_remove(*items) ⇒ Object

Remove items from the selection



339
340
341
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 339

def selection_remove(*items)
  execute(:selection, :remove, *items.flatten)
end

#selection_set(*items) ⇒ Object

items becomes the new selection.



329
330
331
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 329

def selection_set(*items)
  execute(:selection, set, *items.flatten)
end

#selection_toggle(*items) ⇒ Object

Toggle the selection state of each item in items.



344
345
346
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 344

def selection_toggle(*items)
  execute(:selection, :toggle, *items.flatten)
end

#set(item, column = None, value = None) ⇒ Object

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.



354
355
356
357
358
359
360
361
362
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 354

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) ⇒ Object

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



365
366
367
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 365

def state(state_spec = None)
  execute(:state, state_spec)
end

#tag_bind(tag_name, sequence = None, &script) ⇒ Object

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.



378
379
380
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 378

def tag_bind(tag_name, sequence = None, &script)
  execute(:tag, :bind, tag_name, sequence, script)
end

#tag_configure(tag_name, options = None) ⇒ Object

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.



390
391
392
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 390

def tag_configure(tag_name, options = None)
  common_configure([:tag, :configure, tag_name], options)
end

#xview(args) ⇒ Object

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



395
396
397
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 395

def xview(args)
  execute(:xview, args)
end

#yview(args) ⇒ Object

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.



409
410
411
# File 'lib/ffi-tk/widget/tile/treeview.rb', line 409

def yview(args)
  execute(:yview, args)
end