~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to ext/tk/sample/demos-jp/widget

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
# �������������� ( tk.rb �Υ����ɻ��� encoding ����/����˻Ȥ��� )
 
4
$KCODE = 'euc'
 
5
 
 
6
# tk �ط��饤�֥����ɤ߹���
 
7
require 'tk'
 
8
# require 'tkafter'
 
9
 
 
10
# widget demo directory ���֤γ���
 
11
$demo_dir = File.dirname($0)
 
12
 
 
13
# root ������
 
14
$root = TkRoot.new{title "Ruby/Tk Widget Demonstration"}
 
15
 
 
16
# tk �С������μ���
 
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
 
20
 
 
21
# tcl_platform ����ؤΥ����������֥�������
 
22
$tk_platform = TkVarAccess.new('tcl_platform')
 
23
 
 
24
# �ե��������
 
25
#######
 
26
case($tk_version)
 
27
when /^4.*/
 
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-*-*-*-*-*-*',
 
31
                           knjfont)
 
32
  TkOption.add('*kanjiFont', knjfont, 'startupFile')
 
33
  $msg_kanji_font=TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
 
34
                             '-*--24-*-jisx0208.1983-0')
 
35
 
 
36
#when '8.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')
 
41
 
 
42
when /^8.*/
 
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')
 
47
 
 
48
else
 
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-*-*-*-*-*-*',
 
52
                           knjfont)
 
53
  TkOption.add('*kanjiFont', knjfont, 'startupFile')
 
54
  $msg_kanji_font=TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
 
55
                             '-*--24-*-jisx0208.1983-0')
 
56
end
 
57
#######
 
58
 
 
59
# ���᡼������
 
60
$image = {}
 
61
 
 
62
if $tk_major_ver >= 8
 
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==
 
69
EOD
 
70
end
 
71
 
 
72
if $tk_major_ver >= 8
 
73
$image['view'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
 
74
    R0lGODlhEAAQAPMAAMz/zP///8DAwICAgH9/fwAAAAAAAAAAAAAAAAAAAAAA
 
75
    AAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAwRIcMhJB7h3hM33
 
76
    KFjWdQQYap1QrCaGBmrRrS4nj5b53jOgbwXBKGACoYLDIuAoHCmZyYvR1rT5
 
77
    RMAq8LqcIYGsrjPsW1XOmFUEADs=
 
78
EOD
 
79
end
 
80
 
 
81
if $tk_major_ver >= 8
 
82
$image['delete'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
 
83
    R0lGODlhEAAOAKEAAIQAAO/n3v///////yH5BAEKAAIALAAAAAAQAA4AAAIm
 
84
    lI9pAKHbIHNoVhYhTdjlJ2AWKG2g+CldmB6rxo2uybYhbS80eRQAOw==
 
85
EOD
 
86
end
 
87
 
 
88
if $tk_major_ver >= 8
 
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
 
115
EOD
 
116
end
 
117
 
 
118
# ��˥塼����
 
119
TkMenubar.new($root, 
 
120
              [[['File', 0], 
 
121
                  ['About ... ', proc{aboutBox}, 0, '<F1>'],
 
122
                  '---', 
 
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})
 
127
 
 
128
=begin
 
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
 
133
    }
 
134
    menu m
 
135
    text 'File'
 
136
    underline 0
 
137
  }.pack('side'=>'left')
 
138
}.pack('side'=>'top', 'fill'=>'x')
 
139
=end
 
140
 
 
141
# �ƥ����ȥܥå���������
 
142
if $tk_version =~ /^4\.[01]/
 
143
  scr = TkScrollbar.new($root, 'orient'=>'vertical')
 
144
  txt = TkText.new($root) {
 
145
    #wrap 'word'
 
146
    wrap 'char'
 
147
    width 70
 
148
    height 30
 
149
    font $font
 
150
    setgrid 'yes'
 
151
    yscrollcommand proc{|first,last| scr.set first,last}
 
152
  }
 
153
  scr.command(proc{|*args| txt.yview(*args)})
 
154
  scr.pack('side'=>'right', 'fill'=>'y')
 
155
  txt.pack('expand'=>'yes', 'fill'=>'both')
 
156
else
 
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)
 
161
  }
 
