1# -*- coding: utf-8 -*- 2# 3# text widget peering demo (called by 'widget') 4# 5# based on Tcl/Tk8.5.0 widget demos 6 7if defined?($textpeer_demo) && $textpeer_demo 8 $textpeer_demo.destroy 9 $textpeer_demo = nil 10end 11 12# demo toplevel widget 13$textpeer_demo = TkToplevel.new {|w| 14 title("Text Wdget Peering Demonstration") 15 iconname("textpeer") 16 positionWindow(w) 17} 18 19base_frame = TkFrame.new($textpeer_demo).pack(:fill=>:both, :expand=>true) 20 21count = [0] 22 23## Define a widget that we peer from; it won't ever actually be shown though 24first = TkText.new(base_frame, :widgetname=>"text#{count[0] += 1}") 25first.insert :end,"このデモは一つの組を成したテキストウィジェットを示します。" 26first.insert :end,"それらのテキストウィジェットは対等(ピア;peer)の関係に" 27first.insert :end,"なっています。" 28first.insert :end,"それらは、基盤となるデータモデルは共通のものを持ちますが、" 29first.insert :end,"画面表示位置、編集位置、選択範囲(selection)については" 30first.insert :end,"独立に持つことができます。" 31first.insert :end,"各テキストウィジェットの脇にある" 32first.insert :end,"「ピア(peer)の作成」ボタンを使えば、" 33first.insert :end,"新たなピアを追加することが可能です。" 34first.insert :end,"また「ピア(peer)の消去」ボタンを使えば、" 35first.insert :end,"特定のピアウィジェットを消去することもできます。" 36 37Tk.update_idletasks ## for 'first' widget 38 39## Procedures to make and kill clones; most of this is just so that the demo 40## looks nice... 41def makeClone(count, win, txt) 42 cnt = (count[0] += 1) 43 peer = TkText::Peer.new(txt, win, :widgetname=>"text#{cnt}") 44 sbar = TkScrollbar.new(win, :widgetname=>"sb#{cnt}") 45 peer.yscrollbar sbar 46 b1 = TkButton.new(win, :widgetname=>"clone#{cnt}", 47 :text=>'ピア(peer)の作成', 48 :command=>proc{makeClone(count, win, peer)}) 49 b2 = TkButton.new(win, :widgetname=>"kill#{cnt}", 50 :text=>'ピア(peer)の消去', 51 :command=>proc{killClone(win, cnt)}) 52 row = cnt * 2 53 TkGrid.configure(peer, sbar, b1, :sticky=>'nsew', :row=>row) 54 TkGrid.configure('^', '^', b2, :sticky=>'nsew', :row=>(row+=1)) 55 TkGrid.configure(b1, b2, :sticky=>'new') 56 TkGrid.rowconfigure(win, b2, :weight=>1) 57end 58 59def killClone(win, cnt) 60 Tk.destroy("#{win.path}.text#{cnt}", "#{win.path}.sb#{cnt}", 61 "#{win.path}.clone#{cnt}", "#{win.path}.kill#{cnt}") 62end 63 64## Now set up the GUI 65makeClone(count, base_frame, first) 66makeClone(count, base_frame, first) 67first.destroy 68 69## See Code / Dismiss buttons 70TkFrame.new(base_frame){|f| 71 TkButton.new(f, :text=>'閉じる', :width=>15, :command=>proc{ 72 $textpeer_demo.destroy 73 $textpeer_demo = nil 74 }).pack(:side=>:left, :expand=>true) 75 76 TkButton.new(f, :text=>'コード参照', :width=>15, :command=>proc{ 77 showCode 'textpeer' 78 }).pack(:side=>:left, :expand=>true) 79 80 TkGrid.configure(f, '-', '-', :sticky=>'ew', :row=>5000) 81} 82TkGrid.columnconfigure(base_frame, 0, :weight=>1) 83