Class: Tk::Listbox
- Includes:
- Cget, Configure, Scrollable
- Defined in:
- lib/ffi-tk/widget/listbox.rb
Constant Summary
Constants included from Cget
Constants included from WM
Instance Attribute Summary
Attributes inherited from Widget
Class Method Summary collapse
Instance Method Summary collapse
-
#activate(index) ⇒ Object
Sets the active element to the one indicated by index.
-
#bbox(index) ⇒ Object
Returns a list of four numbers describing the bounding box of the text in the element given by index.
- #clear ⇒ Object
-
#curselection ⇒ Object
Returns a list containing the numerical indices of all of the elements in the listbox that are currently selected.
-
#delete(first, last = None) ⇒ Object
Deletes one or more elements of the listbox.
-
#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.
-
#index(index) ⇒ Object
Returns the integer index value that corresponds to index.
-
#insert(index, *elements) ⇒ Object
Inserts zero or more new elements in the list just before the element given by index.
-
#itemcget(index, option) ⇒ Object
Returns the current value of the item configuration option given by option.
-
#itemconfigure(index, options = None) ⇒ Object
Query or modify the configuration options of an item in the listbox.
-
#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.
-
#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.
-
#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.
-
#see(index) ⇒ Object
Adjust the view in the listbox so that the element given by index is visible.
-
#selection_anchor(index) ⇒ Object
Sets the selection anchor to the element given by index.
-
#selection_clear(first, last = None) ⇒ Object
If any of the elements between first and last (inclusive) are selected, they are deselected.
-
#selection_includes(index) ⇒ Object
Returns 1 if the element indicated by index is currently selected, 0 if it is not.
-
#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.
-
#size ⇒ Object
Returns a decimal string indicating the total number of elements in the listbox.
- #value ⇒ Object
- #value=(enumerable) ⇒ Object
Methods included from Cget
#cget, option_hash_to_tcl, option_to_ruby, type_to_ruby
Methods included from 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
Methods included from Bind
Methods included from 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_command ⇒ Object
5 |
# File 'lib/ffi-tk/widget/listbox.rb', line 5 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.
26 27 28 |
# File 'lib/ffi-tk/widget/listbox.rb', line 26 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.
40 41 42 |
# File 'lib/ffi-tk/widget/listbox.rb', line 40 def bbox(index) execute(:bbox, index).to_a(&:to_i) end |
#clear ⇒ Object
7 8 9 |
# File 'lib/ffi-tk/widget/listbox.rb', line 7 def clear delete 0, :end end |
#curselection ⇒ Object
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.
48 49 50 |
# File 'lib/ffi-tk/widget/listbox.rb', line 48 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.
57 58 59 |
# File 'lib/ffi-tk/widget/listbox.rb', line 57 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.
66 67 68 69 70 71 72 |
# File 'lib/ffi-tk/widget/listbox.rb', line 66 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).
77 78 79 |
# File 'lib/ffi-tk/widget/listbox.rb', line 77 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.
86 87 88 |
# File 'lib/ffi-tk/widget/listbox.rb', line 86 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.
93 94 95 |
# File 'lib/ffi-tk/widget/listbox.rb', line 93 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.
119 120 121 |
# File 'lib/ffi-tk/widget/listbox.rb', line 119 def itemconfigure(index, = None) common_configure([:itemconfigure, index], ) 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.
125 126 127 |
# File 'lib/ffi-tk/widget/listbox.rb', line 125 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.
144 145 146 |
# File 'lib/ffi-tk/widget/listbox.rb', line 144 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.
133 134 135 |
# File 'lib/ffi-tk/widget/listbox.rb', line 133 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.
153 154 155 |
# File 'lib/ffi-tk/widget/listbox.rb', line 153 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.
162 163 164 |
# File 'lib/ffi-tk/widget/listbox.rb', line 162 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.
169 170 171 |
# File 'lib/ffi-tk/widget/listbox.rb', line 169 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.
175 176 177 |
# File 'lib/ffi-tk/widget/listbox.rb', line 175 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.
182 183 184 |
# File 'lib/ffi-tk/widget/listbox.rb', line 182 def selection_set(first, last = None) execute(:selection, :set, first, last) end |
#size ⇒ Object
Returns a decimal string indicating the total number of elements in the listbox.
188 189 190 |
# File 'lib/ffi-tk/widget/listbox.rb', line 188 def size execute(:size) end |
#value ⇒ Object
11 12 13 |
# File 'lib/ffi-tk/widget/listbox.rb', line 11 def value get(0, size) end |
#value=(enumerable) ⇒ Object
15 16 17 18 |
# File 'lib/ffi-tk/widget/listbox.rb', line 15 def value=(enumerable) clear enumerable.each{|element| insert(:end, element) } end |