1# -*- coding: utf-8 -*-
2#
3# bitmap widget demo (called by 'widget')
4#
5
6# bitmapRow --
7# Create a row of bitmap items in a window.
8#
9# Arguments:
10# w -           The parent window that is to contain the row.
11# args -        The names of one or more bitmaps, which will be displayed
12#               in a new row across the bottom of w along with their
13#               names.
14
15def bitmapRow(w,*args)
16  TkFrame.new(w){|row|
17    pack('side'=>'top', 'fill'=>'both')
18    for bitmap in args
19      TkFrame.new(row){|base|
20        pack('side'=>'left', 'fill'=>'both', 'pady'=>'.25c', 'padx'=>'.25c')
21        TkLabel.new(base, 'text'=>bitmap, 'width'=>9).pack('side'=>'bottom')
22        Tk::Label.new(base, 'bitmap'=>bitmap).pack('side'=>'bottom')
23      }
24    end
25  }
26end
27
28# toplevel widget が存在すれば削除する
29if defined?($bitmap_demo) && $bitmap_demo
30  $bitmap_demo.destroy
31  $bitmap_demo = nil
32end
33
34# demo 用の toplevel widget を生成
35$bitmap_demo = TkToplevel.new {|w|
36  title("Bitmap Demonstration")
37  iconname("bitmap")
38  positionWindow(w)
39}
40
41base_frame = TkFrame.new($bitmap_demo).pack(:fill=>:both, :expand=>true)
42
43# label 生成
44TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
45            'text'=>"このウィンドウには、Tk に組み込まれたすべてのビットマップが、それらの名前と共に表示されています。Tcl のスクリプト中では、それぞれの名前を用いて参照します。"){
46  pack('side'=>'top')
47}
48
49# frame 生成
50$bitmap_buttons = TkFrame.new(base_frame) {|frame|
51  TkButton.new(frame) {
52    #text '了解'
53    text '閉じる'
54    command proc{
55      tmppath = $bitmap_demo
56      $bitmap_demo = nil
57      tmppath.destroy
58    }
59  }.pack('side'=>'left', 'expand'=>'yes')
60
61  TkButton.new(frame) {
62    text 'コード参照'
63    command proc{showCode 'bitmap'}
64  }.pack('side'=>'left', 'expand'=>'yes')
65}
66$bitmap_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
67
68# frame 設定
69TkFrame.new(base_frame){|f|
70  bitmapRow(f,'error','gray25','gray50','hourglass')
71  bitmapRow(f,'info','question','questhead','warning')
72  pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both')
73}
74
75