From 98a3a9db9718d8a54a66ae5f5e4da080c57cba5c Mon Sep 17 00:00:00 2001 From: nagai Date: Thu, 16 Oct 2003 07:45:51 +0000 Subject: Add Tk::EncodedString and Tk::UTF8_String class to support characters using the \uXXXX escape to the UNICODE string. sample/{demos-en,demos-jp}/unicodeout.rb are samples of Tk::UTF8_String. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/sample/demos-en/unicodeout.rb | 100 ++++++++++++++++++++++++++++++++++ ext/tk/sample/demos-en/widget | 22 ++++---- ext/tk/sample/demos-jp/entry3.rb | 14 ++--- ext/tk/sample/demos-jp/unicodeout.rb | 102 +++++++++++++++++++++++++++++++++++ ext/tk/sample/demos-jp/widget | 22 ++++---- 5 files changed, 233 insertions(+), 27 deletions(-) create mode 100644 ext/tk/sample/demos-en/unicodeout.rb create mode 100644 ext/tk/sample/demos-jp/unicodeout.rb (limited to 'ext/tk/sample') diff --git a/ext/tk/sample/demos-en/unicodeout.rb b/ext/tk/sample/demos-en/unicodeout.rb new file mode 100644 index 0000000000..9e69628e7e --- /dev/null +++ b/ext/tk/sample/demos-en/unicodeout.rb @@ -0,0 +1,100 @@ +# unicodeout.rb -- +# +# This demonstration script shows how you can produce output (in label +# widgets) using many different alphabets. +# +# based on Tcl/Tk8.4.4 widget demos + +if defined?($unicodeout_demo) && $unicodeout_demo + $unicodeout_demo.destroy + $unicodeout_demo = nil +end + +$unicodeout_demo = TkToplevel.new {|w| + title("Unicode Label Demonstration") + iconname("unicodeout") + positionWindow(w) +} + +TkLabel.new($unicodeout_demo, + :font=>$font, :wraplength=>'4i', :justify=>:left, + :text=><:top) +This is a sample of Tk's support for languages that use non-Western \ +character sets. However, what you will actually see below depends \ +largely on what character sets you have installed, and what you see \ +for characters that are not present varies greatly between platforms \ +as well. The strings are written in Tcl using UNICODE characters \ +using the \\uXXXX escape so as to do so in a portable fashion. + +ATTENTION: +The strings are converted to the encoded string objects \ +(completed to rewrite Tcl's escapes) by Tk::UTF8_String method. \ +And the Tk::UTF8_String objects are passed to the label widgets. +EOL + +TkFrame.new($unicodeout_demo){|f| + pack(:side=>:bottom, :fill=>:x, :pady=>'2m') + + TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ + $unicodeout_demo.destroy + $unicodeout_demo = nil + }).pack(:side=>:left, :expand=>true) + + TkButton.new(f, :text=>'See Code', :width=>15, :command=>proc{ + showCode 'unicodeout' + }).pack(:side=>:left, :expand=>true) +} + +wait_msg = TkLabel.new($unicodeout_demo, + :text=>"Please wait while loading fonts...", + :font=>"Helvetica 12 italic").pack + +class Unicodeout_SampleFrame < TkFrame + @@font = $font + + def initialize() + super($unicodeout_demo) + grid_columnconfig(1, :weight=>1) + end + + def add_sample(lang, *args) + sample_txt = Tk::UTF8_String(args.join('')) + l = TkLabel.new(self, :font=>@@font, :text=>lang+':', + :anchor=>:nw, :pady=>0) + s = TkLabel.new(self, :font=>TkFont.new(@@font), :text=>sample_txt, + :anchor=>:nw, :width=>30, :pady=>0) + Tk.grid(l, s, :sticky=>:ew, :pady=>0) + l.grid_config(:padx, '1m') + end +end +f = Unicodeout_SampleFrame.new +f.pack(:expand=>true, :fill=>:both, :padx=>'2m', :pady=>'1m') + +# Processing when some characters are missing might take a while, so make +# sure we're displaying something in the meantime... + +oldCursor = $unicodeout_demo.cursor +$unicodeout_demo.cursor('watch') +Tk.update + +f.add_sample('Arabic', + '\uFE94\uFEF4\uFE91\uFEAE\uFECC\uFEDF\uFE8D\uFE94', + '\uFEE4\uFEE0\uFEDC\uFEDF\uFE8D') +f.add_sample('Trad. Chinese', '\u4E2D\u570B\u7684\u6F22\u5B57') +f.add_sample('Simpl. Chinese', '\u6C49\u8BED') +f.add_sample('Greek', + '\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AE ', + '\u03B3\u03BB\u03CE\u03C3\u03C3\u03B1') +f.add_sample('Hebrew', + '\u05DD\u05D9\u05DC\u05E9\u05D5\u05E8\u05D9 ', + '\u05DC\u05D9\u05D0\u05E8\u05E9\u05D9') +f.add_sample('Japanese', + '\u65E5\u672C\u8A9E\u306E\u3072\u3089\u304C\u306A, ', + '\u6F22\u5B57\u3068\u30AB\u30BF\u30AB\u30CA') +f.add_sample('Korean', '\uB300\uD55C\uBBFC\uAD6D\uC758 \uD55C\uAE00') +f.add_sample('Russian', + '\u0420\u0443\u0441\u0441\u043A\u0438\u0439 ', + '\u044F\u0437\u044B\u043A') + +wait_msg.destroy +$unicodeout_demo.cursor(oldCursor) diff --git a/ext/tk/sample/demos-en/widget b/ext/tk/sample/demos-en/widget index 2c13a5e493..aa702883de 100644 --- a/ext/tk/sample/demos-en/widget +++ b/ext/tk/sample/demos-en/widget @@ -200,25 +200,27 @@ txt.insert('end', "Labels, buttons, checkbuttons, and radiobuttons.\n", tag_titl txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. Labels (text and bitmaps).\n", tag_demo, "demo-label") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "2. Buttons.\n", tag_demo, "demo-button") +txt.insert('end', "2. Labels and UNICODE text. (if supported)\n", tag_demo, "demo-unicodeout") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "3. Checkbuttons (select any of a group).\n", tag_demo, "demo-check") +txt.insert('end', "3. Buttons.\n", tag_demo, "demo-button") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "4. Radiobuttons (select one of a group).\n", tag_demo, "demo-radio") +txt.insert('end', "4. Checkbuttons (select any of a group).\n", tag_demo, "demo-check") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "5. Radiobuttons (if supported 'compound' option).\n", tag_demo, "demo-radio2") +txt.insert('end', "5. Radiobuttons (select one of a group).\n", tag_demo, "demo-radio") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "6. A 15-puzzle game made out of buttons.\n", tag_demo, "demo-puzzle") +txt.insert('end', "6. Radiobuttons (if supported 'compound' option).\n", tag_demo, "demo-radio2") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "7. Iconic buttons that use bitmaps.\n", tag_demo, "demo-icon") +txt.insert('end', "7. A 15-puzzle game made out of buttons.\n", tag_demo, "demo-puzzle") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "8. Two labels displaying images.\n", tag_demo, "demo-image1") +txt.insert('end', "8. Iconic buttons that use bitmaps.\n", tag_demo, "demo-icon") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "9. A simple user interface for viewing images.\n", tag_demo, "demo-image2") +txt.insert('end', "9. Two labels displaying images.\n", tag_demo, "demo-image1") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "10. A simple user interface for viewing images. (if supported)\n", tag_demo, "demo-image3") +txt.insert('end', "10. A simple user interface for viewing images.\n", tag_demo, "demo-image2") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "11. Labelled frames (if supported)\n", tag_demo, "demo-labelframe") +txt.insert('end', "11. A simple user interface for viewing images. (if supported)\n", tag_demo, "demo-image3") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "12. Labelled frames (if supported)\n", tag_demo, "demo-labelframe") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") diff --git a/ext/tk/sample/demos-jp/entry3.rb b/ext/tk/sample/demos-jp/entry3.rb index 4c0b24e28c..9bf3f62097 100644 --- a/ext/tk/sample/demos-jp/entry3.rb +++ b/ext/tk/sample/demos-jp/entry3.rb @@ -29,7 +29,7 @@ TkLabel.new($entry3_demo, 二つめのエントリボックスは,入力された文字列の長さが\ 10文字未満の場合だけを受け付け,制限を越えて書き込もうとしたときには\ ベルを鳴らして知らせます.\ -三つめはアメリカの電話番号を受け付けるエントリボックスです.\ +三つめは米国の電話番号を受け付けるエントリボックスです.\ アルファベットは,電話機のダイヤル上で対応づけられている数字に変換されます.\ 不適切な文字が入力されたり数字以外の文字の位置に数字を入力しようとしたり\ した場合には警告のベルが鳴ります.\ @@ -41,12 +41,12 @@ EOL TkFrame.new($entry3_demo){|f| pack(:side=>:bottom, :fill=>:x, :pady=>'2m') - TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ + TkButton.new(f, :text=>'了解', :width=>15, :command=>proc{ $entry3_demo.destroy $entry3_demo = nil }).pack(:side=>:left, :expand=>true) - TkButton.new(f, :text=>'See Code', :width=>15, :command=>proc{ + TkButton.new(f, :text=>'コード参照', :width=>15, :command=>proc{ showCode 'entry3' }).pack(:side=>:left, :expand=>true) } @@ -71,7 +71,7 @@ def focusAndFlash(widget, fg, bg, count=5) widget.focus(true) end -l1 = TkLabelFrame.new($entry3_demo, :text=>"Integer Entry") +l1 = TkLabelFrame.new($entry3_demo, :text=>"整数エントリ") TkEntry.new(l1, :validate=>:focus, :vcmd=>[ proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P' @@ -80,7 +80,7 @@ TkEntry.new(l1, :validate=>:focus, pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') } -l2 = TkLabelFrame.new($entry3_demo, :text=>"Length-Constrained Entry") +l2 = TkLabelFrame.new($entry3_demo, :text=>"長さ制約付きエントリ") TkEntry.new(l2, :validate=>:key, :invcmd=>proc{Tk.bell}, :vcmd=>[proc{|s| s.length < 10}, '%P'] ).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') @@ -167,7 +167,7 @@ def validatePhoneChange(widget, vmode, idx, char) end -l3 = TkLabelFrame.new($entry3_demo, :text=>"US Phone-Number Entry") +l3 = TkLabelFrame.new($entry3_demo, :text=>"米国電話番号エントリ") TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell}, :textvariable=>entry3content, :vcmd=>[ @@ -186,7 +186,7 @@ TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell}, pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') } -l4 = TkLabelFrame.new($entry3_demo, :text=>"Password Entry") +l4 = TkLabelFrame.new($entry3_demo, :text=>"パスワードエントリ") TkEntry.new(l4, :validate=>:key, :show=>'*', :vcmd=>[ proc{|s| s.length <= 8}, diff --git a/ext/tk/sample/demos-jp/unicodeout.rb b/ext/tk/sample/demos-jp/unicodeout.rb new file mode 100644 index 0000000000..fcc0a21875 --- /dev/null +++ b/ext/tk/sample/demos-jp/unicodeout.rb @@ -0,0 +1,102 @@ +# unicodeout.rb -- +# +# This demonstration script shows how you can produce output (in label +# widgets) using many different alphabets. +# +# based on Tcl/Tk8.4.4 widget demos + +if defined?($unicodeout_demo) && $unicodeout_demo + $unicodeout_demo.destroy + $unicodeout_demo = nil +end + +$unicodeout_demo = TkToplevel.new {|w| + title("Unicode Label Demonstration") + iconname("unicodeout") + positionWindow(w) +} + +TkLabel.new($unicodeout_demo, + :font=>$font, :wraplength=>'4i', :justify=>:left, + :text=><:top) +これは,Tkにおける非欧米文字集合を用いる言語に対するサポートについての\ +サンプルです.ただし,下の表示においてあなたが実際にどのような表示を\ +目にするかは,あなたの環境にどのような文字集合がインストールされているかに\ +大きく依存します.また,対象となる文字集合がインストールされていない場合に\ +どのような表示がなされるかもあなたの環境次第です.\ +スクリプトが可搬性を持つように,文字列は\\uXXXXという\ +Tclのエスケープ表現を用いたUNICODE文字列で書かれています. +文字列はTk::UTF8_StringメソッドによってUTF8形式の文字列であるという\ +エンコード情報付きの文字列オブジェクト\ +(Tclのエスケープ表現の変換済み)に変換して\ +ラベルウィジェットに渡している点に注意してください. +EOL +#' + +TkFrame.new($unicodeout_demo){|f| + pack(:side=>:bottom, :fill=>:x, :pady=>'2m') + + TkButton.new(f, :text=>'了解', :width=>15, :command=>proc{ + $unicodeout_demo.destroy + $unicodeout_demo = nil + }).pack(:side=>:left, :expand=>true) + + TkButton.new(f, :text=>'コード参照', :width=>15, :command=>proc{ + showCode 'unicodeout' + }).pack(:side=>:left, :expand=>true) +} + +wait_msg = TkLabel.new($unicodeout_demo, + :text=>"フォント読み込みの完了まで" + + "しばらくお待ち下さい...", + :font=>"Helvetica 12 italic").pack + +class Unicodeout_SampleFrame < TkFrame + @@font = $font + + def initialize() + super($unicodeout_demo) + grid_columnconfig(1, :weight=>1) + end + + def add_sample(lang, *args) + sample_txt = Tk::UTF8_String(args.join('')) + l = TkLabel.new(self, :font=>@@font, :text=>lang+':', + :anchor=>:nw, :pady=>0) + s = TkLabel.new(self, :font=>TkFont.new(@@font), :text=>sample_txt, + :anchor=>:nw, :width=>30, :pady=>0) + Tk.grid(l, s, :sticky=>:ew, :pady=>0) + l.grid_config(:padx, '1m') + end +end +f = Unicodeout_SampleFrame.new +f.pack(:expand=>true, :fill=>:both, :padx=>'2m', :pady=>'1m') + +# Processing when some characters are missing might take a while, so make +# sure we're displaying something in the meantime... + +oldCursor = $unicodeout_demo.cursor +$unicodeout_demo.cursor('watch') +Tk.update + +f.add_sample('Arabic', + '\uFE94\uFEF4\uFE91\uFEAE\uFECC\uFEDF\uFE8D\uFE94', + '\uFEE4\uFEE0\uFEDC\uFEDF\uFE8D') +f.add_sample('Trad. Chinese', '\u4E2D\u570B\u7684\u6F22\u5B57') +f.add_sample('Simpl. Chinese', '\u6C49\u8BED') +f.add_sample('Greek', + '\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AE ', + '\u03B3\u03BB\u03CE\u03C3\u03C3\u03B1') +f.add_sample('Hebrew', + '\u05DD\u05D9\u05DC\u05E9\u05D5\u05E8\u05D9 ', + '\u05DC\u05D9\u05D0\u05E8\u05E9\u05D9') +f.add_sample('Japanese', + '\u65E5\u672C\u8A9E\u306E\u3072\u3089\u304C\u306A, ', + '\u6F22\u5B57\u3068\u30AB\u30BF\u30AB\u30CA') +f.add_sample('Korean', '\uB300\uD55C\uBBFC\uAD6D\uC758 \uD55C\uAE00') +f.add_sample('Russian', + '\u0420\u0443\u0441\u0441\u043A\u0438\u0439 ', + '\u044F\u0437\u044B\u043A') + +wait_msg.destroy +$unicodeout_demo.cursor(oldCursor) diff --git a/ext/tk/sample/demos-jp/widget b/ext/tk/sample/demos-jp/widget index 3dd285a489..696a9073cc 100644 --- a/ext/tk/sample/demos-jp/widget +++ b/ext/tk/sample/demos-jp/widget @@ -211,33 +211,35 @@ txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. ラベル (テキスト, ビットマップ)\n", tag_demo, "demo-label") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "2. ボタン \n", tag_demo, "demo-button") +txt.insert('end', "2. ラベルとUNICODEテキスト (機能に対応したバージョンのTkが必要)\n", tag_demo, "demo-unicodeout") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "3. チェックボタン (複数を選択可能)\n", +txt.insert('end', "3. ボタン \n", tag_demo, "demo-button") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. チェックボタン (複数を選択可能)\n", tag_demo, "demo-check") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "4. ラジオボタン (任意の一つを選択可能)\n", +txt.insert('end', "5. ラジオボタン (任意の一つを選択可能)\n", tag_demo, "demo-radio") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "5. ラジオボタン (機能に対応したバージョンのTkが必要)\n", +txt.insert('end', "6. ラジオボタン (機能に対応したバージョンのTkが必要)\n", tag_demo, "demo-radio2") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "6. ボタンで作られた15-パズルゲーム\n", +txt.insert('end', "7. ボタンで作られた15-パズルゲーム\n", tag_demo, "demo-puzzle") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "7. ビットマップを使用したアイコンボタン\n", +txt.insert('end', "8. ビットマップを使用したアイコンボタン\n", tag_demo, "demo-icon") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "8. 画像を表示する二つのラベル\n", +txt.insert('end', "9. 画像を表示する二つのラベル\n", tag_demo, "demo-image1") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "9. 画像を見るための簡単なユーザインターフェース\n", +txt.insert('end', "10. 画像を見るための簡単なユーザインターフェース\n", tag_demo, "demo-image2") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "10. 画像を見るための簡単なユーザインターフェース (機能に対応したバージョンのTkが必要)\n", +txt.insert('end', "11. 画像を見るための簡単なユーザインターフェース (機能に対応したバージョンのTkが必要)\n", tag_demo, "demo-image3") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "11. ラベル付きフレーム (機能に対応したバージョンのTkが必要)\n", +txt.insert('end', "12. ラベル付きフレーム (機能に対応したバージョンのTkが必要)\n", tag_demo, "demo-labelframe") txt.insert('end', " \n ", tag_demospace) -- cgit v1.2.3