ffi-tk 2009.11.29

Sign up to get free protection for your applications and to get access to all the features.
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,7 @@
1
+ module Tk
2
+ class MenuButton < Button
3
+ include Cget, Configure
4
+
5
+ def self.tk_command; 'menubutton'; end
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ module Tk
2
+ # Create and manipulate message widgets
3
+ #
4
+ # A message is a widget that displays a textual string.
5
+ #
6
+ # A message widget has three special features.
7
+ #
8
+ # First, it breaks up its string into lines in order to produce a given aspect
9
+ # ratio for the window.
10
+ # The line breaks are chosen at word boundaries wherever possible (if not even
11
+ # a single word would fit on a line, then the word will be split across
12
+ # lines). Newline characters in the string will force line breaks; they can be
13
+ # used, for example, to leave blank lines in the display.
14
+ #
15
+ # The second feature of a message widget is justification.
16
+ # The text may be displayed left-justified (each line starts at the left side
17
+ # of the window), centered on a line-by-line basis, or right-justified (each
18
+ # line ends at the right side of the window).
19
+ #
20
+ # The third feature of a message widget is that it handles control characters
21
+ # and non-printing characters specially.
22
+ # Tab characters are replaced with enough blank space to line up on the next
23
+ # 8-character boundary.
24
+ # Newlines cause line breaks.
25
+ # Other control characters (ASCII code less than 0x20) and characters not
26
+ # defined in the font are displayed as a four-character sequence \xhh where hh
27
+ # is the two-digit hexadecimal number corresponding to the character.
28
+ # In the unusual case where the font does not contain all of the characters in
29
+ # "0123456789abcdef\x" then control characters and undefined characters
30
+ # are not displayed at all.
31
+ class Message < Widget
32
+ include Cget, Configure
33
+
34
+ def self.tk_command; 'message'; end
35
+ end
36
+ end
@@ -0,0 +1,164 @@
1
+ module Tk
2
+ class PanedWindow < Widget
3
+ include Cget, Configure
4
+
5
+ def self.tk_command; 'panedwindow'; end
6
+
7
+ # Add one or more windows to the panedwindow, each in a separate pane.
8
+ # The arguments consist of the names of one or more windows followed by
9
+ # pairs of arguments that specify how to manage the windows.
10
+ # Option may have any of the values accepted by the configure subcommand.
11
+ def add(window, *arguments)
12
+ options, windows = arguments.partition{|arg| arg.respond_to?(:to_tcl_options) }
13
+
14
+ if option = options.first
15
+ execute(:add, window, *windows, option.to_tcl_options)
16
+ else
17
+ execute(:add, window, *windows)
18
+ end
19
+ end
20
+
21
+ # Remove the pane containing window from the panedwindow.
22
+ # All geometry management options for window will be forgotten.
23
+ def forget(window, *windows)
24
+ execute_only(:forget, window, *windows)
25
+ end
26
+
27
+ # Identify the panedwindow component underneath the point given by x and y,
28
+ # in window coordinates.
29
+ # If the point is over a sash or a sash handle, the result is a two element
30
+ # list containing the index of the sash or handle, and a word indicating
31
+ # whether it is over a sash or a handle, such as {0 sash} or {2 handle}.
32
+ # If the point is over any other part of the panedwindow, the result is an
33
+ # empty list.
34
+ def identify(x, y)
35
+ execute(:identify, x, y)
36
+ end
37
+
38
+ # Return a list containing the x and y coordinates of the most recent proxy
39
+ # location.
40
+ def proxy_coord
41
+ execute(:proxy, :coord).to_a
42
+ end
43
+
44
+ # Remove the proxy from the display.
45
+ def proxy_forget
46
+ execute(:proxy, :forget)
47
+ end
48
+
49
+ # Place the proxy at the given x and y coordinates.
50
+ def proxy_place(x, y)
51
+ execute(:proxy, :place, x, y)
52
+ end
53
+
54
+ # Return the current x and y coordinate pair for the sash given by index.
55
+ # Index must be an integer between 0 and 1 less than the number of panes in
56
+ # the panedwindow.
57
+ # The coordinates given are those of the top left corner of the region
58
+ # containing the sash.
59
+ def sash_coord(index)
60
+ execute(:sash, :coord, index)
61
+ end
62
+
63
+ # This command computes the difference between the given coordinates and
64
+ # the coordinates given to the last sash mark command for the given sash.
65
+ # It then moves that sash the computed dif‐ ference.
66
+ def sash_dragto(index, x, y)
67
+ execute_only(:sash, :dragto, index, x, y)
68
+ end
69
+
70
+ # Records x and y for the sash given by index; used in conjunction with
71
+ # later sash dragto commands to move the sash.
72
+ def sash_mark(index, x, y)
73
+ execute(:sash, :mark, index, x, y)
74
+ end
75
+
76
+ # Place the sash given by index at the given coordinates.
77
+ def sash_place(index, x, y)
78
+ execute(:sash, :place, index, x, y)
79
+ end
80
+
81
+ # Query a management option for window.
82
+ # Option may be any value allowed by the paneconfigure subcommand.
83
+ def panecget(window, option)
84
+ execute(:panecget, window, option.to_tcl_option)
85
+ end
86
+
87
+ # Query or modify the management options for window.
88
+ # If no option is specified, returns a list describing all of the available
89
+ # options for pathName (see Tk_ConfigureInfo for information on the format
90
+ # of this list).
91
+ # If option is specified with no value, then the command returns a list
92
+ # describing the one named option (this list will be identical to the
93
+ # corresponding sublist of the value returned if no option is specified).
94
+ # If one or more option-value pairs are specified, then the command
95
+ # modifies the given widget option(s) to have the given value(s); in this
96
+ # case the command returns an empty string.
97
+ # The following options are supported: -after window Insert the window
98
+ # after the window specified.
99
+ # window should be the name of a window already managed by pathName.
100
+ # -before window Insert the window before the window specified.
101
+ # window should be the name of a window already managed by pathName.
102
+ # -height size Specify a height for the window.
103
+ # The height will be the outer dimension of the window including its
104
+ # border, if any.
105
+ # If size is an empty string, or if -height is not specified, then the
106
+ # height requested internally by the window will be used initially; the
107
+ # height may later be adjusted by the movement of sashes in the
108
+ # panedwindow. Size may be any value accepted by Tk_GetPixels.
109
+ # -hide boolean Controls the visibility of a pane.
110
+ # When the boolean is true (according to Tcl_GetBoolean) the pane will not
111
+ # be visible, but it will still be maintained in the list of panes.
112
+ # │ -minsize n Specifies that the size of the window cannot be made less
113
+ # than n.
114
+ # This constraint only affects the size of the widget in the paned
115
+ # dimension — the x dimension for horizontal panedwin‐ dows, the y
116
+ # dimension for vertical panedwindows.
117
+ # May be any value accepted by Tk_GetPixels.
118
+ # -padx n Specifies a non-negative value indicating how much extra space to
119
+ # leave on each side of the window in the X-direction.
120
+ # The value may have any of the forms accepted by Tk_GetPixels.
121
+ # -pady n Specifies a non-negative value indicating how much extra space to
122
+ # leave on each side of the window in the Y-direction.
123
+ # The value may have any of the forms accepted by Tk_GetPixels.
124
+ # -sticky style If a window's pane is larger than the requested dimensions
125
+ # of the window, this option may be used to position (or stretch) the
126
+ # window within its pane.
127
+ # Style is a string that contains zero or more of the characters n, s, e or
128
+ # w. The string can optionally contains spaces or commas, but they are
129
+ # ignored. Each letter refers to a side (north, south, east, or west) that
130
+ # the window will “stick” to.
131
+ # If both n and s (or e and w) are specified, the window will be stretched
132
+ # to fill the entire height (or width) of its cavity.
133
+ # -stretch when Controls how extra space is allocated to each of the panes.
134
+ # When is one of always, first, last, middle, and never.
135
+ # The panedwindow will calculate the required size of all its panes.
136
+ # │ Any remaining (or deficit) space will be distributed to those panes
137
+ # marked for stretching.
138
+ # The space will be distributed based on each panes current ratio of the
139
+ # whole. The when values │ have the following definition: │ always │ This
140
+ # pane will always stretch.
141
+ # │ first │ Only if this pane is the first pane (left-most or top-most)
142
+ # will it stretch.
143
+ # │ last │ Only if this pane is the last pane (right-most or bottom-most)
144
+ # will it stretch.
145
+ # This is the default value.
146
+ # │ middle │ Only if this pane is not the first or last pane will it
147
+ # stretch. │ never │ This pane will never stretch.
148
+ # │ -width size Specify a width for the window.
149
+ # The width will be the outer dimension of the window including its border,
150
+ # if any.
151
+ # If size is an empty string, or if -width is not specified, then the width
152
+ # requested internally by the window will be used initially; the width may
153
+ # later be adjusted by the movement of sashes in the panedwindow.
154
+ # Size may be any value accepted by Tk_Get‐ Pixels.
155
+ def paneconfigure(window, options = None)
156
+ common_configure([:paneconfigure, window], options)
157
+ end
158
+
159
+ # Returns an ordered list of the widgets managed by pathName.
160
+ def panes
161
+ execute(:panes).to_a
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,43 @@
1
+ module Tk
2
+ class RadioButton < Button
3
+ include Cget, Configure
4
+
5
+ def self.tk_command; 'radiobutton'; end
6
+
7
+ # Deselects the radiobutton and sets the associated variable to an empty
8
+ # string. If this radiobutton was not currently selected, the command has
9
+ # no effect.
10
+ def deselect
11
+ execute_only(:deselect)
12
+ end
13
+
14
+ # Flashes the radiobutton.
15
+ # This is accomplished by redisplaying the radiobutton several times,
16
+ # alternating between active and normal colors.
17
+ # At the end of the flash the radiobutton is left in the same normal/active
18
+ # state as when the command was invoked.
19
+ # This command is ignored if the radiobutton's state is disabled.
20
+ def flash
21
+ execute_only(:flash)
22
+ end
23
+
24
+ # Does just what would have happened if the user invoked the radiobutton
25
+ # with the mouse: selects the button and invokes its associated Tcl
26
+ # command, if there is one.
27
+ # The return value is the return value from the Tcl command, or an empty
28
+ # string if there is no command associated with the radiobutton.
29
+ # This command is ignored if the radiobutton's state is disabled.
30
+ def invoke
31
+ execute_only(:invoke)
32
+ end
33
+
34
+ # Selects the radiobutton and sets the associated variable to the value
35
+ # corresponding to this widget.
36
+ # pressed over a radiobutton, the button activates whenever the mouse
37
+ # pointer is inside the button, and deactivates whenever the mouse pointer
38
+ # leaves the button.
39
+ def select
40
+ execute_only(:select)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,8 @@
1
+ module Tk
2
+ class Root < Toplevel
3
+ def initialize
4
+ @tk_parent = nil
5
+ @tk_pathname = '.'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,44 @@
1
+ module Tk
2
+ class Scale < Widget
3
+ include Cget, Configure
4
+
5
+ def self.tk_command; 'scale'; end
6
+
7
+ # Returns a list whose elements are the x and y coordinates of the point
8
+ # along the centerline of the trough that corresponds to value.
9
+ # If value is omitted then the scale's current value is used.
10
+ def coords(value = None)
11
+ execute(:coords, value)
12
+ end
13
+
14
+ # If x and y are omitted, returns the current value of the scale.
15
+ # If x and y are specified, they give pixel coordinates within the widget;
16
+ # the command returns the scale value corresponding to the given pixel.
17
+ # Only one of x or y is used: for horizontal scales y is ignored, and for
18
+ # vertical scales x is ignored.
19
+ def get(x = None, y = None)
20
+ execute(:get, x, y)
21
+ end
22
+
23
+ # Returns a string indicating what part of the scale lies under the
24
+ # coordinates given by x and y.
25
+ # A return value of slider means that the point is over the slider; trough1
26
+ # means that the point is over the portion of the slider above or to the
27
+ # left of the slider; and trough2 means that the point is over the portion
28
+ # of the slider below or to the right of the slider.
29
+ # If the point is not over one of these elements, an empty string is
30
+ # returned.
31
+ def identify(x, y)
32
+ execute(:identify, x, y)
33
+ end
34
+
35
+ # This command is invoked to change the current value of the scale, and
36
+ # hence the position at which the slider is displayed.
37
+ # Value gives the new value for the scale.
38
+ # The command has no effect if the scale is disabled.
39
+ # the button is held down, the action auto-repeats.
40
+ def set(value)
41
+ execute(:set, value)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,114 @@
1
+ module Tk
2
+ class Scrollbar < Widget
3
+ include Cget, Configure
4
+
5
+ def self.tk_command; 'scrollbar'; end
6
+
7
+ # Marks the element indicated by element as active, which causes it to be
8
+ # displayed as specified by the activeBackground and activeRelief options.
9
+ # The only element values understood by this command are arrow1, slider, or
10
+ # arrow2. If any other value is specified then no element of the scrollbar
11
+ # will be active.
12
+ # If element is not specified, the command returns the name of the element
13
+ # that is currently active, or an empty string if no element is
14
+ # active.
15
+ def activate(element = None)
16
+ execute(:activate, element).to_s?
17
+ end
18
+
19
+ # Returns a real number indicating the fractional change in the scrollbar
20
+ # setting that corresponds to a given change in slider position.
21
+ # For example, if the scrollbar is horizontal, the result indicates how
22
+ # much the scrollbar setting must change to move the slider deltaX pixels
23
+ # to the right (deltaY is ignored in this case).
24
+ # If the scrollbar is vertical, the result indicates how much the scrollbar
25
+ # setting must change to move the slider deltaY pixels down.
26
+ # The arguments and the result may be zero or negative.
27
+ def delta(delta_x, delta_y)
28
+ execute(:delta, delta_x, delta_y)
29
+ end
30
+
31
+ # Returns a real number between 0 and 1 indicating where the point given by
32
+ # x and y lies in the trough area of the scrollbar.
33
+ # The value 0 corresponds to the top or left of the trough, the value 1
34
+ # corresponds to the bottom or right, 0.5 corresponds to the middle, and so
35
+ # on. X and y must be pixel coordinates relative to the scrollbar widget.
36
+ # If x and y refer to a point outside the trough, the closest point in the
37
+ # trough is used.
38
+ def fraction(x, y)
39
+ execute(:fraction, x, y)
40
+ end
41
+
42
+ # Returns the scrollbar settings in the form of a list whose elements are
43
+ # the arguments to the most recent set widget command.
44
+ def get
45
+ execute(:get)
46
+ end
47
+
48
+ # Returns the name of the element under the point given by x and y (such as
49
+ # arrow1), or an empty string if the point does not lie in any element of
50
+ # the scrollbar.
51
+ # X and y must be pixel coordinates relative to the scrollbar widget.
52
+ def identify(x, y)
53
+ execute(:identify, x, y)
54
+ end
55
+
56
+ # This command is invoked by the scrollbar's associated widget to tell the
57
+ # scrollbar about the current view in the widget.
58
+ # The command takes two arguments, each of which is a real fraction between
59
+ # 0 and 1.
60
+ # The fractions describe the range of the document that is visible in the
61
+ # associated widget.
62
+ # For example, if first is 0.2 and last is 0.4, it means that the first
63
+ # part of the document visible in the window is 20% of the way through the
64
+ # document, and the last visible part is 40% of the way through.
65
+ # Fraction is a real number between 0 and 1.
66
+ # The widget should adjust its view so that the point given by fraction
67
+ # appears at the beginning of the widget.
68
+ # If fraction is 0 it refers to the beginning of the document.
69
+ # 1.0 refers to the end of the document, 0.333 refers to a point one-third
70
+ # of the way through the document, and so on.
71
+ # The widget should adjust its view by number units.
72
+ # The units are defined in whatever way makes sense for the widget, such as
73
+ # characters or lines in a text widget.
74
+ # Number is either 1, which means one unit should scroll off the top or
75
+ # left of the window, or -1, which means that one unit should scroll off
76
+ # the bottom or right of the window.
77
+ # The widget should adjust its view by number pages.
78
+ # It is up to the widget to define the meaning of a page; typically it is
79
+ # slightly less than what fits in the window, so that there is a slight
80
+ # overlap between the old and new views.
81
+ # Number is either 1, which means the next page should become visible, or
82
+ # -1, which means that the previous page should become visible.
83
+ #
84
+ # In this form the arguments are all integers.
85
+ # TotalUnits gives the total size of the object being displayed in the
86
+ # associated widget.
87
+ # The meaning of one unit depends on the associated widget; for example, in
88
+ # a text editor widget units might correspond to lines of text.
89
+ # WindowUnits indicates the total number of units that can fit in the
90
+ # associated window at one time.
91
+ # FirstUnit and lastUnit give the indices of the first and last units
92
+ # currently visible in the associated window (zero corresponds to the first
93
+ # unit of the object).
94
+ # Unit is an integer that indicates what should appear at the top or left
95
+ # of the associated widget's window.
96
+ # It has the same meaning as the firstUnit and lastUnit arguments to the
97
+ # set widget command.
98
+ # the action auto-repeats.
99
+ # held down, the action auto-repeats.
100
+ # the mouse button is released.
101
+ # held down, the action auto-repeats.
102
+ # the action auto-repeats.
103
+ # button 2 is pressed over one of the arrows, it causes the same behavior
104
+ # as pressing button 1.
105
+ # the view changes to the very bottom (right) of the document; if the mouse
106
+ # is anywhere else then the button press has no effect.
107
+ # toplevel .tl text .tl.t -yscrollcommand {.tl.s set} scrollbar .tl.s
108
+ # -command {.tl.t yview} grid .tl.t .tl.s -sticky nsew grid columnconfigure
109
+ # .tl 0 -weight 1 grid rowconfigure .tl 0 -weight 1
110
+ def set(first, second, third = None, fourth = None)
111
+ execute(:set, first, second, third, fourth)
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,198 @@
1
+ module Tk
2
+ class Spinbox < Widget
3
+ include Cget, Configure
4
+
5
+ def self.tk_command; 'spinbox'; end
6
+
7
+ # Returns a list of four numbers describing the bounding box of the
8
+ # character given by index.
9
+ # The first two elements of the list give the x and y coordinates of the
10
+ # upper-left corner of the screen area covered by the character (in pixels
11
+ # relative to the widget) and the last two elements give the width and
12
+ # height of the character, in pixels.
13
+ # The bounding box may refer to a region outside the visible area of the
14
+ # window.
15
+ def bbox(index)
16
+ execute(:bbox, index).to_a(&:to_i)
17
+ end
18
+
19
+ # Delete one or more elements of the spinbox.
20
+ # First is the index of the first character to delete, and last is the
21
+ # index of the character just after the last one to delete.
22
+ # If last is not specified it defaults to first+1, i.e.
23
+ # a single character is deleted.
24
+ # This command returns an empty string.
25
+ def delete(first, last = None)
26
+ execute_only(:delete, first, last)
27
+ end
28
+
29
+ # Returns the spinbox's string.
30
+ def get
31
+ execute(:get)
32
+ end
33
+
34
+ # Arrange for the insertion cursor to be displayed just before the
35
+ # character given by index.
36
+ def icursor(index)
37
+ execute_only(:icursor, index)
38
+ end
39
+
40
+ # Returns the name of the window element corresponding to coordinates x and
41
+ # y in the spinbox.
42
+ # Return value is one of: none, buttondown, buttonup, entry.
43
+ def identify(x, y)
44
+ execute(:identify, x, y).to_sym
45
+ end
46
+
47
+ # Returns the numerical index corresponding to index.
48
+ def index(index)
49
+ execute(:index, index)
50
+ end
51
+
52
+ # Insert the characters of string just before the character indicated by
53
+ # index. Returns an empty string.
54
+ def insert(index, string)
55
+ execute_only(:insert, index, string)
56
+ end
57
+
58
+ # Causes the specified element, either buttondown or buttonup, to be
59
+ # invoked, triggering the action associated with it.
60
+ def invoke(element)
61
+ execute(:invoke, element)
62
+ end
63
+
64
+ # Records x and the current view in the spinbox window; used in conjunction
65
+ # with later scan dragto commands.
66
+ # Typically this command is associated with a mouse button press in the
67
+ # widget.
68
+ def scan_mark(x)
69
+ execute_only(:scan, :mark, x)
70
+ end
71
+
72
+ # This command computes the difference between its x argument and the x
73
+ # argument to the last scan mark command for the widget.
74
+ # It then adjusts the view left or right by 10 times the difference in
75
+ # x-coordinates. This command is typically associated with mouse motion
76
+ # events in the widget, to produce the effect of dragging the spinbox at
77
+ # high speed through the window.
78
+ def scan_dragto(x)
79
+ execute_only(:scan, :dragto, x)
80
+ end
81
+
82
+ # Locate the end of the selection nearest to the character given by index,
83
+ # and adjust that end of the selection to be at index (i.e.
84
+ # including but not going beyond index).
85
+ # The other end of the selection is made the anchor point for future select
86
+ # to commands.
87
+ # If the selection is not currently in the spinbox, then a new selection is
88
+ # created to include the characters between index and the most recent
89
+ # selection anchor point, inclusive.
90
+ def selection_adjust(index)
91
+ execute_only(:selection, :adjust, index)
92
+ end
93
+
94
+ # Clear the selection if it is currently in this widget.
95
+ # If the selection is not in this widget then the command has no effect.
96
+ def selection_clear
97
+ execute_only(:selection, :clear)
98
+ end
99
+
100
+ # Sets or gets the currently selected element.
101
+ # If a spinbutton element is specified, it will be displayed depressed.
102
+ def selection_element(element = None)
103
+ execute(:selection, :element, element)
104
+ end
105
+
106
+ # Set the selection anchor point to just before the character given by
107
+ # index. Does not change the selection.
108
+ def selection_from(index)
109
+ execute_only(:selection, :from, index)
110
+ end
111
+
112
+ # Returns 1 if there is are characters selected in the spinbox, 0 if
113
+ # nothing is selected.
114
+ def selection_present
115
+ execute(:selection, :present).to_boolean
116
+ end
117
+
118
+ # Sets the selection to include the characters starting with the one
119
+ # indexed by start and ending with the one just before end.
120
+ # If end refers to the same character as start or an earlier one, then the
121
+ # spinbox's selection is cleared.
122
+ def selection_range(from, to)
123
+ execute(:selection, :range, from, to)
124
+ end
125
+
126
+ # If index is before the anchor point, set the selection to the characters
127
+ # from index up to but not including the anchor point.
128
+ # If index is the same as the anchor point, do nothing.
129
+ # If index is after the anchor point, set the selection to the characters
130
+ # from the anchor point up to but not including index.
131
+ # The anchor point is determined by the most recent select from or select
132
+ # adjust command in this widget.
133
+ # If the selection is not in this widget then a new selection is created
134
+ # using the most recent anchor point specified for the widget.
135
+ # Returns an empty string.
136
+ def selection_to(index)
137
+ execute(:selection, :to, index)
138
+ end
139
+
140
+ # If string is specified, the spinbox will try and set it to this value,
141
+ # otherwise it just returns the spinbox's string.
142
+ # If validation is on, it will occur when setting the string.
143
+ def set(string = None)
144
+ if None == string
145
+ execute(:set)
146
+ else
147
+ execute_only(:set, string)
148
+ end
149
+ end
150
+
151
+ # This command is used to force an evaluation of the validateCommand
152
+ # independent of the conditions specified by the validate option.
153
+ # This is done by temporarily setting the validate option to all.
154
+ # It returns 0 or 1.
155
+ def validate
156
+ execute(:validate).to_boolean
157
+ end
158
+
159
+ # Returns a list containing two elements.
160
+ # Each element is a real fraction between 0 and 1; together they describe
161
+ # the horizontal span that is visible in the window.
162
+ # For example, if the first element is .2 and the second element is .6, 20%
163
+ # of the spinbox's text is off-screen to the left, the middle 40% is
164
+ # visible in the window, and 40% of the text is off-screen to the right.
165
+ # These are the same values passed to scrollbars via the -xscrollcommand
166
+ # option.
167
+ #
168
+ # Adjusts the view in the window so that the character given by index is
169
+ # displayed at the left edge of the window.
170
+ def xview(index = None)
171
+ if None == index
172
+ execute(:xview)
173
+ else
174
+ execute_only(:xview, index)
175
+ end
176
+ end
177
+
178
+ # Adjusts the view in the window so that the character fraction of the way
179
+ # through the text appears at the left edge of the window.
180
+ # Fraction must be a fraction between 0 and 1.
181
+ def xview_moveto(fraction)
182
+ execute(:xview, :moveto, fraction)
183
+ end
184
+
185
+ # This command shifts the view in the window left or right according to
186
+ # number and what.
187
+ # Number must be an integer.
188
+ # What must be either units or pages or an abbreviation of one of these.
189
+ # If what is units, the view adjusts left or right by number average-width
190
+ # characters on the display; if it is pages then the view adjusts by number
191
+ # screenfuls. If number is negative then characters farther to the left
192
+ # become visible; if it is positive then characters farther to the right
193
+ # become visible.
194
+ def xview_scroll(number, what)
195
+ execute(:xview, :scroll, number, what)
196
+ end
197
+ end
198
+ end