Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > media > main > by-pkgid > e2a5fef11a7f55d2dc803b8b7498c8e5 > files > 498

ruby-tcltk-1.8.5-31.el5_9.x86_64.rpm

#!/usr/bin/env ruby

# ´Á»ú¥³¡¼¥ÉÀßÄê ( tk.rb ¤Î¥í¡¼¥É»þ¤Î encoding ¿äÄê/ÀßÄê¤Ë»È¤ï¤ì¤ë )
$KCODE = 'euc'

# tk ´Ø·¸¥é¥¤¥Ö¥é¥ê¤ÎÆɤ߹þ¤ß
require 'tk'
# require 'tkafter'

# widget demo directory °ÌÃ֤γÍÆÀ
$demo_dir = File.dirname($0)

# root ¤ÎÀ¸À®
$root = TkRoot.new{title "Ruby/Tk Widget Demonstration"}

# tk ¥Ð¡¼¥¸¥ç¥ó¤Î¼èÆÀ
$tk_version = Tk::TK_VERSION
$tk_major_ver, $tk_minor_ver = $tk_version.split('.').map{|n| n.to_i}
$tk_patchlevel = Tk::TK_PATCHLEVEL

# tcl_platform ¾ðÊó¤Ø¤Î¥¢¥¯¥»¥¹¥ª¥Ö¥¸¥§¥¯¥È
$tk_platform = TkVarAccess.new('tcl_platform')

# ¥Õ¥©¥ó¥ÈÀßÄê
#######
case($tk_version)
when /^4.*/
  $font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*', nil)
  knjfont = '-*--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-*-*-*-*-*-*',
                             '-*--24-*-jisx0208.1983-0')

#when '8.0'
#  $font = TkFont.new('Helvetica -12')
#  $kanji_font = TkFont.new('Helvetica -12', 'Mincho -12')
#  TkOption.add('*kanjiFont', knjfont, 'startupFile')
#  $msg_kanji_font=TkFont.new('Helvetica 16', 'Gothic 16 bold')

when /^8.*/
  $font = TkFont.new('Helvetica -12')
  $kanji_font = TkFont.new('Helvetica -12', 'Mincho -12')
  TkOption.add('*kanjiFont', knjfont, 'startupFile')
  $msg_kanji_font=TkFont.new('Helvetica 16', 'Gothic 16 bold')

else
  $font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*', nil)
  knjfont = '-*--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-*-*-*-*-*-*',
                             '-*--24-*-jisx0208.1983-0')
end
#######

# ¥¤¥á¡¼¥¸ÀßÄê
$image = {}

