summaryrefslogtreecommitdiff
path: root/ext/tk/sample/demos-jp/widget
blob: 3dd285a4895b8577d0024be89cf6bd526a193201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
#!/usr/bin/env ruby

# tk 関係ライブラリの読み込み
require 'tk'
require 'tkafter'

# widget demo directory 位置の獲得
$demo_dir = File.dirname($0)

# root の生成
$root = TkRoot.new{title "Widget Demonstration"}

# tk バージョンの取得
$tk_version = Tk::TK_VERSION

# tcl_platform 情報へのアクセスオブジェクト
$tk_platform = TkVarAccess.new('tcl_platform')

# フォント設定
$font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*', nil)
knjfont = '-*-r-*--16-*-jisx0208.1983-0'
$kanji_font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
			 knjfont)
TkOption.add('*kanjiFont', knjfont, 'startupFile')
$msg_kanji_font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
			     '-*-r-*--24-*-jisx0208.1983-0')
#######
#case($tk_version)
#when /^4.*/
#  $font = '-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*'
#  $kanji_font = '-*--16-*-jisx0208.1983-0'
#  $msg_kanji_font = '-*--24-*-jisx0208.1983-0'
#  $knjfont_opt = 'kanjifont'
#  TkOption.add('*kanjiFont', $kanji_font, 'startupFile')
#
#when /^8.*/
#  Tk.tk_call('font', 'create', '@ascii', 
#	     '-copy', '-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*')
#  Tk.tk_call('font', 'create', '@kanji', 
#	     '-copy', '-*--16-*-jisx0208.1983-0')
#  Tk.tk_call('font', 'create', '@msg_knj', 
#	     '-copy', '-*--24-*-jisx0208.1983-0')
#  Tk.tk_call('font', 'create', '@cFont', '-compound', '@ascii @kanji')
#  Tk.tk_call('font', 'create', '@cMsgFont', '-compound', '@ascii @msg_knj')
#  $font = '-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*'
#  $kanji_font = '@cFont'
#  $msg_kanji_font = '@cMsgFont'
#  $knjfont_opt = 'font'
#end
#######

# メニュー設定
TkMenubar.new($root, 
	      [[['File', 0], 
		  ['About ... ', proc{aboutBox}, 0, '<F1>'],
		  '---', 
		  ['Quit', proc{exit}, 0, 'Meta-Q']
		]]).pack('side'=>'top', 'fill'=>'x')
$root.bind('F1', proc{aboutBox})

=begin
TkFrame.new($root){|frame|
  TkMenubutton.new(frame){|button|
    m = TkMenu.new(button) {
      add 'command', 'label'=>'Quit', 'command'=>proc{exit}, 'underline'=>0
    }
    menu m
    text 'File'
    underline 0
  }.pack('side'=>'left')
}.pack('side'=>'top', 'fill'=>'x')
=end

# テキストボックスの生成
if $tk_version =~ /^4\.[01]/
  scr = TkScrollbar.new($root, 'orient'=>'vertical')
  txt = TkText.new($root) {
    #wrap 'word'
    wrap 'char'
    width 60
    height 30
    font $font
    setgrid 'yes'
    yscrollcommand proc{|first,last| scr.set first,last}
  }
  scr.command(proc{|*args| txt.yview(*args)})
  scr.pack('side'=>'right', 'fill'=>'y')
  txt.pack('expand'=>'yes', 'fill'=>'both')
else
  textFrame = TkFrame.new($root)
  scr = TkScrollbar.new($root, 'orient'=>'vertical', 
			'highlightthickness'=>0, 'takefocus'=>1) {
    pack('in'=>textFrame, 'side'=>'right', 'fill'=>'y', 'padx'=>1)
  }
  txt = TkText.new($root) {
    #wrap 'word'
    wrap 'char'
    width 60
    height 30
    font $font
    setgrid 'yes'
    highlightthickness 0
    padx 4
    pady 2
    takefocus 0
    yscrollcommand proc{|first,last| scr.set first,last}
  }
  scr.command(proc{|*args| txt.yview(*args)})
#  txt.pack('in'=>textFrame, 'expand'=>'yes', 'fill'=>'both', 'padx'=>1)
  txt.pack('in'=>textFrame, 'expand'=>'yes', 'fill'=>'both')
