3
# �������������� ( tk.rb �Υ����ɻ��� encoding ����/����˻Ȥ��� )
10
# widget demo directory ���֤γ���
11
$demo_dir = File.dirname($0)
14
$root = TkRoot.new{title "Ruby/Tk Widget Demonstration"}
17
$tk_version = Tk::TK_VERSION
18
$tk_major_ver, $tk_minor_ver = $tk_version.split('.').map{|n| n.to_i}
19
$tk_patchlevel = Tk::TK_PATCHLEVEL
21
# tcl_platform ����ؤΥ����������֥�������
22
$tk_platform = TkVarAccess.new('tcl_platform')
28
$font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*', nil)
29
knjfont = '-*--16-*-jisx0208.1983-0'
30
$kanji_font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
32
TkOption.add('*kanjiFont', knjfont, 'startupFile')
33
$msg_kanji_font=TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
34
'-*--24-*-jisx0208.1983-0')
37
# $font = TkFont.new('Helvetica -12')
38
# $kanji_font = TkFont.new('Helvetica -12', 'Mincho -12')
39
# TkOption.add('*kanjiFont', knjfont, 'startupFile')
40
# $msg_kanji_font=TkFont.new('Helvetica 16', 'Gothic 16 bold')
43
$font = TkFont.new('Helvetica -12')
44
$kanji_font = TkFont.new('Helvetica -12', 'Mincho -12')
45
TkOption.add('*kanjiFont', knjfont, 'startupFile')
46
$msg_kanji_font=TkFont.new('Helvetica 16', 'Gothic 16 bold')
49
$font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*', nil)
50
knjfont = '-*--16-*-jisx0208.1983-0'
51
$kanji_font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
53
TkOption.add('*kanjiFont', knjfont, 'startupFile')
54
$msg_kanji_font=TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
55
'-*--24-*-jisx0208.1983-0')
63
$image['refresh'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
64
R0lGODlhEAAQAPMAAMz/zCpnKdb/1z9mPypbKBtLGy9NMPL/9Or+6+P+4j1Y
65
PwQKBP7//xMLFAYBCAEBASH5BAEAAAAALAAAAAAQABAAAwR0EAD3Gn0Vyw0e
66
++CncU7IIAezMA/nhUqSLJizvSdCEEjy2ZIV46AwDAoDHwPYGSoEiUJAAGJ6
67
EDHBNCFINW5OqABKSFk/B9lUa94IDwIFgewFMwQDQwCZQCztTgM9Sl8SOEMG
68
KSAthiaOjBMPDhQONBiXABEAOw==
73
$image['view'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
74
R0lGODlhEAAQAPMAAMz/zP///8DAwICAgH9/fwAAAAAAAAAAAAAAAAAAAAAA
75
AAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAwRIcMhJB7h3hM33
76
KFjWdQQYap1QrCaGBmrRrS4nj5b53jOgbwXBKGACoYLDIuAoHCmZyYvR1rT5
77
RMAq8LqcIYGsrjPsW1XOmFUEADs=
82
$image['delete'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
83
R0lGODlhEAAOAKEAAIQAAO/n3v///////yH5BAEKAAIALAAAAAAQAA4AAAIm
84
lI9pAKHbIHNoVhYhTdjlJ2AWKG2g+CldmB6rxo2uybYhbS80eRQAOw==
89
$image['print'] = TkPhotoImage.new(:height=>19, :format=>'GIF', :data=><<EOD)
90
R0lGODlhGgATAPcAACEQOTEpQjEpUkIpc0IxY0I5c0oxjEo5SlJCY1JCe1JK
91
UlpChFpCjFpGkFpSc1paa2NKc2NKnGNja2tapWtjc29KnHNanHNjc3NjrXNr
92
jHNrnHNzc3tjpXtrtXtzhICAgIRzvYSEjIZzqox7tYyEnIyMjJSEtZSEvZSM
93
lJyMtZyMvZyUlJyUrZyUvZycnKWctaWlpa2czq2lzrWtvbWtzrW1tb21xr21
94
1sa9zs693s7OztbO3tbO597W1t7W7+fe7+fn5////+/n7+/v7+/v9////wAA
95
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
96
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
97
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
98
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
99
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
100
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
101
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
102
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
103
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
104
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
105
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
106
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
107
AAAAAAAAAAAAAAAAAAAAACH5BAEAAEEALAAAAAAaABMAQAj/AIMIHBhkg0GC
108
CBMGIQEiQgseQT4oeCBBAokgRYYQ0JBixg8hRIiUUEBBYYmTByBwiCBCRYwH
109
CxY8cKFw4AogRXLqLAJkQ80gCBBg3BkxZswTNGh4MGqgQQUMJRHCwMkTSE+D
110
Pn8eCKBhxIMhO3ei2OHDBw6sWSlMMMoWgwwfMDZI8GBjx44NARZwEGGi5MkS
111
PcIWKRGz5YgLbAco+KkQBQoJIRgjdGEVq+SaJajqtNrzMgsPCmoIzqmDgmWE
112
KOBuUKAAwYabYTfs4OHjY0giGyhk4MAWRI4eKyRQqPgggYUXPH4A+XBAgwoK
113
DiIsCFxjA9sFEVQQCRJCAYAFDJxiKhAxvMTonEFimrhhYinTBgWiCvxLNX3M
114
DkkpsKV5OYhjBxCMYAICAigUEAA7
121
['About ... ', proc{aboutBox}, 0, '<F1>'],
123
['Quit', proc{exit}, 0, 'Meta-Q']
124
]]).pack('side'=>'top', 'fill'=>'x')
125
$root.bind('F1', proc{aboutBox})
126
$root.bind('Meta-q', proc{exit})
129
TkFrame.new($root){|frame|
130
TkMenubutton.new(frame){|button|
131
m = TkMenu.new(button) {
132
add 'command', 'label'=>'Quit', 'command'=>proc{exit}, 'underline'=>0
137
}.pack('side'=>'left')
138
}.pack('side'=>'top', 'fill'=>'x')
142
if $tk_version =~ /^4\.[01]/
143
scr = TkScrollbar.new($root, 'orient'=>'vertical')
144
txt = TkText.new($root) {
151
yscrollcommand proc{|first,last| scr.set first,last}
153
scr.command(proc{|*args| txt.yview(*args)})
154
scr.pack('side'=>'right', 'fill'=>'y')
155
txt.pack('expand'=>'yes', 'fill'=>'both')
157
textFrame = TkFrame.new($root)
158
scr = TkScrollbar.new($root, 'orient'=>'vertical',
159
'highlightthickness'=>0, 'takefocus'=>1) {
160
pack('in'=>textFrame, 'side'=>'right', 'fill'=>'y', 'padx'=>1)
162
txt = TkText.new($root) {
174
yscrollcommand proc{|first,last| scr.set first,last}
176
scr.command(proc{|*args| txt.yview(*args)})
177
# txt.pack('in'=>textFrame, 'expand'=>'yes', 'fill'=>'both', 'padx'=>1)
178
txt.pack('in'=>textFrame, 'expand'=>'yes', 'fill'=>'both')
179
# textFrame.pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>2)
180
textFrame.pack('expand'=>'yes', 'fill'=>'both')
182
statusBar = TkFrame.new($root) {|f|
184
TkLabel.new(f, 'text'=>" ", 'relief'=>'sunken', 'bd'=>1, 'anchor'=>'w',
185
'font'=>'-*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*') \
186
.pack('side'=>'left', 'padx'=>2, 'expand'=>'yes', 'fill'=>'both')
187
TkLabel.new(f, 'width'=>8, 'relief'=>'sunken', 'bd'=>1, 'anchor'=>'w',
188
'font'=>'-*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*') \
189
.pack('side'=>'left', 'padx'=>2)
190
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>2)
194
tag_title = TkTextTag.new(txt, 'font'=>'-*-Helvetica-Bold-R-Normal--*-180-*-*-*-*-*-*')
195
#tag_kanji_title = TkTextTag.new(txt, 'kanjifont'=>$msg_kanji_font)
196
#tag_middle = TkTextTag.new(txt, 'kanjifont'=>$kanji_font)
197
tag_kanji_title = TkTextTag.new(txt, 'font'=>$msg_kanji_font)
198
tag_middle = TkTextTag.new(txt, 'font'=>$kanji_font)
199
tag_demospace = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c')
201
if TkWinfo.depth($root) == 1
202
tag_demo = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c',
204
$tag_visited = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c',
206
tag_hot = TkTextTag.new(txt, 'background'=>'black', 'foreground'=>'white')
208
tag_demo = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c',
209
'foreground'=>'blue', 'underline'=>1)
210
$tag_visited = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c',
211
'foreground'=>'#303080', 'underline'=>1)
212
# tag_hot = TkTextTag.new(txt, 'relief'=>'raised', 'borderwidth'=>1,
213
# 'background'=>'SeaGreen3')
214
tag_hot = TkTextTag.new(txt, 'borderwidth'=>1, 'foreground'=>'red')
217
#tag_demo.bind('Button-1', proc{invoke txt, txt.index('current')})
218
tag_demo.bind('ButtonRelease-1',
219
proc{|x,y|invoke txt, txt.index("@#{x},#{y}")}, '%x %y')
221
lastLine = TkVariable.new("")
222
newLine = TkVariable.new("")
223
tag_demo.bind('Enter', proc{|x,y|
224
lastLine.value = txt.index("@#{x},#{y} linestart")
225
tag_hot.add(lastLine.value, "#{lastLine.value} lineend")
226
showStatus txt, txt.index("@#{x},#{y}")
229
tag_demo.bind('Leave',
231
tag_hot.remove('1.0','end')
232
txt.configure('cursor','xterm')
233
$statusBarLabel.configure('text'=>"")
235
tag_demo.bind('Motion', proc{|x, y|
236
newLine.value = txt.index("@#{x},#{y} linestart")
237
if newLine.value != lastLine.value
238
tag_hot.remove('1.0','end')
239
lastLine.value = newLine.value
240
if ( txt.tag_names("@#{x},#{y}").find{|t|
241
t.kind_of?(String) && t =~ /^demo-/
243
tag_hot.add(lastLine.value,
244
"#{lastLine.value} lineend -1 chars")
247
showStatus txt, txt.index("@#{x},#{y}")
252
txt.insert('end', 'Ruby/Tk : Widget', tag_title)
253
#txt.insert('end', " �ǥ�ȥ졼�����\n", tag_middle)
254
txt.insert('end', " �ǥ�ȥ졼�����\n", tag_kanji_title)
255
txt.insert('end', <<"EOT")
257
���Υ��ץꥱ�������ϡ�Tk Widget ���Ѥ��ƤɤΤ褦�ʤ��Ȥ��Ǥ��뤫\
258
������Ρ������Ĥ��ξ����ʥ�����ץȤ��Ф���ե���ȥ���ɤ���\
259
�����Ƥ��ޤ����ʲ��˽��֤˵��Ƥ���ǥ�ȥ졼������¹�\
260
����ˤϥޥ����ǥ���å����Ƥ����������ǥ�ȥ졼�����Υ�����\
261
�ɥ��������ȡ��ǥ�ȥ졼�������������� Ruby/Tk �Υ����ɤ�\
262
�뤿��ˡ�"�����ɻ���"�ܥ����å����뤳�Ȥ��Ǥ��ޤ������ʤ���\
263
˾��ʤ顢���Υ����ɤ������뤳�Ȥ��Ǥ��ޤ����������������ɤǥǥ�\
264
�ȥ졼������Ƽ¹Ԥ��뤿��ˤϡ������ɤ��줿������ɥ���\
265
����"�ǥ�Ƽ¹�" �ܥ����å����Ƥ���������
267
�����Υǥ�Ǥϡ����Ū�Ƕ�ΥС������� Tk �Ǥʤ���Х��ݡ��Ȥ���\
268
���ʤ���ǽ��ȤäƼ������Ƥ��ޤ�(�㤨�� Tk8.4 �ʾ�ʤ�)�����Τ��ᡤ\
269
����������ǽ������ʤ� Tk �饤�֥���ȤäƤ�����ˤϡ���������\
270
�ǥ��������ư���ޤ����Τ褦�ʵ�ǽ��ɬ�פǤ���С�����ݡ���\
271
���Ƥ��� Tk �饤�֥���Ȥ��褦�ˡ�tcltklib ��ѥ��뤷�ʤ�����\
277
#txt.insert('end',"��٥�, �ܥ���, �����å��ܥ���, �饸���ܥ���\n",tag_middle)
278
txt.insert('end', "��٥�, �ܥ���, �����å��ܥ���, �饸���ܥ���\n",
280
txt.insert('end', " \n ", tag_demospace)
281
txt.insert('end', "1. ��٥� (�ƥ�����, �ӥåȥޥå�)\n",
282
tag_demo, "demo-label")
283
txt.insert('end', " \n ", tag_demospace)
284
txt.insert('end', "2. ��٥��UNICODE�ƥ����� (��ǽ���б������С�������Tk��ɬ��)\n", tag_demo, "demo-unicodeout")
285
txt.insert('end', " \n ", tag_demospace)
286
txt.insert('end', "3. �ܥ��� \n", tag_demo, "demo-button")
287
txt.insert('end', " \n ", tag_demospace)
288
txt.insert('end', "4. �����å��ܥ��� (ʣ���������ǽ)\n",
289
tag_demo, "demo-check")
290
txt.insert('end', " \n ", tag_demospace)
291
txt.insert('end', "5. �����֥����å��ܥ��� (��ǽ���б������С�������Tk��ɬ��)\n",
292
tag_demo, "demo-check2")
293
txt.insert('end', " \n ", tag_demospace)
294
txt.insert('end', "6. �饸���ܥ��� (Ǥ�դΰ�Ĥ������ǽ)\n",
295
tag_demo, "demo-radio")
296
txt.insert('end', " \n ", tag_demospace)
297
txt.insert('end', "7. �饸���ܥ��� (��ǽ���б������С�������Tk��ɬ��)\n",
298
tag_demo, "demo-radio2")
299
txt.insert('end', " \n ", tag_demospace)
300
txt.insert('end', "8. �����֥饸���ܥ��� (��ǽ���б������С�������Tk��ɬ��)\n",
301
tag_demo, "demo-radio3")
302
txt.insert('end', " \n ", tag_demospace)
303
txt.insert('end', "9. �ܥ���Ǻ��줿15-�ѥ��륲����\n",
304
tag_demo, "demo-puzzle")
305
txt.insert('end', " \n ", tag_demospace)
306
txt.insert('end', "10. �ӥåȥޥåפ���Ѥ�����������ܥ���\n",
307
tag_demo, "demo-icon")
308
txt.insert('end', " \n ", tag_demospace)
309
txt.insert('end', "11. ������ɽ��������ĤΥ�٥�\n",
310
tag_demo, "demo-image1")
311
txt.insert('end', " \n ", tag_demospace)
312
txt.insert('end', "12. �����뤿��δ�ñ�ʥ桼�������ե�����\n",
313
tag_demo, "demo-image2")
314
txt.insert('end', " \n ", tag_demospace)
315
txt.insert('end', "13. �����뤿��δ�ñ�ʥ桼�������ե����� (��ǽ���б������С�������Tk��ɬ��)\n",
316
tag_demo, "demo-image3")
317
txt.insert('end', " \n ", tag_demospace)
318
txt.insert('end', "14. ��٥��դ��ե졼�� (��ǽ���б������С�������Tk��ɬ��)\n",
319
tag_demo, "demo-labelframe")
320
txt.insert('end', " \n ", tag_demospace)
322
txt.insert('end', "\n")
323
#txt.insert('end', "�ꥹ�ȥܥå���\n", tag_middle)
324
txt.insert('end', "�ꥹ�ȥܥå���\n", tag_kanji_title)
325
txt.insert('end', " \n ", tag_demospace)
326
txt.insert('end', "1. ��ƻ�ܸ�.\n", tag_demo, "demo-states")
327
txt.insert('end', " \n ", tag_demospace)
328
txt.insert('end', "2. ��: ���ץꥱ�������Τ�����ۿ����Ѥ���\n",
329
"#{tag_demo.id} demo-colors")
330
txt.insert('end', " \n ", tag_demospace)
331
txt.insert('end', "3. �ʸ���\n", tag_demo, "demo-sayings")
332
txt.insert('end', " \n ", tag_demospace)
334
txt.insert('end', "\n")
335
#txt.insert('end', "����ȥ�ȥ��ԥ�ܥå���\n", tag_middle)
336
txt.insert('end', "����ȥ�\n", tag_kanji_title)
337
txt.insert('end', " \n ", tag_demospace)
338
txt.insert('end', "1. ����������С��ʤ�\n", tag_demo, "demo-entry1")
339
txt.insert('end', " \n ", tag_demospace)
340
txt.insert('end', "2. ���������������\n", tag_demo, "demo-entry2")
341
txt.insert('end', " \n ", tag_demospace)
342
txt.insert('end', "3. ǧ�ڽ����դ��Υ���ȥ�ܥå����ȥѥ���ɥե������ (��ǽ���б������С�������Tk��ɬ��)\n",
343
tag_demo, "demo-entry3")
344
txt.insert('end', " \n ", tag_demospace)
345
txt.insert('end', "4. ���ԥ�ܥå��� (��ǽ���б������С�������Tk��ɬ��)\n",
346
tag_demo, "demo-spin")
347
txt.insert('end', " \n ", tag_demospace)
348
txt.insert('end', "5. ��ñ�ʥե�����\n", tag_demo, "demo-form")
349
txt.insert('end', " \n ", tag_demospace)
351
txt.insert('end', "\n")
352
#txt.insert('end', "�ƥ�����\n", tag_middle)
353
txt.insert('end', "�ƥ�����\n", tag_kanji_title)
354
txt.insert('end', " \n ", tag_demospace)
355
txt.insert('end', "1. ����Ū�ʥƥ�����\n", tag_demo, "demo-text")
356
txt.insert('end', " \n ", tag_demospace)
357
txt.insert('end', "2. ɽ����������.\n", tag_demo, "demo-style")
358
txt.insert('end', " \n ", tag_demospace)
359
txt.insert('end', "3. �ϥ��ѡ��ƥ�����(�����Х����).\n",
360
tag_demo, "demo-bind")
361
txt.insert('end', " \n ", tag_demospace)
362
txt.insert('end', "4. ������ɥ�����������ƥ�����\n",
363
tag_demo, "demo-twind")
364
txt.insert('end', " \n ", tag_demospace)
365
txt.insert('end', "5. ������ɥ�����������ƥ����� (��ǽ���б������С�������Tk��ɬ��)\n",
366
tag_demo, "demo-twind2")
367
txt.insert('end', " \n ", tag_demospace)
368
txt.insert('end', "6. ����\n", tag_demo, "demo-search")
369
txt.insert('end', " \n ", tag_demospace)
371
txt.insert('end', "\n")
372
#txt.insert('end', "������\n", tag_middle)
373
txt.insert('end', "������\n", tag_kanji_title)
374
txt.insert('end', " \n ", tag_demospace)
375
txt.insert('end', "1. �����ƥ�η�\n", tag_demo, "demo-items")
376
txt.insert('end', " \n ", tag_demospace)
377
txt.insert('end', "2. 2 �����Υץ��å�\n", tag_demo, "demo-plot")
378
txt.insert('end', " \n ", tag_demospace)
379
txt.insert('end', "3. �ƥ�����\n", tag_demo, "demo-ctext")
380
txt.insert('end', " \n ", tag_demospace)
381
txt.insert('end', "4. ����η�\n", tag_demo, "demo-arrow")
382
txt.insert('end', " \n ", tag_demospace)
383
txt.insert('end', "5. �롼�顼\n", tag_demo, "demo-ruler")
384
txt.insert('end', " \n ", tag_demospace)
385
txt.insert('end', "6. �ե����ץ��\n", tag_demo, "demo-floor")
386
txt.insert('end', " \n ", tag_demospace)
387
txt.insert('end', "7. �ե����ץ�� (�ۤʤ륭���Х������ƥ������ˡ�����)\n", tag_demo, "demo-floor2")
388
txt.insert('end', " \n ", tag_demospace)
389
txt.insert('end', "8. �����������ǽ�ʥ����Х�\n",
390
tag_demo, "demo-cscroll")
391
txt.insert('end', " \n ", tag_demospace)
393
txt.insert('end', "\n")
394
#txt.insert('end', "��������\n", tag_middle)
395
txt.insert('end', "��������\n", tag_kanji_title)
396
txt.insert('end', " \n ", tag_demospace)
397
txt.insert('end', "1. ��ľ\n", tag_demo.id, "demo-vscale")
398
txt.insert('end', " \n ", tag_demospace)
399
txt.insert('end', "2. ��ʿ\n", tag_demo.id, "demo-hscale")
400
txt.insert('end', " \n ", tag_demospace)
402
txt.insert('end', "\n")
403
txt.insert('end', "�ڥ���ɥ�����ɥ�\n", tag_kanji_title)
404
txt.insert('end', " \n ", tag_demospace)
405
txt.insert('end', "1. ��ʿ���� (��ǽ���б������С�������Tk��ɬ��)\n",
406
tag_demo.id, "demo-paned1")
407
txt.insert('end', " \n ", tag_demospace)
408
txt.insert('end', "2. ��ľ���� (��ǽ���б������С�������Tk��ɬ��)\n",
409
tag_demo.id, "demo-paned2")
410
txt.insert('end', " \n ", tag_demospace)
412
txt.insert('end', "\n")
413
#txt.insert('end', "��˥塼\n", tag_middle)
414
txt.insert('end', "��˥塼\n", tag_kanji_title)
415
txt.insert('end', " \n ", tag_demospace)
416
txt.insert('end', "1. ��˥塼�ȥ��������ɤ�ޤ��������ɥ�\n",
417
tag_demo, "demo-menu")
418
txt.insert('end', " \n ", tag_demospace)
419
txt.insert('end', "2. ��˥塼�ȥ��������ɤ�ޤ��������ɥ� (Tk8.x ����)\n",
420
tag_demo, "demo-menu8x")
421
txt.insert('end', " \n ", tag_demospace)
422
txt.insert('end', "3. �� (��ǽ���б������С�������Tk��ɬ��)\n",
423
tag_demo, "demo-menu84")
424
txt.insert('end', " \n ", tag_demospace)
425
txt.insert('end', "4. ��˥塼�ܥ��� (Tk8.x ����)\n",
426
tag_demo, "demo-menubu")
427
txt.insert('end', " \n ", tag_demospace)
429
txt.insert('end', "\n")
430
#txt.insert('end', "����������������ɥ�\n", tag_middle)
431
txt.insert('end', "����������������ɥ�\n", tag_kanji_title)
432
txt.insert('end', " \n ", tag_demospace)
433
txt.insert('end', "1. ��å������ܥå���\n", tag_demo, "demo-msgbox")
434
txt.insert('end', " \n ", tag_demospace)
435
txt.insert('end', "2. �ե������������������\n", tag_demo, "demo-filebox")
436
txt.insert('end', " \n ", tag_demospace)
437
txt.insert('end', "3. ���������������\n", tag_demo, "demo-clrpick")
438
txt.insert('end', " \n ", tag_demospace)
440
txt.insert('end', "\n")
441
#txt.insert('end', "���˥�����\n", tag_middle)
442
txt.insert('end', "���˥�����\n", tag_kanji_title)
443
txt.insert('end', " \n ", tag_demospace)
444
txt.insert('end', "1. ���˥������٥� (��ǽ���б������С�������Tk��ɬ��)\n", tag_demo, "demo-anilabel")
445
txt.insert('end', " \n ", tag_demospace)
446
txt.insert('end', "2. �ȷ��Υ��˥����� (��ǽ���б������С�������Tk��ɬ��)\n", tag_demo, "demo-aniwave")
447
txt.insert('end', " \n ", tag_demospace)
448
txt.insert('end', "3. ����ҤΥ��ߥ�졼����� (��ǽ���б������С�������Tk��ɬ��)\n", tag_demo, "demo-pendulum")
449
txt.insert('end', " \n ", tag_demospace)
450
txt.insert('end', "4. A celebration of Rube Goldberg (��ǽ���б������С�������Tk��ɬ��)\n", tag_demo, "demo-goldberg")
452
txt.insert('end', "\n")
453
#txt.insert('end', "����¾\n", tag_middle)
454
txt.insert('end', "����¾\n", tag_kanji_title)
455
txt.insert('end', " \n ", tag_demospace)
456
txt.insert('end', "1. �Ȥ߹��ߤΥӥåȥޥå�\n", tag_demo, "demo-bitmap")
457
txt.insert('end', " \n ", tag_demospace)
458
txt.insert('end', "2. �⡼�������������(�������륰���)\n",
459
tag_demo, "demo-dialog1")
460
txt.insert('end', " \n ", tag_demospace)
461
txt.insert('end', "3. �⡼�������������(�������Х륰���)\n",
462
tag_demo, "demo-dialog2")
463
txt.insert('end', " \n ", tag_demospace)
465
txt.state('disabled')
468
################################
470
################################
471
def positionWindow(w)
472
w.geometry('+300+300')
475
# �ƥ��������åȤȡ��ѿ�̾�� TkVariable �Ȥ���(����)���¤Ӥ��Ϥ�
477
def showVars1(parent, *args)
478
if $showVarsWin[parent.path]
480
$showVarsWin[parent.path].destroy
484
top = TkToplevel.new(parent) {|w|
485
title "Variable values"
490
font '-Adobe-helvetica-medium-r-normal--*-180-*-*-*-*-*-*'
491
}.pack('side'=>'top', 'fill'=>'x')
493
args.each{|vnam,vbody|
494
len = vnam.to_s.length if vnam.to_s.length > len
496
args.each{|vnam,vbody|
498
#TkLabel.new(f, 'text'=>"#{vnam}: ").pack('side'=>'left')
499
TkLabel.new(f, 'text'=>"#{vnam}: ",'width'=>len+2).pack('side'=>'left')
500
TkLabel.new(f, 'textvariable'=>vbody, 'anchor'=>'w')\
501
.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x')
502
}.pack('side'=>'top', 'anchor'=>'w', 'fill'=>'x')
506
command proc{w.destroy}
507
}.pack('side'=>'bottom', 'pady'=>2)
509
$showVarsWin[parent.path] = top
512
def showVars2(parent, *args)
513
if $showVarsWin[parent.path]
515
$showVarsWin[parent.path].destroy
519
$showVarsWin[parent.path] = TkToplevel.new(parent) {|w|
520
title "Variable values"
522
TkLabelFrame.new(w, :text=>"�ѿ���:",
523
:font=>{:family=>'Helvetica', :size=>14}){|f|
524
args.each{|vnam,vbody|
525
TkGrid(TkLabel.new(f, :text=>"#{vnam}: ", :anchor=>'w'),
526
TkLabel.new(f, :textvariable=>vbody, :anchor=>'w'),
527
:padx=>2, :pady=>2, :sticky=>'w')
530
f.grid(:sticky=>'news', :padx=>4)
531
f.grid_columnconfig(1, :weight=>1)
532
f.grid_rowconfig(100, :weight=>1)
534
TkButton.new(w, :text=>"�", :width=>8, :default=>:active,
535
:command=>proc{w.destroy}){|b|
536
w.bind('Return', proc{b.invoke})
537
w.bind('Escape', proc{b.invoke})
539
b.grid(:sticky=>'e', :padx=>4, :pady=>[6, 4])
541
w.grid_columnconfig(0, :weight=>1)
542
w.grid_rowconfig(0, :weight=>1)
547
alias showVars showVars1
548
elsif $tk_major_ver == 8 && $tk_minor_ver < 4
549
alias showVars showVars1
551
alias showVars showVars2
555
module PseudoToplevel_Evaluable
556
def pseudo_toplevel_eval(body = Proc.new)
557
Thread.current[:TOPLEVEL] = self
561
Thread.current[:TOPLEVEL] = nil
565
def pseudo_toplevel_evaluable?
566
@pseudo_toplevel_evaluable
568
def pseudo_toplevel_evaluable=(mode)
569
@pseudo_toplevel_evaluable = (mode)? true: false
572
def self.extended(mod)
573
mod.__send__(:extend_object, mod)
574
mod.instance_variable_set('@pseudo_toplevel_evaluable', true)
579
alias __method_missing__ method_missing
580
private :__method_missing__
582
def method_missing(id, *args)
584
has_top = (top = Thread.current[:TOPLEVEL]) &&
585
top.respond_to?(:pseudo_toplevel_evaluable?) &&
586
top.pseudo_toplevel_evaluable? &&
588
rescue Exception => e
593
top.__send__(id, *args)
595
__method_missing__(id, *args)
601
def initialize(*args, &b)
603
@__pseudo_toplevel__ = Thread.current[:TOPLEVEL]
608
if top = @__pseudo_toplevel__
609
orig_top = Thread.current[:TOPLEVEL]
610
Thread.current[:TOPLEVEL] = top
614
Thread.current[:TOPLEVEL] = orig_top
630
Module.new.instance_eval{extend PseudoToplevel_Evaluable}
632
# Module.new.instance_eval{binding}
634
private :_null_binding
636
def eval_samplecode(code)
637
Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } }.run
641
# �ƥ����Ⱦ�Ǥ� click ���Ф���ư��
643
tag = txt.tag_names(idx).find{|t| t.kind_of?(String) && t =~ /^demo-/}
646
cursor = txt.cget('cursor')
649
# eval(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, _null_binding)
651
eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join)
654
$tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars")
657
def invoke (txt, idx)
658
tag = txt.tag_names(idx).find{|t| t.kind_of?(String) && t =~ /^demo-/}
660
current_cursor = txt.cget('cursor')
663
# eval `cat #{tag[5..-1]}.rb`
664
# eval `cat #{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb`
665
eval IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join
667
# txt.cursor('xterm')
668
txt.cursor(current_cursor)
670
$tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars")
675
def showStatus (txt, index)
676
tag = txt.tag_names(index).find{|t| t.kind_of?(String) && t =~ /^demo-/}
677
cursor = txt.cget('cursor')
679
$statusBarLabel.configure('text', " ")
682
demoname = tag[5..-1]
683
$statusBarLabel.configure('text',
684
"����ץ�ץ������ \"#{demoname}\" �μ¹� ")
687
txt.configure('cursor'=>newcursor) if cursor != newcursor
693
$code_window = nil unless defined? $code_window
694
if $code_window == nil || TkWinfo.exist?($code_window) == false
695
$code_window = TkToplevel.new(nil)
696
f = TkFrame.new($code_window)
704
}.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2)
707
# command proc{eval($code_text.get('1.0','end'), _null_binding)}
708
command proc{eval_samplecode($code_text.get('1.0','end'))}
709
}.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2)
710
# f.pack('side'=>'bottom', 'expand'=>'yes', 'fill'=>'x')
711
f.pack('side'=>'bottom', 'fill'=>'x')
713
if $tk_version =~ /^4\.[01]/
714
s = TkScrollbar.new($code_window, 'orient'=>'vertical')
715
$code_text = TkText.new($code_window) {
718
yscrollcommand proc{|first,last| s.set first,last}
720
s.command(proc{|*args| $code_text.yview(*args)})
721
s.pack('side'=>'right', 'fill'=>'y')
722
$code_text.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'both')
724
TkFrame.new($code_window) {|f|
725
pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>1)
727
hs = TkScrollbar.new($code_window, 'highlightthickness'=>0,
728
'orient'=>'horizontal')
729
vs = TkScrollbar.new($code_window, 'highlightthickness'=>0,
730
'orient'=>'vertical')
731
$code_text = TkText.new($code_window) {|t|
735
xscrollcommand proc{|first,last| hs.set first,last}
736
yscrollcommand proc{|first,last| vs.set first,last}
741
hs.command(proc{|*args| $code_text.xview(*args)})
742
vs.command(proc{|*args| $code_text.yview(*args)})
745
$code_text.grid('in'=>f, 'padx'=>1, 'pady'=>1, 'row'=>0, 'column'=>0,
746
'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
747
vs.grid('in'=>f, 'padx'=>1, 'pady'=>1, 'row'=>0, 'column'=>1,
748
'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
749
# xs.grid('in'=>f, 'padx'=>1, 'pady'=>1, 'row'=>1, 'column'=>0,
750
# 'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
751
TkGrid.rowconfigure(f, 0, 'weight'=>1, 'minsize'=>0)
752
TkGrid.columnconfigure(f, 0, 'weight'=>1, 'minsize'=>0)
756
$code_window.deiconify
759
$code_window.title("Demo code: #{file}")
760
$code_window.iconname(file)
761
# fid = open(file, 'r')
762
fid = open([$demo_dir, file].join(File::Separator), 'r')
763
$code_text.delete('1.0', 'end')
764
#$code_text.insert('1.0', `cat #{file}`)
765
$code_text.insert('1.0', fid.read)
766
#$code_mark = TkTextMark.new($code_text, '1.0')
767
#$code_text.set_insert('1.0')
768
TkTextMarkInsert.new($code_text,'1.0')
774
$code_window = nil unless defined? $code_window
775
if $code_window == nil || TkWinfo.exist?($code_window) == false
776
$code_window = TkToplevel.new(nil)
777
tf = TkFrame.new($code_window)
778
$code_text = TkText.new(tf, :font=>'Courier 10', :height=>30,
779
:wrap=>'word', :bd=>1, :setgrid=>true,
780
:highlightthickness=>0, :pady=>2, :padx=>3)
781
xscr = TkScrollbar.new(tf, :bd=>1){assign($code_text)}
782
yscr = TkScrollbar.new(tf, :bd=>1){assign($code_text)}
783
TkGrid($code_text, yscr, :sticky=>'news')
785
tf.grid_rowconfigure(0, :weight=>1)
786
tf.grid_columnconfigure(0, :weight=>1)
788
bf = TkFrame.new($code_window)
790
#b_dis = TkButton.new(bf, :text=>'�', :default=>:active,
791
b_dis = TkButton.new(bf, :text=>'�Ĥ���', :default=>:active,
796
:image=>$image['delete'], :compound=>:left)
797
b_prn = TkButton.new(bf, :text=>'����',
798
:command=>proc{printCode($code_text, file)},
799
:image=>$image['print'], :compound=>:left)
800
b_run = TkButton.new(bf, :text=>'�Ƽ¹�',
802
# eval($code_text.get('1.0','end'), _null_binding)
803
eval_samplecode($code_text.get('1.0','end'))
805
:image=>$image['refresh'], :compound=>:left)
807
TkGrid('x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4])
808
bf.grid_columnconfigure(0, :weight=>1)
810
TkGrid(tf, :sticky=>'news')
811
TkGrid(bf, :sticky=>'ew')
812
$code_window.grid_columnconfigure(0, :weight=>1)
813
$code_window.grid_rowconfigure(0, :weight=>1)
815
$code_window.bind('Return', proc{|win|
816
b_dis.invoke unless win.kind_of?(TkText)
818
$code_window.bindinfo('Return').each{|cmd, arg|
819
$code_window.bind_append('Escape', cmd, arg)
822
$code_window.deiconify
826
$code_window.title("Demo code: #{file}")
827
$code_window.iconname(file)
828
fid = open([$demo_dir, file].join(File::Separator), 'r')
829
$code_text.delete('1.0', 'end')
830
$code_text.insert('1.0', fid.read)
831
TkTextMarkInsert.new($code_text,'1.0')
836
alias showCode showCode1
837
elsif $tk_major_ver == 8 && $tk_minor_ver < 4
838
alias showCode showCode1
840
alias showCode showCode2
845
# Prints the source code currently displayed in the See Code dialog.
846
# Much thanks to Arjen Markus for this.
849
# txt - Name of text widget containing code to print
850
# file - Name of the original file (implicitly for title)
852
def printCode(txt, file)
853
code = txt.get('1.0', 'end - 1c')
855
dir = ENV['HOME'] if ENV['HOME']
856
dir = ENV['TMP'] if ENV['TMP']
857
dir = ENV['TEMP'] if ENV['TEMP']
859
fname = [dir, 'tkdemo-' + file].join(File::Separator)
860
open(fname, 'w'){|fid| fid.print(code)}
862
case Tk::TCL_PLATFORM('platform')
864
msg = `lp -c #{fname}`
865
unless $?.exitstatus == 0
866
Tk.messageBox(:title=>'Print spooling failure',
867
:message=>'���顼��ȯ�����ޤ�����' +
868
'�����˼��Ԥ�����ΤȻפ��ޤ� : ' + msg)
872
printTextWin32(fname)
874
Tk.messageBox(:title=>'Print spooling failure',
875
:message=>'���顼��ȯ�����ޤ�����' +
876
'�����˼��Ԥ�����ΤȻפ��ޤ� : ' +
880
Tk.messageBox(:title=>'Operation not Implemented',
881
:message=>'������ǽ�Ϥޤ���������Ƥ��ޤ���')
883
Tk.messageBox(:title=>'Operation not Implemented',
884
:message=>'���Ф��줿�Ķ� ' +
885
Tk::TCL_PLATFORM('platform') +
887
'������ǽ�ϼ�������Ƥ��ޤ���: ')
895
# Print a file under Windows
898
# filename - Name of the file
900
def printTextWin32(fname)
901
require 'win32/registry'
903
app = Win32::Registry::HKEY_CLASSES_ROOT['.txt']
905
Win32::Registry::HKEY_CLASSES_ROOT.open("#{app}\\shell\\print"){|reg|
906
pcmd = reg['command']
909
app = Tk.tk_call('auto_execok', 'notepad.exe')
910
pcmd = "#{app} /p %1"
913
pcmd.gsub!('%1', fname)
915
cmd = Tk.tk_call('auto_execok', 'start') + ' /min ' + pcmd
918
unless $?.exitstatus == 0
919
fail RuntimeError, msg
925
# Pops up a message box with an "about" message
928
Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo',
929
'message'=>"Ruby/Tk ���������åȥǥ� Ver.1.6.0-jp\n\n" +
930
"based on demos of Tk8.1 -- 8.5 " +
932
"(c) 1996-1997 Sun Microsystems, Inc. / " +
933
"(c) 1997-2000 Ajuba Solutions, Inc. / " +
934
"(c) 2001-2003 Donal K. Fellows )\n\n" +
935
"Your Ruby & Tk Version ::\n" +
936
"Ruby#{RUBY_VERSION}(#{RUBY_RELEASE_DATE})[#{RUBY_PLATFORM}] / Tk#{$tk_patchlevel}#{(Tk::JAPANIZED_TK)? '-jp': ''}\n\n" +
937
"Ruby/Tk release date :: tcltklib #{TclTkLib::RELEASE_DATE}; tk #{Tk::RELEASE_DATE}")
940
####################################
941
# �����ǻ��ꤵ�줿�ǥ��ư����
945
no_launcher = true if ARGV.size > 0
947
# show the root widget to make it lower then demo windows
954
#eval(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join,
956
eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join)
959
$root.withdraw # hide root window
963
$root.winfo_children.each{|w|
964
count += 1 if w.kind_of?(TkToplevel)
966
$root.destroy if count == 0
971
################################