if $tk_major_ver >= 8
$image['refresh'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
    R0lGODlhEAAQAPMAAMz/zCpnKdb/1z9mPypbKBtLGy9NMPL/9Or+6+P+4j1Y
    PwQKBP7//xMLFAYBCAEBASH5BAEAAAAALAAAAAAQABAAAwR0EAD3Gn0Vyw0e
    ++CncU7IIAezMA/nhUqSLJizvSdCEEjy2ZIV46AwDAoDHwPYGSoEiUJAAGJ6
    EDHBNCFINW5OqABKSFk/B9lUa94IDwIFgewFMwQDQwCZQCztTgM9Sl8SOEMG
    KSAthiaOjBMPDhQONBiXABEAOw==
EOD
end

if $tk_major_ver >= 8
$image['view'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
    R0lGODlhEAAQAPMAAMz/zP///8DAwICAgH9/fwAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAwRIcMhJB7h3hM33
    KFjWdQQYap1QrCaGBmrRrS4nj5b53jOgbwXBKGACoYLDIuAoHCmZyYvR1rT5
    RMAq8LqcIYGsrjPsW1XOmFUEADs=
EOD
end

if $tk_major_ver >= 8
$image['delete'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
    R0lGODlhEAAOAKEAAIQAAO/n3v///////yH5BAEKAAIALAAAAAAQAA4AAAIm
    lI9pAKHbIHNoVhYhTdjlJ2AWKG2g+CldmB6rxo2uybYhbS80eRQAOw==
EOD
end

if $tk_major_ver >= 8
$image['print'] = TkPhotoImage.new(:height=>19, :format=>'GIF', :data=><<EOD)
    R0lGODlhGgATAPcAACEQOTEpQjEpUkIpc0IxY0I5c0oxjEo5SlJCY1JCe1JK
    UlpChFpCjFpGkFpSc1paa2NKc2NKnGNja2tapWtjc29KnHNanHNjc3NjrXNr
    jHNrnHNzc3tjpXtrtXtzhICAgIRzvYSEjIZzqox7tYyEnIyMjJSEtZSEvZSM
    lJyMtZyMvZyUlJyUrZyUvZycnKWctaWlpa2czq2lzrWtvbWtzrW1tb21xr21
    1sa9zs693s7OztbO3tbO597W1t7W7+fe7+fn5////+/n7+/v7+/v9////wAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAACH5BAEAAEEALAAAAAAaABMAQAj/AIMIHBhkg0GC
    CBMGIQEiQgseQT4oeCBBAokgRYYQ0JBixg8hRIiUUEBBYYmTByBwiCBCRYwH
    CxY8cKFw4AogRXLqLAJkQ80gCBBg3BkxZswTNGh4MGqgQQUMJRHCwMkTSE+D
    Pn8eCKBhxIMhO3ei2OHDBw6sWSlMMMoWgwwfMDZI8GBjx44NARZwEGGi5MkS
    PcIWKRGz5YgLbAco+KkQBQoJIRgjdGEVq+SaJajqtNrzMgsPCmoIzqmDgmWE
    KOBuUKAAwYabYTfs4OHjY0giGyhk4MAWRI4eKyRQqPgggYUXPH4A+XBAgwoK
    DiIsCFxjA9sFEVQQCRJCAYAFDJxiKhAxvMTonEFimrhhYinTBgWiCvxLNX3M
    DkkpsKV5OYhjBxCMYAICAigUEAA7
EOD
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})
$root.bind('Meta-q', proc{exit})

=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 70
    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 70
    height 30
    font $font
    setgrid 'yes'
    highlightthickness 0
    padx 4
    pady 2
    takefocus 0
    bd 1
    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_kanji_title = TkTextTag.new(txt, 'font'=>$msg_kanji_font)
tag_middle = TkTextTag.new(txt, 'font'=>$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. ¥é¥Ù¥ë¤ÈUNICODE¥Æ¥­¥¹¥È (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", tag_demo, "demo-unicodeout")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3. ¥Ü¥¿¥ó \n", tag_demo, "demo-button")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. ¥Á¥§¥Ã¥¯¥Ü¥¿¥ó (Ê£¿ô¤òÁªÂò²Äǽ)\n", 
           tag_demo, "demo-check")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "5. £³¾õÂÖ¥Á¥§¥Ã¥¯¥Ü¥¿¥ó (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", 
           tag_demo, "demo-check2")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "6. ¥é¥¸¥ª¥Ü¥¿¥ó (Ǥ°Õ¤Î°ì¤Ä¤òÁªÂò²Äǽ)\n", 
           tag_demo, "demo-radio")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "7. ¥é¥¸¥ª¥Ü¥¿¥ó (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", 
           tag_demo, "demo-radio2")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "8. £³¾õÂ֥饸¥ª¥Ü¥¿¥ó (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", 
           tag_demo, "demo-radio3")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "9. ¥Ü¥¿¥ó¤Çºî¤é¤ì¤¿15-¥Ñ¥º¥ë¥²¡¼¥à\n", 
           tag_demo, "demo-puzzle")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "10. ¥Ó¥Ã¥È¥Þ¥Ã¥×¤ò»ÈÍѤ·¤¿¥¢¥¤¥³¥ó¥Ü¥¿¥ó\n", 
           tag_demo, "demo-icon")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "11. ²èÁü¤òɽ¼¨¤¹¤ëÆó¤Ä¤Î¥é¥Ù¥ë\n", 
           tag_demo, "demo-image1")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "12. ²èÁü¤ò¸«¤ë¤¿¤á¤Î´Êñ¤Ê¥æ¡¼¥¶¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹\n", 
           tag_demo, "demo-image2")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "13. ²èÁü¤ò¸«¤ë¤¿¤á¤Î´Êñ¤Ê¥æ¡¼¥¶¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹ (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", 
           tag_demo, "demo-image3")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "14. ¥é¥Ù¥ëÉÕ¤­¥Õ¥ì¡¼¥à (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤Î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. ¥¦¥£¥ó¥É¥¦¤òËä¤á¹þ¤ó¤À¥Æ¥­¥¹¥È (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", 
           tag_demo, "demo-twind2")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "6. ¸¡º÷\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-floor2")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "8. ¥¹¥¯¥í¡¼¥ë²Äǽ¤Ê¥­¥ã¥ó¥Ð¥¹\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. ¥¢¥Ë¥á¡¼¥·¥ç¥ó¥é¥Ù¥ë (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", tag_demo, "demo-anilabel")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. ÇÈ·Á¤Î¥¢¥Ë¥á¡¼¥·¥ç¥ó (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", tag_demo, "demo-aniwave")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3. ¿¶¤ê»Ò¤Î¥·¥ß¥å¥ì¡¼¥·¥ç¥ó (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", tag_demo, "demo-pendulum")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. A celebration of Rube Goldberg (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", tag_demo, "demo-goldberg")

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 showVars1(parent, *args)
  if $showVarsWin[parent.path]
    begin
      $showVarsWin[parent.path].destroy 
    rescue
    end
  end
  top = 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] = top