#  textFrame.pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>2)
  textFrame.pack('expand'=>'yes', 'fill'=>'both')

  statusBar = TkFrame.new($root) {|f|
    $statusBarLabel = \
    TkLabel.new(f, 'text'=>"   ", 'relief'=>'sunken', 'bd'=>1, 'anchor'=>'w', 
		'font'=>'-*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*') \
    .pack('side'=>'left', 'padx'=>2, 'expand'=>'yes', 'fill'=>'both')
    TkLabel.new(f, 'width'=>8, 'relief'=>'sunken', 'bd'=>1, 'anchor'=>'w', 
		'font'=>'-*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*') \
    .pack('side'=>'left', 'padx'=>2)
  }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>2)
end

# テキストタグ設定
tag_title = TkTextTag.new(txt, 'font'=>'-*-Helvetica-Bold-R-Normal--*-180-*-*-*-*-*-*')
tag_kanji_title = TkTextTag.new(txt, 'kanjifont'=>$msg_kanji_font)
tag_middle = TkTextTag.new(txt, 'kanjifont'=>$kanji_font)
tag_demospace = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c')

if TkWinfo.depth($root) == '1'
  tag_demo = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c', 
			   'underline'=>1)
  $tag_visited = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c', 
			      'underline'=>1)
  tag_hot = TkTextTag.new(txt, 'background'=>'black', 'foreground'=>'white')
else
  tag_demo = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c', 
			   'foreground'=>'blue', 'underline'=>1)
  $tag_visited = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c', 
			      'foreground'=>'#303080', 'underline'=>1)
#  tag_hot = TkTextTag.new(txt, 'relief'=>'raised', 'borderwidth'=>1, 
#			  'background'=>'SeaGreen3')
  tag_hot = TkTextTag.new(txt, 'borderwidth'=>1, 'foreground'=>'red')
end

#tag_demo.bind('Button-1', proc{invoke txt, txt.index('current')})
tag_demo.bind('ButtonRelease-1', 
	      proc{|x,y|invoke txt, txt.index("@#{x},#{y}")}, '%x %y')

lastLine = TkVariable.new("")
newLine  = TkVariable.new("")
tag_demo.bind('Enter', proc{|x,y|
		lastLine.value = txt.index("@#{x},#{y} linestart")
		tag_hot.add(lastLine.value, "#{lastLine.value} lineend")
		showStatus txt, txt.index("@#{x},#{y}")
	      },
	      '%x %y')
tag_demo.bind('Leave', 
	      proc{
		tag_hot.remove('1.0','end')
		txt.configure('cursor','xterm')
		$statusBarLabel.configure('text'=>"")
	      })
tag_demo.bind('Motion', proc{|x, y|
		newLine.value = txt.index("@#{x},#{y} linestart")
		if newLine.value != lastLine.value
		  tag_hot.remove('1.0','end')
		  lastLine.value = newLine.value
		  if ( txt.tag_names("@#{x},#{y}").find{|t| 
			t.kind_of?(String) && t =~ /^demo-/
		      } )
		    tag_hot.add(lastLine.value, 
				"#{lastLine.value} lineend -1 chars")
		  end
		end
		showStatus txt, txt.index("@#{x},#{y}")
	      },
	      '%x %y')

# テキスト生成
txt.insert('end', 'Ruby/Tk : Widget', tag_title)
#txt.insert('end', "  デモンストレーション\n", tag_middle)
txt.insert('end', "  デモンストレーション\n", tag_kanji_title)
txt.insert('end', <<"EOT")

このアプリケーションは、Tk Widget を用いてどのようなことができるか\
を示すための、いくつかの小さなスクリプトに対するフロントエンドを提\
供しています。以下に順番に挙げられているデモンストレーションを実行\
するにはマウスでクリックしてください。デモンストレーションのウィン\
ドウが現れると、デモンストレーションを生成した Ruby/Tk のコードを見\
るために、"コード参照"ボタンをクリックすることができます。あなたが\
望むなら、そのコードを修正することができます。修正したコードでデモ\
ンストレーションを再実行するためには、コードが書かれたウィンドウに\
ある"デモ再実行" ボタンをクリックしてください。

