2
# This script is a sample of MultiTkIp class
6
###############################
8
TkLabel.new(:text=>'This is the Default Master Ipnterpreter').pack(:padx=>5, :pady=>3)
9
TkButton.new(:text=>'QUIT', :command=>proc{exit}).pack(:pady=>3)
10
TkFrame.new(:borderwidth=>2, :height=>3,
11
:relief=>:sunken).pack(:fill=>:x, :expand=>true,
14
###############################
16
puts "---- create a safe slave IP with Ruby's safe-level == 1 ----------"
17
ip = MultiTkIp.new_safe_slave(1)
19
puts "\n---- create procs ----------"
20
puts 'x = proc{p [\'proc x\', "$SAFE==#{$SAFE}"]; exit}'
21
x = proc{p ['proc x', "$SAFE==#{$SAFE}"]; exit}
22
TkLabel.new(:text=>'x = proc{p [\'proc x\', "$SAFE==#{$SAFE}"]; exit}',
23
:anchor=>:w).pack(:fill=>:x)
25
puts 'y = proc{|label| p [\'proc y\', "$SAFE==#{$SAFE}", label]; label.text($SAFE)}'
26
y = proc{|label| p ['proc y', "$SAFE==#{$SAFE}", label]; label.text($SAFE)}
27
TkLabel.new(:text=>'y = proc{|label| p [\'proc y\', "$SAFE==#{$SAFE}", label]; label.text($SAFE)}',
28
:anchor=>:w).pack(:fill=>:x)
30
puts 'z = proc{p [\'proc z\', "$SAFE==#{$SAFE}"]; exit}'
31
z = proc{p ['proc z', "$SAFE==#{$SAFE}"]; exit}
32
TkLabel.new(:text=>'z = proc{p [\'proc z\', "$SAFE==#{$SAFE}"]; exit}',
33
:anchor=>:w).pack(:fill=>:x)
35
puts "\n---- call 1st eval_proc ----------"
38
TkLabel.new(:text=>"1st eval_proc : $SAFE == #{$SAFE}").pack
41
TkLabel.new(f, :text=>"$SAFE == ").pack(:side=>:left)
42
# TkLabel.new(f, :text=>" (<-- 'lbl' widget is here)").pack(:side=>:right)
43
l = TkLabel.new(f).pack(:side=>:right)
45
TkButton.new(:text=>':command=>proc{l.text($SAFE)}',
46
:command=>proc{l.text($SAFE)}).pack(:fill=>:x, :padx=>5)
47
TkButton.new(:text=>':command=>x', :command=>x).pack(:fill=>:x, :padx=>5)
48
TkButton.new(:text=>':command=>proc{exit}',
49
:command=>proc{exit}).pack(:fill=>:x, :padx=>5)
50
TkFrame.new(:borderwidth=>2, :height=>3,
51
:relief=>:sunken).pack(:fill=>:x, :expand=>true,
53
l # return the label widget
56
puts "\n---- change the safe slave IP's safe-level ==> 3 ----------"
59
puts "\n---- call 2nd eval_proc ----------"
61
TkLabel.new(:text=>"2nd eval_proc : $SAFE == #{$SAFE}").pack
63
TkLabel.new(f, :text=>"$SAFE == ").pack(:side=>:left)
64
l = TkLabel.new(f, :text=>$SAFE).pack(:side=>:right)
65
TkButton.new(:text=>':command=>proc{l.text($SAFE)}',
66
:command=>proc{l.text($SAFE)}).pack(:fill=>:x,
68
TkButton.new(:text=>':command=>proc{y.call(l)}',
69
:command=>proc{y.call(l)}).pack(:fill=>:x,
71
TkButton.new(:text=>':command=>proc{Thread.new(l, &y).value}',
73
Thread.new(l, &y).value
74
}).pack(:fill=>:x, :padx=>5)
75
TkButton.new(:text=>':command=>proc{z.call}',
76
:command=>proc{z.call}).pack(:fill=>:x, :padx=>5)
77
TkFrame.new(:borderwidth=>2, :height=>3,
78
:relief=>:sunken).pack(:fill=>:x, :expand=>true,
82
puts "\n---- call 1st and 2nd eval_str ----------"
83
p bind = ip.eval_str('
84
TkLabel.new(:text=>"1st and 2nd eval_str : $SAFE == #{$SAFE}").pack
86
TkLabel.new(f, :text=>"$SAFE == ").pack(:side=>:left)
87
l = TkLabel.new(f, :text=>$SAFE).pack(:side=>:right)
88
TkButton.new(:text=>":command=>proc{y.call(l)}",
89
:command=>proc{y.call(l)}).pack(:fill=>:x, :padx=>5)
94
TkButton.new(:text=>':command=>proc{ l.text = $SAFE }',
95
:command=>proc{ l.text = $SAFE }).pack(:fill=>:x, :padx=>5)
96
TkFrame.new(:borderwidth=>2, :height=>3,
97
:relief=>:sunken).pack(:fill=>:x, :expand=>true,
101
puts "\n---- change the safe slave IP's safe-level ==> 4 ----------"
104
puts "\n---- call 3rd and 4th eval_proc ----------"
106
TkLabel.new(:text=>"3rd and 4th eval_proc : $SAFE == #{$SAFE}").pack
109
TkButton.new(:text=>':command=>proc{ lbl.text = $SAFE }',
110
:command=>proc{ lbl.text = $SAFE }).pack(:fill=>:x, :padx=>5)
113
puts "\n---- start event-loop ( current $SAFE == #{$SAFE} ) ----------"