Project

General

Profile

Bug #11908 ยป bug_11908.patch

matsuda (Akira Matsuda), 12/28/2015 03:31 PM

View differences:

ext/tk/lib/tk/optiondb.rb
@@resource_proc_class.instance_variable_set('@method_tbl',
TkCore::INTERP.create_table)
@@resource_proc_class.instance_variable_set('@add_method', false)
@@resource_proc_class.instance_variable_set('@safe_mode', 4)
@@resource_proc_class.instance_variable_set('@safe_mode', 1)
class << @@resource_proc_class
private :new
......
end
end
=end
def __create_new_class(klass, func, safe = 4, add = false, parent = nil)
def __create_new_class(klass, func, safe = 1, add = false, parent = nil)
if klass.kind_of?(TkWindow)
carrier = klass.path
CmdClassID.mutex.synchronize{
......
# If you want to modify the new class or create a new subclass,
# you must do such operation in the block parameter.
# Because the created class is frozen after evaluating the block.
def new_proc_class(klass, func, safe = 4, add = false, parent = nil, &b)
def new_proc_class(klass, func, safe = 1, add = false, parent = nil, &b)
new_klass = __create_new_class(klass, func, safe, add, parent)
new_klass.class_eval(&b) if block_given?
__remove_methods_of_proc_class(new_klass)
......
end
module_function :eval_under_random_base
def new_proc_class_random(klass, func, safe = 4, add = false, &b)
def new_proc_class_random(klass, func, safe = 1, add = false, &b)
eval_under_random_base(){
TkOptionDB.new_proc_class(klass, func, safe, add, self, &b)
}
ext/tk/sample/cmd_res_test.rb
File.dirname(__FILE__)))
f = TkFrame.new(:class=>'BtnFrame').pack
b = TkButton.new(:parent=>f, :widgetname=>'hello').pack
cmd1 = TkOptionDB.new_proc_class(b, [:show_msg, :bye_msg], 3)
cmd2 = TkOptionDB.new_proc_class(:ZZZ, [:show_msg, :bye_msg], 3, false, cmd1)
cmd3 = TkOptionDB.new_proc_class(:ZZZ, [:show_msg, :bye_msg], 3, false, b)
cmd4 = TkOptionDB.new_proc_class(:BTN_CMD, [:show_msg, :bye_msg], 3){
cmd1 = TkOptionDB.new_proc_class(b, [:show_msg, :bye_msg], 1)
cmd2 = TkOptionDB.new_proc_class(:ZZZ, [:show_msg, :bye_msg], 1, false, cmd1)
cmd3 = TkOptionDB.new_proc_class(:ZZZ, [:show_msg, :bye_msg], 1, false, b)
cmd4 = TkOptionDB.new_proc_class(:BTN_CMD, [:show_msg, :bye_msg], 1){
def self.__check_proc_string__(str)
"{|arg| print [arg, $SAFE].inspect, ': '; Proc.new#{str}.call(arg)}"
end
ext/tk/sample/tkoptdb.rb
# '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], 3) {
cmd = TkOptionDB.new_proc_class(:BTN_CMD, [:show_msg, :bye_msg], 1) {
# If you want to check resource string (str),
# please define __check_proc_string__(str) like this.
class << self
    (1-1/1)