1# -*- coding: utf-8 -*-
2#
3# listbox widget demo 'states' (called by 'widget')
4#
5
6# toplevel widget が存在すれば削除する
7if defined?($states_demo) && $states_demo
8  $states_demo.destroy
9  $states_demo = nil
10end
11
12# demo 用の toplevel widget を生成
13$states_demo = TkToplevel.new {|w|
14  title("Listbox Demonstration (states)")
15  iconname("states")
16  positionWindow(w)
17}
18
19base_frame = TkFrame.new($states_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 = $states_demo
37      $states_demo = nil
38      tmppath.destroy
39    }
40  }.pack('side'=>'left', 'expand'=>'yes')
41
42  TkButton.new(frame) {
43    text 'コード参照'
44    command proc{showCode 'states'}
45  }.pack('side'=>'left', 'expand'=>'yes')
46
47}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
48
49# frame 生成
50states_lbox = nil
51TkFrame.new(base_frame, 'borderwidth'=>'.5c') {|w|
52  s = TkScrollbar.new(w)
53  states_lbox = TkListbox.new(w) {
54    setgrid 1
55    height 12
56    yscrollcommand proc{|first,last| s.set first,last}
57  }
58  s.command(proc{|*args| states_lbox.yview(*args)})
59  s.pack('side'=>'right', 'fill'=>'y')
60  states_lbox.pack('side'=>'left', 'expand'=>1, 'fill'=>'both')
61}.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'y')
62
63ins_data = [
64  '愛知','青森','秋田','石川','茨城','岩手','愛媛',
65  '大分','大阪','岡山','沖縄','香川','鹿児島','神奈川',
66  '岐阜','京都','熊本','群馬','高知','埼玉','佐賀',
67  '滋賀','静岡','島根','千葉','東京','徳島','栃木',
68  '鳥取','富山','長崎','長野','奈良','新潟','兵庫',
69  '広島','福井','福岡','福島','北海道','三重','宮城',
70  '宮崎','山形','山口','山梨','和歌山'
71]
72
73states_lbox.insert(0, *ins_data)
74
75