summaryrefslogtreecommitdiff
path: root/jni/ruby/ext/tk/sample/tkextlib/bwidget/select.rb
blob: 3a1a810e1424024b3d8c662165ff145706e4dcaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#
#  select demo  ---  called from demo.rb
#
unless Object.const_defined?('DemoVar')
  fail RuntimeError, "This is NOT a stand alone script. This script is called from 'demo.rb'. "
end

module DemoSelect
  @@var = TkVariable.new_hash

  def self.create(nb)
    frame = nb.insert('end', 'demoSelect', :text=>'Spin & Combo')

    titf1 = Tk::BWidget::TitleFrame.new(frame, :text=>'SpinBox')
    subf = titf1.get_frame
    spin = Tk::BWidget::SpinBox.new(subf, :range=>[1, 100, 1],
                                    :textvariable=>@@var.ref('spin', 'var'),
                                    :helptext=>'This is the SpinBox')
    ent = Tk::BWidget::LabelEntry.new(subf, :label=>'Linked var',
                                      :labelwidth=>10, :labelanchor=>:w,
                                      :textvariable=>@@var.ref('spin', 'var'),
                                      :editable=>0,
                                      :helptext=>"This is an Entry reflecting\nthe linked var of SpinBox")
    labf = Tk::BWidget::LabelFrame.new(subf, :text=>'Options',
                                       :side=>:top, :anchor=>:w,
                                       :relief=>:sunken, :borderwidth=>1,
                                       :helptext=>'Modify some options of SpinBox')
    subf = labf.get_frame
    chk1 = TkCheckbutton.new(subf, :text=>'Non editable',
                             :variable=>@@var.ref('spin', 'editable'),
                             :onvalue=>false, :offvalue=>true,
                             :command=>proc{
                               spin.editable(@@var['spin', 'editable'])
                             })
    chk2 = TkCheckbutton.new(subf, :text=>'Disabled',
                             :variable=>@@var.ref('spin', 'state'),
                             :onvalue=>'disabled', :offvalue=>'normal',
                             :command=>proc{
                               spin.state(@@var['spin', 'state'])
                             })
    Tk.pack(chk1, chk2, :side=>:left, :anchor=>:w)
    Tk.pack(spin, ent, labf, :pady=>4, :fill=>:x)
    titf1.pack

    titf2 = Tk::BWidget::TitleFrame.new(frame, :text=>'ComboBox')
    subf = titf2.get_frame
    combo = Tk::BWidget::ComboBox.new(subf,
                                      :textvariable=>@@var.ref('combo', 'var'),
                                      :values=>[
                                        'first value', 'second value',
                                        'third value', 'fourth value',
                                        'fifth value'
                                      ],
                                      :helptext=>'This is the ComboBox')
    ent = Tk::BWidget::LabelEntry.new(subf, :label=>'Linked var',
                                      :labelwidth=>10, :labelanchor=>:w,
                                      :textvariable=>@@var.ref('combo', 'var'),
                                      :editable=>0, :helptext=>"This is an Entry reflecting\nthe linked var of ComboBox")
    labf = Tk::BWidget::LabelFrame.new(subf, :text=>'Options', :side=>:top,
                                       :anchor=>:w, :relief=>:sunken,
                                       :borderwidth=>1, :helptext=>'Modify some options of ComboBox')
    subf = labf.get_frame
    chk1 = TkCheckbutton.new(subf, :text=>'Non editable',
                             :variable=>@@var.ref('combo', 'editable'),
                             :onvalue=>false, :offvalue=>true,
                             :command=>proc{
                               combo.editable(@@var['combo', 'editable'])
                             })
    chk2 = TkCheckbutton.new(subf, :text=>'Disabled',
                             :variable=>@@var.ref('combo', 'state'),
                             :onvalue=>'disabled', :offvalue=>'normal',
                             :command=>proc{
                               combo.state(@@var['combo', 'state'])
                             })

    Tk.pack(chk1, chk2, :side=>:left, :anchor=>:w)
    Tk.pack(combo, ent, labf, :pady=>4, :fill=>:x)
    Tk.pack(titf1, titf2, :pady=>4)

    frame
  end
end