summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-09 19:29:29 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-09 19:29:29 +0000
commite55330c9c415f673ca5565a9dbd0b84775d53419 (patch)
treeab1c6145288ce3d209e605fe3dbc10c66f487f2f /ext/tk/lib/tk
parent29c3cb6d2061d2d476ef50066b44a5596dd51d99 (diff)
* ext/tk/lib/tk.rb: better operation for SIGINT when processing callbacks.
* ext/tk/lib/tk/msgcat.rb: ditto. * ext/tk/lib/tk/variable.rb: ditto. * ext/tk/lib/tk/timer.rb: ditto. * ext/tk/lib/tk/validation.rb: add Tk::ValidateConfigure.__def_validcmd() to define validatecommand methods easier git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tk')
-rw-r--r--ext/tk/lib/tk/canvastag.rb5
-rw-r--r--ext/tk/lib/tk/msgcat.rb4
-rw-r--r--ext/tk/lib/tk/timer.rb5
-rw-r--r--ext/tk/lib/tk/validation.rb62
-rw-r--r--ext/tk/lib/tk/variable.rb4
-rw-r--r--ext/tk/lib/tk/winfo.rb3
6 files changed, 80 insertions, 3 deletions
diff --git a/ext/tk/lib/tk/canvastag.rb b/ext/tk/lib/tk/canvastag.rb
index 1db7b7b768..bcd7a96430 100644
--- a/ext/tk/lib/tk/canvastag.rb
+++ b/ext/tk/lib/tk/canvastag.rb
@@ -2,13 +2,16 @@
# tk/canvastag.rb - methods for treating canvas tags
#
require 'tk'
-require 'tk/canvas'
require 'tk/tagfont'
module TkcTagAccess
include TkComm
include TkTreatTagFont
+end
+require 'tk/canvas'
+
+module TkcTagAccess
def addtag(tag)
@c.addtag(tag, 'with', @id)
self
diff --git a/ext/tk/lib/tk/msgcat.rb b/ext/tk/lib/tk/msgcat.rb
index 6c46542faf..361b9a5de3 100644
--- a/ext/tk/lib/tk/msgcat.rb
+++ b/ext/tk/lib/tk/msgcat.rb
@@ -57,6 +57,10 @@ class TkMsgCatalog < TkObject
return src_str unless cmd # no cmd -> return src-str (default action)
begin
cmd.call(locale, src_str)
+ rescue SystemExit
+ exit(0)
+ rescue Interrupt
+ exit!(1)
rescue Exception => e
begin
msg = _toUTF8(e.class.inspect) + ': ' +
diff --git a/ext/tk/lib/tk/timer.rb b/ext/tk/lib/tk/timer.rb
index 3696de168b..fa0a582205 100644
--- a/ext/tk/lib/tk/timer.rb
+++ b/ext/tk/lib/tk/timer.rb
@@ -61,11 +61,16 @@ class TkTimer
@in_callback = true
begin
@return_value = @current_proc.call(self)
+ rescue SystemExit
+ exit(0)
+ rescue Interrupt
+ exit!(1)
rescue Exception => e
if @cancel_on_exception &&
@cancel_on_exception.find{|exc| e.kind_of?(exc)}
cancel
@return_value = e
+ @in_callback = false
return e
else
fail e
diff --git a/ext/tk/lib/tk/validation.rb b/ext/tk/lib/tk/validation.rb
index cc205c5ef9..a0bb5feb8b 100644
--- a/ext/tk/lib/tk/validation.rb
+++ b/ext/tk/lib/tk/validation.rb
@@ -5,6 +5,29 @@ require 'tk'
module Tk
module ValidateConfigure
+ def self.__def_validcmd(scope, klass, keys=nil)
+ keys = klass._config_keys unless keys
+ keys.each{|key|
+ eval("def #{key}(*args, &b)
+ __validcmd_call(#{klass.name}, '#{key}', *args, &b)
+ end", scope)
+ }
+ end
+
+ def __validcmd_call(klass, key, *args, &b)
+ return cget(key) if args.empty? && !b
+
+ cmd = (b)? proc(&b) : args.shift
+
+ if cmd.kind_of?(klass)
+ configure(key, cmd)
+ elsif !args.empty?
+ configure(key, [cmd, args])
+ else
+ configure(key, cmd)
+ end
+ end
+
def __validation_class_list
# maybe need to override
[]
@@ -73,6 +96,29 @@ module Tk
end
module ItemValidateConfigure
+ def self.__def_validcmd(scope, klass, keys=nil)
+ keys = klass._config_keys unless keys
+ keys.each{|key|
+ eval("def item_#{key}(id, *args, &b)
+ __item_validcmd_call(#{klass.name}, '#{key}', id, *args, &b)
+ end", scope)
+ }
+ end
+
+ def __item_validcmd_call(tagOrId, klass, key, *args, &b)
+ return itemcget(tagid(tagOrId), key) if args.empty? && !b
+
+ cmd = (b)? proc(&b) : args.shift
+
+ if cmd.kind_of?(klass)
+ itemconfigure(tagid(tagOrId), key, cmd)
+ elsif !args.empty?
+ itemconfigure(tagid(tagOrId), key, [cmd, args])
+ else
+ itemconfigure(tagid(tagOrId), key, cmd)
+ end
+ end
+
def __item_validation_class_list(id)
# maybe need to override
[]
@@ -265,6 +311,9 @@ module TkValidation
super << ValidateCmd
end
+ Tk::ValidateConfigure.__def_validcmd(binding, ValidateCmd)
+
+=begin
def validatecommand(cmd = Proc.new, args = nil)
if cmd.kind_of?(ValidateCmd)
configure('validatecommand', cmd)
@@ -274,8 +323,13 @@ module TkValidation
configure('validatecommand', cmd)
end
end
- alias vcmd validatecommand
+=end
+# def validatecommand(*args, &b)
+# __validcmd_call(ValidateCmd, 'validatecommand', *args, &b)
+# end
+# alias vcmd validatecommand
+=begin
def invalidcommand(cmd = Proc.new, args = nil)
if cmd.kind_of?(ValidateCmd)
configure('invalidcommand', cmd)
@@ -285,5 +339,9 @@ module TkValidation
configure('invalidcommand', cmd)
end
end
- alias invcmd invalidcommand
+=end
+# def invalidcommand(*args, &b)
+# __validcmd_call(ValidateCmd, 'invalidcommand', *args, &b)
+# end
+# alias invcmd invalidcommand
end
diff --git a/ext/tk/lib/tk/variable.rb b/ext/tk/lib/tk/variable.rb
index bfa19fc18d..6398537bfa 100644
--- a/ext/tk/lib/tk/variable.rb
+++ b/ext/tk/lib/tk/variable.rb
@@ -48,6 +48,10 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL')
#_get_eval_string(TkVar_CB_TBL[name1].trace_callback(name2,op))
begin
_get_eval_string(TkVar_CB_TBL[name1].trace_callback(name2, op))
+ rescue SystemExit
+ exit(0)
+ rescue Interrupt
+ exit!(1)
rescue Exception => e
begin
msg = _toUTF8(e.class.inspect) + ': ' +
diff --git a/ext/tk/lib/tk/winfo.rb b/ext/tk/lib/tk/winfo.rb
index a3ce2b2cd2..b4cb79a29a 100644
--- a/ext/tk/lib/tk/winfo.rb
+++ b/ext/tk/lib/tk/winfo.rb
@@ -1,6 +1,9 @@
#
# tk/winfo.rb : methods for winfo command
#
+module TkWinfo
+end
+
require 'tk'
module TkWinfo