1# sayings.rb
2#
3# This demonstration script creates a listbox that can be scrolled
4# both horizontally and vertically.  It displays a collection of
5# well-known sayings.
6#
7# listbox widget demo 'sayings' (called by 'widget')
8#
9
10# toplevel widget
11if defined?($sayings_demo) && $sayings_demo
12  $sayings_demo.destroy
13  $sayings_demo = nil
14end
15
16# demo toplevel widget
17$sayings_demo = TkToplevel.new {|w|
18  title("Listbox Demonstration (well-known sayings)")
19  iconname("sayings")
20  positionWindow(w)
21}
22
23base_frame = TkFrame.new($sayings_demo).pack(:fill=>:both, :expand=>true)
24
25# label
26msg = TkLabel.new(base_frame) {
27  font $font
28  wraplength '4i'
29  justify 'left'
30  text "The listbox below contains a collection of well-known sayings.  You can scan the list using either of the scrollbars or by dragging in the listbox window with button 2 pressed."
31}
32msg.pack('side'=>'top')
33
34# frame
35TkFrame.new(base_frame) {|frame|
36  TkButton.new(frame) {
37    text 'Dismiss'
38    command proc{
39      tmppath = $sayings_demo
40      $sayings_demo = nil
41      tmppath.destroy
42    }
43  }.pack('side'=>'left', 'expand'=>'yes')
44
45  TkButton.new(frame) {
46    text 'Show Code'
47    command proc{showCode 'sayings'}
48  }.pack('side'=>'left', 'expand'=>'yes')
49
50}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
51
52# frame
53sayings_lbox = nil
54TkFrame.new(base_frame, 'borderwidth'=>10) {|w|
55  sv = TkScrollbar.new(w)
56  sh = TkScrollbar.new(w, 'orient'=>'horizontal')
57  sayings_lbox = TkListbox.new(w) {
58    setgrid 1
59    width  20
60    height 10
61    yscrollcommand proc{|first,last| sv.set first,last}
62    xscrollcommand proc{|first,last| sh.set first,last}
63  }
64  sv.command(proc{|*args| sayings_lbox.yview(*args)})
65  sh.command(proc{|*args| sayings_lbox.xview(*args)})
66
67  if $tk_version =~ /^4\.[01]/
68    sv.pack('side'=>'right', 'fill'=>'y')
69    sh.pack('side'=>'bottom', 'fill'=>'x')
70    sayings_lbox.pack('expand'=>'yes', 'fill'=>'y')
71
72  else
73    sayings_lbox.grid('row'=>0, 'column'=>0,
74                      'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
75    sv.grid('row'=>0, 'column'=>1,
76            'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
77    sh.grid('row'=>1, 'column'=>0,
78            'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
79    TkGrid.rowconfigure(w, 0, 'weight'=>1, 'minsize'=>0)
80    TkGrid.columnconfigure(w, 0, 'weight'=>1, 'minsize'=>0)
81  end
82
83}.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'y')
84
85sayings_lbox.insert(0,
86"Waste not, want not",
87"Early to bed and early to rise makes a man healthy, wealthy, and wise",
88"Ask not what your country can do for you, ask what you can do for your country",
89"I shall return",
90"NOT",
91"A picture is worth a thousand words",
92"User interfaces are hard to build",
93"Thou shalt not steal",
94"A penny for your thoughts",
95"Fool me once, shame on you;  fool me twice, shame on me",
96"Every cloud has a silver lining",
97"Where there's smoke there's fire",
98"It takes one to know one",
99"Curiosity killed the cat; but satisfaction brought it back",
100"Take this job and shove it",
101"Up a creek without a paddle",
102"I'm mad as hell and I'm not going to take it any more",
103"An apple a day keeps the doctor away",
104"Don't look a gift horse in the mouth"
105)
106
107