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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# -*- coding: euc-jp -*-
#
# mclist.rb --
#
# This demonstration script creates a toplevel window containing a Ttk
# tree widget configured as a multi-column listbox.
#
# based on "Id: mclist.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
if defined?($mclist_demo) && $mclist_demo
$mclist_demo.destroy
$mclist_demo = nil
end
$mclist_demo = TkToplevel.new {|w|
title("Multi-Column List")
iconname("mclist")
positionWindow(w)
}
base_frame = TkFrame.new($mclist_demo).pack(:fill=>:both, :expand=>true)
## Explanatory text
Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i',
:justify=>:left, :anchor=>'n', :padding=>[10, 2, 10, 6],
:text=><<EOL).pack(:fill=>:x)
Ttk¤È¤Ï¡¤¥Æ¡¼¥Þ»ØÄê²Äǽ¤Ê¿·¤·¤¤¥¦¥£¥¸¥§¥Ã¥È½¸¹ç¤Ç¤¹¡¥\
Ttk::Treeview¥¦¥£¥¸¥§¥Ã¥È¤Ï\
Ttk¥¦¥£¥¸¥§¥Ã¥È¥»¥Ã¥È¤Ë´Þ¤Þ¤ì¤ë¥¦¥£¥¸¥§¥Ã¥È¤Î°ì¤Ä¤Ç¡¤\
¤½¤ì¤¬ÊÝ»ý¤¹¤ëÌÚ¹½Â¤¤Î¥Ç¡¼¥¿¤½¤Î¤â¤Î¤Þ¤Ç¤Ïɽ¼¨¤¹¤ë¤³¤È¤Ê¤¯¡¤\
¼¨¤·¤¿¤¤¾ðÊó¤ò¥Þ¥ë¥Á¥«¥é¥à¤Çɽ¼¨¤µ¤»¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡¥
¤³¤Î¥µ¥ó¥×¥ë¤Ï¡¤Ê£¿ô¤Î¥«¥é¥à¤ò»ý¤Ã¤¿¥ê¥¹¥È¥Ü¥Ã¥¯¥¹¤òºîÀ®¤¹¤ë´Êñ¤ÊÎã¤Ç¤¹¡¥
³Æ¥«¥é¥à¤Î¥¿¥¤¥È¥ë(heading)¤ò¥¯¥ê¥Ã¥¯¤¹¤ì¤Ð¡¤\
¤½¤Î¥«¥é¥à¤Î¾ðÊó¤Ë´ð¤Å¤¤¤Æ¥ê¥¹¥È¤ÎʤÙÂؤ¨¤¬¤Ê¤µ¤ì¤ë¤Ï¤º¤Ç¤¹¡¥\
¤Þ¤¿¡¤¥«¥é¥à¤Î¥¿¥¤¥È¥ë´Ö¤Î¶èÀÚ¤êÉôʬ¤ò¥É¥é¥Ã¥°¤¹¤ë¤³¤È¤Ç¡¤\
¥«¥é¥à¤ÎÉý¤òÊѹ¹¤¹¤ë¤³¤È¤â²Äǽ¤Ç¤¹¡¥
EOL
## See Code / Dismiss
Ttk::Frame.new(base_frame) {|frame|
sep = Ttk::Separator.new(frame)
Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
TkGrid('x',
Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È',
:image=>$image['view'], :compound=>:left,
:command=>proc{showCode 'mclist'}),
Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë',
:image=>$image['delete'], :compound=>:left,
:command=>proc{
$mclist_demo.destroy
$mclist_demo = nil
}),
:padx=>4, :pady=>4)
grid_columnconfigure(0, :weight=>1)
pack(:side=>:bottom, :fill=>:x)
}
container = Ttk::Frame.new(base_frame)
tree = Ttk::Treeview.new(base_frame, :columns=>%w(country capital currency),
:show=>:headings)
if Tk.windowingsystem != 'aquq'
vsb = tree.yscrollbar(Ttk::Scrollbar.new(base_frame))
hsb = tree.xscrollbar(Ttk::Scrollbar.new(base_frame))
else
vsb = tree.yscrollbar(Tk::Scrollbar.new(base_frame))
hsb = tree.xscrollbar(Tk::Scrollbar.new(base_frame))
end
container.pack(:fill=>:both, :expand=>true)
Tk.grid(tree, vsb, :in=>container, :sticky=>'nsew')
Tk.grid(hsb, :in=>container, :sticky=>'nsew')
container.grid_columnconfigure(0, :weight=>1)
container.grid_rowconfigure(0, :weight=>1)
## The data we're going to insert
data = [
['¥¢¥ë¥¼¥ó¥Á¥ó', '¥Ö¥¨¥Î¥¹¥¢¥¤¥ì¥¹', 'ARS'],
['¥ª¡¼¥¹¥È¥é¥ê¥¢', '¥¥ã¥ó¥Ù¥é', 'AUD'],
['¥Ö¥é¥¸¥ë', '¥Ö¥é¥¸¥ê¥¢', 'BRL'],
['¥«¥Ê¥À', '¥ª¥¿¥ï', 'CAD'],
['Ãæ¹ñ', 'Ë̵þ', 'CNY'],
['¥Õ¥é¥ó¥¹', '¥Ñ¥ê', 'EUR'],
['¥É¥¤¥Ä', '¥Ù¥ë¥ê¥ó', 'EUR'],
['¥¤¥ó¥É', '¥Ë¥å¡¼¥Ç¥ê¡¼', 'INR'],
['¥¤¥¿¥ê¥¢', '¥í¡¼¥Þ', 'EUR'],
['ÆüËÜ', 'Åìµþ', 'JPY'],
['¥á¥¥·¥³', '¥á¥¥·¥³¥·¥Æ¥£', 'MXN'],
['¥í¥·¥¢', '¥â¥¹¥¯¥ï', 'RUB'],
['Æ¥Õ¥ê¥«', '¥×¥ì¥È¥ê¥¢', 'ZAR'],
['±Ñ¹ñ', '¥í¥ó¥É¥ó', 'GBP'],
['¥¢¥á¥ê¥«', '¥ï¥·¥ó¥È¥ó D.C.', 'USD'],
]
## Code to insert the data nicely
font = Ttk::Style.lookup(tree[:style], :font)
cols = %w(country capital currency)
cols.zip(%w(¹ñ̾ ¼óÅÔ Ä̲ß)).each{|col, name|
tree.heading_configure(col, :text=>name,
:command=>proc{sort_by(tree, col, false)})
tree.column_configure(col, :width=>TkFont.measure(font, name))
}
data.each{|country, capital, currency|
#tree.insert('', :end, :values=>[country, capital, currency])
tree.insert(nil, :end, :values=>[country, capital, currency])
cols.zip([country, capital, currency]).each{|col, val|
len = TkFont.measure(font, "#{val} ")
if tree.column_cget(col, :width) < len
tree.column_configure(col, :width=>len)
end
}
}
## Code to do the sorting of the tree contents when clicked on
def sort_by(tree, col, direction)
tree.children(nil).map!{|row| [tree.get(row, col), row.id]} .
sort(&((direction)? proc{|x, y| y <=> x}: proc{|x, y| x <=> y})) .
each_with_index{|info, idx| tree.move(info[1], nil, idx)}
tree.heading_configure(col, :command=>proc{sort_by(tree, col, ! direction)})
end
|