summaryrefslogtreecommitdiff
path: root/ext/tk/sample/demos-jp/widget
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-01 16:09:54 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-01 16:09:54 +0000
commit4c4631c2daaf7b2418c1f0e39292c8ee27a64813 (patch)
treedfeb96c4772df8caba4e01e749c8f3e1262f8fe0 /ext/tk/sample/demos-jp/widget
parentce23680755e4e9ab0eed9dc6adb091ef7f1c58cb (diff)
* renewal Ruby/Tk
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/demos-jp/widget')
-rw-r--r--ext/tk/sample/demos-jp/widget412
1 files changed, 359 insertions, 53 deletions
diff --git a/ext/tk/sample/demos-jp/widget b/ext/tk/sample/demos-jp/widget
index 696a9073cc..0544127cbb 100644
--- a/ext/tk/sample/demos-jp/widget
+++ b/ext/tk/sample/demos-jp/widget
@@ -1,8 +1,11 @@
#!/usr/bin/env ruby
+# 漢字コード設定 ( tk.rb のロード時の encoding 推定/設定に使われる )
+$KCODE = 'euc'
+
# tk 関係ライブラリの読み込み
require 'tk'
-require 'tkafter'
+# require 'tkafter'
# widget demo directory 位置の獲得
$demo_dir = File.dirname($0)
@@ -12,43 +15,106 @@ $root = TkRoot.new{title "Widget Demonstration"}
# tk バージョンの取得
$tk_version = Tk::TK_VERSION
+$tk_major_ver, $tk_minor_ver = $tk_version.split('.').map{|n| n.to_i}
+$tk_patchlevel = Tk::TK_PATCHLEVEL
# tcl_platform 情報へのアクセスオブジェクト
$tk_platform = TkVarAccess.new('tcl_platform')
# フォント設定
-$font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*', nil)
-knjfont = '-*-r-*--16-*-jisx0208.1983-0'
-$kanji_font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
- knjfont)
-TkOption.add('*kanjiFont', knjfont, 'startupFile')
-$msg_kanji_font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
- '-*-r-*--24-*-jisx0208.1983-0')
#######
-#case($tk_version)
-#when /^4.*/
-# $font = '-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*'
-# $kanji_font = '-*--16-*-jisx0208.1983-0'
-# $msg_kanji_font = '-*--24-*-jisx0208.1983-0'
-# $knjfont_opt = 'kanjifont'
-# TkOption.add('*kanjiFont', $kanji_font, 'startupFile')
-#
-#when /^8.*/
-# Tk.tk_call('font', 'create', '@ascii',
-# '-copy', '-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*')
-# Tk.tk_call('font', 'create', '@kanji',
-# '-copy', '-*--16-*-jisx0208.1983-0')
-# Tk.tk_call('font', 'create', '@msg_knj',
-# '-copy', '-*--24-*-jisx0208.1983-0')
-# Tk.tk_call('font', 'create', '@cFont', '-compound', '@ascii @kanji')
-# Tk.tk_call('font', 'create', '@cMsgFont', '-compound', '@ascii @msg_knj')
-# $font = '-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*'
-# $kanji_font = '@cFont'
-# $msg_kanji_font = '@cMsgFont'
-# $knjfont_opt = 'font'
-#end
+case($tk_version)
+when /^4.*/
+ $font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*', nil)
+ knjfont = '-*--16-*-jisx0208.1983-0'
+ $kanji_font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
+ knjfont)
+ TkOption.add('*kanjiFont', knjfont, 'startupFile')
+ $msg_kanji_font=TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
+ '-*--24-*-jisx0208.1983-0')
+
+#when '8.0'
+# $font = TkFont.new('Helvetica -12')
+# $kanji_font = TkFont.new('Helvetica -12', 'Mincho -12')
+# TkOption.add('*kanjiFont', knjfont, 'startupFile')
+# $msg_kanji_font=TkFont.new('Helvetica 16', 'Gothic 16 bold')
+
+when /^8.*/
+ $font = TkFont.new('Helvetica -12')
+ $kanji_font = TkFont.new('Helvetica -12', 'Mincho -12')
+ TkOption.add('*kanjiFont', knjfont, 'startupFile')
+ $msg_kanji_font=TkFont.new('Helvetica 16', 'Gothic 16 bold')
+
+else
+ $font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*', nil)
+ knjfont = '-*--16-*-jisx0208.1983-0'
+ $kanji_font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
+ knjfont)
+ TkOption.add('*kanjiFont', knjfont, 'startupFile')
+ $msg_kanji_font=TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
+ '-*--24-*-jisx0208.1983-0')
+end
#######
+# イメージ設定
+$image = {}
+
+if $tk_major_ver >= 8
+$image['refresh'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
+ R0lGODlhEAAQAPMAAMz/zCpnKdb/1z9mPypbKBtLGy9NMPL/9Or+6+P+4j1Y
+ PwQKBP7//xMLFAYBCAEBASH5BAEAAAAALAAAAAAQABAAAwR0EAD3Gn0Vyw0e
+ ++CncU7IIAezMA/nhUqSLJizvSdCEEjy2ZIV46AwDAoDHwPYGSoEiUJAAGJ6
+ EDHBNCFINW5OqABKSFk/B9lUa94IDwIFgewFMwQDQwCZQCztTgM9Sl8SOEMG
+ KSAthiaOjBMPDhQONBiXABEAOw==
+EOD
+end
+
+if $tk_major_ver >= 8
+$image['view'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
+ R0lGODlhEAAQAPMAAMz/zP///8DAwICAgH9/fwAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAwRIcMhJB7h3hM33
+ KFjWdQQYap1QrCaGBmrRrS4nj5b53jOgbwXBKGACoYLDIuAoHCmZyYvR1rT5
+ RMAq8LqcIYGsrjPsW1XOmFUEADs=
+EOD
+end
+
+if $tk_major_ver >= 8
+$image['delete'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
+ R0lGODlhEAAOAKEAAIQAAO/n3v///////yH5BAEKAAIALAAAAAAQAA4AAAIm
+ lI9pAKHbIHNoVhYhTdjlJ2AWKG2g+CldmB6rxo2uybYhbS80eRQAOw==
+EOD
+end
+
+if $tk_major_ver >= 8
+$image['print'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
+ R0lGODlhGgATAPcAACEQOTEpQjEpUkIpc0IxY0I5c0oxjEo5SlJCY1JCe1JK
+ UlpChFpCjFpGkFpSc1paa2NKc2NKnGNja2tapWtjc29KnHNanHNjc3NjrXNr
+ jHNrnHNzc3tjpXtrtXtzhICAgIRzvYSEjIZzqox7tYyEnIyMjJSEtZSEvZSM
+ lJyMtZyMvZyUlJyUrZyUvZycnKWctaWlpa2czq2lzrWtvbWtzrW1tb21xr21
+ 1sa9zs693s7OztbO3tbO597W1t7W7+fe7+fn5////+/n7+/v7+/v9////wAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAACH5BAEAAEEALAAAAAAaABMAQAj/AIMIHBhkg0GC
+ CBMGIQEiQgseQT4oeCBBAokgRYYQ0JBixg8hRIiUUEBBYYmTByBwiCBCRYwH
+ CxY8cKFw4AogRXLqLAJkQ80gCBBg3BkxZswTNGh4MGqgQQUMJRHCwMkTSE+D
+ Pn8eCKBhxIMhO3ei2OHDBw6sWSlMMMoWgwwfMDZI8GBjx44NARZwEGGi5MkS
+ PcIWKRGz5YgLbAco+KkQBQoJIRgjdGEVq+SaJajqtNrzMgsPCmoIzqmDgmWE
+ KOBuUKAAwYabYTfs4OHjY0giGyhk4MAWRI4eKyRQqPgggYUXPH4A+XBAgwoK
+ DiIsCFxjA9sFEVQQCRJCAYAFDJxiKhAxvMTonEFimrhhYinTBgWiCvxLNX3M
+ DkkpsKV5OYhjBxCMYAICAigUEAA7
+EOD
+end
+
# メニュー設定
TkMenubar.new($root,
[[['File', 0],
@@ -57,6 +123,7 @@ TkMenubar.new($root,
['Quit', proc{exit}, 0, 'Meta-Q']
]]).pack('side'=>'top', 'fill'=>'x')
$root.bind('F1', proc{aboutBox})
+$root.bind('Meta-q', proc{exit})
=begin
TkFrame.new($root){|frame|
@@ -77,7 +144,7 @@ if $tk_version =~ /^4\.[01]/
txt = TkText.new($root) {
#wrap 'word'
wrap 'char'
- width 60
+ width 70
height 30
font $font
setgrid 'yes'
@@ -95,7 +162,7 @@ else
txt = TkText.new($root) {
#wrap 'word'
wrap 'char'
- width 60
+ width 70
height 30
font $font
setgrid 'yes'
@@ -103,6 +170,7 @@ else
padx 4
pady 2
takefocus 0
+ bd 1
yscrollcommand proc{|first,last| scr.set first,last}
}
scr.command(proc{|*args| txt.yview(*args)})
@@ -124,11 +192,13 @@ end
# テキストタグ設定
tag_title = TkTextTag.new(txt, 'font'=>'-*-Helvetica-Bold-R-Normal--*-180-*-*-*-*-*-*')
-tag_kanji_title = TkTextTag.new(txt, 'kanjifont'=>$msg_kanji_font)
-tag_middle = TkTextTag.new(txt, 'kanjifont'=>$kanji_font)
+#tag_kanji_title = TkTextTag.new(txt, 'kanjifont'=>$msg_kanji_font)
+#tag_middle = TkTextTag.new(txt, 'kanjifont'=>$kanji_font)
+tag_kanji_title = TkTextTag.new(txt, 'font'=>$msg_kanji_font)
+tag_middle = TkTextTag.new(txt, 'font'=>$kanji_font)
tag_demospace = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c')
-if TkWinfo.depth($root) == '1'
+if TkWinfo.depth($root) == 1
tag_demo = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c',
'underline'=>1)
$tag_visited = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c',
@@ -218,28 +288,34 @@ txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. チェックボタン (複数を選択可能)\n",
tag_demo, "demo-check")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "5. ラジオボタン (任意の一つを選択可能)\n",
+txt.insert('end', "5. 3状態チェックボタン (機能に対応したバージョンのTkが必要)\n",
+ tag_demo, "demo-check2")
+txt.insert('end', " \n ", tag_demospace)
+txt.insert('end', "6. ラジオボタン (任意の一つを選択可能)\n",
tag_demo, "demo-radio")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "6. ラジオボタン (機能に対応したバージョンのTkが必要)\n",
+txt.insert('end', "7. ラジオボタン (機能に対応したバージョンのTkが必要)\n",
tag_demo, "demo-radio2")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "7. ボタンで作られた15-パズルゲーム\n",
+txt.insert('end', "8. 3状態ラジオボタン (機能に対応したバージョンのTkが必要)\n",
+ tag_demo, "demo-radio3")
+txt.insert('end', " \n ", tag_demospace)
+txt.insert('end', "9. ボタンで作られた15-パズルゲーム\n",
tag_demo, "demo-puzzle")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "8. ビットマップを使用したアイコンボタン\n",
+txt.insert('end', "10. ビットマップを使用したアイコンボタン\n",
tag_demo, "demo-icon")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "9. 画像を表示する二つのラベル\n",
+txt.insert('end', "11. 画像を表示する二つのラベル\n",
tag_demo, "demo-image1")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "10. 画像を見るための簡単なユーザインターフェース\n",
+txt.insert('end', "12. 画像を見るための簡単なユーザインターフェース\n",
tag_demo, "demo-image2")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "11. 画像を見るための簡単なユーザインターフェース (機能に対応したバージョンのTkが必要)\n",
+txt.insert('end', "13. 画像を見るための簡単なユーザインターフェース (機能に対応したバージョンのTkが必要)\n",
tag_demo, "demo-image3")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "12. ラベル付きフレーム (機能に対応したバージョンのTkが必要)\n",
+txt.insert('end', "14. ラベル付きフレーム (機能に対応したバージョンのTkが必要)\n",
tag_demo, "demo-labelframe")
txt.insert('end', " \n ", tag_demospace)
@@ -286,7 +362,10 @@ txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. ウィンドウを埋め込んだテキスト\n",
tag_demo, "demo-twind")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "5. 検索\n", tag_demo, "demo-search")
+txt.insert('end', "5. ウィンドウを埋め込んだテキスト (機能に対応したバージョンのTkが必要)\n",
+ tag_demo, "demo-twind2")
+txt.insert('end', " \n ", tag_demospace)
+txt.insert('end', "6. 検索\n", tag_demo, "demo-search")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
@@ -305,7 +384,9 @@ txt.insert('end', "5. ルーラー\n", tag_demo, "demo-ruler")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "6. フロアプラン\n", tag_demo, "demo-floor")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "7. スクロール可能なキャンバス\n",
+txt.insert('end', "7. フロアプラン (異なるキャンバスアイテム作成方法を使用)\n", tag_demo, "demo-floor2")
+txt.insert('end', " \n ", tag_demospace)
+txt.insert('end', "8. スクロール可能なキャンバス\n",
tag_demo, "demo-cscroll")
txt.insert('end', " \n ", tag_demospace)
@@ -381,14 +462,14 @@ end
# 親ウィジェットと,変数名と TkVariable との組(配列)の並びを渡す
$showVarsWin = {}
-def showVars (parent, *args)
+def showVars1(parent, *args)
if $showVarsWin[parent.path]
begin
$showVarsWin[parent.path].destroy
rescue
end
end
- w = TkToplevel.new(parent) {|w|
+ top = TkToplevel.new(parent) {|w|
title "Variable values"
TkLabel.new(w) {
text "変数値:"
@@ -413,7 +494,49 @@ def showVars (parent, *args)
command proc{w.destroy}
}.pack('side'=>'bottom', 'pady'=>2)
}
- $showVarsWin[parent.path] = w
+ $showVarsWin[parent.path] = top
+end
+
+def showVars2(parent, *args)
+ if $showVarsWin[parent.path]
+ begin
+ $showVarsWin[parent.path].destroy
+ rescue
+ end
+ end
+ $showVarsWin[parent.path] = TkToplevel.new(parent) {|w|
+ title "Variable values"
+
+ TkLabelFrame.new(w, :text=>"変数値:",
+ :font=>{:family=>'Helvetica', :size=>14}){|f|
+ args.each{|vnam,vbody|
+ TkGrid(TkLabel.new(f, :text=>"#{vnam}: ", :anchor=>'w'),
+ TkLabel.new(f, :textvariable=>vbody, :anchor=>'w'),
+ :padx=>2, :pady=>2, :sticky=>'w')
+ }
+
+ f.grid(:sticky=>'news', :padx=>4)
+ f.grid_columnconfig(1, :weight=>1)
+ f.grid_rowconfig(100, :weight=>1)
+ }
+ TkButton.new(w, :text=>"了解", :width=>8, :default=>:active,
+ :command=>proc{w.destroy}){|b|
+ w.bind('Return', proc{b.invoke})
+ w.bind('Escape', proc{b.invoke})
+
+ b.grid(:sticky=>'e', :padx=>4, :pady=>[6, 4])
+ }
+ w.grid_columnconfig(0, :weight=>1)
+ w.grid_rowconfig(0, :weight=>1)
+ }
+end
+
+if $tk_major_ver < 8
+ alias showVars showVars1
+elsif $tk_major_ver == 8 && $tk_minor_ver < 4
+ alias showVars showVars1
+else # ver >= 8.4
+ alias showVars showVars2
end
# テキスト上での click に対する動作
@@ -424,7 +547,8 @@ def invoke (txt, index)
txt.cursor('watch')
Tk.update
# eval `cat #{tag[5..-1]}.rb`
- eval `cat #{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb`
+# eval `cat #{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb`
+ eval IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join
Tk.update
# txt.cursor('xterm')
txt.cursor(cursor)
@@ -449,14 +573,15 @@ def showStatus (txt, index)
end
# ソースコードの表示
-def showCode (demo)
+def showCode1(demo)
file = "#{demo}.rb"
$code_window = nil unless defined? $code_window
- if $code_window == nil || TkWinfo.exist?($code_window) == '0'
+ if $code_window == nil || TkWinfo.exist?($code_window) == false
$code_window = TkToplevel.new(nil)
f = TkFrame.new($code_window)
TkButton.new(f) {
- text "了解"
+ #text "了解"
+ text "閉じる"
command proc{
$code_window.destroy
$code_window = nil
@@ -528,13 +653,194 @@ def showCode (demo)
fid.close
end
+def showCode2(demo)
+ file = "#{demo}.rb"
+ $code_window = nil unless defined? $code_window
+ if $code_window == nil || TkWinfo.exist?($code_window) == false
+ $code_window = TkToplevel.new(nil)
+ tf = TkFrame.new($code_window)
+ $code_text = TkText.new(tf, :font=>'Courier 10', :height=>30,
+ :wrap=>'word', :bd=>1, :setgrid=>true,
+ :highlightthickness=>0, :pady=>2, :padx=>3)
+ xscr = TkScrollbar.new(tf, :bd=>1){assign($code_text)}
+ yscr = TkScrollbar.new(tf, :bd=>1){assign($code_text)}
+ TkGrid($code_text, yscr, :sticky=>'news')
+ #TkGrid(xscr)
+ tf.grid_rowconfigure(0, :weight=>1)
+ tf.grid_columnconfigure(0, :weight=>1)
+
+ bf = TkFrame.new($code_window)
+
+ #b_dis = TkButton.new(bf, :text=>'了解', :default=>:active,
+ b_dis = TkButton.new(bf, :text=>'閉じる', :default=>:active,
+ :command=>proc{
+ $code_window.destroy
+ $code_window = nil
+ },
+ :image=>$image['delete'], :compound=>:left)
+ b_prn = TkButton.new(bf, :text=>'印刷',
+ :command=>proc{printCode($code_text, file)},
+ :image=>$image['print'], :compound=>:left)
+ b_run = TkButton.new(bf, :text=>'再実行',
+ :command=>proc{eval($code_text.get('1.0','end'))},
+ :image=>$image['refresh'], :compound=>:left)
+
+ TkGrid('x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4])
+ bf.grid_columnconfigure(0, :weight=>1)
+
+ TkGrid(tf, :sticky=>'news')
+ TkGrid(bf, :sticky=>'ew')
+ $code_window.grid_columnconfigure(0, :weight=>1)
+ $code_window.grid_rowconfigure(0, :weight=>1)
+
+ $code_window.bind('Return', proc{|win|
+ b_dis.invoke unless win.kind_of?(TkText)
+ }, '%W')
+ $code_window.bindinfo('Return').each{|cmd, arg|
+ $code_window.bind_append('Escape', cmd, arg)
+ }
+ else
+ $code_window.deiconify
+ $code_window.raise
+ end
+
+ $code_window.title("Demo code: #{file}")
+ $code_window.iconname(file)
+ fid = open([$demo_dir, file].join(File::Separator), 'r')
+ $code_text.delete('1.0', 'end')
+ $code_text.insert('1.0', fid.read)
+ TkTextMarkInsert.new($code_text,'1.0')
+ fid.close
+end
+
+if $tk_major_ver < 8
+ alias showCode showCode1
+elsif $tk_major_ver == 8 && $tk_minor_ver < 4
+ alias showCode showCode1
+else # ver >= 8.4
+ alias showCode showCode2
+end
+
+
+# printCode --
+# Prints the source code currently displayed in the See Code dialog.
+# Much thanks to Arjen Markus for this.
+#
+# Arguments:
+# txt - Name of text widget containing code to print
+# file - Name of the original file (implicitly for title)
+
+def printCode(txt, file)
+ code = txt.get('1.0', 'end - 1c')
+ dir = '.'
+ dir = ENV['HOME'] if ENV['HOME']
+ dir = ENV['TMP'] if ENV['TMP']
+ dir = ENV['TEMP'] if ENV['TEMP']
+
+ fname = [dir, 'tkdemo-' + file].join(File::Separator)
+ open(fname, 'w'){|fid| fid.print(code)}
+ begin
+ case Tk::TCL_PLATFORM('platform')
+ when 'unix'
+ msg = `lp -c #{fname}`
+ unless $?.exitstatus == 0
+ Tk.messageBox(:title=>'Print spooling failure',
+ :message=>'エラーが発生しました.' +
+ '印刷に失敗したものと思われます : ' + msg)
+ end
+ when 'windows'
+ begin
+ printTextWin32(fname)
+ rescue => e
+ Tk.messageBox(:title=>'Print spooling failure',
+ :message=>'エラーが発生しました.' +
+ '印刷に失敗したものと思われます : ' +
+ e.message)
+ end
+ when 'macintosh'
+ Tk.messageBox(:title=>'Operation not Implemented',
+ :message=>'印刷機能はまだ実装されていません')
+ else
+ Tk.messageBox(:title=>'Operation not Implemented',
+ :message=>'検出された環境 ' +
+ Tk::TCL_PLATFORM('platform') +
+ ' は未知の環境であるため,' +
+ '印刷機能は実装されていません: ')
+ end
+ ensure
+ File.delete(fname)
+ end
+end
+
+# printTextWin32 --
+# Print a file under Windows
+#
+# Arguments:
+# filename - Name of the file
+#
+def printTextWin32(fname)
+ require 'win32/registry'
+ begin
+ app = Win32::Registry::HKEY_CLASSES_ROOT['.txt']
+ pcmd = nil
+ Win32::Registry::HKEY_CLASSES_ROOT.open("#{app}\\shell\\print"){|reg|
+ pcmd = reg['command']
+ }
+ rescue
+ app = Tk.tk_call('auto_execok', 'notepad.exe')
+ pcmd = "#{app} /p %1"
+ end
+
+ pcmd.gsub!('%1', fname)
+ puts pcmd
+ cmd = Tk.tk_call('auto_execok', 'start') + ' /min ' + pcmd
+
+ msg = `#{cmd}`
+ unless $?.exitstatus == 0
+ fail RuntimeError, msg
+ end
+end
+
# aboutBox
#
# Pops up a message box with an "about" message
#
def aboutBox
Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo',
- 'message'=>"Ruby/Tk ウィジェットデモ Ver.1.3.2-jp\n\n( based on Tk ウィジェットデモ :: Copyright (c) 1996-1997 Sun Microsystems, Inc. )\n\nRunning Version :: Ruby#{VERSION}/Tk#{$tk_version}#{(Tk::JAPANIZED_TK)? 'jp': ''}")
+ 'message'=>"Ruby/Tk ウィジェットデモ Ver.1.4.3-jp\n\n" +
+ "based on demos of Tk8.1 -- 8.5 " +
+ "( Copyright:: " +
+ "(c) 1996-1997 Sun Microsystems, Inc. / " +
+ "(c) 1997-2000 Ajuba Solutions, Inc. / " +
+ "(c) 2001-2003 Donal K. Fellows )\n\n" +
+ "Your Ruby & Tk Version ::\n" +
+ "Ruby#{RUBY_VERSION}(#{RUBY_RELEASE_DATE})[#{RUBY_PLATFORM}] / Tk#{$tk_patchlevel}#{(Tk::JAPANIZED_TK)? '-jp': ''}")
+end
+
+####################################
+# 引数で指定されたデモを起動する
+no_launcher = false
+if ARGV[0] == '-n'
+ ARGV.shift
+ no_launcher = true if ARGV.size > 0
+end
+ARGV.each{|cmd|
+ if cmd =~ /(.*).rb/
+ cmd = $1
+ end
+ eval IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join
+}
+if no_launcher
+ $root.withdraw # hide root window
+ Thread.start{
+ loop do
+ count = 0
+ $root.winfo_children.each{|w|
+ count += 1 if w.kind_of?(TkToplevel)
+ }
+ $root.destroy if count == 0
+ end
+ }
end
################################