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,185 @@
1
+ require_relative '../../helper'
2
+
3
+ Tk.init
4
+
5
+ describe Tk::WM do
6
+ root = Tk.root
7
+
8
+ # FIXME: following methods have no specs yet because image commands are missing.
9
+ # * WM.forget
10
+ # * WM.iconbitmap
11
+ # * WM.iconmask
12
+ # * WM.iconname
13
+ # * WM.iconphoto
14
+ # * WM.iconposition
15
+ # * WM.iconwindow
16
+
17
+ describe "WM.aspect" do
18
+ should 'list current attributes' do
19
+ root.wm_aspect.should == nil
20
+ end
21
+
22
+ should 'set aspect ratio' do
23
+ root.wm_aspect = [1, 1, 1, 1]
24
+ root.wm_aspect.should == [1, 1, 1, 1]
25
+ end
26
+
27
+ should 'remove aspect ratio' do
28
+ root.wm_aspect = nil
29
+ root.wm_aspect.should == nil
30
+ end
31
+ end
32
+
33
+ describe 'WM.attributes' do
34
+ it 'lists current attributes' do
35
+ attrs = root.wm_attributes
36
+ attrs[:alpha].should == 1.0
37
+ attrs[:topmost].should == false
38
+ attrs[:zoomed].should == false
39
+ attrs[:fullscreen].should == false
40
+ end
41
+
42
+ it 'queries one attribute' do
43
+ root.wm_attributes(:alpha).should == 1.0
44
+ root.wm_attributes(:topmost).should == false
45
+ root.wm_attributes(:zoomed).should == false
46
+ root.wm_attributes(:fullscreen).should == false
47
+ end
48
+
49
+ it 'sets attributes' do
50
+ root.wm_attributes(fullscreen: true)
51
+
52
+ Tk.interp.do_events_until do
53
+ root.wm_attributes(:fullscreen)
54
+ end
55
+
56
+ root.wm_attributes(:fullscreen).should == true
57
+ root.wm_attributes(fullscreen: false)
58
+
59
+ # TODO somehow fullscreen doesn't change back, on tk side.
60
+ #Tk.interp.do_events_until do
61
+ # root.wm_attributes(:fullscreen) == false
62
+ #end
63
+
64
+ #root.wm_attributes(:fullscreen).should == false
65
+ end
66
+ end
67
+
68
+ describe 'WM.client' do
69
+ it 'has empty WM_CLIENT_MACHINE property' do
70
+ root.wm_client.should == nil
71
+ end
72
+
73
+ it 'sets WM_CLIENT_MACHINE property' do
74
+ root.wm_client = 'foo'
75
+ root.wm_client.should == 'foo'
76
+ root.wm_client = nil
77
+ root.wm_client.should == nil
78
+ end
79
+ end
80
+
81
+ describe 'WM.colormapwindows' do
82
+ it 'queries the WM_COLORMAP_WINDOWS property' do
83
+ root.wm_colormapwindows.should == []
84
+ end
85
+
86
+ it 'sets WM_COLORMAP_WINDOWS property' do
87
+ root.wm_colormapwindows = root
88
+ root.wm_colormapwindows.should == ['.']
89
+ end
90
+ end
91
+
92
+ describe 'WM.command' do
93
+ it 'queries the WM_COMMAND property' do
94
+ root.wm_command.should == []
95
+ end
96
+
97
+ it 'sets queries the WM_COMMAND property' do
98
+ root.wm_command = ['foo', 'bar']
99
+ root.wm_command.should == ['foo', 'bar']
100
+ root.wm_command = []
101
+ root.wm_command.should == []
102
+ end
103
+ end
104
+
105
+ describe 'WM.focusmodel' do
106
+ it 'queries the current focusmdoel' do
107
+ root.wm_focusmodel.should == :passive
108
+ end
109
+
110
+ it 'sets the focusmodel' do
111
+ root.wm_focusmodel = :active
112
+ root.wm_focusmodel.should == :active
113
+ root.wm_focusmodel = :passive
114
+ root.wm_focusmodel.should == :passive
115
+ end
116
+ end
117
+
118
+ describe 'WM.frame' do
119
+ it 'queries the frame info' do
120
+ root.wm_frame.should.not.be.empty
121
+ end
122
+ end
123
+
124
+ describe 'WM.geometry' do
125
+ it 'queries geometry' do
126
+ geometry = root.wm_geometry
127
+ geometry.should.not.be.nil
128
+ geometry.width.should.respond_to :to_int
129
+ geometry.height.should.respond_to :to_int
130
+ geometry.x.should.respond_to :to_int
131
+ geometry.y.should.respond_to :to_int
132
+ end
133
+
134
+ it 'sets geometry' do
135
+ geometry = root.wm_geometry
136
+ root.wm_geometry = '640x480+0+0'
137
+
138
+ Tk.interp.do_events_until do
139
+ root.wm_geometry != geometry
140
+ end
141
+
142
+ root.wm_geometry.should.not == geometry
143
+ end
144
+ end
145
+
146
+ describe 'WM.grid' do
147
+ it 'queries grid info when no grid is set' do
148
+ root.wm_grid.should == nil
149
+ end
150
+
151
+ it 'sets a grid' do
152
+ root.wm_grid = [1,1,1,1]
153
+ root.wm_grid.should == [1,1,1,1]
154
+ end
155
+ end
156
+
157
+ describe 'WM.group' do
158
+ it 'queries group pathname' do
159
+ root.wm_group.should == nil
160
+ end
161
+
162
+ it 'sets group pathname' do
163
+ root.wm_group = '.'
164
+ root.wm_group.should == '.'
165
+ end
166
+ end
167
+
168
+ describe 'WM.iconbitmap' do
169
+ it 'queries iconbitmap' do
170
+ root.wm_iconbitmap.should == nil
171
+ end
172
+
173
+ it 'sets iconbitmap' do
174
+ lambda{ root.wm_iconbitmap = 'some.gif' }.
175
+ should.raise.message.should =~ /^bitmap "some.gif" not defined/
176
+ end
177
+ end
178
+
179
+ describe 'WM.iconify and WM.deiconify' do
180
+ it 'iconifies the window' do
181
+ root.wm_iconify.should == true
182
+ root.wm_deiconify.should == true
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,95 @@
1
+ require_relative '../helper'
2
+
3
+ describe Tk::Event do
4
+ it 'gives a list of defined virtual events' do
5
+ Tk::Event.info.sort.should == [
6
+ "<<Copy>>", "<<Cut>>", "<<Paste>>", "<<PasteSelection>>",
7
+ "<<PrevWindow>>", "<<Redo>>", "<<Undo>>"
8
+ ]
9
+ end
10
+
11
+ it 'shows what sequences invoke a specific virtual event' do
12
+ info = Tk::Event.info('<<Paste>>')
13
+ info.should.include '<Control-Key-v>'
14
+ info.should.is_a? Array
15
+ #"<Control-Key-v>", "<Key-F18>", "<Control-Key-y>"
16
+ #"<Control-Key-v>", "<Key-F18>", "<Control-Lock-Key-V>", "<Control-Key-y>"
17
+ end
18
+
19
+ it 'adds a virtual event' do
20
+ Tk::Event.add('<<Spec>>', '<Control-Alt-Key-Escape>')
21
+ Tk::Event.info.should.include('<<Spec>>')
22
+ Tk::Event.info('<<Spec>>').should == ['<Control-Alt-Key-Escape>']
23
+ end
24
+
25
+ it 'deletes a virtual event' do
26
+ Tk::Event.delete('<<Spec>>', '<Control-Alt-Key-Escape>')
27
+ Tk::Event.info.should.not.include('<<Spec>>')
28
+ Tk::Event.info('<<Spec>>').should == []
29
+ end
30
+
31
+ it 'generates a virtual event and calls it' do
32
+ Tk::Event.add('<<Clear>>', '<BackSpace>')
33
+
34
+ entry = Tk::Entry.new('.')
35
+ entry.bind('<<Clear>>'){ entry.delete(0, :end) }
36
+ entry.bind('<Map>'){
37
+ Tk::Event.generate(entry, '<<Clear>>')
38
+ Tk.interp.do_one_event
39
+ }
40
+ entry.insert 0, 'Hello, World!'
41
+ entry.get.should == 'Hello, World!'
42
+
43
+ entry.pack
44
+ entry.focus
45
+
46
+ Tk.interp.do_events_until{
47
+ entry.get.empty?
48
+ }
49
+
50
+ entry.get.should == ''
51
+ end
52
+
53
+ it 'generates a virtual event and calls normal event' do
54
+ Tk::Event.add('<<Clear>>', '<BackSpace>')
55
+
56
+ entry = Tk::Entry.new('.')
57
+ entry.bind('<<Clear>>'){ entry.delete(0, :end) }
58
+ entry.bind('<Map>'){
59
+ entry.focus
60
+ Tk::Event.generate(entry, '<BackSpace>')
61
+ Tk.interp.do_one_event
62
+ }
63
+ entry.insert 0, 'Hello, World!'
64
+ entry.get.should == 'Hello, World!'
65
+
66
+ entry.pack
67
+ entry.focus
68
+
69
+ Tk.interp.do_events_until{
70
+ entry.get.empty?
71
+ }
72
+
73
+ entry.get.should == ''
74
+ end
75
+
76
+ it 'associates event with button and calls it' do
77
+ entered = false
78
+
79
+ entry = Tk::Entry.new('.')
80
+ entry.bind('<Key>'){ entered = true; Tk.stop }
81
+ entry.bind('<Map>'){
82
+ entry.focus
83
+ Tk::Event.generate(entry, '<KeyPress-a>')
84
+ }
85
+
86
+ entry.pack
87
+ entry.focus
88
+
89
+ Tk.interp.do_events_until{
90
+ entered
91
+ }
92
+
93
+ entered.should == true
94
+ end
95
+ end
@@ -0,0 +1,51 @@
1
+ require_relative '../../helper'
2
+
3
+ Tk.init
4
+
5
+ describe Tk::Tile::Button do
6
+ Style = Tk::Tile::Style
7
+ Button = Tk::Tile::Button
8
+
9
+ it 'sets default to normal, active, or disabled' do
10
+ button = Button.new('.')
11
+ button.cget(:default).should == 'normal'
12
+
13
+ %w{normal active disabled}.each do |state|
14
+ button = Button.new('.', default: state )
15
+ button.cget(:default).should == state
16
+ end
17
+
18
+ lambda {
19
+ Button.new('.', default: 'unkown-')
20
+ }.should.raise RuntimeError
21
+ end
22
+
23
+ it 'sets width and height' do
24
+ button = Button.new('.')
25
+ button.cget(:width).should == 0
26
+
27
+ [10, -10, 10.0, -10.0].each do |i|
28
+ button = Button.new('.', width: i.to_i)
29
+ button.cget(:width).should == i.to_i
30
+
31
+ button = Button.new('.', width: i.to_f)
32
+ button.cget(:width).should == 0
33
+ end
34
+ end
35
+
36
+ # behaves_like Tk::Button -command
37
+ it 'handles -command' do
38
+ ran = false
39
+ Tk.callbacks.size.should == 0
40
+
41
+ button = Button.new('.'){
42
+ ran = true
43
+ button.destroy
44
+ }
45
+ button.invoke
46
+
47
+ Tk.callbacks.size.should == 0
48
+ ran.should == true
49
+ end
50
+ end
51
+
@@ -0,0 +1,13 @@
1
+ require_relative '../../helper'
2
+
3
+ describe Tk::Tile::CheckButton do
4
+ it 'initializes' do
5
+ instance = Tk::Tile::CheckButton.new
6
+ instance.class.should == Tk::Tile::CheckButton
7
+ instance.tk_parent.should == Tk.root
8
+ end
9
+
10
+ it 'needs more specs' do
11
+ end
12
+ end
13
+
@@ -0,0 +1,65 @@
1
+ require_relative '../../helper'
2
+
3
+ describe Tk::Tile::ComboBox do
4
+ it 'initializes' do
5
+ instance = Tk::Tile::ComboBox.new
6
+ instance.class.should == Tk::Tile::ComboBox
7
+ instance.tk_parent.should == Tk.root
8
+ end
9
+
10
+ it 'sets combobox values' do
11
+ b = Tk::Tile::ComboBox.new Tk.root, values: ['a','b']
12
+ b.configure(values: ['c','d']).should == true
13
+ end
14
+
15
+ it 'sets the current value' do
16
+ var = Tk::Variable.new('somevar')
17
+ var.set 'before_combobox'
18
+
19
+ b = Tk::Tile::ComboBox.new Tk.root, textvariable: var, values: ['a','b']
20
+
21
+ b.current.should == -1
22
+
23
+ b.current(1).should == true
24
+ b.current.should == 1
25
+
26
+ var.to_s.should == 'b'
27
+
28
+ b.set('baz').should == true
29
+ var.to_s.should == 'baz'
30
+
31
+ lambda {
32
+ b.current(10).should == false
33
+ }.should.raise RuntimeError
34
+ end
35
+
36
+ it 'sets the value of the combobox to value' do
37
+ b = Tk::Tile::ComboBox.new
38
+ b.set(0).should == true
39
+ b.set(1).should == true
40
+ end
41
+
42
+ it 'gets the current value of the combobox' do
43
+ b = Tk::Tile::ComboBox.new
44
+ b.get.should == ''
45
+
46
+ b.set(1).should == true
47
+ b.get.should == '1'
48
+
49
+ b.set('baz').should == true
50
+ b.get.should == 'baz'
51
+ end
52
+
53
+ it 'sets postcommand' do
54
+ lambda {
55
+ Tk::Tile::ComboBox.new Tk.root, postcommand: proc {}
56
+ }.should.not.raise RuntimeError
57
+
58
+ lambda {
59
+ b = Tk::Tile::ComboBox.new
60
+ b.postcommand { }
61
+ }.should.not.raise RuntimeError
62
+ end
63
+
64
+ end
65
+
@@ -0,0 +1,61 @@
1
+ require_relative '../../helper'
2
+
3
+ Tk.init
4
+
5
+ describe Tk::Tile::Entry do
6
+ Entry = Tk::Tile::Entry
7
+ @entry = Entry.new('.')
8
+
9
+ it 'Returns the current value of the configuration option given' do
10
+ Tk::Tile::Style.theme_use 'alt'
11
+
12
+ @entry.cget(:width ).should >= 0
13
+ @entry.cget(:exportselection ).should == true
14
+ #@entry.cget(:font ).should == "TkTextFont"
15
+ @entry.cget(:invalidcommand ).should == nil
16
+ @entry.cget(:justify ).should == :left
17
+ @entry.cget(:validate ).should == :none
18
+ @entry.cget(:validatecommand ).should == nil
19
+ @entry.cget(:width ).should == 20
20
+ @entry.cget(:xscrollcommand ).should == nil
21
+
22
+ @entry.cget(:takefocus ).should == false
23
+ @entry.cget(:textvariable ).should == nil # ""
24
+ end
25
+
26
+ it 'sets ttk-state independent of tk-state' do
27
+ @entry.cget(:state).should == ['normal']
28
+ @entry.configure(state: 'normal').should == true
29
+ @entry.cget(:state).should == ['normal']
30
+
31
+ @entry.state(:active).should == true
32
+ @entry.state.should == ['active']
33
+
34
+ @entry.state(:disabled).should == true
35
+ @entry.state.should == ['active','disabled']
36
+
37
+ @entry.cget(:state).should == ['normal']
38
+ end
39
+
40
+ it 'sets ttk-state independent of tk-state (or not?)' do
41
+ @entry.cget(:state).should == ['normal']
42
+ @entry.configure(state: 'disabled').should == true
43
+ @entry.cget(:state).should == ['disabled']
44
+
45
+ @entry.state(:active).should == true
46
+ @entry.state.should == ['active','disabled']
47
+
48
+ @entry.state(:disabled).should == true
49
+ @entry.state.should == ['active','disabled']
50
+
51
+ @entry.cget(:state).should == ['disabled']
52
+ end
53
+
54
+ #NOTE fails on 'bacon spec/tile/*' but passes with 'ruby __FILE__'
55
+ #it 'Configure the current value of cursor' do
56
+ # @entry.cget(:cursor ).should == nil #"xterm"
57
+ # @entry.configure(cursor: 'xterm').should == true
58
+ # @entry.cget(:cursor ).should == 'xterm'
59
+ #end
60
+ end
61
+