1#!/usr/bin/env ruby
2require 'remote-tk'
3
4puts <<EOM
5This sample controls the other Tk interpreter (Ruby/Tk, Tcl/Tk, and so on)
6which running on the other process. For this purpose, Ruby/Tk uses Tcl/Tk's
7'send' command. Availability of the command depends on your GUI environment.
8If this script doesn't work, please check your environment (see Tcl/Tk FAQ).
9EOM
10#'
11
12unless (wish = TkWinfo.interps.find{|ip| ip =~ /^wish/})
13  puts ''
14  puts 'Please start "wish" (Tcl/Tk shell) before running this sample script.'
15  exit 1
16end
17
18ip = RemoteTkIp.new(wish)
19ip.eval_proc{TkButton.new(:command=>proc{puts 'This procesure is on the controller-ip (Ruby/Tk)'}, :text=>'print on Ruby/Tk (controller-ip)').pack(:fill=>:x)}
20ip.eval_proc{TkButton.new(:command=>'puts {This procesure is on the remote-ip (wish)}', :text=>'print on wish (remote-ip)').pack(:fill=>:x)}
21
22# If your remote-ip is Ruby/Tk, you can control the remote Ruby by
23# 'ruby' or 'ruby_eval' or 'ruby_cmd' on the Tk interpreter.
24if ip.is_rubytk?
25  ip.eval_proc{TkButton.new(:command=>'ruby {p 111; p Array.new(3,"ruby")}', :text=>'ruby cmd on the remote-ip').pack(:fill=>:x)}
26end
27
28ip.eval_proc{TkButton.new(:command=>'exit', :text=>'QUIT').pack(:fill=>:x)}
29
30TkButton.new(:command=>proc{exit}, :text=>'QUIT',
31             :padx=>10, :pady=>7).pack(:padx=>10, :pady=>7)
32
33Tk.mainloop
34