2004-05-21 22:23:59 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2004-05-22 01:22:09 -04:00
|
|
|
require 'remote-tk'
|
2004-05-21 22:23:59 -04:00
|
|
|
|
2004-05-22 01:22:09 -04:00
|
|
|
# start sub-process
|
|
|
|
ip_name = 'remote_ip'
|
|
|
|
ip_list = TkWinfo.interps
|
2004-05-21 22:23:59 -04:00
|
|
|
fork{
|
|
|
|
exec "/usr/bin/env ruby -r tk -e \"Tk.appname('#{ip_name}');Tk.mainloop\""
|
|
|
|
}
|
2004-05-22 01:22:09 -04:00
|
|
|
sleep 1 until (app = (TkWinfo.interps - ip_list)[0]) && app =~ /^#{ip_name}/
|
2004-05-21 22:23:59 -04:00
|
|
|
p TkWinfo.interps
|
|
|
|
|
2004-05-22 01:22:09 -04:00
|
|
|
# create RemoteTkIp object
|
|
|
|
ip = RemoteTkIp.new(app)
|
2004-05-21 22:23:59 -04:00
|
|
|
|
2004-05-22 01:22:09 -04:00
|
|
|
# setup remote-ip window
|
2004-05-21 22:23:59 -04:00
|
|
|
btns = []
|
|
|
|
ip.eval_proc{
|
2009-03-05 22:56:38 -05:00
|
|
|
btns <<
|
2004-05-21 22:23:59 -04:00
|
|
|
TkButton.new(:command=>proc{
|
2004-10-11 00:51:21 -04:00
|
|
|
puts 'This procesure is on the controller-ip (Ruby-side)'
|
2009-03-05 22:56:38 -05:00
|
|
|
},
|
2004-10-11 00:51:21 -04:00
|
|
|
:text=>'print on controller-ip (Ruby-side)').pack(:fill=>:x)
|
2004-05-21 22:23:59 -04:00
|
|
|
|
2009-03-05 22:56:38 -05:00
|
|
|
btns <<
|
2004-05-21 22:23:59 -04:00
|
|
|
TkButton.new(:command=>
|
2004-10-11 00:51:21 -04:00
|
|
|
'puts {This procesure is on the remote-ip (Tk-side)}',
|
|
|
|
:text=>'print on remote-ip (Tk-side)').pack(:fill=>:x)
|
2004-05-21 22:23:59 -04:00
|
|
|
|
2009-03-05 22:56:38 -05:00
|
|
|
btns <<
|
2004-05-21 22:23:59 -04:00
|
|
|
TkButton.new(:command=>
|
|
|
|
'ruby {
|
|
|
|
puts "This procedure is on the remote-ip (Ruby-side)"
|
|
|
|
p Array.new(3,"ruby")
|
2009-03-05 22:56:38 -05:00
|
|
|
}',
|
2004-10-11 00:51:21 -04:00
|
|
|
:text=>'ruby cmd on the remote-ip').pack(:fill=>:x)
|
2004-05-21 22:23:59 -04:00
|
|
|
|
|
|
|
TkButton.new(:command=>'exit', :text=>'QUIT').pack(:fill=>:x)
|
|
|
|
}
|
|
|
|
|
2004-05-22 01:22:09 -04:00
|
|
|
# setup controller-ip window
|
2004-09-17 02:05:33 -04:00
|
|
|
btns.each_with_index{|btn, idx|
|
2009-03-05 22:56:38 -05:00
|
|
|
# The scope of the eval-block of 'eval_proc' method is different from
|
|
|
|
# the enternal. If you want to pass local values to the eval-block,
|
2004-09-17 02:05:33 -04:00
|
|
|
# use arguments of eval_proc method. They are passed to block-arguments.
|
2009-03-05 22:56:38 -05:00
|
|
|
TkButton.new(:command=>proc{ip.eval_proc(btn){|b| b.flash}},
|
|
|
|
:text=>"flash button-#{idx}",
|
2004-10-11 00:51:21 -04:00
|
|
|
:padx=>10).pack(:padx=>10, :pady=>2)
|
2004-05-21 22:23:59 -04:00
|
|
|
}
|
|
|
|
|
2009-03-05 22:56:38 -05:00
|
|
|
TkButton.new(:command=>proc{exit}, :text=>'QUIT',
|
2004-10-11 00:51:21 -04:00
|
|
|
:padx=>10, :pady=>7).pack(:padx=>10, :pady=>7)
|
2004-05-21 22:23:59 -04:00
|
|
|
|
2004-05-22 01:22:09 -04:00
|
|
|
# start eventloop
|
2004-05-21 22:23:59 -04:00
|
|
|
Tk.mainloop
|