diff options
Diffstat (limited to 'ext/tk/lib/tk/event.rb')
-rw-r--r-- | ext/tk/lib/tk/event.rb | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/ext/tk/lib/tk/event.rb b/ext/tk/lib/tk/event.rb index b85c456d41..4c6c0844b2 100644 --- a/ext/tk/lib/tk/event.rb +++ b/ext/tk/lib/tk/event.rb @@ -1,7 +1,17 @@ # # tk/event.rb - module for event # -require 'tk' + +unless $LOADED_FEATURES.member?('tk.rb') + # change loading order + + $LOADED_FEATURES.delete('tk/event.rb') + + require 'tkutil' + require 'tk' + +else +################################################ module TkEvent class Event < TkUtil::CallbackSubst @@ -42,7 +52,7 @@ module TkEvent end # [ <'%' subst-key char>, <proc type char>, <instance var (accessor) name>] - key_tbl = [ + KEY_TBL = [ [ ?#, ?n, :serial ], [ ?a, ?s, :above ], [ ?b, ?n, :num ], @@ -76,7 +86,7 @@ module TkEvent ] # [ <proc type char>, <proc/method to convert tcl-str to ruby-obj>] - proc_tbl = [ + PROC_TBL = [ [ ?n, TkComm.method(:num_or_str) ], [ ?s, TkComm.method(:string) ], [ ?b, TkComm.method(:bool) ], @@ -106,13 +116,13 @@ module TkEvent # ( which are Tcl strings ) to ruby objects based on the key string # that is generated by _get_subst_key() or _get_all_subst_keys(). # - _setup_subst_table(key_tbl, proc_tbl); + _setup_subst_table(KEY_TBL, PROC_TBL); end - def install_bind(cmd, *args) + def install_bind_for_event_class(klass, cmd, *args) if args.compact.size > 0 args = args.join(' ') - keys = Event._get_subst_key(args) + keys = klass._get_subst_key(args) if cmd.kind_of?(String) id = cmd @@ -120,12 +130,12 @@ module TkEvent id = install_cmd(cmd) else id = install_cmd(proc{|*arg| - TkUtil.eval_cmd(cmd, *Event.scan_args(keys, arg)) + TkUtil.eval_cmd(cmd, *klass.scan_args(keys, arg)) }) end id + ' ' + args else - keys, args = Event._get_all_subst_keys + keys, args = klass._get_all_subst_keys if cmd.kind_of?(String) id = cmd @@ -133,10 +143,17 @@ module TkEvent id = install_cmd(cmd) else id = install_cmd(proc{|*arg| - TkUtil.eval_cmd(cmd, Event.new(*Event.scan_args(keys, arg))) + TkUtil.eval_cmd(cmd, klass.new(*klass.scan_args(keys, arg))) }) end id + ' ' + args end end + + def install_bind(cmd, *args) + install_bind_for_event_class(Event, cmd, *args) + end +end + +################################################ end |