162
  txt = TkText.new($root) {
 
163
    #wrap 'word'
 
164
    wrap 'char'
 
165
    width 70
 
166
    height 30
 
167
    font $font
 
168
    setgrid 'yes'
 
169
    highlightthickness 0
 
170
    padx 4
 
171
    pady 2
 
172
    takefocus 0
 
173
    bd 1
 
174
    yscrollcommand proc{|first,last| scr.set first,last}
 
175
  }
 
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')
 
181
 
 
182
  statusBar = TkFrame.new($root) {|f|
 
183
    $statusBarLabel = \
 
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)
 
191
end
 
192
 
 
193
# �ƥ����ȥ�������
 
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')
 
200
 
 
201
if TkWinfo.depth($root) == 1
 
202
  tag_demo = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c', 
 
203
                           'underline'=>1)
 
204
  $tag_visited = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c', 
 
205
                              'underline'=>1)
 
206
  tag_hot = TkTextTag.new(txt, 'background'=>'black', 'foreground'=>'white')
 
207
else
 
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')
 
215
end
 
216
 
 
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')
 
220
 
 
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}")
 
227
              },
 
228
              '%x %y')
 
229
tag_demo.bind('Leave', 
 
230
              proc{
 
231
                tag_hot.remove('1.0','end')
 
232
                txt.configure('cursor','xterm')
 
233
                $statusBarLabel.configure('text'=>"")
 
234
              })
 
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-/
 
242
                      } )
 
243
                    tag_hot.add(lastLine.value, 
 
244
                                "#{lastLine.value} lineend -1 chars")
 
245
                  end
 
246
                end
 
247
                showStatus txt, txt.index("@#{x},#{y}")
 
248
              },
 
249
              '%x %y')
 
250
 
 
251
# �ƥ���������
 
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")
 
256
 
 
257
���Υ��ץꥱ�������ϡ�Tk Widget ���Ѥ��ƤɤΤ褦�ʤ��Ȥ��Ǥ��뤫\
 
258
�򼨤�����Ρ������Ĥ��ξ����ʥ�����ץȤ��Ф���ե���ȥ���ɤ���\
 
259
�����Ƥ��ޤ����ʲ��˽��֤˵󤲤��Ƥ���ǥ�󥹥ȥ졼������¹�\
 
260
����ˤϥޥ����ǥ���å����Ƥ����������ǥ�󥹥ȥ졼�����Υ�����\
 
261
�ɥ��������ȡ��ǥ�󥹥ȥ졼�������������� Ruby/Tk �Υ����ɤ�\
 
262
�뤿��ˡ�"�����ɻ���"�ܥ���򥯥�å����뤳�Ȥ��Ǥ��ޤ������ʤ���\
 
263
˾��ʤ顢���Υ����ɤ������뤳�Ȥ��Ǥ��ޤ����������������ɤǥǥ�\
 
264
�󥹥ȥ졼������Ƽ¹Ԥ��뤿��ˤϡ������ɤ��񤫤줿������ɥ���\
 
265
����"�ǥ�Ƽ¹�" �ܥ���򥯥�å����Ƥ���������
 
266
 
 
267
�����Υǥ�Ǥϡ����Ū�Ƕ�ΥС������� Tk �Ǥʤ���Х��ݡ��Ȥ���\
 
268
���ʤ���ǽ��ȤäƼ������Ƥ��ޤ�(�㤨�� Tk8.4 �ʾ�ʤ�)�����Τ��ᡤ\
 
269
����������ǽ������ʤ� Tk �饤�֥���ȤäƤ�����ˤϡ���������\
 
270
�ǥ��������ư���ޤ��󡥤��Τ褦�ʵ�ǽ��ɬ�פǤ���С�����򥵥ݡ���\
 
271
���Ƥ��� Tk �饤�֥���Ȥ��褦�ˡ�tcltklib �򥳥�ѥ��뤷�ʤ�����\
 
272
����������
 
273
 
 
274
 
 
275
EOT
 
276
 
 
277
#txt.insert('end',"��٥�, �ܥ���, �����å��ܥ���, �饸���ܥ���\n",tag_middle)
 
278
txt.insert('end', "��٥�, �ܥ���, �����å��ܥ���, �饸���ܥ���\n", 
 
279
           tag_kanji_title)
 
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)
 
