ffi-tk 2009.11.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. data/CHANGELOG +748 -0
  2. data/MANIFEST +188 -0
  3. data/README.md +85 -0
  4. data/Rakefile +47 -0
  5. data/TODO.md +62 -0
  6. data/bin/rwish +33 -0
  7. data/doc/MIT_LICENSE +18 -0
  8. data/doc/TCL_LICENSE +39 -0
  9. data/example/choose_color.rb +22 -0
  10. data/example/choose_directory.rb +22 -0
  11. data/example/dialog.rb +37 -0
  12. data/example/hello.rb +11 -0
  13. data/example/message_box.rb +26 -0
  14. data/example/option_menu.rb +17 -0
  15. data/example/popup.rb +24 -0
  16. data/example/set_palette.rb +32 -0
  17. data/example/text.rb +47 -0
  18. data/example/tile/kroc_demo_small.rb +123 -0
  19. data/example/tile/kroc_rb_demo.rb +135 -0
  20. data/example/tile/notebook.rb +48 -0
  21. data/example/tile/theme_hello.rb +38 -0
  22. data/example/tile/treeview.rb +71 -0
  23. data/example/various.rb +25 -0
  24. data/example/wait.rb +16 -0
  25. data/ffi-tk.gemspec +33 -0
  26. data/lib/ffi-tk.rb +76 -0
  27. data/lib/ffi-tk/command.rb +39 -0
  28. data/lib/ffi-tk/command/after.rb +36 -0
  29. data/lib/ffi-tk/command/bell.rb +34 -0
  30. data/lib/ffi-tk/command/bind.rb +11 -0
  31. data/lib/ffi-tk/command/bindtags.rb +69 -0
  32. data/lib/ffi-tk/command/cget.rb +92 -0
  33. data/lib/ffi-tk/command/choose_color.rb +29 -0
  34. data/lib/ffi-tk/command/choose_directory.rb +45 -0
  35. data/lib/ffi-tk/command/clipboard.rb +102 -0
  36. data/lib/ffi-tk/command/configure.rb +88 -0
  37. data/lib/ffi-tk/command/destroy.rb +12 -0
  38. data/lib/ffi-tk/command/dialog.rb +54 -0
  39. data/lib/ffi-tk/command/event.rb +79 -0
  40. data/lib/ffi-tk/command/focus.rb +70 -0
  41. data/lib/ffi-tk/command/font.rb +124 -0
  42. data/lib/ffi-tk/command/get_open_file.rb +85 -0
  43. data/lib/ffi-tk/command/get_save_file.rb +83 -0
  44. data/lib/ffi-tk/command/grab.rb +141 -0
  45. data/lib/ffi-tk/command/grid.rb +246 -0
  46. data/lib/ffi-tk/command/image.rb +79 -0
  47. data/lib/ffi-tk/command/lower.rb +23 -0
  48. data/lib/ffi-tk/command/message_box.rb +65 -0
  49. data/lib/ffi-tk/command/option_menu.rb +8 -0
  50. data/lib/ffi-tk/command/pack.rb +99 -0
  51. data/lib/ffi-tk/command/place.rb +91 -0
  52. data/lib/ffi-tk/command/popup.rb +14 -0
  53. data/lib/ffi-tk/command/raise.rb +25 -0
  54. data/lib/ffi-tk/command/scrollable.rb +151 -0
  55. data/lib/ffi-tk/command/selection.rb +132 -0
  56. data/lib/ffi-tk/command/set_palette.rb +9 -0
  57. data/lib/ffi-tk/command/tk_cmd.rb +155 -0
  58. data/lib/ffi-tk/command/vars.rb +82 -0
  59. data/lib/ffi-tk/command/wait.rb +39 -0
  60. data/lib/ffi-tk/command/winfo.rb +668 -0
  61. data/lib/ffi-tk/command/wm.rb +1025 -0
  62. data/lib/ffi-tk/core_extensions.rb +154 -0
  63. data/lib/ffi-tk/event/data.rb +60 -0
  64. data/lib/ffi-tk/event/handler.rb +44 -0
  65. data/lib/ffi-tk/ffi/tcl.rb +92 -0
  66. data/lib/ffi-tk/ffi/tcl/cmd_proc.rb +10 -0
  67. data/lib/ffi-tk/ffi/tcl/eval_result.rb +148 -0
  68. data/lib/ffi-tk/ffi/tcl/interp.rb +95 -0
  69. data/lib/ffi-tk/ffi/tcl/obj.rb +89 -0
  70. data/lib/ffi-tk/ffi/tcl/time.rb +36 -0
  71. data/lib/ffi-tk/ffi/tk.rb +35 -0
  72. data/lib/ffi-tk/geometry.rb +32 -0
  73. data/lib/ffi-tk/thread_sender.rb +26 -0
  74. data/lib/ffi-tk/tk.rb +222 -0
  75. data/lib/ffi-tk/variable.rb +46 -0
  76. data/lib/ffi-tk/widget.rb +68 -0
  77. data/lib/ffi-tk/widget/button.rb +41 -0
  78. data/lib/ffi-tk/widget/canvas.rb +806 -0
  79. data/lib/ffi-tk/widget/canvas/arc.rb +18 -0
  80. data/lib/ffi-tk/widget/canvas/bitmap.rb +13 -0
  81. data/lib/ffi-tk/widget/canvas/image.rb +10 -0
  82. data/lib/ffi-tk/widget/canvas/item.rb +170 -0
  83. data/lib/ffi-tk/widget/canvas/line.rb +16 -0
  84. data/lib/ffi-tk/widget/canvas/oval.rb +15 -0
  85. data/lib/ffi-tk/widget/canvas/polygon.rb +16 -0
  86. data/lib/ffi-tk/widget/canvas/rectangle.rb +15 -0
  87. data/lib/ffi-tk/widget/canvas/text.rb +15 -0
  88. data/lib/ffi-tk/widget/canvas/window.rb +11 -0
  89. data/lib/ffi-tk/widget/checkbutton.rb +63 -0
  90. data/lib/ffi-tk/widget/entry.rb +208 -0
  91. data/lib/ffi-tk/widget/frame.rb +12 -0
  92. data/lib/ffi-tk/widget/label.rb +26 -0
  93. data/lib/ffi-tk/widget/labelframe.rb +7 -0
  94. data/lib/ffi-tk/widget/listbox.rb +192 -0
  95. data/lib/ffi-tk/widget/menu.rb +318 -0
  96. data/lib/ffi-tk/widget/menubutton.rb +7 -0
  97. data/lib/ffi-tk/widget/message.rb +36 -0
  98. data/lib/ffi-tk/widget/panedwindow.rb +164 -0
  99. data/lib/ffi-tk/widget/radiobutton.rb +43 -0
  100. data/lib/ffi-tk/widget/root.rb +8 -0
  101. data/lib/ffi-tk/widget/scale.rb +44 -0
  102. data/lib/ffi-tk/widget/scrollbar.rb +114 -0
  103. data/lib/ffi-tk/widget/spinbox.rb +198 -0
  104. data/lib/ffi-tk/widget/text.rb +893 -0
  105. data/lib/ffi-tk/widget/text/peer.rb +10 -0
  106. data/lib/ffi-tk/widget/tile.rb +70 -0
  107. data/lib/ffi-tk/widget/tile/button.rb +8 -0
  108. data/lib/ffi-tk/widget/tile/checkbutton.rb +8 -0
  109. data/lib/ffi-tk/widget/tile/combobox.rb +43 -0
  110. data/lib/ffi-tk/widget/tile/entry.rb +8 -0
  111. data/lib/ffi-tk/widget/tile/frame.rb +13 -0
  112. data/lib/ffi-tk/widget/tile/label.rb +9 -0
  113. data/lib/ffi-tk/widget/tile/labelframe.rb +8 -0
  114. data/lib/ffi-tk/widget/tile/menubutton.rb +8 -0
  115. data/lib/ffi-tk/widget/tile/notebook.rb +93 -0
  116. data/lib/ffi-tk/widget/tile/panedwindow.rb +9 -0
  117. data/lib/ffi-tk/widget/tile/progressbar.rb +59 -0
  118. data/lib/ffi-tk/widget/tile/radiobutton.rb +8 -0
  119. data/lib/ffi-tk/widget/tile/scale.rb +8 -0
  120. data/lib/ffi-tk/widget/tile/scrollbar.rb +41 -0
  121. data/lib/ffi-tk/widget/tile/separator.rb +23 -0
  122. data/lib/ffi-tk/widget/tile/sizegrip.rb +24 -0
  123. data/lib/ffi-tk/widget/tile/style.rb +114 -0
  124. data/lib/ffi-tk/widget/tile/treeview.rb +414 -0
  125. data/lib/ffi-tk/widget/toplevel.rb +14 -0
  126. data/spec/ffi-tk/command/bindtags.rb +18 -0
  127. data/spec/ffi-tk/command/clipboard.rb +18 -0
  128. data/spec/ffi-tk/command/font.rb +67 -0
  129. data/spec/ffi-tk/command/grid.rb +6 -0
  130. data/spec/ffi-tk/command/image.rb +26 -0
  131. data/spec/ffi-tk/command/pack.rb +20 -0
  132. data/spec/ffi-tk/command/place.rb +20 -0
  133. data/spec/ffi-tk/command/selection.rb +13 -0
  134. data/spec/ffi-tk/command/vars.rb +32 -0
  135. data/spec/ffi-tk/command/winfo.rb +233 -0
  136. data/spec/ffi-tk/command/wm.rb +185 -0
  137. data/spec/ffi-tk/event.rb +95 -0
  138. data/spec/ffi-tk/tile/button.rb +51 -0
  139. data/spec/ffi-tk/tile/checkbutton.rb +13 -0
  140. data/spec/ffi-tk/tile/combobox.rb +65 -0
  141. data/spec/ffi-tk/tile/entry.rb +61 -0
  142. data/spec/ffi-tk/tile/frame.rb +65 -0
  143. data/spec/ffi-tk/tile/label.rb +17 -0
  144. data/spec/ffi-tk/tile/labelframe.rb +13 -0
  145. data/spec/ffi-tk/tile/menubutton.rb +13 -0
  146. data/spec/ffi-tk/tile/notebook.rb +103 -0
  147. data/spec/ffi-tk/tile/panedwindow.rb +13 -0
  148. data/spec/ffi-tk/tile/progressbar.rb +78 -0
  149. data/spec/ffi-tk/tile/radiobutton.rb +13 -0
  150. data/spec/ffi-tk/tile/scale.rb +13 -0
  151. data/spec/ffi-tk/tile/scrollbar.rb +43 -0
  152. data/spec/ffi-tk/tile/separator.rb +22 -0
  153. data/spec/ffi-tk/tile/sizegrip.rb +13 -0
  154. data/spec/ffi-tk/tile/style.rb +161 -0
  155. data/spec/ffi-tk/tile/treeview.rb +101 -0
  156. data/spec/ffi-tk/variable.rb +24 -0
  157. data/spec/ffi-tk/widget/button.rb +22 -0
  158. data/spec/ffi-tk/widget/canvas.rb +169 -0
  159. data/spec/ffi-tk/widget/checkbutton.rb +44 -0
  160. data/spec/ffi-tk/widget/entry.rb +155 -0
  161. data/spec/ffi-tk/widget/frame.rb +8 -0
  162. data/spec/ffi-tk/widget/label.rb +16 -0
  163. data/spec/ffi-tk/widget/labelframe.rb +12 -0
  164. data/spec/ffi-tk/widget/listbox.rb +19 -0
  165. data/spec/ffi-tk/widget/menu.rb +12 -0
  166. data/spec/ffi-tk/widget/menubutton.rb +12 -0
  167. data/spec/ffi-tk/widget/message.rb +12 -0
  168. data/spec/ffi-tk/widget/panedwindow.rb +12 -0
  169. data/spec/ffi-tk/widget/radiobutton.rb +12 -0
  170. data/spec/ffi-tk/widget/root.rb +9 -0
  171. data/spec/ffi-tk/widget/scale.rb +12 -0
  172. data/spec/ffi-tk/widget/scrollbar.rb +12 -0
  173. data/spec/ffi-tk/widget/spinbox.rb +12 -0
  174. data/spec/ffi-tk/widget/text.rb +246 -0
  175. data/spec/ffi-tk/widget/toplevel.rb +12 -0
  176. data/spec/helper.rb +3 -0
  177. data/tasks/authors.rake +21 -0
  178. data/tasks/bacon.rake +66 -0
  179. data/tasks/changelog.rake +18 -0
  180. data/tasks/gem.rake +22 -0
  181. data/tasks/gem_setup.rake +113 -0
  182. data/tasks/grancher.rake +12 -0
  183. data/tasks/manifest.rake +4 -0
  184. data/tasks/rcov.rake +17 -0
  185. data/tasks/release.rake +65 -0
  186. data/tasks/reversion.rake +8 -0
  187. data/tasks/setup.rake +12 -0
  188. data/tasks/ycov.rake +84 -0
  189. metadata +261 -0
