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/tkoptdb.rb | 49 |
3 files changed, 73 insertions, 0 deletions
diff --git a/ext/tk/sample/resource.en b/ext/tk/sample/resource.en new file mode 100644 index 000000000..29bd587ea --- /dev/null +++ b/ext/tk/sample/resource.en @@ -0,0 +1,12 @@ +# +# 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 new file mode 100644 index 000000000..61098db4f --- /dev/null +++ b/ext/tk/sample/resource.ja @@ -0,0 +1,12 @@ +# +# 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/tkoptdb.rb b/ext/tk/sample/tkoptdb.rb new file mode 100644 index 000000000..930985dc2 --- /dev/null +++ b/ext/tk/sample/tkoptdb.rb @@ -0,0 +1,49 @@ +#!/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 +} + +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) + } +} + +Tk.mainloop |