~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to ext/tk/sample/demos-en/mclist.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2010-07-31 17:08:39 UTC
  • mfrom: (1.1.4 upstream) (8.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100731170839-j034dmpdqt1cc4p6
Tags: 1.9.2~svn28788-1
* New release based on upstream snapshot from the 1.9.2 branch,
  after 1.9.2 RC2. That branch is (supposed to be) binary-compatible
  with the 1.9.1 branch.
  + Builds fine on i386. Closes: #580852.
* Upgrade to Standards-Version: 3.9.1. No changes needed.
* Updated generated incs.
* Patches that still need work:
  + Unclear status, need more investigation:
   090729_fix_Makefile_deps.dpatch
   090803_exclude_rdoc.dpatch
   203_adjust_base_of_search_path.dpatch
   902_define_YAML_in_yaml_stringio.rb.dpatch
   919_common.mk_tweaks.dpatch
   931_libruby_suffix.dpatch
   940_test_thread_mutex_sync_shorter.dpatch
  + Maybe not needed anymore, keeping but not applying.
   102_skip_test_copy_stream.dpatch (test doesn't block anymore?)
   104_skip_btest_io.dpatch (test doesn't block anymore?)
   201_gem_prelude.dpatch (we don't use that rubygems anyway?)
   202_gem_default_dir.dpatch (we don't use that rubygems anyway?)
   940_test_file_exhaustive_fails_as_root.dpatch
   940_test_priority_fails.dpatch
   100518_load_libc_libm.dpatch
* Add disable-tests.diff: disable some tests that cause failures on FreeBSD.
  Closes: #590002, #543805, #542927.
* However, many new failures on FreeBSD. Since that version is still an
  improvement, add the check that makes test suite failures non-fatal on
  FreeBSD again. That still needs to be investigated.
* Re-add 903_skip_base_ruby_check.dpatch
* Add build-dependency on ruby1.8 and drop all pre-generated files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
# based on "Id: mclist.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
7
7
 
8
8
if defined?($mclist_demo) && $mclist_demo
9
 
  $mclist_demo.destroy 
 
9
  $mclist_demo.destroy
10
10
  $mclist_demo = nil
11
11
end
12
12
 
19
19
base_frame = TkFrame.new($mclist_demo).pack(:fill=>:both, :expand=>true)
20
20
 
21
21
## Explanatory text
22
 
Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', 
23
 
               :justify=>:left, :anchor=>'n', :padding=>[10, 2, 10, 6], 
 
22
Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i',
 
23
               :justify=>:left, :anchor=>'n', :padding=>[10, 2, 10, 6],
24
24
               :text=><<EOL).pack(:fill=>:x)
25
25
Ttk is the new Tk themed widget set. \
26
26
One of the widgets it includes is a tree widget, \
36
36
Ttk::Frame.new(base_frame) {|frame|
37
37
  sep = Ttk::Separator.new(frame)
38
38
  Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
39
 
  TkGrid('x', 
40
 
         Ttk::Button.new(frame, :text=>'See Code', 
41
 
                         :image=>$image['view'], :compound=>:left, 
42
 
                         :command=>proc{showCode 'mclist'}), 
43
 
         Ttk::Button.new(frame, :text=>'Dismiss', 
44
 
                         :image=>$image['delete'], :compound=>:left, 
 
39
  TkGrid('x',
 
40
         Ttk::Button.new(frame, :text=>'See Code',
 
41
                         :image=>$image['view'], :compound=>:left,
 
42
                         :command=>proc{showCode 'mclist'}),
 
43
         Ttk::Button.new(frame, :text=>'Dismiss',
 
44
                         :image=>$image['delete'], :compound=>:left,
45
45
                         :command=>proc{
46
46
                           $mclist_demo.destroy
47
47
                           $mclist_demo = nil
48
 
                         }), 
 
48
                         }),
49
49
         :padx=>4, :pady=>4)
50
50
  grid_columnconfigure(0, :weight=>1)
51
51
  pack(:side=>:bottom, :fill=>:x)
52
52
}
53
53
 
54
54
container = Ttk::Frame.new(base_frame)
55
 
tree = Ttk::Treeview.new(base_frame, :columns=>%w(country capital currency), 
 
55
tree = Ttk::Treeview.new(base_frame, :columns=>%w(country capital currency),
56
56
                          :show=>:headings)
57
57
if Tk.windowingsystem != 'aqua'
58
58
  vsb = tree.yscrollbar(Ttk::Scrollbar.new(base_frame))
70
70
 
71
71
## The data we're going to insert
72
72
data = [
73
 
  ['Argentina',         'Buenos Aires',         'ARS'], 
74
 
  ['Australia',         'Canberra',             'AUD'], 
75
 
  ['Brazil',            'Brazilia',             'BRL'], 
76
 
  ['Canada',            'Ottawa',               'CAD'], 
77
 
  ['China',             'Beijing',              'CNY'], 
78
 
  ['France',            'Paris',                'EUR'], 
79
 
  ['Germany',           'Berlin',               'EUR'], 
80
 
  ['India',             'New Delhi',            'INR'], 
81
 
  ['Italy',             'Rome',                 'EUR'], 
82
 
  ['Japan',             'Tokyo',                'JPY'], 
83
 
  ['Mexico',            'Mexico City',          'MXN'], 
84
 
  ['Russia',            'Moscow',               'RUB'], 
85
 
  ['South Africa',      'Pretoria',             'ZAR'], 
86
 
  ['United Kingdom',    'London',               'GBP'], 
 
73
  ['Argentina',         'Buenos Aires',         'ARS'],
 
74
  ['Australia',         'Canberra',             'AUD'],
 
75
  ['Brazil',            'Brazilia',             'BRL'],
 
76
  ['Canada',            'Ottawa',               'CAD'],
 
77
  ['China',             'Beijing',              'CNY'],
 
78
  ['France',            'Paris',                'EUR'],
 
79
  ['Germany',           'Berlin',               'EUR'],
 
80
  ['India',             'New Delhi',            'INR'],
 
81
  ['Italy',             'Rome',                 'EUR'],
 
82
  ['Japan',             'Tokyo',                'JPY'],
 
83
  ['Mexico',            'Mexico City',          'MXN'],
 
84
  ['Russia',            'Moscow',               'RUB'],
 
85
  ['South Africa',      'Pretoria',             'ZAR'],
 
86
  ['United Kingdom',    'London',               'GBP'],
87
87
  ['United States',     'Washington, D.C.',     'USD'],
88
88
]
89
89
 
91
91
font = Ttk::Style.lookup(tree[:style], :font)
92
92
cols = %w(country capital currency)
93
93
cols.zip(%w(Country Capital Currency)).each{|col, name|
94
 
  tree.heading_configure(col, :text=>name, 
 
94
  tree.heading_configure(col, :text=>name,
95
95
                         :command=>proc{sort_by(tree, col, false)})
96
96
  tree.column_configure(col, :width=>TkFont.measure(font, name))
97
97
}
109
109
 
110
110
## Code to do the sorting of the tree contents when clicked on
111
111
def sort_by(tree, col, direction)
112
 
  tree.children(nil).map!{|row| [tree.get(row, col), row.id]} . 
113
 
    sort(&((direction)? proc{|x, y| y <=> x}: proc{|x, y| x <=> y})) . 
 
112
  tree.children(nil).map!{|row| [tree.get(row, col), row.id]} .
 
113
    sort(&((direction)? proc{|x, y| y <=> x}: proc{|x, y| x <=> y})) .
114
114
    each_with_index{|info, idx| tree.move(info[1], nil, idx)}
115
115
 
116
116
  tree.heading_configure(col, :command=>proc{sort_by(tree, col, ! direction)})