1# bitmap.rb 2# 3# This demonstration script creates a toplevel window that displays 4# all of Tk's built-in bitmaps.# 5# bitmap widget demo (called by 'widget') 6# 7 8# bitmapRow -- 9# Create a row of bitmap items in a window. 10# 11# Arguments: 12# w - The parent window that is to contain the row. 13# args - The names of one or more bitmaps, which will be displayed 14# in a new row across the bottom of w along with their 15# names. 16 17def bitmapRow(w,*args) 18 TkFrame.new(w){|row| 19 pack('side'=>'top', 'fill'=>'both') 20 for bitmap in args 21 TkFrame.new(row){|base| 22 pack('side'=>'left', 'fill'=>'both', 'pady'=>'.25c', 'padx'=>'.25c') 23 TkLabel.new(base, 'text'=>bitmap, 'width'=>9).pack('side'=>'bottom') 24 Tk::Label.new(base, 'bitmap'=>bitmap).pack('side'=>'bottom') 25 } 26 end 27 } 28end 29 30# toplevel widget 31if defined?($bitmap_demo) && $bitmap_demo 32 $bitmap_demo.destroy 33 $bitmap_demo = nil 34end 35 36# demo toplevel widget 37$bitmap_demo = TkToplevel.new {|w| 38 title("Bitmap Demonstration") 39 iconname("bitmap") 40 positionWindow(w) 41} 42 43base_frame = TkFrame.new($bitmap_demo).pack(:fill=>:both, :expand=>true) 44 45# label 46TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left', 47 'text'=>"This window displays all of Tk's built-in bitmaps, along with the names you can use for them in Tcl scripts."){ 48 pack('side'=>'top') 49} 50 51# frame 52$bitmap_buttons = TkFrame.new(base_frame) {|frame| 53 TkButton.new(frame) { 54 text 'Dismiss' 55 command proc{ 56 tmppath = $bitmap_demo 57 $bitmap_demo = nil 58 tmppath.destroy 59 } 60 }.pack('side'=>'left', 'expand'=>'yes') 61 62 TkButton.new(frame) { 63 text 'Show Code' 64 command proc{showCode 'bitmap'} 65 }.pack('side'=>'left', 'expand'=>'yes') 66} 67$bitmap_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') 68 69# frame 70TkFrame.new(base_frame){|f| 71 bitmapRow(f,'error','gray25','gray50','hourglass') 72 bitmapRow(f,'info','question','questhead','warning') 73 pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both') 74} 75 76