UNIXのコマンドラインから,
$ ruby kanji-code.rb
として,起動して下さい.後は,テキストエリアに日本語文字列を入れて,「コー ド表示」ボタンをクリックするだけです.

GTK自体がすでに廃れつつある今日,役に立ちそうにないですが...
Ruby-gnome版に移行しないと行けませんね.
#!/usr/bin/ruby -Ke
require 'gtk'
require 'kconv'
#script実行部分
def run_script()
Thread.start(set_argv){ |argv_text|
`/usr/bin/ruby code.rb #{argv_text} > tmp_result.txt`
get_result()
`rm tmp_result.txt`
}
end
#argv_text定義
def set_argv
text_data = @entry.get_text
return text_data
end
#実行結果取得
def get_result()
@file_name = "tmp_result.txt"
string = nil
open(@file_name) do |fh|
string = fh.read
end
@text2.delete_text(0, @text2.get_length)
@text2.insert_text(string, 0)
end
private :get_result
#window定義部分
window = Gtk::Window.new()
window.signal_connect('delete_event'){Gtk::main_quit}
table = Gtk::Table.new(20,25,true)
button1 = Gtk::Button.new("コード表示")
button1.signal_connect("clicked") do
run_script()
end
table.attach(button1,0,3,0,1)
button2 = Gtk::Button.new("終了")
button2.signal_connect("clicked") do
exit
end
table.attach(button2,3,6,0,1)
separator1 = Gtk::HSeparator.new()
table.attach(separator1,0,25,1,2)
label = Gtk::Label.new("右の枠に日本語文字を入力")
table.attach(label,0,6,2,3)
sep = Gtk::VSeparator.new()
table.attach(sep,6,7,2,3)
@entry = Gtk::Entry.new()
table.attach(@entry,7,24,2,3)
separator2 = Gtk::HSeparator.new()
table.attach(separator2,0,25,3,4)
scwin = Gtk::ScrolledWindow.new
scwin.border_width = 5
scwin.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS)
table.attach(scwin, 0, 25, 4, 20)
result_style = Gtk::Style.new
result_style.set_font(Gdk::Font.fontset_load("-watanabe-mincho-medium-r-*-*-16-*-*-*-*-*-*"))
@text2 = Gtk::Text.new()
@text2.set_editable(false)
@text2.set_style(result_style)
scwin.add(@text2)
window.add(table)
window.show_all
Gtk.main
|
| Back |