321
 
 
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)
 
333
 
 
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)
 
350
 
 
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)
 
370
 
 
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)
 
392
 
 
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)
 
401
 
 
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)
 
411
 
 
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)
 
428
 
 
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)
 
439
 
 
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")
 
451
 
 
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)
 
464
 
 
465
txt.state('disabled')
 
466
scr.focus
 
467
 
 
468
################################
 
469
# method ���
 
470
################################
 
471
def positionWindow(w)
 
472
  w.geometry('+300+300')
 
473
end
 
474
 
 
475
# �ƥ��������åȤȡ��ѿ�̾�� TkVariable �Ȥ���(����)���¤Ӥ��Ϥ�
 
476
$showVarsWin = {}
 
477
def showVars1(parent, *args)
 
478
  if $showVarsWin[parent.path]
 
479
    begin
 
480
      $showVarsWin[parent.path].destroy 
 
481
    rescue
 
482
    end
 
483
  end
 
484
  top = TkToplevel.new(parent) {|w|
 
485
    title "Variable values"
 
486
    TkLabel.new(w) {
 
487
      text "�ѿ���:"
 
488
      width 20
 
489
      anchor 'center'
 
490
      font '-Adobe-helvetica-medium-r-normal--*-180-*-*-*-*-*-*'
 
491
    }.pack('side'=>'top', 'fill'=>'x')
 
492
    len = 1
 
493
    args.each{|vnam,vbody|
 
494
      len = vnam.to_s.length if vnam.to_s.length > len
 
495
    }
 
496
    args.each{|vnam,vbody|
 
497
      TkFrame.new(w){|f|
 
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')
 
503
    }
 
504
    TkButton.new(w) {
 
505
      text "λ��"
 
506
      command proc{w.destroy}
 
507
    }.pack('side'=>'bottom', 'pady'=>2)
 
508
  }
 
509
  $showVarsWin[parent.path] = top
 
510
end
 
511
 
 
512
def showVars2(parent, *args)
 
513
  if $showVarsWin[parent.path]
 
514
    begin
 
515
      $showVarsWin[parent.path].destroy 
 
516
    rescue
 
517
    end
 
518
  end
 
519
  $showVarsWin[parent.path] = TkToplevel.new(parent) {|w|
 
520
    title "Variable values"
 
521
 
 
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')
 
528
      }
 
529
 
 
530
      f.grid(:sticky=>'news', :padx=>4)
 
531
      f.grid_columnconfig(1, :weight=>1)
 
532
      f.grid_rowconfig(100, :weight=>1)
 
533
    }
 
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})
 
538
 
 
539
      b.grid(:sticky=>'e', :padx=>4, :pady=>[6, 4])
 
540
    }
 
541
    w.grid_columnconfig(0, :weight=>1)
 
542
    w.grid_rowconfig(0, :weight=>1)
 
543
  }
 
544
end
 
545
 
 
546
if $tk_major_ver < 8
 
547
  alias showVars showVars1
 
548
elsif $tk_major_ver == 8 && $tk_minor_ver < 4
 
549
  alias showVars showVars1
 
550
else # ver >= 8.4
 
551
  alias showVars showVars2
 
552
end
 
553
 
 
554
# �����ȥåץ�٥륵�ݡ���
 
555
module PseudoToplevel_Evaluable
 
556
  def pseudo_toplevel_eval(body = Proc.new)
 
557
    Thread.current[:TOPLEVEL] = self
 
558
    begin
 
559
      body.call
 
560
    ensure
 
561
      Thread.current[:TOPLEVEL] = nil
 
562
    end
 
563
  end
 
564
 
 
565
  def pseudo_toplevel_evaluable?
 
566
    @pseudo_toplevel_evaluable
 
567
  end
 
568
  def pseudo_toplevel_evaluable=(mode)
 
569
    @pseudo_toplevel_evaluable = (mode)? true: false
 
570
  end
 
571
 
 
572
  def self.extended(mod)
 
573
    mod.__send__(:extend_object, mod)
 
574
    mod.instance_variable_set('@pseudo_toplevel_evaluable', true)
 
575
  end
 
576
end
 
577
 
 
578
class Object
 