一部のデモでは,比較的最近のバージョンの Tk でなければサポートして\
いない機能を使って実装しています(例えば Tk8.4 以上など).そのため,\
そうした機能を持たない Tk ライブラリを使っている場合には,そうした\
デモは正しく動きません.そのような機能が必要であれば,それをサポート\
している Tk ライブラリを使うように,tcltklib をコンパイルしなおして\
ください.


EOT

#txt.insert('end',"ラベル, ボタン, チェックボタン, ラジオボタン\n",tag_middle)
txt.insert('end', "ラベル, ボタン, チェックボタン, ラジオボタン\n", 
	   tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. ラベル (テキスト, ビットマップ)\n", 
	   tag_demo, "demo-label")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. ボタン \n", tag_demo, "demo-button")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3. チェックボタン (複数を選択可能)\n", 
	   tag_demo, "demo-check")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. ラジオボタン (任意の一つを選択可能)\n", 
	   tag_demo, "demo-radio")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "5. ラジオボタン (機能に対応したバージョンのTkが必要)\n", 
	   tag_demo, "demo-radio2")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "6. ボタンで作られた15-パズルゲーム\n", 
	   tag_demo, "demo-puzzle")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "7. ビットマップを使用したアイコンボタン\n", 
	   tag_demo, "demo-icon")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "8. 画像を表示する二つのラベル\n", 
	   tag_demo, "demo-image1")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "9. 画像を見るための簡単なユーザインターフェース\n", 
	   tag_demo, "demo-image2")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "10. 画像を見るための簡単なユーザインターフェース (機能に対応したバージョンのTkが必要)\n", 
	   tag_demo, "demo-image3")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "11. ラベル付きフレーム (機能に対応したバージョンのTkが必要)\n", 
	   tag_demo, "demo-labelframe")
txt.insert('end', " \n ", tag_demospace)

txt.insert('end', "\n")
#txt.insert('end', "リストボックス\n", tag_middle)
txt.insert('end', "リストボックス\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. 都道府県.\n", tag_demo, "demo-states")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. 色: アプリケーションのための配色を変える\n", 
	   "#{tag_demo.id} demo-colors")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3. 格言集\n", tag_demo, "demo-sayings")
txt.insert('end', " \n ", tag_demospace)

txt.insert('end', "\n")
#txt.insert('end', "エントリとスピンボックス\n", tag_middle)
txt.insert('end', "エントリ\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. スクロールバーなし\n", tag_demo, "demo-entry1")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. スクロールバーあり\n", tag_demo, "demo-entry2")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3. 認証処理付きのエントリボックスとパスワードフィールド (機能に対応したバージョンのTkが必要)\n", 
	   tag_demo, "demo-entry3")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. スピンボックス (機能に対応したバージョンのTkが必要)\n", 
	   tag_demo, "demo-spin")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "5. 簡単なフォーム\n", tag_demo, "demo-form")
txt.insert('end', " \n ", tag_demospace)

txt.insert('end', "\n")
#txt.insert('end', "テキスト\n", tag_middle)
txt.insert('end', "テキスト\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. 基本的なテキスト\n", tag_demo, "demo-text")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. 表示スタイル.\n", tag_demo, "demo-style")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3. ハイパーテキスト(タグバインド).\n", 
	   tag_demo, "demo-bind")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. ウィンドウを埋め込んだテキスト\n", 
	   tag_demo, "demo-twind")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "5. 検索\n", tag_demo, "demo-search")
txt.insert('end', " \n ", tag_demospace)

txt.insert('end', "\n")
#txt.insert('end', "キャンバス\n", tag_middle)
txt.insert('end', "キャンバス\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. アイテムの型\n", tag_demo, "demo-items")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. 2 次元のプロット\n", tag_demo, "demo-plot")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3. テキスト\n", tag_demo, "demo-ctext")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. 矢印の形\n", tag_demo, "demo-arrow")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "5. ルーラー\n", tag_demo, "demo-ruler")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "6. フロアプラン\n", tag_demo, "demo-floor")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "7. スクロール可能なキャンバス\n", 
	   tag_demo, "demo-cscroll")
txt.insert('end', " \n ", tag_demospace)

