summaryrefslogtreecommitdiff
path: root/ext/tk/sample/tkoptdb.rb
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-24 16:46:07 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-24 16:46:07 +0000
commit17e1936d8bdd897cebd03ed198a826ee395572ac (patch)
treec911d2fd21b63dfccc1610f3afdc023233b50e2f /ext/tk/sample/tkoptdb.rb
parentb60ba5942968e782cfc407385e175c449924f1d7 (diff)
tk.rb :
* TkToplevel, TkFrame, TkPanedwindow, TkOptionDB : bug fix * TkOptionDB : make it more secure to use procs defined on resourceDB sample/tkoptdb.rb, sample/resource.ja, sample/resource.en : * sample script how to use TkOptionDB. resource.ja and resource.en are samples of resource definition file which are read by tkoptdb.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3998 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/tkoptdb.rb')
-rw-r--r--ext/tk/sample/tkoptdb.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/ext/tk/sample/tkoptdb.rb b/ext/tk/sample/tkoptdb.rb
new file mode 100644
index 0000000000..930985dc22
--- /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