@@ -0,0 +1,24 @@
1
+ module Tk
2
+ module Tile
3
+ class Sizegrip < Tk::Widget
4
+ def self.tk_command; 'ttk::sizegrip'; end
5
+ include TileWidget, Cget, Configure
6
+
7
+ # # USAGE
8
+ # Using pack:
9
+ # pack [ttk::frame $top.statusbar] -side bottom -fill x
10
+ # pack [ttk::sizegrip $top.statusbar.grip] -side right -anchor se
11
+ # Using grid:
12
+ # grid [ttk::sizegrip $top.statusbar.grip] \
13
+ # -row $lastRow -column $lastColumn -sticky se
14
+ # # ... optional: add vertical scrollbar in $lastColumn,
15
+ # # ... optional: add horizontal scrollbar in $lastRow
16
+
17
+ # BUG: http://tcl.activestate.com/man/tcl8.5/TkCmd/ttk_sizegrip.htm
18
+ # If the containing toplevel's position was specified relative to the
19
+ # right or bottom of the screen (e.g., 'wm geometry ... wxh-x-y' instead
20
+ # of “wm geometry ... wxh+x+y”), the sizegrip widget will not resize the
21
+ # window. ttk::sizegrip widgets only support “southeast” resizing.
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,114 @@
1
+ module Tk
2
+ module Tile
3
+ def self.style(style, parent_name)
4
+ [style, parent_name.to_s.split('::').last].join('.')
5
+ end
6
+
7
+ module Style
8
+ extend Tk::Cget, Tk::Configure
9
+ TkkStyleCmd = 'ttk::style'.freeze
10
+
11
+ # Returns a list of all known themes.
12
+ def self.theme_names
13
+ Tk.execute('ttk::style', 'theme', 'names')
14
+ end
15
+
16
+ # Sets the current theme to themeName, and refreshes all widgets.
17
+ def self.theme_use(name)
18
+ return unless theme_names.include? name
19
+ Tk.execute_only('ttk::style', 'theme', 'use', name) && name
20
+ end
21
+
22
+ # Temporarily sets the current theme to themeName, evaluate script,
23
+ # then restore the previous theme. Typically script simply defines
24
+ # styles and elements, though arbitrary Tcl code may appear.
25
+ def self.theme_settings(name, &block)
26
+ return unless block
27
+ raise ArgumentError unless theme_names.include? name
28
+
29
+ id = Tk.uuid(:proc){|uuid| Tk.callbacks[uuid] = block }
30
+ cmd = "{ RubyFFI::callback #{id} }"
31
+ Tk.eval "ttk::style theme settings #{name} #{cmd}"
32
+ #Tk.execute_only('ttk::style', 'theme', 'settings', name, cmd)
33
+ Tk.callbacks.delete(id) if id
34
+ name
35
+ end
36
+
37
+ # Creates a new theme. It is an error if themeName already exists.
38
+ # If -parent is specified, the new theme will inherit styles, elements, and
39
+ # layouts from the parent theme basedon. If -settings is present, script is
40
+ # evaluated in the context of the new theme as per ttk::style theme settings.
41
+ def self.theme_create(name, options={}, &block)
42
+ raise ArgumentError if theme_names.include? name
43
+ options = options.to_tcl_options
44
+
45
+ if block
46
+ id = Tk.uuid(:proc){|uuid| Tk.callbacks[uuid] = block }
47
+ options << " -settings { RubyFFI::callback #{id} }"
48
+ end
49
+ res = Tk.execute_only('ttk::style', 'theme', 'create', name, options)
50
+ Tk.callbacks.delete(id) if id
51
+ res
52
+ end
53
+
54
+
55
+ # Returns the list of elements defined in the current theme.
56
+ def self.element_names
57
+ Tk.execute('ttk::style', 'element', 'names')
58
+ end
59
+
60
+ # Returns the list of element's options.
61
+ def self.element_options(name)
62
+ return unless element_names.include? name
63
+ Tk.execute('ttk::style', 'element', 'options', name).to_a
64
+ end
65
+
66
+ # Creates a new element in the current theme of type type. The only
67
+ # built-in element type is image (see ttk_image(n)), although themes
68
+ # may define other element types (see Ttk_RegisterElementFactory).
69
+ def self.element_create(name, type, args=nil, options={})
70
+ if type == 'image' || type == :image
71
+ Tk.execute_only('ttk::style', 'element', 'create', name, 'image', args, options.to_tcl_options)
72
+ else
73
+ #Tk.execute_only('ttk::style', 'element', 'create', name, type)
74
+ end
75
+ end
76
+
77
+
78
+ # Define the widget layout for style style. See LAYOUTS below for the format
79
+ # of layoutSpec. If layoutSpec is omitted, return the layout specification
80
+ # for style style.
81
+ def self.layout(name, layout_spec)
82
+ Tk.execute_only('ttk::style', 'layout', name, layout_spec)
83
+ end
84
+
85
+ # Sets dynamic values of the specified option(s) in style.
86
+ # Each statespec / value pair is examined in order; the value
87
+ # corresponding to the first matching statespec is used.
88
+ def self.map(style, options={})
89
+ style.kind_of?(Hash) && (options, style = style, nil)
90
+ style = '.' unless style
91
+
92
+ Tk.execute_only('ttk::style', 'map', style, options.to_tcl_options )
93
+ end
94
+
95
+ # Sets the default value of the specified option(s) in style.
96
+ def self.configure(style=nil, options={})
97
+ style.kind_of?(Hash) && (keys, style = style, nil)
98
+ style = '.' unless style
99
+
100
+ Tk.execute_only('ttk::style','configure', style, options.to_tcl_options)
101
+ end
102
+
103
+ # Returns the value specified for -option in style style in state
104
+ # state, using the standard lookup rules for element options.
105
+ # state is a list of state names; if omitted, it defaults to all
106
+ # bits off (the “normal” state). If the default argument is present,
107
+ # it is used as a fallback value in case no specification
108
+ # for -option is found.
109
+ def self.lookup(style, option, state=Tk::None, default=Tk::None)
110
+ Tk.execute('ttk::style', 'lookup', style, option.to_tcl_option, state, default).to_s
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,414 @@
1
+ module Tk
2
+ module Tile
3
+ # The ttk::treeview widget displays a hierarchical collection of items.
4
+ # Each item has a textual label, an optional image, and an optional list of
5
+ # data values.
6
+ # The data values are displayed in successive columns after the tree label.
7
+ # The order in which data values are displayed may be controlled by setting
8
+ # the -displaycolumns widget option.
9
+ # The tree widget can also display column headings.
10
+ # Columns may be accessed by number or by symbolic names listed in the
11
+ # -columns widget option; see COLUMN IDENTIFIERS.
12
+ # Each item is identified by a unique name.
13
+ # The widget will generate item IDs if they are not supplied by the caller.
14
+ # There is a distinguished root item, named {}.
15
+ # The root item itself is not displayed; its children appear at the top
16
+ # level of the hierarchy.
17
+ # Each item also has a list of tags, which can be used to associate event
18
+ # bindings with individual items and control the appearance of the item.
19
+ # Treeview widgets support horizontal and vertical scrolling with the
20
+ # standard -[xy]scrollcommand options and [xy]view widget commands.
21
+ class Treeview < Tk::Widget
22
+ include Tk::Tile::TileWidget, Cget, Configure
23
+
24
+ def self.tk_command; 'ttk::treeview'; end
25
+
26
+ # Delete all items
27
+ def clear
28
+ delete(*children(nil))
29
+ end
30
+
31
+ # Returns the bounding box (relative to the treeview widget's window) of
32
+ # the specified item in the form x y width height.
33
+ # If column is specified, returns the bounding box of that cell.
34
+ # If the item is not visible (i.e., if it is a descendant of a closed item
35
+ # or is scrolled offscreen), returns the empty list.
36
+ def bbox(item, column = None)
37
+ execute(:bbox, item, column)
38
+ end
39
+
40
+ # If newchildren is not specified, returns the list of children belonging
41
+ # to item.
42
+ # If newchildren is specified, replaces item's child list with newchildren.
43
+ # Items in the old child list not present in the new child list are
44
+ # detached from the tree.
45
+ # None of the items in newchildren may be an ancestor of item.
46
+ def children(item, *new_children)
47
+ if new_children.empty?
48
+ execute(:children, item).to_a.map{|child| Item.new(self, child) }
49
+ else
50
+ execute(:children, item, *new_children.flatten)
51
+ end
52
+ end
53
+
54
+ # Query or modify the options for the specified column.
55
+ #
56
+ # If no +options+ is specified, returns an Hash of option/value pairs.
57
+ #
58
+ # If +options+ is a Symbol/String, returns the value of that option.
59
+ #
60
+ # Otherwise, the options are updated with the specified values.
61
+ #
62
+ # The following options may be set on each column:
63
+ # id: name
64
+ # The column name. This is a read-only option. For example
65
+ # `list.column('#n')` returns the data column associated with display
66
+ # column `#n`.
67
+ #
68
+ # anchor: name
69
+ # Specifies how the text in this column should be aligned with respect
70
+ # to the cell.
71
+ # One of n, ne, e, se, s, sw, w, nw, or center.
72
+ #
73
+ # minwidth: width
74
+ # The minimum width of the column in pixels.
75
+ # The treeview widget will not make the column any smaller than
76
+ # minwidth when the widget is resized or the user drags a column
77
+ # separator.
78
+ #
79
+ # stretch: boolean
80
+ # Specifies whether or not the column's width should be adjusted when
81
+ # the widget is resized.
82
+ #
83
+ # width: w
84
+ # The width of the column in pixels.
85
+ # Default is something reasonable, probably 200 or so.
86
+ #
87
+ # Use +column+ '#0' to configure the tree column.
88
+ def column(column, options = None)
89
+ common_configure([:column, column], options, stretch: :boolean)
90
+ end
91
+
92
+ # Deletes each of the items in +items+ and all of their descendants.
93
+ # The root item may not be deleted.
94
+ #
95
+ # @see detach
96
+ def delete(*items)
97
+ items = items.flatten
98
+ execute_only(:delete, items) if items.any?
99
+ end
100
+
101
+ # Unlinks all of the specified items in +items+ from the tree.
102
+ # The items and all of their descendants are still present and may be
103
+ # reinserted at another point in the tree but will not be displayed.
104
+ # The root item may not be detached.
105
+ #
106
+ # @see delete
107
+ def detach(*items)
108
+ execute(:detach, *items.flatten)
109
+ end
110
+
111
+ # Returns true if the specified item is present in the tree, false
112
+ # otherwise.
113
+ def exists(item)
114
+ execute(:exists, item).to_boolean
115
+ end
116
+ alias exist? exists
117
+
118
+ # If item is specified, sets the focus item to item.
119
+ # Otherwise, returns the current focus item, or {} if there is none.
120
+ def focus_item(item = None)
121
+ result = execute(:focus, item)
122
+ Item.new(self, result) if result
123
+ end
124
+
125
+ # Query or modify the heading options for the specified column.
126
+ # Valid options are: -text text The text to display in the column heading.
127
+ # -image imageName Specifies an image to display to the right of the column
128
+ # heading. -anchor anchor Specifies how the heading text should be aligned.
129
+ # One of the standard Tk anchor values.
130
+ # -command script A script to evaluate when the heading label is pressed.
131
+ # Use pathname heading #0 to configure the tree column heading.
132
+ def heading(column, options = None)
133
+ common_configure([:heading, column], options)
134
+ end
135
+
136
+ # Returns a description of the specified component under the point given by
137
+ # x and y, or the empty string if no such component is present at that
138
+ # position. The following subcommands are supported:
139
+ def identify_component(x, y)
140
+ execute(:identify, component, x, y)
141
+ end
142
+
143
+ # Returns the item ID of the item at position y.
144
+ def identify_row(x, y)
145
+ execute(:identify, row, x, y)
146
+ end
147
+
148
+ # Returns the data column identifier of the cell at position x.
149
+ # The tree column has ID #0.
150
+ def identify_column(x, y)
151
+ execute(:identify, column, x, y)
152
+ end
153
+
154
+ # Returns the integer index of item within its parent's list of children.
155
+ def index(item)
156
+ execute(:index, item)
157
+ end
158
+
159
+ # Creates a new item.
160
+ # parent is the item ID of the parent item, or the empty string {} to
161
+ # create a new top-level item.
162
+ # index is an integer, or the value end, specifying where in the list of
163
+ # parent's children to insert the new item.
164
+ # If index is less than or equal to zero, the new node is inserted at the
165
+ # beginning; if index is greater than or equal to the current number of
166
+ # children, it is inserted at the end.
167
+ # If -id is specified, it is used as the item identifier; id must not
168
+ # already exist in the tree.
169
+ # Otherwise, a new unique identifier is generated.
170
+ #
171
+ # Returns the item identifier of the newly created item.
172
+ def insert(parent, index, options = {})
173
+ id = execute(:insert, parent, index, options.to_tcl_options)
174
+ Item.new(self, id)
175
+ end
176
+
177
+ Item = Struct.new(:tk_parent, :id)
178
+ class Item
179
+ def initialize(tk_parent, id)
180
+ self.tk_parent, self.id = tk_parent, id.to_s
181
+ end
182
+
183
+ def insert(index, options = {})
184
+ tk_parent.insert(id, index, options)
185
+ end
186
+
187
+ def index
188
+ tk_parent.index(id)
189
+ end
190
+
191
+ def options(options = None)
192
+ tk_parent.item(id, options)
193
+ end
194
+
195
+ def bbox(column = None)
196
+ tk_parent.bbox(id, column).to_a
197
+ end
198
+
199
+ def move(parent, index)
200
+ tk_parent.move_item(id, parent, index)
201
+ end
202
+
203
+ def delete
204
+ tk_parent.delete(id)
205
+ end
206
+
207
+ def detach
208
+ tk_parent.detach(id)
209
+ end
210
+
211
+ def exists
212
+ tk_parent.exists(id)
213
+ end
214
+ alias exist? exists
215
+
216
+ def children(*new_children)
217
+ tk_parent.children(id, *new_children)
218
+ end
219
+
220
+ def selection_add
221
+ tk_parent.selection_add(id)
222
+ end
223
+ alias select selection_add
224
+
225
+ def selection_remove
226
+ tk_parent.selection_remove(id)
227
+ end
228
+ alias deselect selection_remove
229
+
230
+ def selection_toggle
231
+ tk_parent.selection_toggle(id)
232
+ end
233
+ alias toggle selection_toggle
234
+
235
+ def set(column = None, value = None)
236
+ tk_parent.set(id, column, value)
237
+ end
238
+
239
+ def prev
240
+ tk_parent.prev(id)
241
+ end
242
+
243
+ def next
244
+ tk_parent.next(id)
245
+ end
246
+
247
+ def parent
248
+ tk_parent.parent(id)
249
+ end
250
+
251
+ def focus
252
+ tk_parent.focus_item(id)
253
+ end
254
+
255
+ def see
256
+ tk_parent.see(id)
257
+ end
258
+
259
+ def to_tcl
260
+ id
261
+ end
262
+
263
+ def inspect
264
+ "#<Treeview::Item @tk_parent=%p @id=%p>" % [tk_parent.tk_pathname, id]
265
+ end
266
+
267
+ private :id=
268
+ end
269
+
270
+ # Test the widget state, execute passed block if state matches statespec.
271
+ def instate(statespec)
272
+ result = execute(:instate, statespec).to_boolean
273
+ yield if result && block_given?
274
+ result
275
+ end
276
+
277
+ # Query or modify the options for the specified item.
278
+ # If no -option is specified, returns a dictionary of option/value pairs.
279
+ # If a single -option is specified, returns the value of that option.
280
+ # Otherwise, the item's options are updated with the specified values.
281
+ # See ITEM OPTIONS for the list of available options.
282
+ def item(item, options = None)
283
+ common_configure([:item, item], options)
284
+ end
285
+
286
+ # Moves item to position index in parent's list of children.
287
+ # It is illegal to move an item under one of its descendants.
288
+ # If index is less than or equal to zero, item is moved to the beginning;
289
+ # if greater than or equal to the number of children, it is moved to the
290
+ # end.
291
+ def move(item, parent, index)
292
+ execute(:move, item, parent, index)
293
+ end
294
+
295
+ # Returns the item's next sibling, or nil if item is the last child of its
296
+ # parent.
297
+ def next(item)
298
+ id = execute(:next, item)
299
+ Item.new(self, id) if id
300
+ end
301
+
302
+ # Returns the parent of item, or nil if item is at the top level of the
303
+ # hierarchy.
304
+ def parent(item)
305
+ id = execute(:parent, item)
306
+ Item.new(self, id) if id
307
+ end
308
+
309
+ # Returns the item's previous sibling, or nil if item is the first child
310
+ # of its parent.
311
+ def prev(item)
312
+ id = execute(:prev, item)
313
+ Item.new(self, id) if id
314
+ end
315
+
316
+ # Ensure that item is visible: sets all of item's ancestors to -open true,
317
+ # and scrolls the widget if necessary so that item is within the visible
318
+ # portion of the tree.
319
+ def see(item)
320
+ execute(:see, item)
321
+ end
322
+
323
+ # Returns the list of selected items.
324
+ def selection
325
+ execute(:selection).to_a
326
+ end
327
+
328
+ # +items+ becomes the new selection.
329
+ def selection_set(*items)
330
+ execute(:selection, set, *items.flatten)
331
+ end
332
+
333
+ # Add +items+ to the selection
334
+ def selection_add(*items)
335
+ execute(:selection, :add, *items.flatten)
336
+ end
337
+
338
+ # Remove +items+ from the selection
339
+ def selection_remove(*items)
340
+ execute(:selection, :remove, *items.flatten)
341
+ end
342
+
343
+ # Toggle the selection state of each item in +items+.
344
+ def selection_toggle(*items)
345
+ execute(:selection, :toggle, *items.flatten)
346
+ end
347
+
348
+ # With one argument, returns a dictionary of column/value pairs for the
349
+ # specified item.
350
+ # With two arguments, returns the current value of the specified column.
351
+ # With three arguments, sets the value of column column in item item to
352
+ # the specified value.
353
+ # See also COLUMN IDENTIFIERS.
354
+ def set(item, column = None, value = None)
355
+ if None == column
356
+ execute(:set, item)
357
+ elsif None == value
358
+ execute(:set, item, column).to_s
359
+ else
360
+ execute_only(:set, item, column, value)
361
+ end
362
+ end
363
+
364
+ # Modify or query the widget state; see ttk::widget(n).
365
+ def state(state_spec = None)
366
+ execute(:state, state_spec)
367
+ end
368
+
369
+ # Add a Tk binding script for the event sequence sequence to the tag
370
+ # tagName. When an X event is delivered to an item, binding scripts for
371
+ # each of the item's -tags are evaluated in order as per bindtags(n).
372
+ # <KeyPress>, <KeyRelease>, and virtual events are sent to the focus item.
373
+ # <ButtonPress>, <ButtonRelease>, and <Motion> events are sent to the
374
+ # item under the mouse pointer.
375
+ # No other event types are supported.
376
+ # The binding script undergoes %-substitutions before evaluation; see
377
+ # bind(n) for details.
378
+ def tag_bind(tag_name, sequence = None, &script)
379
+ execute(:tag, :bind, tag_name, sequence, script)
380
+ end
381
+
382
+ # Query or modify the options for the specified tagName.
383
+ # If one or more option/value pairs are specified, sets the value of those
384
+ # options for the specified tag.
385
+ # If a single option is specified, returns the value of that option (or the
386
+ # empty string if the option has not been specified for tagName).
387
+ # With no additional arguments, returns a dictionary of the option
388
+ # settings for tagName.
389
+ # See TAG OPTIONS for the list of available options.
390
+ def tag_configure(tag_name, options = None)
391
+ common_configure([:tag, :configure, tag_name], options)
392
+ end
393
+
394
+ # Standard command for horizontal scrolling; see widget(n).
395
+ def xview(args)
396
+ execute(:xview, args)
397
+ end
398
+
399
+ # Standard command for vertical scrolling; see ttk::widget(n).
400
+ # Each item should have the same number of values as the -columns widget
401
+ # option. If there are fewer values than columns, the remaining values are
402
+ # assumed empty.
403
+ # If there are more values than columns, the extra values are ignored.
404
+ # Specifies the text foreground color.
405
+ # Specifies the cell or item background color.
406
+ # Generated whenever the selection changes.
407
+ # Generated just before setting the focus item to -open true.
408
+ # Generated just after setting the focus item to -open false.
409
+ def yview(args)
410
+ execute(:yview, args)
411
+ end
412
+ end
413
+ end
414
+ end