summaryrefslogtreecommitdiff
path: root/ext/tk/sample/demos-en/widget
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-07-10 09:52:30 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-07-10 09:52:30 +0000
commitd2271cbdd18ea55851f21abd8862e5a3b6b98c9b (patch)
treea5b67350a63cf86c7f375ac60961514111817e07 /ext/tk/sample/demos-en/widget
parenta1a07fbfa1c0263cf3e51eca2bf2907a917bde5c (diff)
* ext/tk/tcltklib.c: make SEGV risk lower at exit.
* ext/tk/lib/tk.rb: ditto. * ext/tk/lib/multi-tk.rb: fail to call function-style methods on slave interpreters. The strategy (MultiTkIp_PseudoToplevel_Evaluable) to fix the problem is a little tricky. You may have to take care of conflicting with it. * ext/tk/lib/tk.rb: a little change for the pseudo-toplevel strategy. * ext/tk/lib/tk/font.rb: ditto. * ext/tk/lib/tk/msgcat.rb: ditto. * ext/tk/lib/tkextlib/itk/incr_tk.rb: ditto. * ext/tk/sample/demos-en/widget: fail to call function-style methods on sample scripts. To fix it, a strategy which similar to the way on MultiTiIp is used. Please take care when re-write and re-run a demo script on the Widget-Demo code viewer. * ext/tk/sample/demos-jp/widget: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/demos-en/widget')
-rw-r--r--ext/tk/sample/demos-en/widget103
1 files changed, 94 insertions, 9 deletions
diff --git a/ext/tk/sample/demos-en/widget b/ext/tk/sample/demos-en/widget
index cb60bc86ea..3c50582211 100644
--- a/ext/tk/sample/demos-en/widget
+++ b/ext/tk/sample/demos-en/widget
@@ -509,12 +509,93 @@ else # ver >= 8.4
alias showVars showVars2
end
+# Pseudo-Toplevel support
+module PseudoToplevel_Evaluable
+ def pseudo_toplevel_eval(body = Proc.new)
+ Thread.current[:TOPLEVEL] = self
+ begin
+ body.call
+ ensure
+ Thread.current[:TOPLEVEL] = nil
+ end
+ end
+
+ def pseudo_toplevel_evaluable?
+ @pseudo_toplevel_evaluable
+ end
+ def pseudo_toplevel_evaluable=(mode)
+ @pseudo_toplevel_evaluable = (mode)? true: false
+ end
+
+ def self.extended(mod)
+ mod.__send__(:extend_object, mod)
+ mod.instance_variable_set('@pseudo_toplevel_evaluable', true)
+ end
+end
+
+class Object
+ alias __method_missing__ method_missing
+ private :__method_missing__
+
+ def method_missing(id, *args)
+ begin
+ has_top = (top = Thread.current[:TOPLEVEL]) &&
+ top.respond_to?(:pseudo_toplevel_evaluable?) &&
+ top.pseudo_toplevel_evaluable? &&
+ top.respond_to?(id)
+ rescue Exception => e
+ has_top = false
+ end
+
+ if has_top
+ top.__send__(id, *args)
+ else
+ __method_missing__(id, *args)
+ end
+ end
+end
+
+class Proc
+ def initialize(*args, &b)
+ super
+ @__pseudo_toplevel__ = Thread.current[:TOPLEVEL]
+ end
+
+ alias __call__ call
+ def call(*args, &b)
+ if top = @__pseudo_toplevel__
+ orig_top = Thread.current[:TOPLEVEL]
+ Thread.current[:TOPLEVEL] = top
+ begin
+ __call__(*args, &b)
+ ensure
+ Thread.current[:TOPLEVEL] = orig_top
+ end
+ else
+ __call__(*args, &b)
+ end
+ end
+end
+
+def proc(&b)
+ Proc.new(&b)
+end
+def lambda(&b)
+ Proc.new(&b)
+end
+
def _null_binding
+ Module.new.instance_eval{extend PseudoToplevel_Evaluable}
# binding
- Module.new.instance_eval{binding}
+ # Module.new.instance_eval{binding}
end
private :_null_binding
+def eval_samplecode(code)
+ Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } }.run
+ Tk.update
+end
+
# invoke --
# This procedure is called when the user clicks on a demo description.
# It is responsible for invoking the demonstration.
@@ -529,8 +610,9 @@ def invoke(txt, idx)
cursor = txt.cget('cursor')
txt.cursor('watch')
Tk.update
- eval(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, _null_binding)
- Tk.update
+ # eval(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, _null_binding)
+ # Tk.update
+ eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join)
txt.cursor(cursor)
$tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars")
@@ -596,7 +678,8 @@ def showCode1(demo)
}.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2)
TkButton.new(f) {
text "Rerun Demo"
- command proc{eval($code_text.get('1.0','end'), _null_binding)}
+ # command proc{eval($code_text.get('1.0','end'), _null_binding)}
+ command proc{eval_samplecode($code_text.get('1.0','end'))}
}.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2)
# f.pack('side'=>'bottom', 'expand'=>'yes', 'fill'=>'x')
f.pack('side'=>'bottom', 'fill'=>'x')
@@ -690,7 +773,8 @@ def showCode2(demo)
:image=>$image['print'], :compound=>:left)
b_run = TkButton.new(bf, :text=>'Rerun Demo',
:command=>proc{
- eval($code_text.get('1.0','end'), _null_binding)
+ # eval($code_text.get('1.0','end'), _null_binding)
+ eval_samplecode($code_text.get('1.0','end'))
},
:image=>$image['refresh'], :compound=>:left)
@@ -812,7 +896,7 @@ end
#
def aboutBox
Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo',
- 'message'=>"Ruby/Tk widget demonstration Ver.1.5.6-en\n\n" +
+ 'message'=>"Ruby/Tk widget demonstration Ver.1.6.0-en\n\n" +
"based on demos of Tk8.1 -- 8.5 " +
"( Copyright:: " +
"(c) 1996-1997 Sun Microsystems, Inc. / " +
@@ -837,11 +921,12 @@ ARGV.each{|cmd|
if cmd =~ /(.*).rb/
cmd = $1
end
- eval(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join,
- _null_binding)
+ #eval(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join,
+ # _null_binding)
+ eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join)
}
if no_launcher
- $root.withdraw # hide root window
+ $root.withdraw # hide root window
Thread.start{
loop do
count = 0