Class: Tk::Listbox

Inherits:
Widget show all
Includes:
Cget, Configure, Scrollable
Defined in:
lib/ffi-tk/widget/listbox.rb

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 Cget

#cget, option_hash_to_tcl, option_to_ruby, type_to_ruby

Methods included from Configure

#configure

Methods included from Scrollable

#xscrollbar, #xscrollcommand, #xview, #xview_moveto, #xview_scroll, #yscrollbar, #yscrollcommand, #yview, #yview_moveto, #yview_pickplace, #yview_scroll

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, unbind, #unbind

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 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 Clipboard

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

Methods included from Place

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

Methods included from 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



6
7
8
# File 'lib/ffi-tk/widget/listbox.rb', line 6

def self.tk_command
  'listbox'
end

Instance Method Details

#activate(index) ⇒ Object

Sets the active element to the one indicated by index. If index is outside the range of elements in the listbox then the closest element is activated. The active element is drawn as specified by -activestyle when the widget has the input focus, and its index may be retrieved with the index active.



29
30
31
# File 'lib/ffi-tk/widget/listbox.rb', line 29

def activate(index)
  execute_only(:activate, index)
end

#bbox(index) ⇒ Object

Returns a list of four numbers describing the bounding box of the text in the element given by index. The first two elements of the list give the x and y coordinates of the upper-left corner of the screen area covered by the text (specified in pixels relative to the widget) and the last two elements give the width and height of the area, in pixels. If no part of the element given by index is visible on the screen, or if index refers to a non-existent element, then the result is an empty string; if the element is partially visible, the result gives the full area of the element, including any parts that are not visible.



43
44
45
# File 'lib/ffi-tk/widget/listbox.rb', line 43

def bbox(index)
  execute(:bbox, index).to_a(&:to_i)
end

#clearObject



10
11
12
# File 'lib/ffi-tk/widget/listbox.rb', line 10

def clear
  delete 0, :end
end

#curselectionObject

Returns a list containing the numerical indices of all of the elements in the listbox that are currently selected. If there are no elements selected in the listbox then an empty string is returned.



51
52
53
# File 'lib/ffi-tk/widget/listbox.rb', line 51

def curselection
  execute(:curselection).to_a(&:to_i)
end

#delete(first, last = None) ⇒ Object

Deletes one or more elements of the listbox. First and last are indices specifying the first and last elements in the range to delete. If last is not specified it defaults to first, i.e. a single element is deleted.



60
61
62
# File 'lib/ffi-tk/widget/listbox.rb', line 60

def delete(first, last = None)
  execute_only(:delete, first, last)
end

#get(first, last = None) ⇒ Object

If last is omitted, returns the contents of the listbox element indicated by first, or an empty string if first refers to a non-existent element. If last is specified, the command returns a list whose elements are all of the listbox elements between first and last, inclusive. Both first and last may have any of the standard forms for indices.



69
70
71
72
73
74
75
# File 'lib/ffi-tk/widget/listbox.rb', line 69

def get(first, last = None)
  if None == last
    execute(:get, first).to_s
  else
    execute(:get, first, last).to_a
  end
end

#index(index) ⇒ Object

Returns the integer index value that corresponds to index. If index is end the return value is a count of the number of elements in the listbox (not the index of the last element).



80
81
82
# File 'lib/ffi-tk/widget/listbox.rb', line 80

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

#insert(index, *elements) ⇒ Object

Inserts zero or more new elements in the list just before the element given by index. If index is specified as end then the new elements are added to the end of the list. Returns an empty string.



89
90
91
# File 'lib/ffi-tk/widget/listbox.rb', line 89

def insert(index, *elements)
  execute_only(:insert, index, *elements)
end

#itemcget(index, option) ⇒ Object

Returns the current value of the item configuration option given by option. Option may have any of the values accepted by the listbox itemconfigure command.



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

def itemcget(index, option)
  execute(:itemcget, index, option.to_tcl_option)
end

#itemconfigure(index, options = None) ⇒ Object

