diff options
Diffstat (limited to 'ext/tk/sample')
| -rw-r--r-- | ext/tk/sample/resource.en | 12 | ||||
| -rw-r--r-- | ext/tk/sample/resource.ja | 12 | ||||
| -rw-r--r-- | ext/tk/sample/tkbiff.rb | 149 | ||||
| -rw-r--r-- | ext/tk/sample/tkbrowse.rb | 79 | ||||
| -rw-r--r-- | ext/tk/sample/tkdialog.rb | 62 | ||||
| -rw-r--r-- | ext/tk/sample/tkfrom.rb | 132 | ||||
| -rw-r--r-- | ext/tk/sample/tkhello.rb | 10 | ||||
| -rw-r--r-- | ext/tk/sample/tkline.rb | 45 | ||||
| -rw-r--r-- | ext/tk/sample/tkmenubutton.rb | 136 | ||||
| -rw-r--r-- | ext/tk/sample/tkoptdb.rb | 82 | ||||
| -rw-r--r-- | ext/tk/sample/tktimer.rb | 50 | ||||
| -rw-r--r-- | ext/tk/sample/tktimer2.rb | 43 |
12 files changed, 0 insertions, 812 deletions
diff --git a/ext/tk/sample/resource.en b/ext/tk/sample/resource.en deleted file mode 100644 index 29bd587ea2..0000000000 --- a/ext/tk/sample/resource.en +++ /dev/null @@ -1,12 +0,0 @@ -# -# see Tcl/Tk's "options" manual for "Database Name" and "Database Class" -# -*BtnFrame.borderWidth: 5 -*BtnFrame.relief: ridge -*BtnFrame.Button.background: wheat -*BtnFrame.Button.foreground: red -*hello.text: HELLO -*quit.text: QUIT -*BTN_CMD.show_msg: {|arg| print "($SAFE=#{$SAFE}) ";\ - print "Hello!! This is a sample of #{arg}.\n"} -*BTN_CMD.bye_msg: {print "($SAFE=#{$SAFE}) Good-bye.\n"} diff --git a/ext/tk/sample/resource.ja b/ext/tk/sample/resource.ja deleted file mode 100644 index 61098db4f8..0000000000 --- a/ext/tk/sample/resource.ja +++ /dev/null @@ -1,12 +0,0 @@ -# -# see Tcl/Tk's "options" manual for "Database Name" and "Database Class" -# -*BtnFrame.borderWidth: 5 -*BtnFrame.relief: ridge -*BtnFrame.Button.background: wheat -*BtnFrame.Button.foreground: red -*hello.text: こんにちは -*quit.text: 終了 -*BTN_CMD.show_msg: {|arg| print "($SAFE=#{$SAFE}) ";\ - print "こんにちは!! #{arg} のサンプルです.\n"} -*BTN_CMD.bye_msg: {print "($SAFE=#{$SAFE}) さようなら.\n"} diff --git a/ext/tk/sample/tkbiff.rb b/ext/tk/sample/tkbiff.rb deleted file mode 100644 index ac27184437..0000000000 --- a/ext/tk/sample/tkbiff.rb +++ /dev/null @@ -1,149 +0,0 @@ -#! /usr/local/bin/ruby - -if ARGV[0] != '-d' - unless $DEBUG - exit if fork - end -else - ARGV.shift -end - -if ARGV.length == 0 - if ENV['MAIL'] - $spool = ENV['MAIL'] - else - $spool = '/usr/spool/mail/' + ENV['USER'] - end -else - $spool = ARGV[0] -end - -require "parsedate" -require "base64" - -include ParseDate - -class Mail - def Mail.new(f) - if !f.kind_of?(IO) - f = open(f, "r") - me = super - f.close - else - me = super - end - return me - end - - def initialize(f) - @header = {} - @body = [] - while line = f.gets() - line.chop! - next if /^From / =~ line # skip From-line - break if /^$/ =~ line # end of header - if /^(\S+):\s*(.*)/ =~ line - @header[attr = $1.capitalize] = $2 - elsif attr - sub(/^\s*/, '') - @header[attr] += "\n" + $_ - end - end - - return unless $_ - - while line = f.gets() - break if /^From / =~ line - @body.push($_) - end - end - - def header - return @header - end - - def body - return @body - end - -end - -require "tkscrollbox" - -$top = TkRoot.new -$top.withdraw -$list = TkScrollbox.new($top) { - relief 'raised' - width 80 - height 8 - setgrid 'yes' - pack -} -TkButton.new($top) { - text 'Dismiss' - command proc {$top.withdraw} - pack('fill'=>'both','expand'=>'yes') -} -$top.bind "Control-c", proc{exit} -$top.bind "Control-q", proc{exit} -$top.bind "space", proc{exit} - -$spool_size = 0 -$check_time = Time.now - -def check - $check_time = Time.now - size = File.size($spool) - if size and size != $spool_size - $spool_size = size - pop_up if size > 0 - end - Tk.after 5000, proc{check} -end - -if defined? Thread - Thread.start do - loop do - sleep 600 - if Time.now - $check_time > 200 - Tk.after 5000, proc{check} - end - end - end -end - -def pop_up - outcount = 0; - $list.delete 0, 'end' - f = open($spool, "r") - while !f.eof? - mail = Mail.new(f) - date, from, subj = mail.header['Date'], mail.header['From'], mail.header['Subject'] - next if !date - y = m = d = 0 - y, m, d = parsedate(date) if date - from = "sombody@somewhere" if ! from - subj = "(nil)" if ! subj - from = decode_b(from) - subj = decode_b(subj) - $list.insert 'end', format('%-02d/%02d/%02d [%-28.28s] %s',y,m,d,from,subj) - outcount += 1 - end - f.close - if outcount == 0 - $list.insert 'end', "You have no mail." - else - $list.see 'end' - end - $top.deiconify - Tk.after 2000, proc{$top.withdraw} -end - -$list.insert 'end', "You have no mail." -check -Tk.after 2000, proc{$top.withdraw} -begin - Tk.mainloop -rescue - `echo #$! > /tmp/tkbiff` -end diff --git a/ext/tk/sample/tkbrowse.rb b/ext/tk/sample/tkbrowse.rb deleted file mode 100644 index 882f0a489b..0000000000 --- a/ext/tk/sample/tkbrowse.rb +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/local/bin/ruby -# -# This script generates a directory browser, which lists the working -# directory and allows you to open files or subdirectories by -# double-clicking. - -# Create a scrollbar on the right side of the main window and a listbox -# on the left side. - -require "tkscrollbox" - -# The procedure below is invoked to open a browser on a given file; if the -# file is a directory then another instance of this program is invoked; if -# the file is a regular file then the Mx editor is invoked to display -# the file. - -$dirlist = {} - -def browsedir (dir) - if $dirlist.key? dir - $dirlist[dir] - else - top = if $dirlist.size > 0 then TkToplevel.new else nil end - list = TkScrollbox.new(top) { - relief 'raised' - width 20 - height 20 - setgrid 'yes' - pack - } - list.insert 'end', *`ls #{dir}`.split - - # Set up bindings for the browser. - - list.focus - list.bind "Control-q", proc{exit} - list.bind "Control-c", proc{exit} - list.bind "Control-p", proc{ - print "selection <", TkSelection.get, ">\n" - } - - list.bind "Double-Button-1", proc{ - for i in TkSelection.get.split - print "clicked ", i, "\n" - browse dir, i - end - } - $dirlist[dir] = list - end -end - -def browse (dir, file) - file="#{dir}/#{file}" - if File.directory? file - browsedir(file) - else - if File.file? file - if ENV['EDITOR'] - system format("%s %s&", ENV['EDITOR'], file) - else - system "xedit #{file}&" - end - else - STDERR.print "\"#{file}\" isn't a directory or regular file" - end - end -end - -# Fill the listbox with a list of all the files in the directory (run -# the "ls" command to get that information). - -if ARGV.length>0 - dir = ARGV[0] -else - dir="." -end - -browsedir(dir) -Tk.mainloop diff --git a/ext/tk/sample/tkdialog.rb b/ext/tk/sample/tkdialog.rb deleted file mode 100644 index e83e16d0a8..0000000000 --- a/ext/tk/sample/tkdialog.rb +++ /dev/null @@ -1,62 +0,0 @@ -#! /usr/local/bin/ruby -require "tk" - -root = TkFrame.new -top = TkFrame.new(root) { - relief 'raised' - border 1 -} -msg = TkMessage.new(top) { - text "File main.c hasn't been saved to disk since \ -it was last modified. What should I do?" - justify 'center' - aspect 200 - font '-Adobe-helvetica-medium-r-normal--*-240*' - pack('padx'=>5, 'pady'=>5, 'expand'=>'yes') -} -top.pack('fill'=>'both') -root.pack - -bot = TkFrame.new(root) { - relief 'raised' - border 1 -} - -TkFrame.new(bot) { |left| - relief 'sunken' - border 1 - pack('side'=>'left', 'expand'=>'yes', 'padx'=>10, 'pady'=> 10) - TkButton.new(left) { - text "Save File" - command "quit 'save'" - pack('expand'=>'yes','padx'=>6,'pady'=> 6) - top.bind "Enter", proc{state 'active'} - msg.bind "Enter", proc{state 'active'} - bot.bind "Enter", proc{state 'active'} - top.bind "Leave", proc{state 'normal'} - msg.bind "Leave", proc{state 'normal'} - bot.bind "Leave", proc{state 'normal'} - Tk.root.bind "ButtonRelease-1", proc{quit 'save'} - Tk.root.bind "Return", proc{quit 'save'} - } -} -TkButton.new(bot) { - text "Quit Anyway" - command "quit 'quit'" - pack('side'=>'left', 'expand'=>'yes', 'padx'=>10) -} -TkButton.new(bot) { - text "Return To Editor" - command "quit 'return'" - pack('side'=>'left', 'expand'=>'yes', 'padx'=>10) -} -bot.pack -root.pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes') - -def quit(button) - print "aaa\n" - print "You pressed the \"#{button}\" button; bye-bye!\n" - exit -end - -Tk.mainloop diff --git a/ext/tk/sample/tkfrom.rb b/ext/tk/sample/tkfrom.rb deleted file mode 100644 index 8c3efb8137..0000000000 --- a/ext/tk/sample/tkfrom.rb +++ /dev/null @@ -1,132 +0,0 @@ -#! /usr/local/bin/ruby - -require "parsedate" -require "base64" - -include ParseDate - -class Mail - def Mail.new(f) - if !f.kind_of?(IO) - f = open(f, "r") - me = super(f) - f.close - else - me = super - end - return me - end - - def initialize(f) - @header = {} - @body = [] - while line = f.gets() - $_.chop! - next if /^From / =~ line # skip From-line - break if /^$/ =~ line # end of header - if /^(\S+):\s*(.*)/ =~ line - @header[attr = $1.capitalize] = $2 - elsif attr - sub(/^\s*/, '') - @header[attr] += "\n" + $_ - end - end - - return unless $_ - - while line = f.gets() - break if /^From / =~ line - @body.push($_) - end - end - - def header - return @header - end - - def body - return @body - end - -end - -if ARGV.length == 0 - if ENV['MAIL'] - ARGV[0] = ENV['MAIL'] - elsif ENV['USER'] - ARGV[0] = '/usr/spool/mail/' + ENV['USER'] - elsif ENV['LOGNAME'] - ARGV[0] = '/usr/spool/mail/' + ENV['LOGNAME'] - end -end - -require "tk" -list = scroll = nil -TkFrame.new{|f| - list = TkListbox.new(f) { - yscroll proc{|idx| - scroll.set *idx - } - relief 'raised' -# geometry "80x5" - width 80 - height 5 - setgrid 'yes' - pack('side'=>'left','fill'=>'both','expand'=>'yes') - } - scroll = TkScrollbar.new(f) { - command proc{|idx| - list.yview *idx - } - pack('side'=>'right','fill'=>'y') - } - pack -} -root = Tk.root -TkButton.new(root) { - text 'Dismiss' - command proc {exit} - pack('fill'=>'both','expand'=>'yes') -} -root.bind "Control-c", proc{exit} -root.bind "Control-q", proc{exit} -root.bind "space", proc{exit} - -$outcount = 0; -for file in ARGV - next if File.exist?(file) - atime = File.atime(file) - mtime = File.mtime(file) - f = open(file, "r") - begin - until f.eof - mail = Mail.new(f) - date = mail.header['Date'] - next unless date - from = mail.header['From'] - subj = mail.header['Subject'] - y = m = d = 0 - y, m, d = parsedate(date) if date - from = "sombody@somewhere" unless from - subj = "(nil)" unless subj - from = decode_b(from) - subj = decode_b(subj) - list.insert 'end', format('%-02d/%02d/%02d [%-28.28s] %s',y,m,d,from,subj) - $outcount += 1 - end - ensure - f.close - File.utime(atime, mtime, file) - list.see 'end' - end -end - -limit = 10000 -if $outcount == 0 - list.insert 'end', "You have no mail." - limit = 2000 -end -Tk.after limit, proc{ - exit -} -Tk.mainloop diff --git a/ext/tk/sample/tkhello.rb b/ext/tk/sample/tkhello.rb deleted file mode 100644 index 5188fe1c8c..0000000000 --- a/ext/tk/sample/tkhello.rb +++ /dev/null @@ -1,10 +0,0 @@ -require "tk" - -TkButton.new(nil, - 'text' => 'hello', - 'command' => proc{print "hello\n"}).pack('fill'=>'x') -TkButton.new(nil, - 'text' => 'quit', - 'command' => 'exit').pack('fill'=>'x') - -Tk.mainloop diff --git a/ext/tk/sample/tkline.rb b/ext/tk/sample/tkline.rb deleted file mode 100644 index 2406b0749f..0000000000 --- a/ext/tk/sample/tkline.rb +++ /dev/null @@ -1,45 +0,0 @@ - -require "tkclass" - -$tkline_init = FALSE -def start_random - return if $tkline_init - $tkline_init = TRUE - if defined? Thread - Thread.start do - loop do - sleep 2 - Line.new($c, rand(400), rand(200), rand(400), rand(200)) - end - end - end -end - -$c = Canvas.new -$c.pack -$start_x = start_y = 0 - -def do_press(x, y) - $start_x = x - $start_y = y - $current_line = Line.new($c, x, y, x, y) - start_random -end -def do_motion(x, y) - if $current_line - $current_line.coords $start_x, $start_y, x, y - end -end - -def do_release(x, y) - if $current_line - $current_line.coords $start_x, $start_y, x, y - $current_line.fill 'black' - $current_line = nil - end -end - -$c.bind("1", proc{|e| do_press e.x, e.y}) -$c.bind("B1-Motion", proc{|x, y| do_motion x, y}, "%x %y") -$c.bind("ButtonRelease-1", proc{|x, y| do_release x, y}, "%x %y") -Tk.mainloop diff --git a/ext/tk/sample/tkmenubutton.rb b/ext/tk/sample/tkmenubutton.rb deleted file mode 100644 index 02a903ebb8..0000000000 --- a/ext/tk/sample/tkmenubutton.rb +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/env ruby -# -# menubutton sample : based on sample menubuttons on the Tcl/Tk demo script -# -require 'tk' - -TkLabel.new(:text=>'Sample of TkMenubutton').pack(:side=>:top) - -TkFrame.new{|f| - pack(:side=>:top) - - - TkMenubutton.new(:parent=>f, :text=>'Right', :underline=>0, - :direction=>:right, :relief=>:raised){|mb| - menu TkMenu.new(:parent=>mb, :tearoff=>0){ - add(:command, :label=>'Right menu: first item', - :command=>proc{print 'You have selected the first item' + - " from the Right menu.\n"}) - add(:command, :label=>'Right menu: second item', - :command=>proc{print 'You have selected the second item' + - " from the Right menu.\n"}) - } - pack(:side=>:left, :padx=>25, :pady=>25) - } - - TkMenubutton.new(:parent=>f, :text=>'Below', :underline=>0, - :direction=>:below, :relief=>:raised){|mb| - menu(TkMenu.new(:parent=>mb, :tearoff=>0){ - add(:command, :label=>'Below menu: first item', - :command=>proc{print 'You have selected the first item' + - " from the Below menu.\n"}) - add(:command, :label=>'Below menu: second item', - :command=>proc{print 'You have selected the second item' + - " from the Below menu.\n"}) - }) - pack(:side=>:left, :padx=>25, :pady=>25) - } - - TkMenubutton.new(:parent=>f, :text=>'Above', :underline=>0, - :direction=>:above, :relief=>:raised){|mb| - menu TkMenu.new(:parent=>mb, :tearoff=>0){ - add(:command, :label=>'Above menu: first item', - :command=>proc{print 'You have selected the first item' + - " from the Above menu.\n"}) - add(:command, :label=>'Above menu: second item', - :command=>proc{print 'You have selected the second item' + - " from the Above menu.\n"}) - } - pack(:side=>:left, :padx=>25, :pady=>25) - } - - TkMenubutton.new(:parent=>f, :text=>'Left', :underline=>0, - :direction=>:left, :relief=>:raised){|mb| - menu(TkMenu.new(:parent=>mb, :tearoff=>0){ - add(:command, :label=>'Left menu: first item', - :command=>proc{print 'You have selected the first item' + - " from the Left menu.\n"}) - add(:command, :label=>'Left menu: second item', - :command=>proc{print 'You have selected the second item' + - " from the Left menu.\n"}) - }) - pack(:side=>:left, :padx=>25, :pady=>25) - } -} - -############################ -TkFrame.new(:borderwidth=>2, :relief=>:sunken, - :height=>5).pack(:side=>:top, :fill=>:x, :padx=>20) -############################ - -TkLabel.new(:text=>'Sample of TkOptionMenu').pack(:side=>:top) - -colors = %w(Black red4 DarkGreen NavyBlue gray75 Red Green Blue gray50 - Yellow Cyan Magenta White Brown DarkSeaGreen DarkViolet) - -TkFrame.new{|f| - pack(:side=>:top) - - b1 = TkOptionMenubutton . - new(:parent=>f, :values=>%w(one two three)) . - pack(:side=>:left, :padx=>25, :pady=>25) - - b2 = TkOptionMenubutton.new(:parent=>f, :values=>colors) {|optMB| - colors.each{|color| - no_sel = TkPhotoImage.new(:height=>16, :width=>16){ - put 'gray50', *[ 0, 0, 16, 1] - put 'gray50', *[ 0, 1, 1, 16] - put 'gray75', *[ 0, 15, 16, 16] - put 'gray75', *[15, 1, 16, 16] - put color, *[ 1, 1, 15, 15] - } - sel = TkPhotoImage.new(:height=>16, :width=>16){ - put 'Black', *[ 0, 0, 16, 2] - put 'Black', *[ 0, 2, 2, 16] - put 'Black', *[ 2, 14, 16, 16] - put 'Black', *[14, 2, 16, 14] - put color, *[ 2, 2, 14, 14] - } - optMB.entryconfigure(color, :hidemargin=>1, - :image=>no_sel, :selectimage=>sel) - } - optMB.menuconfigure(:tearoff, 1) - %w(Black gray75 gray50 White).each{|color| - optMB.entryconfigure(color, :columnbreak=>true) - } - pack(:side=>:left, :padx=>25, :pady=>25) - } - - TkButton.new(:parent=>f){ - text 'show values' - command proc{p [b1.value, b2.value]} - pack(:side=>:left, :padx=>25, :pady=>5, :anchor=>:s) - } -} - - -############################ -TkFrame.new(:borderwidth=>2, :relief=>:sunken, - :height=>5).pack(:side=>:top, :fill=>:x, :padx=>20) -############################ - -root = TkRoot.new(:title=>'menubutton samples') - -TkButton.new(root, :text=>'exit', :command=>proc{exit}){ - pack(:side=>:top, :padx=>25, :pady=>5, :anchor=>:e) -} - -# VirtualEvent <<MenuSelect>> on Tcl/Tk ==> '<MenuSelect>' on Ruby/Tk -# ( remove the most external <, > for Ruby/Tk notation ) -TkMenu.bind('<MenuSelect>', proc{|widget| - p widget.entrycget('active', :label) - }, '%W') - -############################ - -Tk.mainloop diff --git a/ext/tk/sample/tkoptdb.rb b/ext/tk/sample/tkoptdb.rb deleted file mode 100644 index 066bd9501a..0000000000 --- a/ext/tk/sample/tkoptdb.rb +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env ruby -# -# sample script of TkOptionDB -# -# If 'LANG' environment variable's value is started by 'ja', -# then read Japanese resource data and display Japanese button text. -# In other case, read English resource data and display English text. -# -require "tk" - -if ENV['LANG'] =~ /^ja/ - # read Japanese resource - TkOptionDB.readfile(File.expand_path('resource.ja', File.dirname(__FILE__))) -else - # read English resource - TkOptionDB.readfile(File.expand_path('resource.en', File.dirname(__FILE__))) -end - -# 'show_msg' and 'bye_msg' procedures can be defined on BTN_CMD resource. -# Those procedures are called under $SAFE==2 -cmd = TkOptionDB.new_proc_class(:BTN_CMD, [:show_msg, :bye_msg], 2) { - # If you want to check resource string (str), - # please define __check_proc_string__(str) like this. - class << self - def __check_proc_string__(str) - print "($SAFE=#{$SAFE}) check!! str.tainted?::#{str.tainted?}" - str.untaint - print "==>#{str.tainted?} : " - str - end - end -} - -# following two frame widgets use same database entry -TkFrame.new(:class=>'BtnFrame'){|f| - pack(:padx=>5, :pady=>5) - TkButton.new(:parent=>f, :widgetname=>'hello'){ - command proc{ - print "($SAFE=#{$SAFE}) : " - cmd.show_msg(TkOptionDB.inspect) - } - pack(:fill=>:x, :padx=>10, :pady=>10) - } - TkButton.new(:command=>proc{print "($SAFE=#{$SAFE}) : "; cmd.bye_msg; exit}, - :parent=>f, :widgetname=>'quit'){ - pack(:fill=>:x, :padx=>10, :pady=>10) - } -} - -class BtnFrame < TkFrame; end -BtnFrame.new{|f| - pack(:padx=>5, :pady=>5) - TkButton.new(:parent=>f, :widgetname=>'hello'){ - command proc{ - print "($SAFE=#{$SAFE}) : " - cmd.show_msg(TkOptionDB.inspect) - } - pack(:fill=>:x, :padx=>10, :pady=>10) - } - TkButton.new(:command=>proc{print "($SAFE=#{$SAFE}) : "; cmd.bye_msg; exit}, - :parent=>f, :widgetname=>'quit'){ - pack(:fill=>:x, :padx=>10, :pady=>10) - } -} - -# if unknown class, use default option values -TkFrame.new(:class=>'BtnFrame2'){|f| - pack(:padx=>5, :pady=>5) - TkButton.new(:parent=>f, :widgetname=>'hello'){ - command proc{ - print "($SAFE=#{$SAFE}) : " - cmd.show_msg(TkOptionDB.inspect) - } - pack(:fill=>:x, :padx=>10, :pady=>10) - } - TkButton.new(:command=>proc{print "($SAFE=#{$SAFE}) : "; cmd.bye_msg; exit}, - :parent=>f, :widgetname=>'quit'){ - pack(:fill=>:x, :padx=>10, :pady=>10) - } -} - -Tk.mainloop diff --git a/ext/tk/sample/tktimer.rb b/ext/tk/sample/tktimer.rb deleted file mode 100644 index 34377e2f39..0000000000 --- a/ext/tk/sample/tktimer.rb +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/local/bin/ruby -# This script generates a counter with start and stop buttons. - -require "tk" -$label = TkLabel.new { - text '0.00' - relief 'raised' - width 10 - pack('side'=>'bottom', 'fill'=>'both') -} - -TkButton.new { - text 'Start' - command proc { - if $stopped - $stopped = FALSE - tick - end - } - pack('side'=>'left','fill'=>'both','expand'=>'yes') -} -TkButton.new { - text 'Stop' - command proc{ - exit if $stopped - $stopped = TRUE - } - pack('side'=>'right','fill'=>'both','expand'=>'yes') -} - -$seconds=0 -$hundredths=0 -$stopped=TRUE - -def tick - if $stopped then return end - Tk.after 50, proc{tick} - $hundredths+=5 - if $hundredths >= 100 - $hundredths=0 - $seconds+=1 - end - $label.text format("%d.%02d", $seconds, $hundredths) -end - -root = Tk.root -root.bind "Control-c", proc{root.destroy} -root.bind "Control-q", proc{root.destroy} -Tk.root.focus -Tk.mainloop diff --git a/ext/tk/sample/tktimer2.rb b/ext/tk/sample/tktimer2.rb deleted file mode 100644 index dc4e8a6964..0000000000 --- a/ext/tk/sample/tktimer2.rb +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env ruby -# This script is a re-implementation of tktimer.rb with TkTimer(TkAfter) class. - -require "tk" - -# new notation : -# * symbols are acceptable as keys or values of the option hash -# * the parent widget can be given by :parent key on the option hash -root = TkRoot.new(:title=>'timer sample') -label = TkLabel.new(:parent=>root, :relief=>:raised, :width=>10) \ - .pack(:side=>:bottom, :fill=>:both) - -# define the procedure repeated by the TkTimer object -tick = proc{|aobj| #<== TkTimer object - cnt = aobj.return_value + 5 # return_value keeps a result of the last proc - label.text format("%d.%02d", *(cnt.divmod(100))) - cnt #==> return value is kept by TkTimer object - # (so, can be send to the next repeat-proc) -} - -timer = TkTimer.new(50, -1, tick).start(0, proc{ label.text('0.00'); 0 }) - # ==> repeat-interval : (about) 50 ms, - # repeat : infinite (-1) times, - # repeat-procedure : tick (only one, in this case) - # - # ==> wait-before-call-init-proc : 0 ms, - # init_proc : proc{ label.text('0.00'); 0 } - # - # (0ms)-> init_proc ->(50ms)-> tick ->(50ms)-> tick ->.... - -TkButton.new(:text=>'Start') { - command proc{ timer.continue unless timer.running? } - pack(:side=>:left, :fill=>:both, :expand=>true) -} -TkButton.new(:text=>'Stop') { - command proc{ timer.stop if timer.running? } - pack('side'=>'right','fill'=>'both','expand'=>'yes') -} - -ev_quit = TkVirtualEvent.new('Control-c', 'Control-q') -Tk.root.bind(ev_quit, proc{Tk.exit}).focus - -Tk.mainloop |