579
  alias __method_missing__ method_missing
 
580
  private :__method_missing__
 
581
 
 
582
  def method_missing(id, *args)
 
583
    begin
 
584
      has_top = (top = Thread.current[:TOPLEVEL]) && 
 
585
                   top.respond_to?(:pseudo_toplevel_evaluable?) && 
 
586
                   top.pseudo_toplevel_evaluable? && 
 
587
                   top.respond_to?(id)
 
588
    rescue Exception => e
 
589
      has_top = false
 
590
    end
 
591
 
 
592
    if has_top
 
593
      top.__send__(id, *args)
 
594
    else
 
595
      __method_missing__(id, *args)
 
596
    end
 
597
  end
 
598
end
 
599
 
 
600
class Proc
 
601
  def initialize(*args, &b)
 
602
    super
 
603
    @__pseudo_toplevel__ = Thread.current[:TOPLEVEL]
 
604
  end
 
605
 
 
606
  alias __call__ call
 
607
  def call(*args, &b)
 
608
    if top = @__pseudo_toplevel__
 
609
      orig_top = Thread.current[:TOPLEVEL]
 
610
      Thread.current[:TOPLEVEL] = top
 
611
      begin
 
612
        __call__(*args, &b)
 
613
      ensure
 
614
        Thread.current[:TOPLEVEL] = orig_top
 
615
      end
 
616
    else
 
617
      __call__(*args, &b)
 
618
    end
 
619
  end
 
620
end
 
621
 
 
622
def proc(&b)
 
623
  Proc.new(&b)
 
624
end
 
625
def lambda(&b)
 
626
  Proc.new(&b)
 
627
end
 
628
 
 
629
def _null_binding
 
630
  Module.new.instance_eval{extend PseudoToplevel_Evaluable}
 
631
  # binding
 
632
  # Module.new.instance_eval{binding}
 
633
end
 
634
private :_null_binding
 
635
 
 
636
def eval_samplecode(code)
 
637
  Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } }.run
 
638
  Tk.update
 
639
end
 
640
 
 
641
# �ƥ����Ⱦ�Ǥ� click ���Ф���ư��
 
642
def invoke(txt, idx)
 
643
  tag = txt.tag_names(idx).find{|t| t.kind_of?(String) && t =~ /^demo-/}
 
644
  return unless tag
 
645
 
 
646
  cursor = txt.cget('cursor')
 
647
  txt.cursor('watch')
 
648
  Tk.update
 
649
  # eval(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, _null_binding)
 
650
  # Tk.update
 
651
  eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join)
 
652
  txt.cursor(cursor)
 
653
 
 
654
  $tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars")
 
655
end
 
656
=begin
 
657
def invoke (txt, idx)
 
658
  tag = txt.tag_names(idx).find{|t| t.kind_of?(String) && t =~ /^demo-/}
 
659
  return unless tag
 
660
  current_cursor = txt.cget('cursor')
 
661
  txt.cursor('watch')
 
662
  Tk.update
 
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
 
666
  Tk.update
 
667
#  txt.cursor('xterm')
 
668
  txt.cursor(current_cursor)
 
669
 
 
670
  $tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars")
 
671
end
 
672
=end
 
673
 
 
674
# ����ɽ��
 
675
def showStatus (txt, index)
 
676
  tag = txt.tag_names(index).find{|t| t.kind_of?(String) && t =~ /^demo-/}
 
677
  cursor = txt.cget('cursor')
 
678
  unless tag
 
679
    $statusBarLabel.configure('text', " ")
 
680
    newcursor = 'xterm'
 
681
  else
 
682
    demoname = tag[5..-1]
 
683
    $statusBarLabel.configure('text', 
 
684
                             "����ץ�ץ������ \"#{demoname}\" �μ¹� ")
 
685
    newcursor = 'hand2'
 
686
  end
 
687
  txt.configure('cursor'=>newcursor) if cursor != newcursor
 
688
end
 
689
 
 
690
# �����������ɤ�ɽ��
 
691
def showCode1(demo)
 
692
  file = "#{demo}.rb"
 
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)
 
697
    TkButton.new(f) {
 
698
      #text "λ��"
 
699
      text "�Ĥ���"
 
700
      command proc{
 
701
        $code_window.destroy
 
702
        $code_window = nil
 
703
      }
 
704
    }.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2)
 
