1# -*- coding: utf-8 -*- 2# 3# listbox widget demo 'sayings' (called by 'widget') 4# 5 6# toplevel widget が存在すれば削除する 7if defined?($sayings_demo) && $sayings_demo 8 $sayings_demo.destroy 9 $sayings_demo = nil 10end 11 12# demo 用の toplevel widget を生成 13$sayings_demo = TkToplevel.new {|w| 14 title("Listbox Demonstration (well-known sayings)") 15 iconname("sayings") 16 positionWindow(w) 17} 18 19base_frame = TkFrame.new($sayings_demo).pack(:fill=>:both, :expand=>true) 20 21# label 生成 22msg = TkLabel.new(base_frame) { 23 font $font 24 wraplength '4i' 25 justify 'left' 26 text "下のリストボックスにはいろいろな格言が入っています。リストをスクロールさせるのはスクロールバーでもできますし、リストボックスの中でマウスのボタン2(中ボタン)を押したままドラッグしてもできます。" 27} 28msg.pack('side'=>'top') 29 30# frame 生成 31TkFrame.new(base_frame) {|frame| 32 TkButton.new(frame) { 33 #text '了解' 34 text '閉じる' 35 command proc{ 36 tmppath = $sayings_demo 37 $sayings_demo = nil 38 tmppath.destroy 39 } 40 }.pack('side'=>'left', 'expand'=>'yes') 41 42 TkButton.new(frame) { 43 text 'コード参照' 44 command proc{showCode 'sayings'} 45 }.pack('side'=>'left', 'expand'=>'yes') 46 47}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') 48 49# frame 生成 50sayings_lbox = nil 51TkFrame.new(base_frame, 'borderwidth'=>10) {|w| 52 sv = TkScrollbar.new(w) 53 sh = TkScrollbar.new(w, 'orient'=>'horizontal') 54 sayings_lbox = TkListbox.new(w) { 55 setgrid 1 56 width 20 57 height 10 58 yscrollcommand proc{|first,last| sv.set first,last} 59 xscrollcommand proc{|first,last| sh.set first,last} 60 } 61 sv.command(proc{|*args| sayings_lbox.yview(*args)}) 62 sh.command(proc{|*args| sayings_lbox.xview(*args)}) 63 64 if $tk_version =~ /^4\.[01]/ 65 sv.pack('side'=>'right', 'fill'=>'y') 66 sh.pack('side'=>'bottom', 'fill'=>'x') 67 sayings_lbox.pack('expand'=>'yes', 'fill'=>'y') 68 69 else 70 sayings_lbox.grid('row'=>0, 'column'=>0, 71 'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news') 72 sv.grid('row'=>0, 'column'=>1, 73 'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news') 74 sh.grid('row'=>1, 'column'=>0, 75 'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news') 76 TkGrid.rowconfigure(w, 0, 'weight'=>1, 'minsize'=>0) 77 TkGrid.columnconfigure(w, 0, 'weight'=>1, 'minsize'=>0) 78 end 79 80}.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'y') 81 82sayings_lbox.insert(0, 83"Waste not, want not", 84"Early to bed and early to rise makes a man healthy, wealthy, and wise", 85"Ask not what your country can do for you, ask what you can do for your country", 86"I shall return", 87"NOT", 88"A picture is worth a thousand words", 89"User interfaces are hard to build", 90"Thou shalt not steal", 91"A penny for your thoughts", 92"Fool me once, shame on you; fool me twice, shame on me", 93"Every cloud has a silver lining", 94"Where there's smoke there's fire", 95"It takes one to know one", 96"Curiosity killed the cat", 97"Take this job and shove it", 98"Up a creek without a paddle", 99"I'm mad as hell and I'm not going to take it any more", 100"An apple a day keeps the doctor away", 101"Don't look a gift horse in the mouth" 102) 103 104