end

def showVars2(parent, *args)
  if $showVarsWin[parent.path]
    begin
      $showVarsWin[parent.path].destroy 
    rescue
    end
  end
  $showVarsWin[parent.path] = TkToplevel.new(parent) {|w|
    title "Variable values"

    TkLabelFrame.new(w, :text=>"ÊÑ¿ôÃÍ:", 
                     :font=>{:family=>'Helvetica', :size=>14}){|f|
      args.each{|vnam,vbody|
        TkGrid(TkLabel.new(f, :text=>"#{vnam}: ", :anchor=>'w'), 
               TkLabel.new(f, :textvariable=>vbody, :anchor=>'w'), 
               :padx=>2, :pady=>2, :sticky=>'w')
      }

      f.grid(:sticky=>'news', :padx=>4)
      f.grid_columnconfig(1, :weight=>1)
      f.grid_rowconfig(100, :weight=>1)
    }
    TkButton.new(w, :text=>"λ²ò", :width=>8, :default=>:active, 
                 :command=>proc{w.destroy}){|b|
      w.bind('Return', proc{b.invoke})
      w.bind('Escape', proc{b.invoke})

      b.grid(:sticky=>'e', :padx=>4, :pady=>[6, 4])
    }
    w.grid_columnconfig(0, :weight=>1)
    w.grid_rowconfig(0, :weight=>1)
  }
end

if $tk_major_ver < 8
  alias showVars showVars1
elsif $tk_major_ver == 8 && $tk_minor_ver < 4
  alias showVars showVars1
else # ver >= 8.4
  alias showVars showVars2
end

# µ¿»÷¥È¥Ã¥×¥ì¥Ù¥ë¥µ¥Ý¡¼¥È
module PseudoToplevel_Evaluable
  def pseudo_toplevel_eval(body = Proc.new)
    Thread.current[:TOPLEVEL] = self
    begin
      body.call
    ensure
      Thread.current[:TOPLEVEL] = nil
    end
  end

  def pseudo_toplevel_evaluable?
    @pseudo_toplevel_evaluable
  end
  def pseudo_toplevel_evaluable=(mode)
    @pseudo_toplevel_evaluable = (mode)? true: false
  end

  def self.extended(mod)
    mod.__send__(:extend_object, mod)
    mod.instance_variable_set('@pseudo_toplevel_evaluable', true)
  end
end

class Object
  alias __method_missing__ method_missing
  private :__method_missing__

  def method_missing(id, *args)
    begin
      has_top = (top = Thread.current[:TOPLEVEL]) && 
                   top.respond_to?(:pseudo_toplevel_evaluable?) && 
                   top.pseudo_toplevel_evaluable? && 
                   top.respond_to?(id)
    rescue Exception => e
      has_top = false
    end

    if has_top
      top.__send__(id, *args)
    else
      __method_missing__(id, *args)
    end
  end
end

class Proc
  def initialize(*args, &b)
    super
    @__pseudo_toplevel__ = Thread.current[:TOPLEVEL]
  end

  alias __call__ call
  def call(*args, &b)
    if top = @__pseudo_toplevel__
      orig_top = Thread.current[:TOPLEVEL]
      Thread.current[:TOPLEVEL] = top
      begin
        __call__(*args, &b)
      ensure
        Thread.current[:TOPLEVEL] = orig_top
      end
    else
      __call__(*args, &b)
    end
  end
end

def proc(&b)
  Proc.new(&b)
end
def lambda(&b)
  Proc.new(&b)
end

def _null_binding
  Module.new.instance_eval{extend PseudoToplevel_Evaluable}
  # binding
  # Module.new.instance_eval{binding}
end
private :_null_binding

def eval_samplecode(code)
  Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } }.run
  Tk.update
end

