#!/usr/bin/env ruby # -*- coding: euc-jp -*- # �������������� ( tk.rb �Υ����ɻ��� encoding ����/����˻Ȥ��� ) #if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!!!! unless defined?(::Encoding.default_external) $KCODE = 'euc' else DEFAULT_TK_ENCODING = 'EUC-JP' end # tk �ط��饤�֥����ɤ߹��� require 'tk' # require 'tkafter' $RubyTk_WidgetDemo = true # widget demo directory ���֤γ��� # $demo_dir = File.dirname($0) $demo_dir = File.dirname(__FILE__) # 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 14 bold', 'Gothic 14 bold') else $font = TkFont.new('Helvetica 14', nil) knjfont = '-*--16-*-jisx0208.1983-0' $kanji_font = TkFont.new('Helvetic 14', knjfont) TkOption.add('*kanjiFont', knjfont, 'startupFile') $msg_kanji_font=TkFont.new('Helvetica 14', '-*--24-*-jisx0208.1983-0') end ####### # ���᡼������ $image = {} if $tk_major_ver >= 8 $image['refresh'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><= 8 $image['view'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><= 8 $image['delete'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><= 8 $image['print'] = TkPhotoImage.new(:height=>19, :format=>'GIF', :data=><= 8 $root.add_menubar([[['File', 0], ['About ... ', proc{aboutBox}, 0, ''], '---', ['Quit', proc{exit}, 0, 'Ctrl-Q'] ]]) else TkMenubar.new($root, [[['File', 0], ['About ... ', proc{aboutBox}, 0, ''], '---', ['Quit', proc{exit}, 0, 'Ctrl-Q'] ]]).pack('side'=>'top', 'fill'=>'x') end $root.bind('F1', proc{aboutBox}) $root.bind('Control-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| if $tk_version =~ /^4.*/ statusfont = '-*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*' else statusfont = 'Helvetica 10' end $statusBarLabel = \ TkLabel.new(f, 'text'=>" ", 'relief'=>'sunken', 'bd'=>1, 'anchor'=>'w', 'font'=>statusfont) \ .pack('side'=>'left', 'padx'=>2, 'expand'=>'yes', 'fill'=>'both') TkLabel.new(f, 'width'=>8, 'relief'=>'sunken', 'bd'=>1, 'anchor'=>'w', 'font'=>statusfont) \ .pack('side'=>'left', 'padx'=>2) }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>2) end # �ƥ����ȥ������� if $tk_version =~ /^4.*/ tag_title = TkTextTag.new(txt, 'font'=>'-*-Helvetica-Bold-R-Normal--*-180-*-*-*-*-*-*') else tag_title = TkTextTag.new(txt, 'font'=>'Helvetica 18 bold') end #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 �򥳥�ѥ��뤷�ʤ�����\ ���������� �⤷���ʤ��� Tk �� (�ǽ餫��ޤफ���󥹥ȡ��뤷�����ˤ��) \ Ttk (Tile) ��ĥ�����ѤǤ�����֤Ǥ���ʤ顢\ Ttk ��ĥ�Υǥ� (sample/tkextlib/tile/demo.rb) �⤼�һ�ƤߤƤ��������� ( ¿ʬ�����ߤΤ��ʤ��δĶ��ˤ� Ttk ��ĥ��\ #{ begin require 'tkextlib/tile' "���Ǥ�Ƴ������Ƥ��ޤ�" rescue "�ޤ����󥹥ȡ��뤵��Ƥ��ޤ���" end }\ ��) Ttk ��ĥ�ϡ�Tk8.5 �ʾ�Ǥ�ɸ��ε�ǽ�Ȥ����Ȥ߹��ޤ�Ƥ��ޤ��� 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', "15. �ơ��ޤ��б��������������åȤδ�ñ���� (Tile/Ttk��ĥ�ؤ��б���ɬ��)\n", tag_demo, "demo-ttkbut") 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', "4. ��ˤĤ��ƤΥޥ�������ꥹ�� (Tile/Ttk��ĥ�ؤ��б���ɬ��)\n", tag_demo, "demo-mclist") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "5. �ǥ��쥯�ȥ�֥饦�� (Tile/Ttk��ĥ�ؤ��б���ɬ��)\n", tag_demo, "demo-tree") 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. ����ܥܥå��� (Tile/Ttk��ĥ�ؤ��б���ɬ��)\n", tag_demo, "demo-combo") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "6. ��ñ�ʥե�����\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', "7. �ƥ����ȥ��������åȤ�������(peering) (��ǽ���б������С�������Tk��ɬ��)\n", tag_demo, "demo-textpeer") 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', "9. �������ܡ��ɾ�ε��Τν�� (Tile/Ttk��ĥ�ؤ��б���ɬ��)\n", tag_demo, "demo-knightstour") 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', "3. �ץ����쥹�С� (Tile/Ttk��ĥ�ؤ��б���ɬ��)\n", tag_demo.id, "demo-ttkprogress") 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', "3. �ơ��ޤ��б����������ߥڥ��� (Tile/Ttk��ĥ�ؤ��б���ɬ��)\n", tag_demo.id, "demo-ttkpane") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "4. �Ρ��ȥ֥å����������å� (Tile/Ttk��ĥ�ؤ��б���ɬ��)\n", tag_demo.id, "demo-ttknote") 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', "5. �ơ��ޤ��б�������˥塼�ܥ��� (Tile/Ttk��ĥ�ؤ��б���ɬ��)\n", tag_demo.id, "demo-ttkmenu") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "6. �ơ��ޤ��б������ġ���С� (Tile/Ttk��ĥ�ؤ��б���ɬ��)\n", tag_demo.id, "demo-toolbar") 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. �ܺ٥ƥ������դ��Υ�å������ܥå��� (��ǽ���б������С�������Tk��ɬ��)\n", tag_demo, "demo-msgbox2") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "3. �ե������������������\n", tag_demo, "demo-filebox") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "4. ���������������\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" base = TkFrame.new(w).pack(:fill=>:both, :expand=>true) TkLabel.new(base) { text "�ѿ���:" width 20 anchor 'center' if $tk_version =~ /^4.*/ font '-Adobe-helvetica-medium-r-normal--*-180-*-*-*-*-*-*' else font 'Helvetica 14' end }.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(base){|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(base) { 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) {|top| title "Variable values" base = TkFrame.new(top).pack(:fill=>:both, :expand=>true) TkLabelFrame.new(base, :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(base, :text=>"λ��", :width=>8, :default=>:active, :command=>proc{top.destroy}){|b| top.bind('Return', proc{b.invoke}) top.bind('Escape', proc{b.invoke}) b.grid(:sticky=>'e', :padx=>4, :pady=>[6, 4]) } base.grid_columnconfig(0, :weight=>1) base.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, file=nil) #eval(code) #_null_binding.pseudo_toplevel_eval{ eval(code) } #Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } } Thread.new{ _null_binding.pseudo_toplevel_eval{ begin if file eval(code, binding, "(eval:#{file})") else eval(code) end rescue Exception=>e #p e TkBgError.show(e.message + "\n" + "\n---< backtrace of Ruby side >-----\n" + e.backtrace.join("\n") + "\n---< backtrace of Tk side >-------") end } } 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, tag[5..-1] + '.rb') 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'=>'right', 'expand'=>'false', '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'=>'right', 'expand'=>'false', 'pady'=>2) TkLabel.new(f,'text'=>'line:').pack('side'=>'left') linenum =TkLabel.new(f,'text'=>'').pack('side'=>'left') TkLabel.new(f,'text'=>' pos:').pack('side'=>'left') posnum =TkLabel.new(f,'text'=>'').pack('side'=>'left') $set_linenum = proc{|w| line, pos = w.index('insert').split('.') linenum.text = line posnum.text = pos } f.pack('side'=>'bottom', 'expand'=>'true', '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 btag = TkBindTag.new btag.bind('Key', $set_linenum, '%W') btag.bind('Button', $set_linenum, '%W') btags = $code_text.bindtags btags.insert(btags.index($code_text.class) + 1, btag) $code_text.bindtags = btags else $code_window.deiconify $code_window.raise end $code_window.title("Demo code: #{file}") $code_window.iconname(file) code = open([$demo_dir, file].join(File::Separator), 'r'){|fid| fid.read } $code_text.delete('1.0', 'end') code.force_encoding('EUC-JP') if defined?(::Encoding.default_external) $code_text.insert('1.0', code) TkTextMarkInsert.new($code_text,'1.0') $set_linenum.call($code_text) 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) lf = TkFrame.new(bf) TkLabel.new(lf, :text=>'line:').pack(:side=>:left) linenum =TkLabel.new(lf, :text=>'').pack(:side=>:left) TkLabel.new(lf, :text=>' pos:').pack(:side=>:left) posnum =TkLabel.new(lf, :text=>'').pack(:side=>:left) $set_linenum = proc{|w| line, pos = w.index('insert').split('.') linenum.text = line posnum.text = pos } #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(lf, 'x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4]) bf.grid_columnconfigure(1, :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) } btag = TkBindTag.new btag.bind('Key', $set_linenum, '%W') btag.bind('Button', $set_linenum, '%W') btags = $code_text.bindtags btags.insert(btags.index($code_text.class) + 1, btag) $code_text.bindtags = btags else $code_window.deiconify $code_window.raise end $code_window.title("Demo code: #{file}") $code_window.iconname(file) code = open([$demo_dir, file].join(File::Separator), 'r'){|fid| fid.read } $code_text.delete('1.0', 'end') code.force_encoding('EUC-JP') if defined?(::Encoding.default_external) $code_text.insert('1.0', code) TkTextMarkInsert.new($code_text,'1.0') $set_linenum.call($code_text) 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.7.0-jp\n\n" + "based on demos of Tk8.1 -- 8.5 " + "( Copyright of Tcl/Tk demos:: " + "(c) 1996-1997 Sun Microsystems, Inc. / " + "(c) 1997-2000 Ajuba Solutions, Inc. / " + "(c) 2001-2007 Donal K. Fellows / " + "(c) 2002-2007 Daniel A. Steffen )\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, cmd + '.rb') } 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