txt.insert('end', "\n")
#txt.insert('end', "スケール\n", tag_middle)
txt.insert('end', "スケール\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. 垂直\n", tag_demo.id, "demo-vscale")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. 水平\n", tag_demo.id, "demo-hscale")
txt.insert('end', " \n ", tag_demospace)

txt.insert('end', "\n")
txt.insert('end', "ペインドウィンドウ\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. 水平方向 (機能に対応したバージョンのTkが必要)\n", 
	   tag_demo.id, "demo-paned1")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. 垂直方向 (機能に対応したバージョンのTkが必要)\n", 
	   tag_demo.id, "demo-paned2")
txt.insert('end', " \n ", tag_demospace)

txt.insert('end', "\n")
#txt.insert('end', "メニュー\n", tag_middle)
txt.insert('end', "メニュー\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. メニューとカスケードを含んだウィンドウ\n", 
	   tag_demo, "demo-menu")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. メニューとカスケードを含んだウィンドウ (Tk8.x 専用)\n", 
	   tag_demo, "demo-menu8x")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3.                 〃                (機能に対応したバージョンのTkが必要)\n", 
	   tag_demo, "demo-menu84")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. メニューボタン (Tk8.x 専用)\n", 
	   tag_demo, "demo-menubu")
txt.insert('end', " \n ", tag_demospace)

txt.insert('end', "\n")
#txt.insert('end', "ダイアログウィンドウ\n", tag_middle)
txt.insert('end', "ダイアログウィンドウ\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. メッセージボックス\n", tag_demo, "demo-msgbox")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. ファイル選択ダイアログ\n", tag_demo, "demo-filebox")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3. 色選択ダイアログ\n", tag_demo, "demo-clrpick")
txt.insert('end', " \n ", tag_demospace)

txt.insert('end', "\n")
#txt.insert('end', "その他\n", tag_middle)
txt.insert('end', "その他\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. 組み込みのビットマップ\n", tag_demo, "demo-bitmap")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. モーダルダイアログ(ローカルグラブ)\n", 
	   tag_demo, "demo-dialog1")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3. モーダルダイアログ(グローバルグラブ)\n", 
	   tag_demo, "demo-dialog2")
txt.insert('end', " \n ", tag_demospace)

txt.state('disabled')
scr.focus

################################
# method 定義
################################
def positionWindow(w)
  w.geometry('+300+300')
end

# 親ウィジェットと,変数名と TkVariable との組(配列)の並びを渡す
$showVarsWin = {}
def showVars (parent, *args)
  if $showVarsWin[parent.path]
    begin
      $showVarsWin[parent.path].destroy 
    rescue
    end
  end
  w = TkToplevel.new(parent) {|w|
    title "Variable values"
    TkLabel.new(w) {
      text "変数値:"
      width 20
      anchor 'center'
      font '-Adobe-helvetica-medium-r-normal--*-180-*-*-*-*-*-*'
    }.pack('side'=>'top', 'fill'=>'x')
    len = 1
    args.each{|vnam,vbody|
      len = vnam.to_s.length if vnam.to_s.length > len
    }
    args.each{|vnam,vbody|
      TkFrame.new(w){|f|
	#TkLabel.new(f, 'text'=>"#{vnam}: ").pack('side'=>'left')
	TkLabel.new(f, 'text'=>"#{vnam}: ",'width'=>len+2).pack('side'=>'left')
	TkLabel.new(f, 'textvariable'=>vbody, 'anchor'=>'w')\
	           .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x')
      }.pack('side'=>'top', 'anchor'=>'w', 'fill'=>'x')
    }
    TkButton.new(w) {
      text "了解"
      command proc{w.destroy}
    }.pack('side'=>'bottom', 'pady'=>2)
  }
  $showVarsWin[parent.path] = w
end

# テキスト上での click に対する動作
def invoke (txt, index)
  tag = txt.tag_names(index).find{|t| t.kind_of?(String) && t =~ /^demo-/}
  return unless tag
  cursor = txt.cget('cursor')
  txt.cursor('watch')
  Tk.update
#  eval `cat #{tag[5..-1]}.rb`
  eval `cat #{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb`
  Tk.update
#  txt.cursor('xterm')
  txt.cursor(cursor)

  $tag_visited.add("#{index} linestart +1 chars", "#{index} lineend +1 chars")
end