# ¥Æ¥­¥¹¥È¾å¤Ç¤Î click ¤ËÂФ¹¤ëÆ°ºî
def invoke(txt, idx)
  tag = txt.tag_names(idx).find{|t| t.kind_of?(String) && t =~ /^demo-/}
  return unless tag

  cursor = txt.cget('cursor')
  txt.cursor('watch')
  Tk.update
  # eval(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, _null_binding)
  # Tk.update
  eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join)
  txt.cursor(cursor)

  $tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars")
end
=begin
def invoke (txt, idx)
  tag = txt.tag_names(idx).find{|t| t.kind_of?(String) && t =~ /^demo-/}
  return unless tag
  current_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`
  eval IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join
  Tk.update
#  txt.cursor('xterm')
  txt.cursor(current_cursor)

  $tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars")
end
=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 showCode1(demo)
  file = "#{demo}.rb"
  $code_window = nil unless defined? $code_window
  if $code_window == nil || TkWinfo.exist?($code_window) == false
    $code_window = TkToplevel.new(nil)
    f = TkFrame.new($code_window)
    TkButton.new(f) {
      #text "λ²ò"
      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'), _null_binding)}
      command proc{eval_samplecode($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

def showCode2(demo)
  file = "#{demo}.rb"
  $code_window = nil unless defined? $code_window
  if $code_window == nil || TkWinfo.exist?($code_window) == false
    $code_window = TkToplevel.new(nil)
    tf = TkFrame.new($code_window)
    $code_text = TkText.new(tf, :font=>'Courier 10', :height=>30, 
                           :wrap=>'word', :bd=>1, :setgrid=>true, 
                           :highlightthickness=>0, :pady=>2, :padx=>3)
    xscr = TkScrollbar.new(tf, :bd=>1){assign($code_text)}
    yscr = TkScrollbar.new(tf, :bd=>1){assign($code_text)}
    TkGrid($code_text, yscr, :sticky=>'news')
    #TkGrid(xscr)
    tf.grid_rowconfigure(0, :weight=>1)
    tf.grid_columnconfigure(0, :weight=>1)

    bf = TkFrame.new($code_window)
    
    #b_dis = TkButton.new(bf, :text=>'λ²ò', :default=>:active, 
    b_dis = TkButton.new(bf, :text=>'ÊĤ¸¤ë', :default=>:active, 
                         :command=>proc{
                           $code_window.destroy
                           $code_window = nil
                         }, 
                         :image=>$image['delete'], :compound=>:left)
    b_prn = TkButton.new(bf, :text=>'°õºþ', 
                         :command=>proc{printCode($code_text, file)}, 
                         :image=>$image['print'], :compound=>:left)
    b_run = TkButton.new(bf, :text=>'ºÆ¼Â¹Ô', 
                         :command=>proc{
                           # eval($code_text.get('1.0','end'), _null_binding)
                           eval_samplecode($code_text.get('1.0','end'))
                         }, 
                         :image=>$image['refresh'], :compound=>:left)

    TkGrid('x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4])
    bf.grid_columnconfigure(0, :weight=>1)

    TkGrid(tf, :sticky=>'news')
    TkGrid(bf, :sticky=>'ew')
    $code_window.grid_columnconfigure(0, :weight=>1)
    $code_window.grid_rowconfigure(0, :weight=>1)

    $code_window.bind('Return', proc{|win|
                        b_dis.invoke unless win.kind_of?(TkText)
                      }, '%W')
    $code_window.bindinfo('Return').each{|cmd, arg|
      $code_window.bind_append('Escape', cmd, arg)
    }
  else
    $code_window.deiconify
    $code_window.raise
  end

  $code_window.title("Demo code: #{file}")
  $code_window.iconname(file)
  fid = open([$demo_dir, file].join(File::Separator), 'r')
  $code_text.delete('1.0', 'end')
  $code_text.insert('1.0', fid.read)
  TkTextMarkInsert.new($code_text,'1.0')
  fid.close
end

if $tk_major_ver < 8
  alias showCode showCode1
elsif $tk_major_ver == 8 && $tk_minor_ver < 4
  alias showCode showCode1
else # ver >= 8.4
  alias showCode showCode2
end


# printCode --
# Prints the source code currently displayed in the See Code dialog.
# Much thanks to Arjen Markus for this.
#
# Arguments:
# txt -         Name of text widget containing code to print
# file -        Name of the original file (implicitly for title)

def printCode(txt, file)
  code = txt.get('1.0', 'end - 1c')
  dir = '.'
  dir = ENV['HOME'] if ENV['HOME']
  dir = ENV['TMP'] if ENV['TMP']
  dir = ENV['TEMP'] if ENV['TEMP']

  fname = [dir, 'tkdemo-' + file].join(File::Separator)
  open(fname, 'w'){|fid| fid.print(code)}
  begin
    case Tk::TCL_PLATFORM('platform')
    when 'unix'
      msg = `lp -c #{fname}`
      unless $?.exitstatus == 0
        Tk.messageBox(:title=>'Print spooling failure', 
                      :message=>'¥¨¥é¡¼¤¬È¯À¸¤·¤Þ¤·¤¿¡¥' + 
                                '°õºþ¤Ë¼ºÇÔ¤·¤¿¤â¤Î¤È»×¤ï¤ì¤Þ¤¹ : ' + msg)
      end
    when 'windows'
      begin
        printTextWin32(fname)
      rescue => e
        Tk.messageBox(:title=>'Print spooling failure', 
                      :message=>'¥¨¥é¡¼¤¬È¯À¸¤·¤Þ¤·¤¿¡¥' + 
                                '°õºþ¤Ë¼ºÇÔ¤·¤¿¤â¤Î¤È»×¤ï¤ì¤Þ¤¹ : ' + 
                                e.message)
      end      
    when 'macintosh'
      Tk.messageBox(:title=>'Operation not Implemented', 
                    :message=>'°õºþµ¡Ç½¤Ï¤Þ¤À¼ÂÁõ¤µ¤ì¤Æ¤¤¤Þ¤»¤ó')
    else
      Tk.messageBox(:title=>'Operation not Implemented', 
                    :message=>'¸¡½Ð¤µ¤ì¤¿´Ä¶­ ' + 
                              Tk::TCL_PLATFORM('platform') + 
                              ' ¤Ï̤ÃΤδĶ­¤Ç¤¢¤ë¤¿¤á¡¤' + 
                              '°õºþµ¡Ç½¤Ï¼ÂÁõ¤µ¤ì¤Æ¤¤¤Þ¤»¤ó: ')
    end
  ensure
    File.delete(fname)
  end
