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,101 @@
1
+ require_relative '../../helper'
2
+
3
+ describe Tk::Tile::Treeview do
4
+ it 'initializes' do
5
+ instance = Tk::Tile::Treeview.new
6
+ instance.class.should == Tk::Tile::Treeview
7
+ instance.tk_parent.should == Tk.root
8
+ end
9
+
10
+ list = Tk::Tile::Treeview.new
11
+
12
+ it 'shows configuration' do
13
+ list.cget(:takefocus).should == false
14
+ list.cget(:columns).should == []
15
+ list.cget(:displaycolumns).should == ['#all']
16
+ list.cget(:show).should == ['tree', 'headings']
17
+ list.cget(:selectmode).should == :extended
18
+ list.cget(:height).should == 10
19
+ list.cget(:padding).should == []
20
+ list.cget(:xscrollcommand).should == nil
21
+ list.cget(:yscrollcommand).should == nil
22
+ list.cget(:takefocus).should == false
23
+ list.cget(:cursor).should == nil
24
+ list.cget(:style).should == []
25
+ list.cget(:class).should == nil
26
+ end
27
+
28
+ it 'returns the widget state' do
29
+ list.ttk_state('active').should == true
30
+ end
31
+
32
+ it 'executes a block if the state matches the spec' do
33
+ value = nil
34
+ list.instate('active'){ value = :active }
35
+ value.should == :active
36
+ list.instate('!active'){ value = :inactive }
37
+ value.should == :active
38
+ end
39
+
40
+ it 'creates a new item on root' do
41
+ @item0 = list.insert(nil, 0, text: 'something')
42
+ @item0.tk_parent.should == list
43
+ @item0.id.should == 'I001'
44
+ end
45
+
46
+ it 'gets list of children' do
47
+ list.children(nil).to_a.should == [@item0]
48
+ end
49
+
50
+ it 'returns options of the item' do
51
+ @item0.options.should == {
52
+ text: 'something',
53
+ image: '',
54
+ values: '',
55
+ open: 0,
56
+ tags: '',
57
+ }
58
+ end
59
+
60
+ it 'returns options of a column' do
61
+ list.column('#0').should == {
62
+ width: 200,
63
+ minwidth: 20,
64
+ stretch: true,
65
+ anchor: 'w',
66
+ id: '',
67
+ }
68
+ end
69
+
70
+ it 'knows the index of the item' do
71
+ @item0.index.should == 0
72
+ end
73
+
74
+ it 'returns the bbox of the item' do
75
+ @item0.bbox.should == []
76
+ end
77
+
78
+ it 'gets parent of item' do
79
+ @item0.parent.id.should == ''
80
+ end
81
+
82
+ it 'detaches the item' do
83
+ @item0.detach
84
+ @item0.should.exist
85
+ end
86
+
87
+ it 'deletes the item' do
88
+ @item0.delete
89
+ @item0.should.not.exist
90
+ end
91
+
92
+ it 'heading' do
93
+ list.heading('#0').should == {
94
+ text: '',
95
+ image: '',
96
+ anchor: 'center',
97
+ command: '',
98
+ state: ''
99
+ }
100
+ end
101
+ end
@@ -0,0 +1,24 @@
1
+ require_relative '../helper'
2
+
3
+ Tk.init
4
+
5
+ describe Tk::Variable do
6
+ it 'creates a Variable' do
7
+ @var = Tk::Variable.new('somevar')
8
+ @var.name.should == "somevar"
9
+ end
10
+
11
+ it 'cannot get a value from it yet' do
12
+ lambda{ @var.get }.should.raise(NameError)
13
+ end
14
+
15
+ it 'sets the value and retrieves it' do
16
+ @var.set('Hello, World!')
17
+ @var.to_s.should == 'Hello, World!'
18
+ end
19
+
20
+ it 'unsets the variable' do
21
+ @var.unset
22
+ lambda{ @var.get }.should.raise(NameError)
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../../helper'
2
+
3
+ describe Tk::Button do
4
+ it 'handles -command' do
5
+ ran = false
6
+ Tk.callbacks.size.should == 0
7
+
8
+ button = Tk::Button.new{
9
+ ran = true
10
+ button.destroy
11
+ }
12
+ button.invoke
13
+
14
+ Tk.callbacks.size.should == 0
15
+ ran.should == true
16
+ end
17
+
18
+ it 'sets the text of the button' do
19
+ button = Tk::Button.new(text: 'Hello, World!')
20
+ button.cget(:text).should == 'Hello, World!'
21
+ end
22
+ end
@@ -0,0 +1,169 @@
1
+ require_relative '../../helper'
2
+
3
+ describe Tk::Canvas do
4
+ it 'creates a canvas' do
5
+ @canvas = Tk::Canvas.new
6
+ @canvas.tk_pathname.should == '.canvas0'
7
+ @canvas.pack fill: :both, expand: true
8
+ end
9
+
10
+ it 'creates text' do
11
+ @text = @canvas.create_text(0, 0, text: 'Hello, World!')
12
+ @text.id.should == 1
13
+ @text.canvas.should == @canvas
14
+
15
+ @text.activefill.should == nil
16
+ @text.activestipple.should == nil
17
+ @text.anchor.should == "center"
18
+ @text.disabledfill.should == nil
19
+ @text.disabledstipple.should == nil
20
+ @text.fill.should == "black"
21
+ @text.font.should == "TkDefaultFont"
22
+ @text.justify.should == :left
23
+ @text.state.should == nil
24
+ @text.stipple.should == nil
25
+ @text.tags.should == []
26
+ @text.text.should == "Hello, World!"
27
+ @text.underline.should == -1
28
+ @text.width.should == 0
29
+ end
30
+
31
+ it 'creates a rectangle' do
32
+ @rect = @canvas.create_rectangle(10, 11, 12, 13)
33
+ @rect.id.should == 2
34
+ @rect.canvas.should == @canvas
35
+
36
+ @rect.dash.should == 0
37
+ @rect.activedash.should == 0
38
+ @rect.disableddash.should == 0
39
+ @rect.dashoffset.should == 0
40
+ @rect.fill.should == nil
41
+ @rect.activefill.should == nil
42
+ @rect.disabledfill.should == nil
43
+ @rect.offset.should == '0,0'
44
+ @rect.outline.should == 'black'
45
+ @rect.activeoutline.should == nil
46
+ @rect.disabledoutline.should == nil
47
+ @rect.outlineoffset.should == 0
48
+ @rect.outlinestipple.should == nil
49
+ @rect.activeoutlinestipple.should == nil
50
+ @rect.disabledoutlinestipple.should == nil
51
+ @rect.stipple.should == nil
52
+ @rect.activestipple.should == nil
53
+ @rect.disabledstipple.should == nil
54
+ @rect.state.should == nil
55
+ @rect.tags.should == []
56
+ @rect.width.should == 0
57
+ @rect.activewidth.should == 0
58
+ @rect.disabledwidth.should == 0
59
+ end
60
+
61
+ it 'creates an arc' do
62
+ @arc = @canvas.create_arc(20, 21, 22, 23)
63
+ @arc.id.should == 3
64
+ @arc.canvas.should == @canvas
65
+
66
+ @arc.dash.should == 0
67
+ @arc.activedash.should == 0
68
+ @arc.disableddash.should == 0
69
+ @arc.dashoffset.should == 0
70
+ @arc.fill.should == nil
71
+ @arc.activefill.should == nil
72
+ @arc.disabledfill.should == nil
73
+ @arc.offset.should == '0,0'
74
+ @arc.outline.should == 'black'
75
+ @arc.activeoutline.should == nil
76
+ @arc.disabledoutline.should == nil
77
+ @arc.outlineoffset.should == 0.0
78
+ @arc.outlinestipple.should == nil
79
+ @arc.activeoutlinestipple.should == nil
80
+ @arc.disabledoutlinestipple.should == nil
81
+ @arc.stipple.should == nil
82
+ @arc.activestipple.should == nil
83
+ @arc.disabledstipple.should == nil
84
+ @arc.state.should == nil
85
+ @arc.tags.should == []
86
+ @arc.width.should == 0
87
+ @arc.activewidth.should == 0
88
+ @arc.disabledwidth.should == 0
89
+ @arc.extent.should == 90.0
90
+ @arc.start.should == 0
91
+ @arc.style.should == :pieslice
92
+ end
93
+
94
+ it 'creates a polygon' do
95
+ @poly = @canvas.create_polygon(50, 50, 60, 60, 70, 70, 80, 70, 90, 60, 100, 50)
96
+ @poly.id.should == 4
97
+ @poly.canvas.should == @canvas
98
+
99
+ @poly.dash.should == 0
100
+ @poly.activedash.should == 0
101
+ @poly.disableddash.should == 0
102
+ @poly.dashoffset.should == 0
103
+ @poly.fill.should == 'black'
104
+ @poly.activefill.should == nil
105
+ @poly.disabledfill.should == nil
106
+ @poly.offset.should == '0,0'
107
+ @poly.outline.should == nil
108
+ @poly.activeoutline.should == nil
109
+ @poly.disabledoutline.should == nil
110
+ @poly.outlinestipple.should == nil
111
+ @poly.activeoutlinestipple.should == nil
112
+ @poly.disabledoutlinestipple.should == nil
113
+ @poly.stipple.should == nil
114
+ @poly.activestipple.should == nil
115
+ @poly.disabledstipple.should == nil
116
+ @poly.state.should == nil
117
+ @poly.tags.should == []
118
+ @poly.width.should == 0
119
+ @poly.activewidth.should == 0
120
+ @poly.disabledwidth.should == 0
121
+ @poly.joinstyle.should == :round
122
+ @poly.smooth.should == false
123
+ @poly.splinesteps.should == 12
124
+ end
125
+
126
+ it 'creates a line' do
127
+ @line = @canvas.create_line(10, 15, 20, 25)
128
+ @line.id.should == 5
129
+ @line.canvas.should == @canvas
130
+
131
+ @line.dash.should == 0
132
+ @line.activedash.should == 0
133
+ @line.disableddash.should == 0
134
+ @line.dashoffset.should == 0
135
+ @line.fill.should == 'black'
136
+ @line.activefill.should == nil
137
+ @line.disabledfill.should == nil
138
+ @line.stipple.should == nil
139
+ @line.activestipple.should == nil
140
+ @line.disabledstipple.should == nil
141
+ @line.state.should == nil
142
+ @line.tags.should == []
143
+ @line.width.should == 0
144
+ @line.activewidth.should == 0
145
+ @line.disabledwidth.should == 0
146
+ @line.arrow.should == :none
147
+ @line.arrowshape.should == ["8", "10", "3"]
148
+ @line.capstyle.should == :butt
149
+ @line.joinstyle.should == :round
150
+ @line.smooth.should == false
151
+ @line.splinesteps.should == 12
152
+ end
153
+
154
+ it 'creates a window' do
155
+ entry = Tk::Entry.new(Tk.root)
156
+ @win = @canvas.create_window(10, 10, window: entry)
157
+ @win.id.should == 6
158
+ @win.canvas.should == @canvas
159
+
160
+ @win.state.should == nil
161
+ @win.tags.should == []
162
+ @win.anchor.should == 'center'
163
+ @win.height.should == 0
164
+ @win.width.should == 0
165
+ @win.window.should == entry
166
+ end
167
+ end
168
+
169
+ # %w[ ].each{|name| puts "@line.%s.should == nil" % [name.delete(':,')] }
@@ -0,0 +1,44 @@
1
+ require_relative '../../helper'
2
+
3
+ describe Tk::CheckButton do
4
+ it 'initializes' do
5
+ cb = Tk::CheckButton.new
6
+ cb.class.should == Tk::CheckButton
7
+ cb.tk_parent.should == Tk.root
8
+ cb.destroy
9
+ end
10
+
11
+ it 'associates a variable with the value' do
12
+ value = Tk::Variable.new('checkbutton_value')
13
+ cb = Tk::CheckButton.new(variable: value)
14
+ value.to_boolean.should == false
15
+ cb.select
16
+ value.to_boolean.should == true
17
+ cb.deselect
18
+ value.to_boolean.should == false
19
+ end
20
+
21
+ it 'assigns a command block on initialize' do
22
+ toggled = false
23
+ value = Tk::Variable.new('checkbutton_value')
24
+ cb = Tk::CheckButton.new(variable: value){ toggled = !toggled }
25
+ cb.pack
26
+ cb.focus
27
+
28
+ toggled.should == false
29
+
30
+ Tk::Wait.visibility(cb)
31
+
32
+ Tk::Event.generate(cb, '<1>')
33
+ Tk.interp.do_events_until{ toggled }
34
+ toggled.should == true
35
+
36
+ Tk::Event.generate(cb, '<1>')
37
+ Tk.interp.do_events_until{ !toggled }
38
+ toggled.should == false
39
+
40
+ Tk::Event.generate(cb, '<1>')
41
+ Tk.interp.do_events_until{ toggled }
42
+ toggled.should == true
43
+ end
44
+ end
@@ -0,0 +1,155 @@
1
+ require_relative '../../helper'
2
+
3
+ describe Tk::Entry do
4
+ @entry = Tk::Entry.new
5
+
6
+ it "returns the entry's string" do
7
+ @entry.get.should == ''
8
+ end
9
+
10
+ it 'inserts text at index' do
11
+ @entry.insert(:end, 'Hello, World!')
12
+ @entry.get.should == 'Hello, World!'
13
+ end
14
+
15
+ it 'returns a list of four numbers describing the bounding box of the character given by index' do
16
+ index_bbox = @entry.bbox(0)
17
+ index_bbox.should.be.kind_of? Array
18
+ index_bbox.size.should == 4
19
+ end
20
+
21
+ it 'Returns the current value of the configuration option given' do
22
+ @entry.cget(:background ).should == "#ffffff"
23
+ @entry.cget(:bd ).should == 1
24
+ @entry.cget(:bg ).should == "#ffffff"
25
+ @entry.cget(:borderwidth ).should == 1
26
+ @entry.cget(:cursor ).should == "xterm"
27
+ @entry.cget(:disabledbackground ).should == "#d9d9d9"
28
+ @entry.cget(:disabledforeground ).should == "#a3a3a3"
29
+ @entry.cget(:exportselection ).should == true
30
+ @entry.cget(:fg ).should == "#000000"
31
+ @entry.cget(:font ).should == "TkTextFont"
32
+ @entry.cget(:foreground ).should == "#000000"
33
+ @entry.cget(:highlightbackground).should == "#d9d9d9"
34
+ @entry.cget(:highlightcolor ).should == "#000000"
35
+ @entry.cget(:highlightthickness ).should == 1
36
+ @entry.cget(:insertbackground ).should == "#000000"
37
+ @entry.cget(:insertborderwidth ).should == 0
38
+ @entry.cget(:insertofftime ).should == 300
39
+ @entry.cget(:insertontime ).should == 600
40
+ @entry.cget(:insertwidth ).should == 2
41
+ @entry.cget(:invalidcommand ).should == nil
42
+ @entry.cget(:invcmd ).should == nil
43
+ @entry.cget(:justify ).should == :left
44
+ @entry.cget(:readonlybackground ).should == "#d9d9d9"
45
+ @entry.cget(:relief ).should == :sunken
46
+ @entry.cget(:selectbackground ).should == "#c3c3c3"
47
+ @entry.cget(:selectborderwidth ).should == 0
48
+ @entry.cget(:selectforeground ).should == "#000000"
49
+ @entry.cget(:show ).should == nil
50
+ @entry.cget(:state ).should == ['normal']
51
+ @entry.cget(:takefocus ).should == false
52
+ @entry.cget(:textvariable ).should == nil
53
+ @entry.cget(:validate ).should == :none
54
+ @entry.cget(:validatecommand ).should == nil
55
+ @entry.cget(:vcmd ).should == nil
56
+ @entry.cget(:width ).should == 20
57
+ @entry.cget(:xscrollcommand ).should == nil
58
+ end
59
+
60
+ it 'configures a single option' do
61
+ @entry.configure(validate: :focus)
62
+ @entry.cget(:validate).should == :focus
63
+ @entry.configure(validate: :none)
64
+ @entry.cget(:validate).should == :none
65
+ end
66
+
67
+ it 'configures more options at once' do
68
+ @entry.configure(justify: :right, validate: :focus)
69
+ @entry.cget(:validate).should == :focus
70
+ @entry.cget(:justify).should == :right
71
+
72
+ @entry.configure(justify: :left, validate: :none)
73
+ @entry.cget(:validate).should == :none
74
+ @entry.cget(:justify).should == :left
75
+ end
76
+
77
+ it "deletes character at index" do
78
+ @entry.delete(5)
79
+ @entry.get.should == "Hello World!"
80
+ end
81
+
82
+ it "deletes character between indices" do
83
+ @entry.delete(5, 11)
84
+ @entry.get.should == "Hello!"
85
+ end
86
+
87
+ it "Puts the insertion cursor just before the character given by index" do
88
+ @entry.icursor(5)
89
+ @entry.insert(:insert, ", World")
90
+ @entry.get.should == "Hello, World!"
91
+ end
92
+
93
+ it "Returns the numerical index corresponding to index" do
94
+ @entry.index(:insert).should == 12
95
+ end
96
+
97
+ it "Insert the string just before the character indicated by index" do
98
+ @entry.insert(0, 'OHAI ')
99
+ @entry.get.should == 'OHAI Hello, World!'
100
+ end
101
+
102
+ it 'uses the scan commands' do
103
+ lambda{
104
+ @entry.scan_mark(0)
105
+ @entry.scan_dragto(10)
106
+ }.should.not.raise
107
+ end
108
+
109
+ it 'Returns whether a selection is present' do
110
+ @entry.selection_present.should == false
111
+ end
112
+
113
+ it 'adjusts the selection' do
114
+ @entry.selection_adjust(0)
115
+ @entry.index('sel.first').should == 0
116
+ @entry.selection_adjust(5)
117
+ @entry.index('sel.last').should == 5
118
+ end
119
+
120
+ it 'Clears the selection' do
121
+ @entry.selection_present.should == true
122
+ @entry.selection_clear
123
+ @entry.selection_present.should == false
124
+ end
125
+
126
+ it 'Selects the characters at start ending with the one just before end' do
127
+ @entry.selection_range(1, 4)
128
+ @entry.index('sel.first').should == 1
129
+ @entry.index('sel.last').should == 4
130
+ end
131
+
132
+ it 'Adjusts selection with the from and to commands' do
133
+ @entry.selection_from(2)
134
+ @entry.selection_to(5)
135
+ @entry.index('sel.first').should == 2
136
+ @entry.index('sel.last').should == 5
137
+ end
138
+
139
+ it 'validates the entry without validation command' do
140
+ @entry.validate.should == true
141
+ end
142
+
143
+ it 'validates the entry with validation command' do
144
+ @entry.configure validatecommand: lambda{|*args| true }
145
+ @entry.validate.should == true
146
+
147
+ @entry.configure validatecommand: lambda{|*args| false }
148
+ @entry.validate.should == false
149
+ end
150
+ end
151
+
152
+ # puts
153
+ # @entry.configure.map{|c| c.first[1..-1] }.each{|k,v|
154
+ # puts "@entry.cget(%-20p).should == %p" % [k.to_sym, @entry.cget(k)]
155
+ # }