# 状態表示
def showStatus (txt, index)
  tag = txt.tag_names(index).find{|t| t.kind_of?(String) && t =~ /^demo-/}
  cursor = txt.cget('cursor')
  unless tag
    $statusBarLabel.configure('text', " ")
    newcursor = 'xterm'
  else
    demoname = tag[5..-1]
    $statusBarLabel.configure('text', 
			     "サンプルプログラム \"#{demoname}\" の実行 ")
    newcursor = 'hand2'
  end
  txt.configure('cursor'=>newcursor) if cursor != newcursor
end

# ソースコードの表示
def showCode (demo)
  file = "#{demo}.rb"
  $code_window = nil unless defined? $code_window
  if $code_window == nil || TkWinfo.exist?($code_window) == '0'
    $code_window = TkToplevel.new(nil)
    f = TkFrame.new($code_window)
    TkButton.new(f) {
      text "了解"
      command proc{
	$code_window.destroy
	$code_window = nil
      }
    }.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2)
    TkButton.new(f) {
      text "再実行"
      command proc{eval($code_text.get('1.0','end'))}
    }.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2)
#    f.pack('side'=>'bottom', 'expand'=>'yes', 'fill'=>'x')
    f.pack('side'=>'bottom', 'fill'=>'x')

    if $tk_version =~ /^4\.[01]/
      s = TkScrollbar.new($code_window, 'orient'=>'vertical')
      $code_text = TkText.new($code_window) {
	height 40
	setgrid 'yes'
	yscrollcommand proc{|first,last| s.set first,last}
      }
      s.command(proc{|*args| $code_text.yview(*args)})
      s.pack('side'=>'right', 'fill'=>'y')
      $code_text.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'both')
    else
      TkFrame.new($code_window) {|f|
	pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>1)

	hs = TkScrollbar.new($code_window, 'highlightthickness'=>0, 
			     'orient'=>'horizontal')
	vs = TkScrollbar.new($code_window, 'highlightthickness'=>0, 
			     'orient'=>'vertical')
	$code_text = TkText.new($code_window) {|t|
	  height 40
	  #wrap 'word'
	  wrap 'char'
	  xscrollcommand proc{|first,last| hs.set first,last}
	  yscrollcommand proc{|first,last| vs.set first,last}
	  setgrid 'yes'
	  highlightthickness 0
	  pady 2
	  padx 3
	  hs.command(proc{|*args| $code_text.xview(*args)})
	  vs.command(proc{|*args| $code_text.yview(*args)})
	}

	$code_text.grid('in'=>f, 'padx'=>1, 'pady'=>1, 'row'=>0, 'column'=>0, 
			'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
	vs.grid('in'=>f, 'padx'=>1, 'pady'=>1, 'row'=>0, 'column'=>1, 
		'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
#	xs.grid('in'=>f, 'padx'=>1, 'pady'=>1, 'row'=>1, 'column'=>0, 
#		'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
	TkGrid.rowconfigure(f, 0, 'weight'=>1, 'minsize'=>0)
	TkGrid.columnconfigure(f, 0, 'weight'=>1, 'minsize'=>0)
      }
    end
  else
    $code_window.deiconify
    $code_window.raise
  end
  $code_window.title("Demo code: #{file}")
  $code_window.iconname(file)
#  fid = open(file, 'r')
  fid = open([$demo_dir, file].join(File::Separator), 'r')
  $code_text.delete('1.0', 'end')
  #$code_text.insert('1.0', `cat #{file}`)
  $code_text.insert('1.0', fid.read)
  #$code_mark = TkTextMark.new($code_text, '1.0')
  #$code_text.set_insert('1.0')
  TkTextMarkInsert.new($code_text,'1.0')
  fid.close
end

# aboutBox
#
#      Pops up a message box with an "about" message
#
def aboutBox
  Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo', 
		'message'=>"Ruby/Tk ウィジェットデモ Ver.1.3.2-jp\n\n( based on Tk ウィジェットデモ :: Copyright (c) 1996-1997 Sun Microsystems, Inc. )\n\nRunning Version :: Ruby#{VERSION}/Tk#{$tk_version}#{(Tk::JAPANIZED_TK)? 'jp': ''}")
end

################################
# イベント待ちに入る
Tk.mainloop