705
    TkButton.new(f) {
 
706
      text "�Ƽ¹�"
 
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')
 
712
 
 
713
    if $tk_version =~ /^4\.[01]/
 
714
      s = TkScrollbar.new($code_window, 'orient'=>'vertical')
 
715
      $code_text = TkText.new($code_window) {
 
716
        height 40
 
717
        setgrid 'yes'
 
718
        yscrollcommand proc{|first,last| s.set first,last}
 
719
      }
 
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')
 
723
    else
 
724
      TkFrame.new($code_window) {|f|
 
725
        pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>1)
 
726
 
 
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|
 
732
          height 40
 
733
          #wrap 'word'
 
734
          wrap 'char'
 
735
          xscrollcommand proc{|first,last| hs.set first,last}
 
736
          yscrollcommand proc{|first,last| vs.set first,last}
 
737
          setgrid 'yes'
 
738
          highlightthickness 0
 
739
          pady 2
 
740
          padx 3
 
741
          hs.command(proc{|*args| $code_text.xview(*args)})
 
742
          vs.command(proc{|*args| $code_text.yview(*args)})
 
743
        }
 
744
 
 
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)
 
753
      }
 
754
    end
 
755
  else
 
756
    $code_window.deiconify
 
757
    $code_window.raise
 
758
  end
 
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')
 
769
  fid.close
 
770
end
 
771
 
 
772
def showCode2(demo)
 
773
  file = "#{demo}.rb"
 
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')
 
784
    #TkGrid(xscr)
 
785
    tf.grid_rowconfigure(0, :weight=>1)
 
786
    tf.grid_columnconfigure(0, :weight=>1)
 
787
 
 
788
    bf = TkFrame.new($code_window)
 
789
    
 
790
    #b_dis = TkButton.new(bf, :text=>'λ��', :default=>:active, 
 
791
    b_dis = TkButton.new(bf, :text=>'�Ĥ���', :default=>:active, 
 
792
                         :command=>proc{
 
793
                           $code_window.destroy
 
794
                           $code_window = nil
 
795
                         }, 
 
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=>'�Ƽ¹�', 
 
801
                         :command=>proc{
 
802
                           # eval($code_text.get('1.0','end'), _null_binding)
 
803
                           eval_samplecode($code_text.get('1.0','end'))
 
804
                         }, 
 
805
                         :image=>$image['refresh'], :compound=>:left)
 
806
 
 
807
    TkGrid('x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4])
 
808
    bf.grid_columnconfigure(0, :weight=>1)
 
809
 
 
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)
 
814
 
 
815
    $code_window.bind('Return', proc{|win|
 
816
                        b_dis.invoke unless win.kind_of?(TkText)
 
817
                      }, '%W')
 
818
    $code_window.bindinfo('Return').each{|cmd, arg|
 
819
      $code_window.bind_append('Escape', cmd, arg)
 
820
    }
 
821
  else
 
822
    $code_window.deiconify
 
823
    $code_window.raise
 
824
  end
 
825
 
 
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')
 
832
  fid.close
 
833
end
 
834
 
 
835
if $tk_major_ver < 8
 
836
  alias showCode showCode1
 
837
elsif $tk_major_ver == 8 && $tk_minor_ver < 4
 
838
  alias showCode showCode1
 
839
else # ver >= 8.4
 
840
  alias showCode showCode2
 
841
end
 
842
 
 
843
 
 
844
# printCode --
 
845
# Prints the source code currently displayed in the See Code dialog.
 
846
# Much thanks to Arjen Markus for this.
 
847
#
 
848
# Arguments:
 
849
# txt -         Name of text widget containing code to print
 
850
# file -        Name of the original file (implicitly for title)
 
851
 
 
852
def printCode(txt, file)
 
853
  code = txt.get('1.0', 'end - 1c')
 
854
  dir = '.'
 
855
  dir = ENV['HOME'] if ENV['HOME']
 
856
  dir = ENV['TMP'] if ENV['TMP']
 
857
  dir = ENV['TEMP'] if ENV['TEMP']
 
858
 
 
859
  fname = [dir, 'tkdemo-' + file].join(File::Separator)
 
