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,18 @@
1
+ module Tk
2
+ class Canvas
3
+ # Items of type arc appear on the display as arc-shaped regions.
4
+ # An arc is a section of an oval delimited by two angles (specified by the
5
+ # :start and :extent options) and displayed in one of several ways
6
+ # (specified by the :style option).
7
+ class Arc < Item
8
+ options(
9
+ :dash, :activedash, :disableddash, :dashoffset, :fill, :activefill,
10
+ :disabledfill, :offset, :outline, :activeoutline, :disabledoutline,
11
+ :outlineoffset, :outlinestipple, :activeoutlinestipple,
12
+ :disabledoutlinestipple, :stipple, :activestipple, :disabledstipple,
13
+ :state, :tags, :width, :activewidth, :disabledwidth, :extent, :start,
14
+ :style
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module Tk
2
+ class Canvas
3
+ # Items of type bitmap appear on the display as images with two colors,
4
+ # foreground and background.
5
+ class Bitmap < Item
6
+ options(
7
+ :state, :tags, :anchor, :background, :activebackground,
8
+ :disabledbackground, :bitmap, :activebitmap, :disabledbitmap,
9
+ :foreground, :activeforeground, :disabledforeground
10
+ )
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module Tk
2
+ class Canvas
3
+ # Items of type image are used to display images on a canvas.
4
+ class Image < Item
5
+ options(
6
+ :state, :tags, :anchor, :image, :activeimage, :disabledimage
7
+ )
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,170 @@
1
+ module Tk
2
+ class Canvas
3
+ class Item < Struct.new(:canvas, :id)
4
+ OPTION_MAP = {
5
+ activebackground: :bitmap,
6
+ activebitmap: :bitmap,
7
+ activedash: :integer,
8
+ activefill: :color,
9
+ activeforeground: :bitmap,
10
+ activeimage: :string,
11
+ activeoutline: :color,
12
+ activeoutlinestipple: :bitmap,
13
+ activestipple: :bitmap,
14
+ activewidth: :integer,
15
+ anchor: :string,
16
+ arrow: :symbol,
17
+ arrowshape: :list,
18
+ background: :color,
19
+ bitmap: :bitmap,
20
+ capstyle: :symbol,
21
+ dash: :integer,
22
+ dashoffset: :integer,
23
+ disabledbackground: :bitmap,
24
+ disabledbitmap: :bitmap,
25
+ disableddash: :integer,
26
+ disabledfill: :color,
27
+ disabledforeground: :bitmap,
28
+ disabledimage: :string,
29
+ disabledoutline: :color,
30
+ disabledoutlinestipple: :bitmap,
31
+ disabledstipple: :bitmap,
32
+ disabledwidth: :integer,
33
+ extent: :float,
34
+ fill: :color,
35
+ font: :font,
36
+ foreground: :color,
37
+ height: :integer,
38
+ image: :string,
39
+ joinstyle: :symbol,
40
+ justify: :symbol,
41
+ offset: :string,
42
+ outline: :color,
43
+ outlineoffset: :integer,
44
+ outlinestipple: :bitmap,
45
+ smooth: :boolean,
46
+ splinesteps: :integer,
47
+ start: :float,
48
+ state: :symbol,
49
+ stipple: :bitmap,
50
+ style: :symbol,
51
+ tags: :list,
52
+ text: :string,
53
+ underline: :integer,
54
+ width: :integer,
55
+ width: :integer,
56
+ window: :pathname
57
+ }
58
+
59
+ def self.create(canvas, type, id)
60
+ klass = Canvas.const_get(type.to_s.capitalize)
61
+ klass.new(canvas, id)
62
+ end
63
+
64
+ OPTIONS_CODE = <<-RUBY
65
+ def %s
66
+ Cget.type_to_ruby(%p, canvas.itemcget(id, %p))
67
+ end
68
+ RUBY
69
+
70
+ def self.options(*names)
71
+ names.each do |name|
72
+ type = OPTION_MAP.fetch(name)
73
+ class_eval(OPTIONS_CODE % [name, type, name], __FILE__, __LINE__)
74
+ end
75
+ end
76
+
77
+ def to_tcl
78
+ TclString.new(id.to_s)
79
+ end
80
+
81
+ def inspect
82
+ "#<%s %d>" % [self.class.name, id]
83
+ end
84
+
85
+ def cget(option)
86
+ canvas.itemcget(self, option)
87
+ end
88
+
89
+ def addtag(tag)
90
+ canvas.addtag_withtag(tag, self)
91
+ end
92
+
93
+ def bbox
94
+ canvas.bbox(self)
95
+ end
96
+
97
+ def bind(sequence = None, &command)
98
+ canvas.bind(self, sequence, &command)
99
+ end
100
+
101
+ def coords(*coord_list)
102
+ canvas.coords(self, *coord_list)
103
+ end
104
+
105
+ def dchars(first, last = None)
106
+ canvas.dchars(self, first, last)
107
+ end
108
+
109
+ def delete
110
+ canvas.delete(self)
111
+ end
112
+
113
+ def dtag(tag)
114
+ canvas.dtag(self, tag)
115
+ end
116
+
117
+ def focus
118
+ canvas.focus(self)
119
+ end
120
+
121
+ def gettags
122
+ canvas.gettags(self)
123
+ end
124
+
125
+ def icursor(index)
126
+ canvas.icursor(self, index)
127
+ end
128
+
129
+ def index(index)
130
+ canvas.index(self, index)
131
+ end
132
+
133
+ def configure(options = None)
134
+ canvas.itemconfigure(self, options)
135
+ end
136
+
137
+ def lower(below = None)
138
+ canvas.lower(self, below)
139
+ end
140
+
141
+ def move(x_amount, y_amount)
142
+ canvas.move(self, x_amount, y_amount)
143
+ end
144
+
145
+ def raise(above = None)
146
+ canvas.raise(self, above)
147
+ end
148
+
149
+ def scale(x_origin, y_origin, x_scale, y_scale)
150
+ canvas.scale(self, x_origin, y_origin, x_scale, y_scale)
151
+ end
152
+
153
+ def select_adjust(index)
154
+ canvas.select_adjust(self, index)
155
+ end
156
+
157
+ def select_from(index)
158
+ canvas.select_from(self, index)
159
+ end
160
+
161
+ def select_to(index)
162
+ canvas.select_to(self, index)
163
+ end
164
+
165
+ def type
166
+ canvas.type(self)
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,16 @@
1
+ module Tk
2
+ class Canvas
3
+ # Items of type line appear on the display as one or more connected line
4
+ # segments or curves.
5
+ # Line items support coordinate indexing operations using the Canvas
6
+ # methods: [Canvas.dchars], [Canvas.index], and [Canvas.insert].
7
+ class Line < Item
8
+ options(
9
+ :dash, :activedash, :disableddash, :dashoffset, :fill, :activefill,
10
+ :disabledfill, :stipple, :activestipple, :disabledstipple, :state,
11
+ :tags, :width, :activewidth, :disabledwidth, :arrow, :arrowshape,
12
+ :capstyle, :joinstyle, :smooth, :splinesteps
13
+ )
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module Tk
2
+ class Canvas
3
+ # Items of type oval appear as circular or oval regions on the display.
4
+ # Each oval may have an outline, a fill, or both.
5
+ class Oval < Item
6
+ options(
7
+ :dash, :activedash, :disableddash, :dashoffset, :fill, :activefill,
8
+ :disabledfill, :offset, :outline, :activeoutline, :disabledoutline,
9
+ :outlineoffset, :outlinestipple, :activeoutlinestipple,
10
+ :disabledoutlinestipple, :stipple, :activestipple, :disabledstipple,
11
+ :state, :tags, :width, :activewidth, :disabledwidth
12
+ )
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module Tk
2
+ class Canvas
3
+ # Items of type polygon appear as polygonal or curved filled regions on the
4
+ # display. [Polygon] supports coordinate indexing operations using the
5
+ # [Canvas] methods: [Canvas.dchars], [Canvas.index], and [Canvas.insert].
6
+ class Polygon < Item
7
+ options(
8
+ :dash, :activedash, :disableddash, :dashoffset, :fill, :activefill,
9
+ :disabledfill, :offset, :outline, :activeoutline, :disabledoutline,
10
+ :outlinestipple, :activeoutlinestipple, :disabledoutlinestipple,
11
+ :stipple, :activestipple, :disabledstipple, :state, :tags, :width,
12
+ :activewidth, :disabledwidth, :joinstyle, :smooth, :splinesteps
13
+ )
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module Tk
2
+ class Canvas
3
+ # Items of type rectangle appear as rectangular regions on the display.
4
+ # Each rectangle may have an outline, a fill, or both.
5
+ class Rectangle < Item
6
+ options(
7
+ :dash, :activedash, :disableddash, :dashoffset, :fill, :activefill,
8
+ :disabledfill, :offset, :outline, :activeoutline, :disabledoutline,
9
+ :outlineoffset, :outlinestipple, :activeoutlinestipple,
10
+ :disabledoutlinestipple, :stipple, :activestipple, :disabledstipple,
11
+ :state, :tags, :width, :activewidth, :disabledwidth
12
+ )
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Tk
2
+ class Canvas
3
+ # A text item displays a string of characters on the screen in one or more
4
+ # lines. [Canvas::Text] items support indexing and selection, along with the
5
+ # following text-related [Canvas] methods: [Canvas.dchars], [Canvas.focus],
6
+ # [Canvas.icursor], and [Canvas.index].
7
+ class Text < Item
8
+ options(
9
+ :activefill, :activestipple, :anchor, :disabledfill, :disabledstipple,
10
+ :fill, :font, :justify, :state, :stipple, :tags, :text, :underline,
11
+ :width
12
+ )
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Tk
2
+ class Canvas
3
+ # Items of type window cause a particular window to be displayed at a given
4
+ # position on the canvas.
5
+ class Window < Item
6
+ options(
7
+ :state, :tags, :anchor, :height, :width, :window
8
+ )
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,63 @@
1
+ module Tk
2
+ # Create and manipulate checkbutton widgets
3
+ class CheckButton < Button
4
+ include Cget, Configure
5
+
6
+ def self.tk_command; 'checkbutton'; end
7
+
8
+ def initialize(parent = Tk.root, options = None)
9
+ if block_given?
10
+ super do |options|
11
+ options[:command] = register_command(:command, &Proc.new)
12
+ end
13
+ else
14
+ super
15
+ end
16
+ end
17
+
18
+ # Deselects the checkbutton and sets the associated variable to its “off”
19
+ # value.
20
+ def deselect
21
+ execute_only(:deselect)
22
+ end
23
+
24
+ # Flashes the checkbutton.
25
+ # This is accomplished by redisplaying the checkbutton several times,
26
+ # alternating between active and normal colors.
27
+ # At the end of the flash the checkbutton is left in the same normal/active
28
+ # state as when the command was invoked.
29
+ # This command is ignored if the checkbutton's state is disabled.
30
+ def flash
31
+ execute_only(:flash)
32
+ end
33
+
34
+ # Does just what would have happened if the user invoked the checkbutton
35
+ # with the mouse: toggle the selection state of the button and invoke the
36
+ # Tcl command associated with the checkbutton, if there is one.
37
+ # The return value is the return value from the Tcl command, or an empty
38
+ # string if there is no command associated with the checkbutton.
39
+ # This command is ignored if the checkbut‐ ton's state is disabled.
40
+ def invoke
41
+ execute_only(:invoke)
42
+ end
43
+
44
+ # Selects the checkbutton and sets the associated variable to its “on”
45
+ # value.
46
+ def select
47
+ execute_only(:select)
48
+ end
49
+
50
+ # Toggles the selection state of the button, redisplaying it and modifying
51
+ # its associated variable to reflect the new state.
52
+ # pressed over a checkbutton, the button activates whenever the mouse
53
+ # pointer is inside the button, and deactivates whenever the mouse pointer
54
+ # leaves the button.
55
+ # minus (-) deselects the button.
56
+ # labelframe .lbl -text "Steps:" checkbutton .c1 -text Lights -variable
57
+ # lights checkbutton .c2 -text Cameras -variable cameras checkbutton .c3
58
+ # -text Action! -variable action pack .c1 .c2 .c3 -in .lbl pack .lbl
59
+ def toggle
60
+ execute_only(:toggle)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,208 @@
1
+ module Tk
2
+ # An entry is a widget that displays a one-line text string and allows that
3
+ # string to be edited using widget methods described below, which are
4
+ # typically bound to keystrokes and mouse actions.
5
+ # When first created, an entry's string is empty.
6
+ # A portion of the entry may be selected as described below.
7
+ # If an entry is exporting its selection (see the exportSelection option),
8
+ # then it will observe the standard X11 protocols for handling the selection;
9
+ # entry selections are available as type STRING.
10
+ # Entries also observe the standard Tk rules for dealing with the input focus.
11
+ # When an entry has the input focus it displays an insertion cursor to
12
+ # indicate where new characters will be inserted.
13
+ #
14
+ # Entries are capable of displaying strings that are too long to fit entirely
15
+ # within the widget's window.
16
+ # In this case, only a portion of the string will be displayed; methods
17
+ # described below may be used to change the view in the window.
18
+ # Entries use the standard xScrollCommand mechanism for interacting with
19
+ # scrollbars (see the description of the xScrollCommand option for details).
20
+ # They also support scanning, as described below.
21
+ class Entry < Widget
22
+ include Cget, Configure
23
+
24
+ def self.tk_command; 'entry'; end
25
+
26
+ def value
27
+ get
28
+ end
29
+
30
+ def value=(string)
31
+ delete 0, :end
32
+ insert 0, string
33
+ end
34
+
35
+ def clear
36
+ delete 0, :end
37
+ end
38
+
39
+ def cursor
40
+ index(:insert)
41
+ end
42
+
43
+ def cursor=(index)
44
+ icursor(index)
45
+ end
46
+
47
+ # Returns a list of four numbers describing the bounding box of the
48
+ # character given by index.
49
+ # The first two elements of the list give the x and y coordinates of the
50
+ # upper-left corner of the screen area covered by the character (in pixels
51
+ # relative to the widget) and the last two elements give the width and
52
+ # height of the character, in pixels.
53
+ # The bounding box may refer to a region outside the visible area of the
54
+ # window.
55
+ def bbox(index)
56
+ execute(:bbox, index).to_a(&:to_i)
57
+ end
58
+
59
+ # Delete one or more elements of the entry.
60
+ # First is the index of the first character to delete, and last is the index
61
+ # of the character just after the last one to delete.
62
+ # If last is not specified it defaults to first+1, i.e. a single character
63
+ # is deleted.
64
+ def delete(first, last = None)
65
+ execute(:delete, first, last)
66
+ end
67
+
68
+ # Returns the entry's string.
69
+ def get
70
+ execute(:get).to_s
71
+ end
72
+
73
+ # Arrange for the insertion cursor to be displayed just before the character
74
+ # given by index.
75
+ def icursor(index)
76
+ execute_only(:icursor, index)
77
+ end
78
+
79
+ # Returns the numerical index corresponding to index.
80
+ def index(index)
81
+ execute(:index, index)
82
+ end
83
+
84
+ # Insert the characters of string just before the character indicated by
85
+ # index.
86
+ def insert(index, string)
87
+ execute_only(:insert, index, string)
88
+ end
89
+
90
+ # Records x and the current view in the entry window; used in conjunction
91
+ # with later scan dragto commands.
92
+ # Typically this command is associated with a mouse button press in the
93
+ # widget.
94
+ def scan_mark(x)
95
+ execute_only(:scan, :mark, x)
96
+ end
97
+
98
+ # This command computes the difference between its x argument and the x
99
+ # argument to the last scan mark command for the widget.
100
+ # It then adjusts the view left or right by 10 times the difference in
101
+ # x-coordinates.
102
+ # This command is typically associated with mouse motion events in the
103
+ # widget, to produce the effect of dragging the entry at high speed through
104
+ # the window.
105
+ def scan_dragto(x)
106
+ execute_only(:scan, :dragto, x)
107
+ end
108
+
109
+ # Locate the end of the selection nearest to the character given by index,
110
+ # and adjust that end of the selection to be at index (i.e. including but
111
+ # not going beyond index).
112
+ # The other end of the selection is made the anchor point for future select
113
+ # to commands.
114
+ # If the selection is not currently in the entry, then a new selection is
115
+ # created to include the characters between index and the most recent
116
+ # selection anchor point, inclusive.
117
+ def selection_adjust(index)
118
+ execute_only(:selection, :adjust, index)
119
+ end
120
+
121
+ # Clear the selection if it is currently in this widget.
122
+ # If the selection is not in this widget then the command has no effect.
123
+ def selection_clear
124
+ execute_only(:selection, :clear)
125
+ end
126
+
127
+ # Set the selection anchor point to just before the character given by
128
+ # index.
129
+ # Does not change the selection.
130
+ def selection_from(index)
131
+ execute_only(:selection, :from, index)
132
+ end
133
+
134
+ # Returns true if there is are characters selected in the entry, false if
135
+ # nothing is selected.
136
+ def selection_present
137
+ execute(:selection, :present) == 1
138
+ end
139
+
140
+ # Sets the selection to include the characters starting with the one indexed
141
+ # by start and ending with the one just before end.
142
+ # If end refers to the same character as start or an earlier one, then the
143
+ # entry's selection is cleared.
144
+ def selection_range(from, to)
145
+ execute_only(:selection, :range, from, to)
146
+ end
147
+
148
+ # If index is before the anchor point, set the selection to the characters
149
+ # from index up to but not including the anchor point.
150
+ # If index is the same as the anchor point, do nothing.
151
+ # If index is after the anchor point, set the selection to the characters
152
+ # from the anchor point up to but not including index.
153
+ # The anchor point is determined by the most recent select from or select
154
+ # adjust command in this widget.
155
+ # If the selection is not in this widget then a new selection is created
156
+ # using the most recent anchor point specified for the widget.
157
+ def selection_to(index)
158
+ execute_only(:selection, :to, index)
159
+ end
160
+
161
+ # This command is used to force an evaluation of the validateCommand
162
+ # independent of the conditions specified by the validate option.
163
+ # This is done by temporarily setting the validate option to all.
164
+ # It returns true or false.
165
+ def validate
166
+ execute(:validate) == 1
167
+ end
168
+
169
+ # Adjusts the view in the window so that the character given by index is
170
+ # displayed at the left edge of the window.
171
+ #
172
+ # If no index is given, it returns a list containing two elements.
173
+ # Each element is a real fraction between 0 and 1; together they describe
174
+ # the horizontal span that is visible in the window.
175
+ # For example, if the first element is 0.2 and the second element is 0.6,
176
+ # 20% of the entry's text is off-screen to the left, the middle 40% is
177
+ # visible in the window, and 40% of the text is off-screen to the right.
178
+ # These are the same values passed to scrollbars via the :xscrollcommand
179
+ # option.
180
+ def xview(index = None)
181
+ if index == None
182
+ execute(:xview)
183
+ else
184
+ execute_only(:xview, index)
185
+ end
186
+ end
187
+
188
+ # Adjusts the view in the window so that the character fraction of the way
189
+ # through the text appears at the left edge of the window.
190
+ # Fraction must be a fraction between 0 and 1.
191
+ def xview_moveto(fraction)
192
+ execute_only(:xview, :moveto, fraction)
193
+ end
194
+
195
+ # This command shifts the view in the window left or right according to
196
+ # number and what.
197
+ # Number must be an integer.
198
+ # What must be either units or pages or an abbreviation of one of these.
199
+ # If what is units, the view adjusts left or right by number average-width
200
+ # characters on the display; if it is pages then the view adjusts by number
201
+ # screenfuls.
202
+ # If number is negative then characters farther to the left become visible;
203
+ # if it is positive then characters farther to the right become visible.
204
+ def xview_scroll(number, what)
205
+ execute_only(:xview, :scroll, number, what)
206
+ end
207
+ end
208
+ end