end

# printTextWin32 --
#    Print a file under Windows
#
# Arguments:
# filename -            Name of the file
#
def printTextWin32(fname)
  require 'win32/registry'
  begin
    app = Win32::Registry::HKEY_CLASSES_ROOT['.txt']
    pcmd = nil
    Win32::Registry::HKEY_CLASSES_ROOT.open("#{app}\\shell\\print"){|reg|
      pcmd = reg['command']
    }
  rescue
    app = Tk.tk_call('auto_execok', 'notepad.exe')
    pcmd = "#{app} /p %1"
  end

  pcmd.gsub!('%1', fname)
  puts pcmd
  cmd = Tk.tk_call('auto_execok', 'start') + ' /min ' + pcmd
  
  msg = `#{cmd}`
  unless $?.exitstatus == 0
    fail RuntimeError, msg
  end
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.6.0-jp\n\n" + 
                           "based on demos of Tk8.1 -- 8.5  " + 
                           "( Copyright:: " + 
                           "(c) 1996-1997 Sun Microsystems, Inc. / " + 
                           "(c) 1997-2000 Ajuba Solutions, Inc. / " + 
                           "(c) 2001-2003 Donal K. Fellows )\n\n" +
                           "Your Ruby & Tk Version ::\n" + 
                           "Ruby#{RUBY_VERSION}(#{RUBY_RELEASE_DATE})[#{RUBY_PLATFORM}] / Tk#{$tk_patchlevel}#{(Tk::JAPANIZED_TK)? '-jp': ''}\n\n" + 
                           "Ruby/Tk release date :: tcltklib #{TclTkLib::RELEASE_DATE}; tk #{Tk::RELEASE_DATE}")
end

####################################
# °ú¿ô¤Ç»ØÄꤵ¤ì¤¿¥Ç¥â¤òµ¯Æ°¤¹¤ë
no_launcher = false
if ARGV[0] == '-n'
  ARGV.shift
  no_launcher = true if ARGV.size > 0
else
  # show the root widget to make it lower then demo windows
  Tk.update
end
ARGV.each{|cmd| 
  if cmd =~ /(.*).rb/
    cmd = $1
  end
  #eval(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join, 
  #     _null_binding)
  eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join)
}
if no_launcher
  $root.withdraw  # hide root window
  Thread.start{
    loop do
      count = 0
      $root.winfo_children.each{|w|
        count += 1 if w.kind_of?(TkToplevel)
      }
      $root.destroy if count == 0
    end
  }
end

################################
# ¥¤¥Ù¥ó¥ÈÂÔ¤Á¤ËÆþ¤ë
Tk.mainloop