2003-06-24 12:46:07 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
#
|
|
|
|
# sample script of TkOptionDB
|
|
|
|
#
|
2009-03-05 22:56:38 -05:00
|
|
|
# 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.
|
2003-06-24 12:46:07 -04:00
|
|
|
#
|
|
|
|
require "tk"
|
|
|
|
|
2003-09-07 03:10:44 -04:00
|
|
|
if __FILE__ == $0 || !TkCore::INTERP.safe?
|
|
|
|
if ENV['LANG'] =~ /^ja/
|
|
|
|
# read Japanese resource
|
2009-03-05 22:56:38 -05:00
|
|
|
TkOptionDB.read_with_encoding(File.expand_path('resource.ja',
|
|
|
|
File.dirname(__FILE__)),
|
2004-10-11 00:51:21 -04:00
|
|
|
'euc-jp')
|
2003-09-07 03:10:44 -04:00
|
|
|
else
|
|
|
|
# read English resource
|
2009-03-05 22:56:38 -05:00
|
|
|
TkOptionDB.readfile(File.expand_path('resource.en',
|
2004-10-11 00:51:21 -04:00
|
|
|
File.dirname(__FILE__)))
|
2003-09-07 03:10:44 -04:00
|
|
|
end
|
2003-06-24 12:46:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# 'show_msg' and 'bye_msg' procedures can be defined on BTN_CMD resource.
|
|
|
|
# Those procedures are called under $SAFE==2
|
2003-09-07 03:10:44 -04:00
|
|
|
cmd = TkOptionDB.new_proc_class(:BTN_CMD, [:show_msg, :bye_msg], 3) {
|
2009-03-05 22:56:38 -05:00
|
|
|
# If you want to check resource string (str),
|
2003-06-24 12:46:07 -04:00
|
|
|
# please define __check_proc_string__(str) like this.
|
|
|
|
class << self
|
|
|
|
def __check_proc_string__(str)
|
2003-09-07 03:10:44 -04:00
|
|
|
print "($SAFE=#{$SAFE} >>>) check!! str.tainted?::#{str.tainted?}"
|
2003-06-24 12:46:07 -04:00
|
|
|
str.untaint
|
2003-09-07 03:10:44 -04:00
|
|
|
print "==>#{str.tainted?} (<<< $SAFE=#{$SAFE}): "
|
2003-06-24 12:46:07 -04:00
|
|
|
str
|
|
|
|
end
|
2003-12-09 09:38:15 -05:00
|
|
|
private :__check_proc_string__
|
2003-06-24 12:46:07 -04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2003-06-25 10:40:32 -04:00
|
|
|
# following two frame widgets use same database entry
|
2003-06-24 12:46:07 -04:00
|
|
|
TkFrame.new(:class=>'BtnFrame'){|f|
|
|
|
|
pack(:padx=>5, :pady=>5)
|
2009-03-05 22:56:38 -05:00
|
|
|
TkButton.new(:parent=>f, :widgetname=>'hello'){
|
2003-06-24 12:46:07 -04:00
|
|
|
command proc{
|
2003-09-07 03:10:44 -04:00
|
|
|
print "($SAFE=#{$SAFE} >>>) : "
|
2003-06-24 12:46:07 -04:00
|
|
|
cmd.show_msg(TkOptionDB.inspect)
|
2003-09-07 03:10:44 -04:00
|
|
|
print "(<<< $SAFE=#{$SAFE})"
|
2009-03-05 22:56:38 -05:00
|
|
|
}
|
2003-06-24 12:46:07 -04:00
|
|
|
pack(:fill=>:x, :padx=>10, :pady=>10)
|
|
|
|
}
|
2003-09-07 03:10:44 -04:00
|
|
|
TkButton.new(:command=>proc{
|
2004-10-11 00:51:21 -04:00
|
|
|
print "($SAFE=#{$SAFE} >>>) : "
|
|
|
|
cmd.bye_msg
|
|
|
|
print "(<<< $SAFE=#{$SAFE} ) : "
|
|
|
|
exit
|
2009-03-05 22:56:38 -05:00
|
|
|
},
|
2004-10-11 00:51:21 -04:00
|
|
|
:parent=>f, :widgetname=>'quit'){
|
2003-06-24 12:46:07 -04:00
|
|
|
pack(:fill=>:x, :padx=>10, :pady=>10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-25 10:40:32 -04:00
|
|
|
class BtnFrame < TkFrame; end
|
|
|
|
BtnFrame.new{|f|
|
|
|
|
pack(:padx=>5, :pady=>5)
|
2009-03-05 22:56:38 -05:00
|
|
|
TkButton.new(:parent=>f, :widgetname=>'hello'){
|
2003-06-25 10:40:32 -04:00
|
|
|
command proc{
|
2003-09-07 03:10:44 -04:00
|
|
|
print "($SAFE=#{$SAFE} >>>) : "
|
2003-06-25 10:40:32 -04:00
|
|
|
cmd.show_msg(TkOptionDB.inspect)
|
2003-09-07 03:10:44 -04:00
|
|
|
print "(<<< $SAFE=#{$SAFE})"
|
2009-03-05 22:56:38 -05:00
|
|
|
}
|
2003-06-25 10:40:32 -04:00
|
|
|
pack(:fill=>:x, :padx=>10, :pady=>10)
|
|
|
|
}
|
2003-09-07 03:10:44 -04:00
|
|
|
TkButton.new(:command=>proc{
|
2004-10-11 00:51:21 -04:00
|
|
|
print "($SAFE=#{$SAFE} >>>) : "
|
|
|
|
cmd.bye_msg
|
|
|
|
print "(<<< $SAFE=#{$SAFE})"
|
|
|
|
exit
|
2009-03-05 22:56:38 -05:00
|
|
|
},
|
2004-10-11 00:51:21 -04:00
|
|
|
:parent=>f, :widgetname=>'quit'){
|
2003-06-25 10:40:32 -04:00
|
|
|
pack(:fill=>:x, :padx=>10, :pady=>10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# if unknown class, use default option values
|
|
|
|
TkFrame.new(:class=>'BtnFrame2'){|f|
|
|
|
|
pack(:padx=>5, :pady=>5)
|
2009-03-05 22:56:38 -05:00
|
|
|
TkButton.new(:parent=>f, :widgetname=>'hello'){
|
2003-06-25 10:40:32 -04:00
|
|
|
command proc{
|
2003-09-07 03:10:44 -04:00
|
|
|
print "($SAFE=#{$SAFE} >>>) : "
|
2003-06-25 10:40:32 -04:00
|
|
|
cmd.show_msg(TkOptionDB.inspect)
|
2003-09-07 03:10:44 -04:00
|
|
|
print "(<<< $SAFE=#{$SAFE})"
|
2009-03-05 22:56:38 -05:00
|
|
|
}
|
2003-06-25 10:40:32 -04:00
|
|
|
pack(:fill=>:x, :padx=>10, :pady=>10)
|
|
|
|
}
|
2003-09-07 03:10:44 -04:00
|
|
|
TkButton.new(:command=>proc{
|
2004-10-11 00:51:21 -04:00
|
|
|
print "($SAFE=#{$SAFE} >>>) : "
|
|
|
|
cmd.bye_msg
|
|
|
|
print "(<<< $SAFE=#{$SAFE})"
|
|
|
|
exit
|
2009-03-05 22:56:38 -05:00
|
|
|
},
|
2004-10-11 00:51:21 -04:00
|
|
|
:parent=>f, :widgetname=>'quit'){
|
2003-06-25 10:40:32 -04:00
|
|
|
pack(:fill=>:x, :padx=>10, :pady=>10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-24 12:46:07 -04:00
|
|
|
Tk.mainloop
|