~ubuntu-branches/ubuntu/intrepid/ruby1.8/intrepid-updates

« back to all changes in this revision

Viewing changes to ext/tk/sample/optobj_sample.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
#
 
3
#  sample script of Tk::OptionObj
 
4
#
 
5
require "tk"
 
6
 
 
7
optobj = Tk::OptionObj.new('foreground'=>'red', 'background'=>'black')
 
8
 
 
9
f = TkFrame.new.pack(:side=>:left, :anchor=>:n, :padx=>5, :pady=>30)
 
10
 
 
11
b1 = TkButton.new(f, :text=>'AAA').pack(:fill=>:x)
 
12
b2 = TkButton.new(f, :text=>'BBB').pack(:fill=>:x)
 
13
b3 = TkButton.new(f, :text=>'CCC').pack(:fill=>:x)
 
14
 
 
15
optobj.assign( b1, 
 
16
              [ b2, 'configure', 
 
17
                { 'foreground'=>'background', 
 
18
                  'background'=>'foreground' } ], 
 
19
              [ b3, nil, 
 
20
                { 'foreground'=>'background', 
 
21
                  'activeforeground'=>nil, 
 
22
                  'background'=>['foreground', 'activeforeground'] } ] )
 
23
 
 
24
optobj.update('activeforeground'=>'yellow')
 
25
 
 
26
TkButton.new(f){
 
27
  configure( optobj.assign(self) + {:text=>'DDD'} )
 
28
  pack(:fill=>:x)
 
29
}
 
30
 
 
31
TkButton.new(f){
 
32
  configure( optobj.assign([self, nil, 
 
33
                             {'foreground'=>'activeforeground', 
 
34
                              'background'=>'foreground', 
 
35
                              'activeforeground'=>'background'}]) \
 
36
             + {:text=>'EEE', :relief=>:groove, :borderwidth=>5} )
 
37
  pack(:fill=>:x)
 
38
}
 
39
 
 
40
optobj.notify  # To apply the convert_key ( 3rd element of widget info 
 
41
               # (that is, {'foreground'=>'activeforeground', ,,, } ) 
 
42
               # of the 'EEE' button 
 
43
 
 
44
TkButton.new(f, :text=>'toggle', 
 
45
             :command=>proc{
 
46
               fg = optobj['foreground']
 
47
               bg = optobj['background']
 
48
               optobj.configure('foreground'=>bg, 'background'=>fg)
 
49
             }).pack(:fill=>:x, :pady=>10)
 
50
 
 
51
TkButton.new(f, :text=>'exit', 
 
52
                :command=>proc{exit}).pack(:fill=>:x, :pady=>10)
 
53
 
 
54
TkFrame.new{|f|
 
55
  pack(:side=>:right, :expand=>true, :fill=>:both)
 
56
  TkLabel.new(f, :text=>'source::').pack(:anchor=>:w)
 
57
  TkFrame.new(f){|ff|
 
58
    TkText.new(ff){
 
59
      yscrollbar(TkScrollbar.new(ff){pack(:fill=>:y, :side=>:right)})
 
60
      insert('end', File.read(__FILE__))
 
61
      pack(:side=>:left, :expand=>true, :fill=>:both)
 
62
    }
 
63
    pack(:expand=>true, :fill=>:both)
 
64
  }
 
65
}
 
66
 
 
67
Tk.mainloop