Query or modify the configuration options of an item in the listbox. If no option is specified, returns a list describing all of the available options for the item (see Tk_ConfigureInfo for information on the format of this list). If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more option-value pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. The following options are currently supported for items: -background color Color specifies the background color to use when displaying the item. It may have any of the forms accepted by Tk_GetColor. -foreground color Color specifies the foreground color to use when displaying the item. It may have any of the forms accepted by Tk_GetColor. -selectbackground color color specifies the background color to use when displaying the item while it is selected. It may have any of the forms accepted by Tk_GetColor. -selectforeground color color specifies the foreground color to use when displaying the item while it is selected. It may have any of the forms accepted by Tk_GetColor.



122
123
124
# File 'lib/ffi-tk/widget/listbox.rb', line 122

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

#nearest(y) ⇒ Object

Given a y-coordinate within the listbox window, this command returns the index of the (visible) listbox element nearest to that y-coordinate.



128
129
130
# File 'lib/ffi-tk/widget/listbox.rb', line 128

def nearest(y)
  execute(:nearest, y)
end

#scan_dragto(x, y) ⇒ Object

This command computes the difference between its x and y arguments and the x and y arguments to the last scan mark command for the widget. It then adjusts the view by 10 times the difference in coordinates. This command is typically associated with mouse motion events in the widget, to produce the effect of dragging the list at high speed through the window. The return value is an empty string.



147
148
149
# File 'lib/ffi-tk/widget/listbox.rb', line 147

def scan_dragto(x, y)
  execute_only(:scan, :dragto, x, y)
end

#scan_mark(x, y) ⇒ Object

Records x and y and the current view in the listbox window; used in conjunction with later scan dragto commands. Typically this command is associated with a mouse button press in the widget. It returns an empty string.



136
137
138
# File 'lib/ffi-tk/widget/listbox.rb', line 136

def scan_mark(x, y)
  execute_only(:scan, :mark, x, y)
end

#see(index) ⇒ Object

Adjust the view in the listbox so that the element given by index is visible. If the element is already visible then the command has no effect; if the element is near one edge of the window then the listbox scrolls to bring the element into view at the edge; otherwise the listbox scrolls to center the element.



156
157
158
# File 'lib/ffi-tk/widget/listbox.rb', line 156

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

#selection_anchor(index) ⇒ Object

Sets the selection anchor to the element given by index. If index refers to a non-existent element, then the closest element is used. The selection anchor is the end of the selection that is fixed while dragging out a selection with the mouse. The index anchor may be used to refer to the anchor element.



165
166
167
# File 'lib/ffi-tk/widget/listbox.rb', line 165

def selection_anchor(index)
  execute(:selection, :anchor, index)
end

#selection_clear(first, last = None) ⇒ Object

If any of the elements between first and last (inclusive) are selected, they are deselected. The selection state is not changed for elements outside this range.



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

def selection_clear(first, last = None)
  execute(:selection, :clear, first, last)
end

#selection_includes(index) ⇒ Object

Returns 1 if the element indicated by index is currently selected, 0 if it is not.



178
179
180
# File 'lib/ffi-tk/widget/listbox.rb', line 178

def selection_includes(index)
  execute(:selection, :includes, index)
end

#selection_set(first, last = None) ⇒ Object

Selects all of the elements in the range between first and last, inclusive, without affecting the selection state of elements outside that range.



185
186
187
# File 'lib/ffi-tk/widget/listbox.rb', line 185

def selection_set(first, last = None)
  execute(:selection, :set, first, last)
end

#sizeObject

Returns a decimal string indicating the total number of elements in the listbox.



191
192
193
# File 'lib/ffi-tk/widget/listbox.rb', line 191

def size
  execute(:size)
end

#valueObject



14
15
16
# File 'lib/ffi-tk/widget/listbox.rb', line 14

def value
  get(0, size)
end

#value=(enumerable) ⇒ Object



18
19
20
21
# File 'lib/ffi-tk/widget/listbox.rb', line 18

def value=(enumerable)
  clear
  enumerable.each { |element| insert(:end, element) }
end