summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk.rb
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-02 07:08:18 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-02 07:08:18 +0000
commitd7d2f8bfe294f886ebb6ba3d7bf94a3a5e884049 (patch)
tree202fdc4daf958bdad32c9ea2e2cc48b40a782304 /ext/tk/lib/tk.rb
parent1c59b283a5cc2478aaed7d7a8ccd5bae2f121ce1 (diff)
* ext/tcltklib/tcltklib.c: enforce thread-check and exception-handling to
avoid SEGV trouble. [KNOWN BUG] When supports pthread and running multiple Tk interpreters, an interrupt signal causes SEGV frequently. That may be a trouble of Ruby's signal handler. * ext/tk/tkutil/tkutil.c; fix a bug on converting a SJIS string array to a Tcl's list string. * ext/tk/tcltklib.c: wrap Tcl's original "namespace" command to protect from namespace crash. * ext/tk/lib/multi-tk.rb: enforce exception-handling. * ext/tk/lib/multi-tk.rb: catch IRB_EXIT to work on irb. * ext/tk/lib/tk.rb: ditto. * ext/tk/tcltklib.c: add TclTkLib.mainloop_thread? * ext/tk/lib/multi-tk.rb: (bug fix) callback returns a value. * ext/tk/lib/tk/canvas.rb (delete): bug fix when multiple arguments. * ext/tk/lib/clock.rb: fix 'no method error'. * ext/tk/lib/clock.rb (self.clicks): accept a Symbol argument. * ext/tk/lib/variable.rb: be able to set default_value_type; :numeric, :bool, :string, :symbol, :list, :numlist or nil (default; same to :string). If set a type, TkVariable#value returns a value of the type. * ext/tk/lib/tkextlib/tclx/tclx.rb: add Tk::TclX.signal to warn the risk of using TclX extension's 'signal' command. * ext/tk/sample/irbtk.rb: irb with Ruby/Tk. * ext/tk/sample/demos-*/anilabel.rb: bug fix on 'show code' * ext/tk/sample/demos-*/aniwave.rb: new Ruby/Tk animation demo. * ext/tk/sample/demos-*/pendulum.rb: ditto. * ext/tk/sample/demos-*/goldberg.rb: ditto. * ext/tk/sample/demos-*/widget: add entries of animation demos. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8048 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tk.rb')
-rw-r--r--ext/tk/lib/tk.rb89
1 files changed, 75 insertions, 14 deletions
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index e7217ff975..95e26d7264 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -565,6 +565,15 @@ end
module_function :bool, :number, :num_or_str, :string
module_function :list, :simplelist, :window, :image_obj, :procedure
+ def subst(str, *opts)
+ # opts := :nobackslashes | :nocommands | novariables
+ tk_call('subst',
+ *(opts.collect{|opt|
+ opt = opt.to_s
+ (opt[0] == ?-)? opt: '-' << opt
+ } << str))
+ end
+
def _toUTF8(str, encoding = nil)
TkCore::INTERP._toUTF8(str, encoding)
end
@@ -1110,13 +1119,14 @@ module TkCore
INTERP._invoke_without_enc('bind', 'all', "<#{WIDGET_DESTROY_HOOK}>",
install_cmd(proc{|path|
unless TkCore::INTERP.deleted?
- if (widget = TkCore::INTERP.tk_windows[path])
- if widget.respond_to?(:__destroy_hook__)
- begin
+ begin
+ if (widget=TkCore::INTERP.tk_windows[path])
+ if widget.respond_to?(:__destroy_hook__)
widget.__destroy_hook__
- rescue Exception
end
end
+ rescue Exception=>e
+ p e if $DEBUG
end
end
}) << ' %W')
@@ -1175,11 +1185,24 @@ module TkCore
def TkCore.callback(*arg)
begin
- TkCore::INTERP.tk_cmd_tbl[arg.shift].call(*arg)
- rescue SystemExit
- exit(0)
- rescue Interrupt
- exit!(1)
+ if TkCore::INTERP.tk_cmd_tbl.kind_of?(Hash)
+ #TkCore::INTERP.tk_cmd_tbl[arg.shift].call(*arg)
+ normal_ret = false
+ ret = catch(:IRB_EXIT) do # IRB hack
+ retval = TkCore::INTERP.tk_cmd_tbl[arg.shift].call(*arg)
+ normal_ret = true
+ retval
+ end
+ unless normal_ret
+ # catch IRB_EXIT
+ exit(ret)
+ end
+ ret
+ end
+ rescue SystemExit=>e
+ exit(e.status)
+ rescue Interrupt=>e
+ fail(e)
rescue Exception => e
begin
msg = _toUTF8(e.class.inspect) + ': ' +
@@ -1194,6 +1217,8 @@ module TkCore
e.backtrace.join("\n") +
"\n---< backtrace of Tk side >-------"
end
+ # TkCore::INTERP._set_global_var('errorInfo', msg)
+ # fail(e)
fail(e, msg)
end
end
@@ -1383,6 +1408,22 @@ module TkCore
TclTkLib.mainloop(check_root)
end
+ def mainloop_thread?
+ # true : current thread is mainloop
+ # nil : there is no mainloop
+ # false : mainloop is running on the other thread
+ # ( At then, it is dangerous to call Tk interpreter directly. )
+ TclTkLib.mainloop_thread?
+ end
+
+ def mainloop_exist?
+ TclTkLib.mainloop_thread? != nil
+ end
+
+ def is_mainloop?
+ TclTkLib.mainloop_thread? == true
+ end
+
def mainloop_watchdog(check_root = true)
# watchdog restarts mainloop when mainloop is dead
TclTkLib.mainloop_watchdog(check_root)
@@ -1738,13 +1779,34 @@ module Tk
end
def Tk.pack(*args)
- #TkPack.configure(*args)
- TkPack(*args)
+ TkPack.configure(*args)
+ end
+ def Tk.pack_forget(*args)
+ TkPack.forget(*args)
+ end
+ def Tk.unpack(*args)
+ TkPack.forget(*args)
end
def Tk.grid(*args)
TkGrid.configure(*args)
end
+ def Tk.grid_forget(*args)
+ TkGrid.forget(*args)
+ end
+ def Tk.ungrid(*args)
+ TkGrid.forget(*args)
+ end
+
+ def Tk.place(*args)
+ TkPlace.configure(*args)
+ end
+ def Tk.place_forget(*args)
+ TkPlace.forget(*args)
+ end
+ def Tk.unplace(*args)
+ TkPlace.forget(*args)
+ end
def Tk.update(idle=nil)
if idle
@@ -3541,7 +3603,7 @@ class TkWindow<TkObject
self
end
- def grid_forget
+ def grid_forget
#tk_call('grid', 'forget', epath)
TkGrid.forget(self)
self
@@ -3940,7 +4002,7 @@ end
#Tk.freeze
module Tk
- RELEASE_DATE = '2005-01-28'.freeze
+ RELEASE_DATE = '2005-03-02'.freeze
autoload :AUTO_PATH, 'tk/variable'
autoload :TCL_PACKAGE_PATH, 'tk/variable'
@@ -3950,7 +4012,6 @@ module Tk
autoload :TCL_PRECISION, 'tk/variable'
end
-
# call setup script for Tk extension libraries (base configuration)
begin
require 'tkextlib/setup.rb'