19
19
base_frame = TkFrame.new($mclist_demo).pack(:fill=>:both, :expand=>true)
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)
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,
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,
46
46
$mclist_demo.destroy
49
49
:padx=>4, :pady=>4)
50
50
grid_columnconfigure(0, :weight=>1)
51
51
pack(:side=>:bottom, :fill=>:x)
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),
57
57
if Tk.windowingsystem != 'aqua'
58
58
vsb = tree.yscrollbar(Ttk::Scrollbar.new(base_frame))
71
71
## The data we're going to insert
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'],
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))
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)}
116
116
tree.heading_configure(col, :command=>proc{sort_by(tree, col, ! direction)})