aboutsummaryrefslogtreecommitdiffstats
path: root/ext/tk/sample/demos-en
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-16 07:45:51 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-16 07:45:51 +0000
commit98a3a9db9718d8a54a66ae5f5e4da080c57cba5c (patch)
treeebca1fb8cbbd8d33e46c7c8267fc26c5d67a5c61 /ext/tk/sample/demos-en
parente45c4cd1ac8523f83b1d72b068ba009e3d9fe6db (diff)
downloadruby-98a3a9db9718d8a54a66ae5f5e4da080c57cba5c.tar.gz
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
Diffstat (limited to 'ext/tk/sample/demos-en')
-rw-r--r--ext/tk/sample/demos-en/unicodeout.rb100
-rw-r--r--ext/tk/sample/demos-en/widget22
2 files changed, 112 insertions, 10 deletions
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=><<EOL).pack(:side=>: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")