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