ruby/ext/tk/sample/tkmsgcat-load_rb.rb
nagai 41b74c6e20 * ext/tk/extconf.rb: New strategy for searching Tcl/Tk libraries.
* ext/tk/*: Support new features of Tcl/Tk8.6b1 and minor bug fixes.
     ( [KNOWN BUG] Ruby/Tk on Ruby 1.9 will not work on Cygwin. )
* ext/tk/*: Unify sources between Ruby 1.8 & 1.9.
            Improve default_widget_set handling.
* ext/tk/*: Multi-TkInterpreter (multi-tk.rb) works on Ruby 1.8 & 1.9.
     ( [KNOWN BUG] On Ruby 1.8, join to a long term Thread on Tk
       callbacks may freeze. On Ruby 1.9, cannot create a second 
       master interpreter (creating slaves are OK); supported master
       interpreter is the default master interpreter only. )
* ext/tk/lib/tkextlib/*: Update supported versions of Tk extensions.
         Tcllib 1.8/Tklib 0.4.1  ==>  Tcllib 1.11.1/Tklib 0.5
         BWidgets 1.7            ==>  BWidgets 1.8
         TkTable 2.9             ==>  TkTable 2.10
         TkTreeCtrl 2005-12-02   ==>  TkTreeCtrl 2.2.9
         Tile 0.8.0/8.5.1        ==>  Tile 0.8.3/8.6b1
         IncrTcl 2005-02-14      ==>  IncrTcl 2008-12-15
         TclX 2005-02-07         ==>  TclX 2008-12-15
         Trofs 0.4.3             ==>  Trofs 0.4.4


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@24064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-07-12 23:09:52 +00:00

102 lines
2.9 KiB
Ruby

#!/usr/bin/env ruby
require 'tk'
demo_dir = File.dirname($0)
msgcat_dir = [demo_dir, 'msgs_rb'].join(File::Separator)
top_win = nil
#msgcat = TkMsgCatalog.new('::tk')
msgcat = TkMsgCatalog.new('::tkmsgcat_demo')
default_locale = msgcat.locale
#msgcat.load_rb(msgcat_dir)
msgcat.load(msgcat_dir)
col_proc = TkComm.install_bind(proc{|w, color, frame, label|
TkComm.window(frame).background(color)
Tk.update
TkComm.window(label).text(
msgcat["%1$s:: %2$s", 'Color',
color.capitalize])
w.flash; w.flash
Tk.callback_break;
}, "%W")
del_proc = TkComm.install_cmd(proc{top_win.destroy; top_win = nil})
err_proc = TkComm.install_cmd(proc{fail(RuntimeError,
msgcat['Application Error'])})
show_sample = proc{|loc|
top_win = TkToplevel.new(:title=>loc)
msgcat.locale = loc
#msgcat.load_rb(msgcat_dir)
msgcat.load(msgcat_dir)
TkLabel.new(top_win){
text "preferences:: #{msgcat.preferences.join(' ')}"
pack(:pady=>10, :padx=>10)
}
lbl = TkLabel.new(top_win, :text=>msgcat["%1$s:: %2$s",
'Color', '']).pack(:anchor=>'w')
bg = TkFrame.new(top_win).pack(:ipadx=>20, :ipady=>10,
:expand=>true, :fill=>:both)
TkFrame.new(bg){|f|
['blue', 'green', 'red'].each{|col|
TkButton.new(f, :text=>msgcat[col]){
bind('ButtonRelease-1', col_proc, "#{col} #{bg.path} #{lbl.path}")
}.pack(:fill=>:x)
}
}.pack(:anchor=>'center', :pady=>15)
TkFrame.new(top_win){|f|
TkButton.new(f, :text=>msgcat['Delete'],
:command=>del_proc).pack(:side=>:right, :padx=>5)
TkButton.new(f, :text=>msgcat['Error'],
:command=>err_proc).pack(:side=>:left, :padx=>5)
}.pack(:side=>:bottom, :fill=>:x)
top_win
}
# listbox for locale list
TkLabel.new(:text=>"Please click a locale.").pack(:padx=>5, :pady=>3)
TkFrame.new{|f|
TkButton.new(f, :text=>msgcat['Exit'],
:command=>proc{exit}).pack(:side=>:right, :padx=>5)
}.pack(:side=>:bottom, :fill=>:x)
f = TkFrame.new.pack(:side=>:top, :fill=>:both, :expand=>true)
lbox = TkListbox.new(f).pack(:side=>:left, :fill=>:both, :expand=>true)
lbox.yscrollbar(TkScrollbar.new(f, :width=>12).pack(:side=>:right, :fill=>:y))
lbox.bind('ButtonRelease-1'){|ev|
idx = lbox.index("@#{ev.x},#{ev.y}")
if idx == 0
loc = default_locale
else
loc = lbox.get(idx)
end
if top_win != nil && top_win.exist?
top_win.destroy
end
top_win = show_sample.call(loc)
}
lbox.insert('end', 'default')
Dir.entries(msgcat_dir).sort.each{|f|
if f =~ /^(.*).msg$/
lbox.insert('end', $1)
end
}
top_win = show_sample.call(default_locale)
# start eventloop
Tk.mainloop