diff options
| author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-02 21:39:23 +0000 |
|---|---|---|
| committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-02 21:39:23 +0000 |
| commit | c6032f06e6fce39e120ee176ce03690b84b8de10 (patch) | |
| tree | 3d13ba78122dd8bdd42e1d92df44c9e880906dc1 /ext/tk/sample/demos-jp | |
| parent | bb4dcac3c3a9efcd7c8004da5a582a87bf335b30 (diff) | |
| download | ruby-c6032f06e6fce39e120ee176ce03690b84b8de10.tar.gz ruby-c6032f06e6fce39e120ee176ce03690b84b8de10.tar.xz ruby-c6032f06e6fce39e120ee176ce03690b84b8de10.zip | |
* add or modify some widget demo scripts
* (bug fix) TkGrid failed to treat RELATIVE PLACEMENT
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4291 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/demos-jp')
| -rw-r--r-- | ext/tk/sample/demos-jp/ixset2 | 368 | ||||
| -rw-r--r-- | ext/tk/sample/demos-jp/menu84.rb | 208 | ||||
| -rw-r--r-- | ext/tk/sample/demos-jp/menubu.rb | 14 | ||||
| -rw-r--r-- | ext/tk/sample/demos-jp/puzzle.rb | 14 | ||||
| -rw-r--r-- | ext/tk/sample/demos-jp/radio2.rb | 106 | ||||
| -rw-r--r-- | ext/tk/sample/demos-jp/text.rb | 28 | ||||
| -rw-r--r-- | ext/tk/sample/demos-jp/widget | 24 |
7 files changed, 746 insertions, 16 deletions
diff --git a/ext/tk/sample/demos-jp/ixset2 b/ext/tk/sample/demos-jp/ixset2 new file mode 100644 index 000000000..8947daa4b --- /dev/null +++ b/ext/tk/sample/demos-jp/ixset2 @@ -0,0 +1,368 @@ +#!/usr/bin/env ruby +# +# ixset -- +# A nice interface to "xset" to change X server settings +# + +require 'tk' + +class Xsettings + # + # Button actions + # + def quit + @root.destroy + end + + def ok + writesettings + quit + end + + def cancel + readsettings + dispsettings + @btn_APPLY.state(:disabled) + @btn_CANCEL.state(:disabled) + end + + # apply is just "writesettings" + def apply + writesettings + @btn_APPLY.state(:disabled) + @btn_CANCEL.state(:disabled) + end + + # + # Read current settings + # + def readsettings + xfd = open("|xset q", 'r') + xfd.readlines.each{|line| + fields = line.chomp.strip.split(/\s+/) + case fields[0] + when "auto" + if fields[1] == 'repeat:' + @kbdrep = fields[2] + @w_kbdrep.set(@kbdrep) + @kbdcli = fields[6] + end + + when "bell" + @bellvol = fields[2] + @bellpit = fields[5] + @belldur = fields[8] + + when "acceleration:" + @mouseacc = fields[1] + @mousethr = fields[3] + + when "prefer" + if fields[2] == 'yes' + @screenbla = 'blank' + else + @screenbla = 'noblank' + end + @w_screenbla.set(@screenbla) + + when "timeout:" + @screentim = fields[1] + @screencyc = fields[3] + + end + } + + xfd.close + end + + # + # Write settings into the X server + # + def writesettings + @bellvol = @w_bellvol.get + @bellpit = @w_bellpit.get + @belldur = @w_belldur.get + + @kbdrep = @w_kbdrep.get + if @kbdrep == 'on' + @kbdcli = @w_kbdcli.get + else + @kbdcli = 'off' + end + + @mouseacc = @w_mouseacc.get + @mousethr = @w_mousethr.get + + @screentim = @w_screentim.get + @screencyc = @w_screencyc.get + @screenbla = @w_screenbla.get + + system("xset \ + b #{@bellvol} #{@bellpit} #{@belldur} \ + c #{@kbdcli} \ + r #{@kbdrep} \ + m #{@mouseacc} #{@mousethr} \ + s #{@screentim} #{@screencyc} \ + s #{@screenbla}") + end + + # + # Sends all settings to the window + # + def dispsettings + @w_bellvol.set(@bellvol) + @w_bellpit.set(@bellpit) + @w_belldur.set(@belldur) + + @w_kbdonoff.set(@w_kbdrep.get) + @w_kbdcli.set(@kbdcli) + + @w_mouseacc.set(@mouseacc) + @w_mousethr.set(@mousethr) + + @w_screenblank.set(@w_screenbla.get) + @w_screenpat.set(@w_screenbla.get) + + @w_screentim.set(@screentim) + @w_screencyc.set(@screencyc) + end + + # + # Create all windows, and pack them + # + class LabelEntry + def initialize(parent, text, length, range=[]) + @frame = TkFrame.new(parent) + TkLabel.new(@frame, 'text'=>text).pack('side'=>'left') + if range.size > 0 + @entry = TkSpinbox.new(@frame, 'width'=>length, 'relief'=>'sunken', + 'from'=>range[0], 'to'=>range[1]) + else + @entry = TkEntry.new(@frame, 'width'=>length, 'relief'=>'sunken') + end + @entry.pack('side'=>'right','expand'=>'y', 'fill'=>'x') + end + def epath + @frame + end + def pack(keys) + @frame.pack(keys) + end + def get + @entry.value + end + def set(value) + @entry.delete(0,'end') + @entry.insert(0, value) + end + end + + def createwindows + win = self + + # + # Buttons + # + btn_frame = TkFrame.new(@root) + buttons = [ + @btn_OK = TkButton.new(btn_frame, 'command'=>proc{win.ok}, + 'default'=>'active', 'text'=>'了解'), + @btn_APPLY = TkButton.new(btn_frame, 'command'=>proc{win.writesettings}, + 'default'=>'normal', 'text'=>'適用', + 'state'=>'disabled'), + @btn_CANCEL = TkButton.new(btn_frame, 'command'=>proc{win.cancel}, + 'default'=>'normal', 'text'=>'取消', + 'state'=>'disabled'), + @btn_QUIT = TkButton.new(btn_frame, 'command'=>proc{win.quit}, + 'default'=>'normal', 'text'=>'中止') + ] + buttons.each{|b| b.pack('side'=>'left', 'expand'=>'yes', 'pady'=>5) } + + @root.bind('Return', proc{@btn_OK.flash; @btn_OK.invoke}) + @root.bind('Escape', proc{@btn_QUIT.flash; @btn_QUIT.invoke}) + @root.bind('1', proc{|w| + unless buttons.index(w) + @btn_APPLY.state(:normal) + @btn_CANCEL.state(:normal) + end + }, '%W') + @root.bind('Key', proc{|w, k| + unless buttons.index(w) + case k + when 'Return', 'Escape', 'Tab', /.*Shift.*/ + # do nothing + else + @btn_APPLY.state(:normal) + @btn_CANCEL.state(:normal) + end + end + }, '%W %K') + + # + # Bell settings + # + bell = TkLabelframe.new(@root, 'text'=>'ベル設定', + 'padx'=>'1.5m', 'pady'=>'1.5m') + @w_bellvol = TkScale.new(bell, 'from'=>0, 'to'=>100, 'length'=>200, + 'tickinterval'=>20, 'orient'=>'horizontal', + 'label'=>"音量 (%)") + + f = TkFrame.new(bell) + @w_bellpit = LabelEntry.new(f, "音程 (Hz)", 6, [25, 20000]) + @w_bellpit.pack('side'=>'left', 'padx'=>5) + @w_belldur = LabelEntry.new(f, "持続時間 (ms)", 6, [1, 10000]) + @w_belldur.pack('side'=>'right', 'padx'=>5) + + @w_bellvol.pack('side'=>'top', 'expand'=>'yes') + f.pack('side'=>'top', 'expand'=>'yes') + + # + # Keyboard settings + # + kbdonoff = nil + kbdcli = nil + kbd = TkLabelframe.new(@root, 'text'=>'キーボードリピート設定', + 'padx'=>'1.5m', 'pady'=>'1.5m') + f = TkFrame.new(kbd) + @w_kbdonoff = TkCheckButton.new(f, 'text'=>'クリック音あり', + 'relief'=>'flat', + 'onvalue'=>'on', 'offvalue'=>'off', + 'variable'=>@w_kbdrep ) { + def self.set(value) + if value == 'on' + self.select + else + self.deselect + end + end + pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x', 'padx'=>[0, '1m']) + } + @w_kbdcli = TkScale.new(f, 'from'=>0, 'to'=>100, 'length'=>200, + 'tickinterval'=>20, 'orient'=>'horizontal', + 'label'=>'クリック音量 (%)') + @w_kbdcli.pack('side'=>'left', 'expand'=>'yes', + 'fill'=>'x', 'padx'=>['1m', 0]) + f.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2, 'fill'=>'x') + + # + # Mouse settings + # + mouse = TkLabelframe.new(@root, 'text'=>'マウス設定', + 'padx'=>'1.5m', 'pady'=>'1.5m') + f = TkFrame.new(mouse) + @w_mouseacc = LabelEntry.new(f, '加速量', 5) + @w_mouseacc.pack('side'=>'left', 'padx'=>[0, '1m']) + @w_mousethr = LabelEntry.new(f, '閾値 (pixels)', 3, [1, 2000]) + @w_mousethr.pack('side'=>'right', 'padx'=>['1m', 0]) + f.pack('side'=>'top', 'expand'=>'yes') + + # + # Screen Saver settings + # + screen = TkLabelframe.new(@root, 'text'=>'スクリーンセーバ設定', + 'padx'=>'1.5m', 'pady'=>'1.5m') + @w_screenblank = TkRadioButton.new(screen, 'text'=>'ブランク表示', + 'relief'=>'flat', 'anchor'=>'w', + 'variable'=>@w_screenbla, + 'value'=>'blank') { + def self.set(value) + if value == 'blank' + self.select + else + self.deselect + end + end + } + + @w_screenpat = TkRadioButton.new(screen, 'text'=>'パターン表示', + 'relief'=>'flat', 'anchor'=>'w', + 'variable'=>@w_screenbla, + 'value'=>'noblank') { + def self.set(value) + if value != 'blank' + self.select + else + self.deselect + end + end + } + + @w_screentim = LabelEntry.new(screen, 'タイムアウト (s)', 5, [1, 100000]) + @w_screencyc = LabelEntry.new(screen, '周期 (s)', 5, [1, 100000]) + + Tk.grid(@w_screenblank, @w_screentim, 'sticky'=>'e') + Tk.grid(@w_screenpat, @w_screencyc, 'sticky'=>'e') + TkGrid.configure(@w_screenblank, @w_screenpat, 'sticky'=>'ew') + + # + # Main window + # + param = { + 'side'=>'top', 'fill'=>'both', 'expand'=>'yes', + 'padx'=>'1m', 'pady'=>'1m' + } + btn_frame.pack('side'=>'top', 'fill'=>'both') + bell.pack(param) + kbd.pack(param) + mouse.pack(param) + screen.pack(param) + + # + # Let the user resize our window + # + @root.minsize(10,10) + end + + def initialize(title) + @root = TkRoot.new('title'=>title) + + @kbdrep = 'on' + @w_kbdrep = TkVariable.new(@kbdrep) + def @w_kbdrep.get + self.value + end + def @w_kbdrep.set(val) + self.value=val + end + + @kbdcli = 0 + + @bellvol = 100 + @bellpit = 440 + @belldur = 100 + + @mouseacc = "3/1" + @mousethr = 4 + + @screenbla = "blank" + @w_screenbla = TkVariable.new(@screenbla) + def @w_screenbla.get + self.value + end + def @w_screenbla.set(val) + self.value=val + end + + @screentim = 600 + @screencyc = 600 + + # + # Listen what "xset" tells us... + # + readsettings + + # + # Create all windows + # + createwindows + + # + # Write xset parameters + # + dispsettings + end +end + +Xsettings.new(File.basename($0,'.rb')) + +Tk.mainloop diff --git a/ext/tk/sample/demos-jp/menu84.rb b/ext/tk/sample/demos-jp/menu84.rb new file mode 100644 index 000000000..ea5fdf648 --- /dev/null +++ b/ext/tk/sample/demos-jp/menu84.rb @@ -0,0 +1,208 @@ +# +# menus widget demo (called by 'widget') +# + +# toplevel widget +if defined?($menu84_demo) && $menu84_demo + $menu84_demo.destroy + $menu84_demo = nil +end + +# demo toplevel widget +$menu84_demo = TkToplevel.new {|w| + title("File Selection Dialogs") + iconname("menu84") + positionWindow(w) +} + +begin + windowingsystem = Tk.windowingsystem() +rescue + windowingsystem = "" +end + +# label +TkLabel.new($menu84_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { + if $tk_platform['platform'] == 'macintosh' || + windowingsystem == "classic" || windowingsystem == "aqua" + text("このウィンドウにはカスケードメニューを持つメニューバーが付けられています。Command+x ('x'はコマンドキーシンボルに続けて表示されている文字です) とタイプすることによっても項目の機能を呼び出すことができます。最後のメニューは、マウスでウィンドウの外にドラッグすることによって、独立したパレットとなるように切り放すことが可能です。") + else + text("このウィンドウにはカスケードメニューを持つメニューバーが付けられています。Alt+x ('x'はメニュー上で下線が引かれた文字です) とタイプすることによってもメニューを呼び出すことができます。矢印キーを使って、メニュー間を移動することも可能です。メニューが表示されている時には、現在位置の項目をスペースキーで選択したり、下線が引かれた文字を入力することでその項目を選択したりすることができます。もし項目にアクセラレータの指定がなされていたならば、その指定されたキー入力を行うことで、メニューを表示させることなく直接その項目の機能を呼び出せます。最後のメニューは、メニューの最初の項目を選択することによって、独立したパレットとなるように切り放すことが可能です。") + end +}.pack('side'=>'top') + + +menustatus = TkVariable.new(" ") +TkFrame.new($menu84_demo) {|frame| + TkLabel.new(frame, 'textvariable'=>menustatus, 'relief'=>'sunken', + 'bd'=>1, 'font'=>['Helvetica', '10'], + 'anchor'=>'w').pack('side'=>'left', 'padx'=>2, + 'expand'=>true, 'fill'=>'both') + pack('side'=>'bottom', 'fill'=>'x', 'pady'=>2) +} + + +# frame +TkFrame.new($menu84_demo) {|frame| + TkButton.new(frame) { + text '了解' + command proc{ + tmppath = $menu84_demo + $menu84_demo = nil + tmppath.destroy + } + }.pack('side'=>'left', 'expand'=>'yes') + + TkButton.new(frame) { + text 'コード参照' + command proc{showCode 'menu84'} + }.pack('side'=>'left', 'expand'=>'yes') +}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') + + +# create menu frame +$menu84_frame = TkMenu.new($menu84_demo, 'tearoff'=>false) + +# menu +TkMenu.new($menu84_frame, 'tearoff'=>false) {|m| + $menu84_frame.add('cascade', 'label'=>'File', 'menu'=>m, 'underline'=>0) + add('command', 'label'=>'Open...', 'command'=>proc{fail 'これは単なるデモですから、"Open..." 項目の機能は特に定義されてはいません。'}) + add('command', 'label'=>'New', 'command'=>proc{fail 'これは単なるデモですから、"New" 項目の機能は特に定義されてはいません。'}) + add('command', 'label'=>'Save', 'command'=>proc{fail 'これは単なるでもですから、"Save" 項目の機能は特に定義されてはいません。'}) + add('command', 'label'=>'Save As...', 'command'=>proc{fail 'これは単なるでもですから、"Save As..." 項目の機能は特に定義されてはいません。'}) + add('separator') + add('command', 'label'=>'Print Setup...', 'command'=>proc{fail 'これは単なるデモですから、"Print Setup..." 項目の機能は特に定義されてはいません。'}) + add('command', 'label'=>'Print...', 'command'=>proc{fail 'これは単なるデモですから、"Print..." 項目の機能は特に定義されてはいません。'}) + add('separator') + add('command', 'label'=>'Dismiss Menus Demo', 'command'=>proc{$menu84_demo.destroy}) +} + +if $tk_platform['platform'] == 'macintosh' || + windowingsystem = "classic" || windowingsystem = "aqua" + modifier = 'Command' +elsif $tk_platform['platform'] == 'windows' + modifier = 'Control' +else + modifier = 'Meta' +end + +TkMenu.new($menu84_frame, 'tearoff'=>false) {|m| + $menu84_frame.add('cascade', 'label'=>'Basic', 'menu'=>m, 'underline'=>0) + add('command', 'label'=>'Long entry that does nothing') + ['A','B','C','D','E','F','G'].each{|c| + add('command', 'label'=>"Print letter \"#{c}\"", + 'underline'=>14, 'accelerator'=>"Meta+#{c}", + 'command'=>proc{print c,"\n"}, 'accelerator'=>"#{modifier}+#{c}") + $menu84_demo.bind("#{modifier}-#{c.downcase}", proc{print c,"\n"}) + } +} + +TkMenu.new($menu84_frame, 'tearoff'=>false) {|m| + $menu84_frame.add('cascade', 'label'=>'Cascades', 'menu'=>m, 'underline'=>0) + add('command', 'label'=>'Print hello', + 'command'=>proc{print "Hello\n"}, + 'accelerator'=>"#{modifier}+H", 'underline'=>6) + $menu84_demo.bind("#{modifier}-h", proc{print "Hello\n"}) + add('command', 'label'=>'Print goodbye', + 'command'=>proc{print "Goodbye\n"}, + 'accelerator'=>"#{modifier}+G", 'underline'=>6) + $menu84_demo.bind("#{modifier}-g", proc{print "Goodbye\n"}) + + TkMenu.new(m, 'tearoff'=>false) {|cascade_check| + m.add('cascade', 'label'=>'Check button', + 'menu'=>cascade_check, 'underline'=>0) + oil = TkVariable.new(0) + add('check', 'label'=>'オイル検査', 'variable'=>oil) + trans = TkVariable.new(0) + add('check', 'label'=>'トランスミッション検査', 'variable'=>trans) + brakes = TkVariable.new(0) + add('check', 'label'=>'ブレーキ検査', 'variable'=>brakes) + lights = TkVariable.new(0) + add('check', 'label'=>'ライト検査', 'variable'=>lights) + add('separator') + add('command', 'label'=>'Show current values', + 'command'=>proc{showVars($menu84_demo, + ['オイル', oil], + ['トランスミッション', trans], + ['ブレーキ', brakes], + ['ライト', lights])} ) + invoke 1 + invoke 3 + } + + TkMenu.new(m, 'tearoff'=>false) {|cascade_radio| + m.add('cascade', 'label'=>'Radio buttons', + 'menu'=>cascade_radio, 'underline'=>0) + pointSize = TkVariable.new + add('radio', 'label'=>'10 point', 'variable'=>pointSize, 'value'=>10) + add('radio', 'label'=>'14 point', 'variable'=>pointSize, 'value'=>14) + add('radio', 'label'=>'18 point', 'variable'=>pointSize, 'value'=>18) + add('radio', 'label'=>'24 point', 'variable'=>pointSize, 'value'=>24) + add('radio', 'label'=>'32 point', 'variable'=>pointSize, 'value'=>32) + add('separator') + style = TkVariable.new + add('radio', 'label'=>'Roman', 'variable'=>style, 'value'=>'roman') + add('radio', 'label'=>'Bold', 'variable'=>style, 'value'=>'bold') + add('radio', 'label'=>'Italic', 'variable'=>style, 'value'=>'italic') + add('separator') + add('command', 'label'=>'現在値の表示', + 'command'=>proc{showVars($menu84_demo, + ['pointSize', pointSize], + ['style', style])} ) + invoke 1 + invoke 7 + } +} + +TkMenu.new($menu84_frame, 'tearoff'=>false) {|m| + $menu84_frame.add('cascade', 'label'=>'Icons', 'menu'=>m, 'underline'=>0) + add('command', 'hidemargin'=>1, + 'bitmap'=>'@'+[$demo_dir,'images','pattern.bmp'].join(File::Separator), + 'command'=>proc{TkDialog.new('title'=>'Bitmap Menu Entry', + 'text'=>'あなたが選択したメニュー項目は、文字列の代わりにビットマップイメージで項目を表示したものです。それ以外の点では、ほかのメニュー項目との間で特に違いがあるわけではありません。', + 'bitmap'=>'', 'default'=>0, + 'buttons'=>'閉じる')} ) + ['info', 'questhead', 'error'].each{|icon| + add('command', 'bitmap'=>icon, 'hidemargin'=>1, + 'command'=>proc{print "You invoked the #{icon} bitmap\n"}) + } + + entryconfigure(2, :columnbreak=>true) +} + +TkMenu.new($menu84_frame, 'tearoff'=>false) {|m| + $menu84_frame.add('cascade', 'label'=>'More', 'menu'=>m, 'underline'=>0) + [ 'An entry','Another entry','Does nothing','Does almost nothing', + 'Make life meaningful' ].each{|i| + add('command', 'label'=>i, + 'command'=>proc{print "You invoked \"#{i}\"\n"}) + } + + m.entryconfigure('Does almost nothing', + 'bitmap'=>'questhead', 'compound'=>'left', + 'command'=>proc{ + TkDialog.new('title'=>'Compound Menu Entry', + 'message'=>'あなたが選択したメニュー項目は、ビットマップイメージと文字列とを同時に一つの項目に表示するようにしたものです。それ以外の点では、ほかのメニュー項目との間で特に違いがあるわけではありません。', + 'buttons'=>['了解'], 'bitmap'=>'') + }) +} + +TkMenu.new($menu84_frame) {|m| + $menu84_frame.add('cascade', 'label'=>'Colors', 'menu'=>m, 'underline'=>0) + ['red', 'orange', 'yellow', 'green', 'blue'].each{|c| + add('command', 'label'=>c, 'background'=>c, + 'command'=>proc{print "You invoked \"#{c}\"\n"}) + } +} + +$menu84_demo.menu($menu84_frame) + +TkMenu.bind('<MenuSelect>', proc{|w| + begin + label = w.entrycget('active', 'label') + rescue + label = " " + end + menustatus.value = label + Tk.update(true) + }, '%W') diff --git a/ext/tk/sample/demos-jp/menubu.rb b/ext/tk/sample/demos-jp/menubu.rb index 90056e02c..8b4d7980d 100644 --- a/ext/tk/sample/demos-jp/menubu.rb +++ b/ext/tk/sample/demos-jp/menubu.rb @@ -193,8 +193,18 @@ TkFrame.new(center) {|f| 'White','Brown','DarkSeaGreen','DarkViolet'] colorMenuButton = TkMenubutton.new(f) m = optionMenu(colorMenuButton, paletteColor, *colors) - topBorderColor = 'gray50' - bottomBorderColor = 'gray75' + begin + windowingsystem = Tk.windowingsystem() + rescue + windowingsystem = "" + end + if windowingsystem == "classic" || windowingsystem == "aqua" + topBorderColor = 'Black' + bottomBorderColor = 'Black' + else + topBorderColor = 'gray50' + bottomBorderColor = 'gray75' + end for i in 0..15 image = TkPhotoImage.new('height'=>16, 'width'=>16) image.put(topBorderColor, 0, 0, 16, 1) diff --git a/ext/tk/sample/demos-jp/puzzle.rb b/ext/tk/sample/demos-jp/puzzle.rb index 7e7aafac2..24c48693a 100644 --- a/ext/tk/sample/demos-jp/puzzle.rb +++ b/ext/tk/sample/demos-jp/puzzle.rb @@ -47,10 +47,20 @@ TkFrame.new($puzzle_demo) {|frame| # Special trick: scrollbar widget を生成してその trough color を用いることで # 空白部分のための暗色を選択し,設定する # +begin + if Tk.windowingsystem() == 'aqua' + frameSize = 160 + else + frameSize = 120 + end +rescue + frameSize = 120 +end + s = TkScrollbar.new($puzzle_demo) base = TkFrame.new($puzzle_demo) { - width 120 - height 120 + width frameSize + height frameSize borderwidth 2 relief 'sunken' bg s['troughcolor'] diff --git a/ext/tk/sample/demos-jp/radio2.rb b/ext/tk/sample/demos-jp/radio2.rb new file mode 100644 index 000000000..62425af90 --- /dev/null +++ b/ext/tk/sample/demos-jp/radio2.rb @@ -0,0 +1,106 @@ +# radio.rb +# +# This demonstration script creates a toplevel window containing +# several radiobutton widgets. +# +# radiobutton widget demo (called by 'widget') +# + +# toplevel widget +if defined?($radio2_demo) && $radio2_demo + $radio2_demo.destroy + $radio2_demo = nil +end + +# demo toplevel widget +$radio2_demo = TkToplevel.new {|w| + title("Radiobutton Demonstration") + iconname("radio") + positionWindow(w) +} + +# label +msg = TkLabel.new($radio2_demo) { + font $font + wraplength '5i' + justify 'left' + text "下には2つのラジオボタングループが表示されています。ボタンをクリックすると、そのボタンだけがそのグループの中で選択されます。各グループに対してそのグループの中のどのボタンが選択されているかを示す変数が割り当てられています。現在の変数の値を見るには「変数参照」ボタンをクリックしてください。" +} +msg.pack('side'=>'top') + +# +size = TkVariable.new +color = TkVariable.new +align = TkVariable.new + +# frame +TkFrame.new($radio2_demo) {|frame| + TkButton.new(frame) { + text '了解' + command proc{ + tmppath = $radio2_demo + $radio2_demo = nil + $showVarsWin[tmppath.path] = nil + tmppath.destroy + } + }.pack('side'=>'left', 'expand'=>'yes') + + TkButton.new(frame) { + text 'コード参照' + command proc{showCode 'radio'} + }.pack('side'=>'left', 'expand'=>'yes') + + TkButton.new(frame) { + text '変数参照' + command proc{ + showVars($radio2_demo, + ['size', size], ['color', color], ['compound', align]) + } + }.pack('side'=>'left', 'expand'=>'yes') +}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') + +# frame +f_left = TkLabelFrame.new($radio2_demo, 'text'=>'文字サイズ', + 'pady'=>2, 'padx'=>2) +f_mid = TkLabelFrame.new($radio2_demo, 'text'=>'色', + 'pady'=>2, 'padx'=>2) +f_right = TkLabelFrame.new($radio2_demo, 'text'=>'ビットマップ配置', + 'pady'=>2, 'padx'=>2) +f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') +f_mid.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') +f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') + +# radiobutton +[10, 12, 18, 24].each {|sz| + TkRadioButton.new(f_left) { + text "ポイントサイズ #{sz}" + variable size + relief 'flat' + value sz + }.pack('side'=>'top', 'pady'=>2, 'anchor'=>'w', 'fill'=>'x') +} + +['赤', '緑', '青', '黄', '橙', '紫'].each {|col| + TkRadioButton.new(f_mid) { + text col + variable color + relief 'flat' + value col.downcase + anchor 'w' + }.pack('side'=>'top', 'pady'=>2, 'fill'=>'x') +} + +label = TkLabel.new(f_right, 'text'=>'ラベル', 'bitmap'=>'questhead', + 'compound'=>'left') +label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top') +label.height(TkWinfo.reqheight(label)) +abtn = ['Top', 'Left', 'Right', 'Bottom'].collect{|a| + lower = a.downcase + TkRadioButton.new(f_right, 'text'=>a, 'variable'=>align, 'relief'=>'flat', + 'value'=>lower, 'indicatoron'=>0, 'width'=>7, + 'command'=>proc{label.compound(align.value)}) +} + +Tk.grid('x', abtn[0]) +Tk.grid(abtn[1], label, abtn[2]) +Tk.grid('x', abtn[3]) diff --git a/ext/tk/sample/demos-jp/text.rb b/ext/tk/sample/demos-jp/text.rb index a8232088a..179589d82 100644 --- a/ext/tk/sample/demos-jp/text.rb +++ b/ext/tk/sample/demos-jp/text.rb @@ -15,6 +15,13 @@ $text_demo = TkToplevel.new {|w| positionWindow(w) } +# version check +if ((Tk::TK_VERSION.split('.').collect{|n| n.to_i} <=> [8,4]) < 0) + undo_support = false +else + undo_support = true +end + # frame 生成 TkFrame.new($text_demo) {|frame| TkButton.new(frame) { @@ -47,7 +54,7 @@ TkText.new($text_demo){|t| pack('expand'=>'yes', 'fill'=>'both') # テキスト挿入 - insert('0.0', %q| + insert('0.0', <<EOT) このウィンドウはテキスト widget です。1行またはそれ以上のテキストを表 示・編集することができます。以下はテキスト widget でできる操作について まとめたものです。 @@ -82,12 +89,27 @@ TkText.new($text_demo){|t| カーソルの右側の文字を削除します。Meta-バックスペースは挿入カーソルの 右側の単語を削除し、Meta-D は挿入カーソルの左側の単語を削除します。 コントロール-K は挿入カーソルから行末までを削除し、その位置に改行 -しかなかった場合は、改行を削除します。 +しかなかった場合は、改行を削除します。#{ + if undo_support + undo_text = "Control-z は最後に行った変更の取り消し(undo)を行い、" + case $tk_platform['platform'] + when "unix", "macintosh" + undo_text << "Control-Shift-z" + else # 'windows' + undo_text << "Control-y" + end + undo_text << "はundoした変更の再適用(redo)を行います。" + else + "" + end +} + 8. ウィンドウのリサイズ。この widget は "setGrid" オプションをオンにし てありますので、ウィンドウをリサイズする時には高さと幅は常に文字高と文 字幅の整数倍になります。また、ウィンドウを狭くした場合には長い行が自動 -的に折り返され、常に全ての内容が見えるようになっています。|) +的に折り返され、常に全ての内容が見えるようになっています。 +EOT set_insert('0.0') } diff --git a/ext/tk/sample/demos-jp/widget b/ext/tk/sample/demos-jp/widget index b13bd0573..6c9bf2aa7 100644 --- a/ext/tk/sample/demos-jp/widget +++ b/ext/tk/sample/demos-jp/widget @@ -211,19 +211,22 @@ txt.insert('end', " \n ", tag_demospace) txt.insert('end', "4. ラジオボタン (任意の一つを選択可能)\n", tag_demo, "demo-radio") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "5. ボタンで作られた15-パズルゲーム\n", +txt.insert('end', "5. ラジオボタン (機能に対応したバージョンのTkが必要)\n", + tag_demo, "demo-radio2") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "6. ボタンで作られた15-パズルゲーム\n", tag_demo, "demo-puzzle") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "6. ビットマップを使用したアイコンボタン\n", +txt.insert('end', "7. ビットマップを使用したアイコンボタン\n", tag_demo, "demo-icon") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "7. 画像を表示する二つのラベル\n", +txt.insert('end', "8. 画像を表示する二つのラベル\n", tag_demo, "demo-image1") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "8. 画像を見るための簡単なユーザインターフェース\n", +txt.insert('end', "9. 画像を見るための簡単なユーザインターフェース\n", tag_demo, "demo-image2") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "9. ラベル付きフレーム (Tkに実装されている場合に限る)\n", +txt.insert('end', "10. ラベル付きフレーム (機能に対応したバージョンのTkが必要)\n", tag_demo, "demo-labelframe") txt.insert('end', " \n ", tag_demospace) @@ -247,7 +250,7 @@ txt.insert('end', "1. スクロールバーなし\n", tag_demo, "demo-entry1") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "2. スクロールバーあり\n", tag_demo, "demo-entry2") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "3. スピンボックス (Tkに実装されている場合に限る)\n", +txt.insert('end', "3. スピンボックス (機能に対応したバージョンのTkが必要)\n", tag_demo, "demo-spin") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "4. 簡単なフォーム\n", tag_demo, "demo-form") @@ -302,10 +305,10 @@ txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") txt.insert('end', "ペインドウィンドウ\n", tag_kanji_title) txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "1. 水平方向 (Tkに実装されている場合に限る)\n", +txt.insert('end', "1. 水平方向 (機能に対応したバージョンのTkが必要)\n", tag_demo.id, "demo-paned1") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "2. 垂直方向 (Tkに実装されている場合に限る)\n", +txt.insert('end', "2. 垂直方向 (機能に対応したバージョンのTkが必要)\n", tag_demo.id, "demo-paned2") txt.insert('end', " \n ", tag_demospace) @@ -319,7 +322,10 @@ txt.insert('end', " \n ", tag_demospace) txt.insert('end', "2. メニューとカスケードを含んだウィンドウ (Tk8.x 専用)\n", tag_demo, "demo-menu8x") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "3. メニューボタン (Tk8.x 専用)\n", +txt.insert('end', "3. 〃 (機能に対応したバージョンのTkが必要)\n", + tag_demo, "demo-menu84") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. メニューボタン (Tk8.x 専用)\n", tag_demo, "demo-menubu") txt.insert('end', " \n ", tag_demospace) |