860
  open(fname, 'w'){|fid| fid.print(code)}
 
861
  begin
 
862
    case Tk::TCL_PLATFORM('platform')
 
863
    when 'unix'
 
864
      msg = `lp -c #{fname}`
 
865
      unless $?.exitstatus == 0
 
866
        Tk.messageBox(:title=>'Print spooling failure', 
 
867
                      :message=>'���顼��ȯ�����ޤ�����' + 
 
868
                                '�����˼��Ԥ�����ΤȻפ��ޤ� : ' + msg)
 
869
      end
 
870
    when 'windows'
 
871
      begin
 
872
        printTextWin32(fname)
 
873
      rescue => e
 
874
        Tk.messageBox(:title=>'Print spooling failure', 
 
875
                      :message=>'���顼��ȯ�����ޤ�����' + 
 
876
                                '�����˼��Ԥ�����ΤȻפ��ޤ� : ' + 
 
877
                                e.message)
 
878
      end      
 
879
    when 'macintosh'
 
880
      Tk.messageBox(:title=>'Operation not Implemented', 
 
881
                    :message=>'������ǽ�Ϥޤ���������Ƥ��ޤ���')
 
882
    else
 
883
      Tk.messageBox(:title=>'Operation not Implemented', 
 
884
                    :message=>'���Ф��줿�Ķ� ' + 
 
885
                              Tk::TCL_PLATFORM('platform') + 
 
886
                              ' ��̤�ΤδĶ��Ǥ��뤿�ᡤ' + 
 
887
                              '������ǽ�ϼ�������Ƥ��ޤ���: ')
 
888
    end
 
889
  ensure
 
890
    File.delete(fname)
 
891
  end
 
892
end
 
893
 
 
894
# printTextWin32 --
 
895
#    Print a file under Windows
 
896
#
 
897
# Arguments:
 
898
# filename -            Name of the file
 
899
#
 
900
def printTextWin32(fname)
 
901
  require 'win32/registry'
 
902
  begin
 
903
    app = Win32::Registry::HKEY_CLASSES_ROOT['.txt']
 
904
    pcmd = nil
 
905
    Win32::Registry::HKEY_CLASSES_ROOT.open("#{app}\\shell\\print"){|reg|
 
906
      pcmd = reg['command']
 
907
    }
 
908
  rescue
 
909
    app = Tk.tk_call('auto_execok', 'notepad.exe')
 
910
    pcmd = "#{app} /p %1"
 
911
  end
 
912
 
 
913
  pcmd.gsub!('%1', fname)
 
914
  puts pcmd
 
915
  cmd = Tk.tk_call('auto_execok', 'start') + ' /min ' + pcmd
 
916
  
 
917
  msg = `#{cmd}`
 
918
  unless $?.exitstatus == 0
 
919
    fail RuntimeError, msg
 
920
  end
 
921
end
 
922
 
 
923
# aboutBox
 
924
#
 
925
#      Pops up a message box with an "about" message
 
926
#
 
927
def aboutBox
 
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  " + 
 
931
                           "( Copyright:: " + 
 
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}")
 
938
end
 
939
 
 
940
####################################
 
941
# �����ǻ��ꤵ�줿�ǥ��ư����
 
942
no_launcher = false
 
943
if ARGV[0] == '-n'
 
944
  ARGV.shift
 
945
  no_launcher = true if ARGV.size > 0
 
946
else
 
947
  # show the root widget to make it lower then demo windows
 
948
  Tk.update
 
949
end
 
950
ARGV.each{|cmd| 
 
951
  if cmd =~ /(.*).rb/
 
952
    cmd = $1
 
953
  end
 
954
  #eval(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join, 
 
955
  #     _null_binding)
 
956
  eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join)
 
957
}
 
958
if no_launcher
 
959
  $root.withdraw  # hide root window
 
960
  Thread.start{
 
961
    loop do
 
962
      count = 0
 
963
      $root.winfo_children.each{|w|
 
964
        count += 1 if w.kind_of?(TkToplevel)
 
965
      }
 
966
      $root.destroy if count == 0
 
967
    end
 
968
  }
 
969
end
 
970
 
 
971
################################
 
972
# ���٥���Ԥ�������
 
973
Tk.mainloop