tkxxs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjI5OGY5YjdkM2I1ZmRmY2I4ZWQ3NTI4NWNjNjUyNDFlZWFjODMzMg==
5
+ data.tar.gz: !binary |-
6
+ M2E4NjdlNTU4ZjM3ZjRhZTVkMGM2ZTJhOGIzNTkzMmQ2ZTA1NDI1Yg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ N2U0MjBlMmZmMGQ2NGMxYzRlYWFhNWZkOWM5NDNhZWMwZDBmNWM0ZmUwMzk4
10
+ NzhmOTIwYTRmMWE1MjU0ZTZmNmQzMjI3ZTc3MzZhODRkODI2NzZkMDE5ODBh
11
+ N2NmMjdmOTZjNGFhOGZiZDZjZWU1Yzg2ZmZjNWU2YmQzNjIyZTc=
12
+ data.tar.gz: !binary |-
13
+ Y2Y2MTAyZDhkZmNiY2QyNjRiMmZlMzQ3NzVlMzQwYjU5YzZhNzViY2IwMzRj
14
+ NGYzNmU2MGM4OTJjM2ExOGUwZDQ5NWI1YjU1MzVkNDA3NjQ5ODYxMzAyNWM1
15
+ NWUxOGZiZTExZGIwZDg3MmVlOWI5NjMxOGE5Y2YyNjg2YzMzM2U=
@@ -0,0 +1,25 @@
1
+ # -*- ruby -*-
2
+
3
+ require "autotest/restart"
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.testlib = "minitest/unit"
7
+ #
8
+ # at.extra_files << "../some/external/dependency.rb"
9
+ #
10
+ # at.libs << ":../some/external"
11
+ #
12
+ # at.add_exception "vendor"
13
+ #
14
+ # at.add_mapping(/dependency.rb/) do |f, _|
15
+ # at.files_matching(/test_.*rb$/)
16
+ # end
17
+ #
18
+ # %w(TestA TestB).each do |klass|
19
+ # at.extra_class_map[klass] = "test/test_misc.rb"
20
+ # end
21
+ # end
22
+
23
+ # Autotest.add_hook :run_command do |at|
24
+ # system "rake build"
25
+ # end
File without changes
@@ -0,0 +1,2 @@
1
+
2
+ * Axel Friedrich: axel dod friedrich_smail ad gmx dod de
@@ -0,0 +1,6 @@
1
+ === 0.1.0 / 2014-01-01
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Axel Friedrich and contributors (see the CONTRIBUTORS file)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ .autotest
2
+ CONTRIBUTORS
3
+ History.txt
4
+ LICENSE
5
+ Manifest.txt
6
+ README.txt
7
+ Rakefile
8
+ ext/readme.txt
9
+ ext/tkballoonhelp.rb
10
+ ext/tkballoonhelp_ORIGINAL.rb
11
+ images/screenshot.png
12
+ lib/icon.gif
13
+ lib/tkxxs.rb
14
+ lib/tkxxs/conf.rb
15
+ lib/tkxxs/tkxxs_classes.rb
16
+ lib/tkxxs/version.rb
17
+ rdoc_developers_hanna.bat
18
+ rdoc_users_hanna.bat
19
+ samples/big_example.rb
20
+ samples/small_example.rb
@@ -0,0 +1,168 @@
1
+ = TKXXS
2
+
3
+ * https://github.com/Axel2
4
+
5
+ == References
6
+
7
+ * Reference for input dialogs: TKXXS
8
+ * Reference for the output window: TKXXS::OutW
9
+
10
+ TKXXS_CLASSES is intended for developers only.
11
+
12
+
13
+ == Description
14
+
15
+ TKXXS provides a very simple and very easy to use GUI (graphical user interface) for Ruby; It gives you a persistent output window and popping up (modal) dialogs for input; For a screenshot, see: images/screenshot.png; Tested on Windows, only.
16
+
17
+ TKXXS shall:
18
+
19
+ * improve the usability of little applications, which otherwise would use a command line interface (CLI); for example by a GUI-file chooser
20
+ * give a simple GUI front-end for apps, which take parameters on the command line. (stdout can easily be redirected to the OutputWindow.)
21
+ * take only little more effort and coding time over programming a CLI;
22
+ * be able to easily upgrade existing CLI-applications;
23
+ * be comfortable in use (e.g. provide incremental search, tool-tip-help, ...);
24
+ * be easy to install.
25
+
26
+
27
+ Drawbacks:
28
+ * I'v tested it only on Windows. Other operating system probably will need modifications, which I would like to merge in.
29
+ * For sure some more drawbacks which I'm not aware of now.
30
+
31
+
32
+ TKXXS uses TK (easy to install).
33
+
34
+
35
+ == Dialogs
36
+
37
+ As of now, the following dialogs exist:
38
+
39
+ * ask_single_line
40
+ * single_choice
41
+ * multi_choice
42
+ * open_file
43
+ * open_files
44
+ * choose_dir
45
+ * save_file
46
+
47
+ All dialog-methods have three arguments:
48
+
49
+ * Arg #1: (mostly optional) "The most important thing for this dialog"
50
+ * ask_single_line -> question
51
+ * single_choice -> choices (not optional)
52
+ * multi_choice -> choices (not optional)
53
+ * open_file -> initialdir
54
+ * open_files -> initialdir
55
+ * choose_dir -> initialdir
56
+ * save_file -> filename
57
+ * Arg #2: (optional) Help string, which is shown in the balloon help
58
+ * Arg #3: (optional) Hash, which takes additional arguments and optionally Arg#1 and Arg#2.
59
+
60
+ == Small Example (see: samples/small_example.rb)
61
+
62
+ require 'tkxxs'
63
+ include TKXXS
64
+
65
+ class MyTinyUI
66
+
67
+ def initialize( )
68
+ @outW = OutW.new # create Output Window
69
+ @outW.puts "Hello"
70
+ ask_name
71
+
72
+ Tk.mainloop # You always needs this!
73
+ end # initialize
74
+
75
+ def ask_name( )
76
+ name = ask_single_line("Your name?")
77
+ @outW.puts "Hello #{name}."
78
+ end # ask_name
79
+ end
80
+
81
+ MyTinyUI.new
82
+
83
+
84
+ When running this script, you should resize the popping up windows as you like; size and position will be stored for the next time.
85
+
86
+ You close the application simply by clicking the close-icon on top of the output window.
87
+
88
+ == More elaborated example
89
+
90
+ See samples/big_example.rb
91
+
92
+
93
+ == Installation
94
+
95
+ === Prerequisites
96
+
97
+ * Tested only on Windows
98
+ * Ruby 1.8.7 or 1.9.x with TK (e.g. RubyInstaller)
99
+ * gem Platform (starting with capital letter "P"!)
100
+
101
+ === Install
102
+
103
+ gem install tkxxs
104
+
105
+ == Misc
106
+
107
+ TKXXS stands for "TK very very small".
108
+
109
+ == TODO
110
+
111
+ * TODO: Encodings OK?
112
+ * TODO: Write instruction for using OCRA with TKXXS.
113
+ * TODO: There are several not-so-good things; I marked them with "TODO" in the doc and in the source code.
114
+ * TODO: Find somebody to improve the English wording.
115
+ * TODO: Prepare for localization (at least, translation). May be these are a starting points:
116
+ * discussion[https://www.ruby-forum.com/topic/178478]
117
+ * discussion[https://www.ruby-forum.com/topic/4402551]
118
+ * ruby-gettext[http://www.yotabanana.com/hiki/ruby-gettext.html]
119
+ * r18n[https://github.com/ai/r18n]
120
+ * i18n[http://guides.rubyonrails.org/i18n.html]
121
+
122
+ == Future
123
+
124
+ 2013-12-29: I wrote this code several years ago. Now I thought I should document it and give it to public. I'll _not_ develop it further, but I'll try to include pull requests.
125
+
126
+ == For developers
127
+
128
+ * For user's doc, tkxxs_classes.rb is not rdoc'ed in order to get a clearer documentation.
129
+ * To create documentation of all files:
130
+ <tt>rdoc -t TKXXS --force-update [-f hanna] -x ./samples --main ./tkxxs/README.rdoc ./tkxxs/README.rdoc ./lib</tt>
131
+ * Class names inside module TKXXS_CLASSES end with capital letter D.
132
+ * Arguments of "initialize" in tkxxs_classes.rb are documented at the corresponding module methods of TKXXS, if they exist (to avoid duplicates of documentation).
133
+
134
+
135
+ == LICENSE:
136
+
137
+ (The MIT License)
138
+
139
+ Copyright (c) 2010-2014 Axel Friedrich and contributors (see the CONTRIBUTORS file)
140
+
141
+ Permission is hereby granted, free of charge, to any person obtaining
142
+ a copy of this software and associated documentation files (the
143
+ 'Software'), to deal in the Software without restriction, including
144
+ without limitation the rights to use, copy, modify, merge, publish,
145
+ distribute, sublicense, and/or sell copies of the Software, and to
146
+ permit persons to whom the Software is furnished to do so, subject to
147
+ the following conditions:
148
+
149
+ The above copyright notice and this permission notice shall be
150
+ included in all copies or substantial portions of the Software.
151
+
152
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
153
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
154
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
155
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
156
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
157
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
158
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
@@ -0,0 +1,42 @@
1
+ # -*- ruby -*-
2
+
3
+ require "rubygems"
4
+ require "hoe"
5
+
6
+ Hoe.plugin :isolate
7
+ Hoe.plugin :seattlerb
8
+
9
+ # Hoe.plugin :compiler
10
+ # Hoe.plugin :doofus
11
+ # Hoe.plugin :email
12
+ # Hoe.plugin :gem_prelude_sucks
13
+ # Hoe.plugin :git
14
+ # Hoe.plugin :history
15
+ # Hoe.plugin :inline
16
+ # Hoe.plugin :isolate
17
+ # Hoe.plugin :minitest
18
+ # Hoe.plugin :perforce
19
+ # Hoe.plugin :racc
20
+ # Hoe.plugin :rcov
21
+ # Hoe.plugin :rubyforge
22
+ # Hoe.plugin :seattlerb
23
+
24
+ Hoe.spec "tkxxs" do
25
+ developer "Axel Friedrich", "axel dod friedrich underscore smail ad gmx dod de"
26
+ license "MIT"
27
+
28
+ spec_extras[:rdoc_options] = proc do |ary|
29
+ #rdoc.bat -t TKXXS --force-update -f hanna --op ./doc -x lib/tkxxs/tkxxs_classes.rb -x lib/tkxxs/samples --main ./README.txt ./README.txt ./lib/tkxxs.rb
30
+
31
+
32
+ ary.push "-x", "lib/tkxxs/tkxxs_classes.rb"
33
+ ary.push "-x", "lib/tkxxs/samples"
34
+ ary.push "-x", "lib/tkxxs/conf.rb"
35
+ end
36
+
37
+ dependency "Platform", "~> 0.4.0"
38
+ end
39
+
40
+ # vim: syntax=ruby
41
+
42
+
@@ -0,0 +1,3 @@
1
+ I took /ext/tk/sample/tkballonhelp.rb from Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) and modified it. A copy of the original file is tkballoonhelp_ORIGINAL.rb. As far as I know, licence is Ruby's licence. Newer version of this file are available here: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_3/ext/tk/sample/
2
+
3
+ Axel Friedrich
@@ -0,0 +1,332 @@
1
+ #
2
+ # tkballoonhelp.rb : simple balloon help widget
3
+ # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
4
+ #
5
+ # Add a balloon help to a widget.
6
+ # This widget has only poor featureas. If you need more useful features,
7
+ # please try to use the Tix extension of Tcl/Tk under Ruby/Tk.
8
+ #
9
+ # The interval time to display a balloon help is defined 'interval' option
10
+ # (default is 750ms).
11
+ #
12
+ # Modifications by Axel Friedrich:
13
+ # * 2010-03-01:
14
+ # * 2010-01-31: Shifting position of balloon if it is out of screen
15
+ # * TODO: wraplength
16
+ require 'tk'
17
+
18
+ module Tk
19
+ module RbWidget
20
+ class BalloonHelp<TkLabel
21
+ end
22
+ end
23
+ end
24
+ class Tk::RbWidget::BalloonHelp<TkLabel
25
+ DEFAULT_FOREGROUND = 'black'
26
+ DEFAULT_BACKGROUND = 'white'
27
+ DEFAULT_INTERVAL = 750
28
+
29
+ def _balloon_binding(interval)
30
+ @timer = TkAfter.new(interval, 1, proc{show})
31
+ def @timer.interval(val)
32
+ @sleep_time = val
33
+ end
34
+ @bindtag = TkBindTag.new
35
+ @bindtag.bind('Enter', proc{@timer.start})
36
+ @bindtag.bind('Motion', proc{@timer.restart; erase})
37
+ @bindtag.bind('Any-ButtonPress', proc{@timer.restart; erase})
38
+ @bindtag.bind('Leave', proc{@timer.stop; erase})
39
+ tags = @parent.bindtags
40
+ idx = tags.index(@parent)
41
+ unless idx
42
+ ppath = TkComm.window(@parent.path)
43
+ idx = tags.index(ppath) || 0
44
+ end
45
+ tags[idx,0] = @bindtag
46
+ @parent.bindtags(tags)
47
+ end
48
+ private :_balloon_binding
49
+
50
+ def initialize(parent=nil, keys={})
51
+ @parent = parent || Tk.root
52
+
53
+ @frame = TkToplevel.new(@parent)
54
+ if defined?($tkxxs_) && $tkxxs_[:userscreenx]
55
+ $balloonhlp_ = Hash.new
56
+ $balloonhlp_[:userscreenx] = $tkxxs_[:userscreenx]
57
+ $balloonhlp_[:userscreeny] = $tkxxs_[:userscreeny]
58
+ $balloonhlp_[:userscreenwidth] = $tkxxs_[:userscreenwidth]
59
+ $balloonhlp_[:userscreenheight] = $tkxxs_[:userscreenheight]
60
+ elsif !defined?($balloonhlp_) || !$balloonhlp_[:userscreenx]
61
+ userscreen(@frame)
62
+ end
63
+ @frame.withdraw
64
+ @frame.overrideredirect(true)
65
+ @frame.transient(TkWinfo.toplevel(@parent))
66
+ @epath = @frame.path
67
+
68
+ if keys
69
+ keys = _symbolkey2str(keys)
70
+ else
71
+ keys = {}
72
+ end
73
+
74
+ @command = keys.delete('command')
75
+
76
+ @interval = keys.delete('interval'){DEFAULT_INTERVAL}
77
+ _balloon_binding(@interval)
78
+
79
+ # @label = TkLabel.new(@frame, 'background'=>'bisque').pack
80
+ @label = TkLabel.new(@frame,
81
+ ## :wraplength => '2i', # Axel
82
+ 'foreground'=>DEFAULT_FOREGROUND,
83
+ ## 'background'=>DEFAULT_BACKGROUND).pack # -Axel
84
+ 'background'=>DEFAULT_BACKGROUND).pack(:expand=>1, :fill=>:both)
85
+ @label.configure(_symbolkey2str(keys)) unless keys.empty?
86
+ @path = @label
87
+ end
88
+
89
+ def userscreen( root )
90
+ # TODO: Screen "pops"; other way?
91
+ root.state('zoomed')
92
+ root.update
93
+
94
+ if RUBY_PLATFORM[/mingw|mswin|bccwin/ix] # Windows
95
+ root.state('zoomed') # OK on Windows, bad on Linux
96
+ else
97
+ # Linux: works
98
+ # Other: not tested
99
+ root.height = root.winfo_screenheight
100
+ root.width = root.winfo_screenwidth
101
+ end
102
+
103
+ root.winfo_geometry =~ /(\d+)x(\d+)\+([+-]?\d+)\+([+-]?\d+)/
104
+ xwg = $3.to_i
105
+ ywg = $4.to_i
106
+ root.geometry =~ /(\d+)x(\d+)\+([+-]?\d+)\+([+-]?\d+)/
107
+ gw = $1.to_i
108
+ gh = $2.to_i
109
+
110
+ ## sw = root.winfo_screenwidth
111
+ ## sh = root.winfo_screenheight
112
+
113
+ rx = root.winfo_rootx
114
+ ry = root.winfo_rooty # maybe, taskbar height
115
+
116
+ border = -[xwg,ywg].min
117
+ userscreenx = xwg + border
118
+ userscreeny= ywg + border
119
+ userscreenwidth = gw
120
+ userscreenheight = gh + ry - ywg - border
121
+
122
+ $balloonhlp_ ||= Hash.new
123
+ $balloonhlp_[:userscreenx ] = userscreenx
124
+ $balloonhlp_[:userscreeny ] = userscreeny
125
+ $balloonhlp_[:userscreenwidth ] = userscreenwidth
126
+ $balloonhlp_[:userscreenheight] = userscreenheight
127
+
128
+ root.state('normal')
129
+ nil
130
+ end # userscreen
131
+
132
+ def epath
133
+ @epath
134
+ end
135
+
136
+ def interval(val)
137
+ if val
138
+ @timer.interval(val)
139
+ else
140
+ @interval
141
+ end
142
+ end
143
+
144
+ def command(cmd = Proc.new)
145
+ @command = cmd
146
+ self
147
+ end
148
+
149
+ def show
150
+ x = TkWinfo.pointerx(@parent)
151
+ y = TkWinfo.pointery(@parent)
152
+ ## @frame.geometry("+#{x+1}+#{y+1}")
153
+
154
+ if @command
155
+ case @command.arity
156
+ when 0
157
+ @command.call
158
+ when 2
159
+ @command.call(x - TkWinfo.rootx(@parent), y - TkWinfo.rooty(@parent))
160
+ when 3
161
+ @command.call(x - TkWinfo.rootx(@parent), y - TkWinfo.rooty(@parent),
162
+ self)
163
+ else
164
+ @command.call(x - TkWinfo.rootx(@parent), y - TkWinfo.rooty(@parent),
165
+ self, @parent)
166
+ end
167
+ end
168
+
169
+ @frame.geometry("+#{x+1}+#{y+1}")
170
+ @frame.update
171
+
172
+ rw = TkWinfo.reqwidth(@frame)
173
+ rh = TkWinfo.reqheight(@frame)
174
+ geom1 = geom(x,y,rw,rh)
175
+ @frame.geometry(geom1)
176
+
177
+ @frame.deiconify
178
+ @frame.raise
179
+
180
+ ## @org_cursor = @parent['cursor'] # -patch Nagai
181
+ ## @parent.cursor('crosshair') # -patch Nagai
182
+ begin # +patch Nagai
183
+ @org_cursor = @parent.cget('cursor') # +patch Nagai
184
+ rescue # +patch Nagai
185
+ @org_cursor = @parent['cursor'] # +patch Nagai
186
+ end # +patch Nagai
187
+ begin # +patch Nagai
188
+ @parent.configure('cursor', 'crosshair') # +patch Nagai
189
+ rescue # +patch Nagai
190
+ @parent.cursor('crosshair') # +patch Nagai
191
+ end # +patch Nagai
192
+
193
+ @frame.update
194
+ end
195
+
196
+ def geom( x,y,rw,rh, gapx=1, gapy=10 ) # gap: pixels; may not be 0!
197
+ xcorrected = false
198
+ ## rw = TkWinfo.reqwidth(@frame)
199
+ ## rh = TkWinfo.reqheight(@frame)
200
+ xmin = $balloonhlp_[:userscreenx]
201
+ ymin = $balloonhlp_[:userscreeny]
202
+ xmax= xmin + $balloonhlp_[:userscreenwidth]
203
+ ymax= ymin + $balloonhlp_[:userscreenheight]
204
+
205
+ origx = x
206
+ x += gapx
207
+ y += gapy
208
+
209
+ if x + rw > xmax
210
+ x = [(xmax-rw), xmin].max # Shift left
211
+ xcorrected = true
212
+ end
213
+
214
+ y = y - gapy - rh if y + rh > ymax # Shift up
215
+
216
+ if y < ymin # height will overlap pointer
217
+ y = ymin
218
+ x = origx - rw - gapx if xcorrected # Shift left
219
+ end
220
+
221
+ if x < xmin # to big
222
+ x = xmin
223
+ wrap_help
224
+ end
225
+ geom = "+#{ x }+#{ y }" # balloon may not overlap cursor - why?
226
+
227
+ geom
228
+ end # geom
229
+
230
+
231
+ def wrap_help( )
232
+ #TODO: Introduce "wraplength"
233
+ puts 'Cannot show balloon help: to big.'
234
+ end # wrap_help
235
+
236
+
237
+ def erase
238
+ ## @parent.cursor(@org_cursor) # -patch Nagai
239
+ begin # +patch Nagai
240
+ @parent.configure('cursor', @org_cursor) # +patch Nagai
241
+ rescue # +patch Nagai
242
+ @parent.cursor(@org_cursor) # +patch Nagai
243
+ end # +patch Nagai
244
+ @frame.withdraw
245
+ end
246
+
247
+ def destroy
248
+ @frame.destroy
249
+ end
250
+ end
251
+
252
+ ################################################
253
+ # test
254
+ ################################################
255
+ if __FILE__ == $0
256
+ TkButton.new('text'=>'This button has a balloon help') {|b|
257
+ pack('fill'=>'x')
258
+ Tk::RbWidget::BalloonHelp.new(b, 'text'=>' Message ')
259
+ }
260
+ TkButton.new('text'=>'This button has another balloon help') {|b|
261
+ pack('fill'=>'x')
262
+ Tk::RbWidget::BalloonHelp.new(b,
263
+ 'text'=>"CONFIGURED MESSAGE\nchange colors, and so on",
264
+ 'interval'=>200, 'font'=>'courier',
265
+ 'background'=>'gray', 'foreground'=>'red')
266
+ }
267
+
268
+ sb = TkScrollbox.new.pack(:fill=>:x)
269
+ sb.insert(:end, *%w(aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm))
270
+ =begin
271
+ # CASE1 : command takes no arguemnt
272
+ bh = Tk::RbWidget::BalloonHelp.new(sb, :interval=>500,
273
+ :relief=>:ridge, :background=>'white',
274
+ :command=>proc{
275
+ y = TkWinfo.pointery(sb) - TkWinfo.rooty(sb)
276
+ bh.text "current index == #{sb.nearest(y)}"
277
+ })
278
+ =end
279
+ =begin
280
+ # CASE2 : command takes 2 arguemnts
281
+ bh = Tk::RbWidget::BalloonHelp.new(sb, :interval=>500,
282
+ :relief=>:ridge, :background=>'white',
283
+ :command=>proc{|x, y|
284
+ bh.text "current index == #{sb.nearest(y)}"
285
+ })
286
+ =end
287
+ =begin
288
+ # CASE3 : command takes 3 arguemnts
289
+ Tk::RbWidget::BalloonHelp.new(sb, :interval=>500,
290
+ :relief=>:ridge, :background=>'white',
291
+ :command=>proc{|x, y, bhelp|
292
+ bhelp.text "current index == #{sb.nearest(y)}"
293
+ })
294
+ =end
295
+ =begin
296
+ # CASE4a : command is a Proc object and takes 4 arguemnts
297
+ cmd = proc{|x, y, bhelp, parent|
298
+ bhelp.text "current index == #{parent.nearest(y)}"
299
+ }
300
+
301
+ Tk::RbWidget::BalloonHelp.new(sb, :interval=>500,
302
+ :relief=>:ridge, :background=>'white',
303
+ :command=>cmd)
304
+
305
+ sb2 = TkScrollbox.new.pack(:fill=>:x)
306
+ sb2.insert(:end, *%w(AAA BBB CCC DDD EEE FFF GGG HHH III JJJ KKK LLL MMM))
307
+ Tk::RbWidget::BalloonHelp.new(sb2, :interval=>500,
308
+ :padx=>5, :relief=>:raised,
309
+ :background=>'gray25', :foreground=>'white',
310
+ :command=>cmd)
311
+ =end
312
+ #=begin
313
+ # CASE4b : command is a Method object and takes 4 arguemnts
314
+ def set_msg(x, y, bhelp, parent)
315
+ bhelp.text "current index == #{parent.nearest(y)}"
316
+ end
317
+ cmd = self.method(:set_msg)
318
+
319
+ Tk::RbWidget::BalloonHelp.new(sb, :interval=>500,
320
+ :relief=>:ridge, :background=>'white',
321
+ :command=>cmd)
322
+
323
+ sb2 = TkScrollbox.new.pack(:fill=>:x)
324
+ sb2.insert(:end, *%w(AAA BBB CCC DDD EEE FFF GGG HHH III JJJ KKK LLL MMM))
325
+ Tk::RbWidget::BalloonHelp.new(sb2, :interval=>500,
326
+ :padx=>5, :relief=>:raised,
327
+ :background=>'gray25', :foreground=>'white',
328
+ :command=>cmd)
329
+ #=end
330
+
331
+ Tk.mainloop
332
+ end