1 # One or more ScrolledLists with HSeparators between them.
2 # There is a hierarchical relationship between them:
3 # the right list displays the substructure of the selected item
8 from WindowList
import ListedToplevel
9 from Separator
import HSeparator
10 from ScrolledList
import ScrolledList
12 class MultiScrolledLists
:
14 def __init__(self
, root
, nlists
=2):
20 self
.top
= top
= ListedToplevel(root
)
21 top
.protocol("WM_DELETE_WINDOW", self
.close
)
22 top
.bind("<Escape>", self
.close
)
24 # create frames and separators in between
28 for i
in range(nlists
-1):
29 sepa
= HSeparator(last
)
30 self
.separators
.append(sepa
)
31 frame
, last
= sepa
.parts()
32 self
.frames
.append(frame
)
33 self
.frames
.append(last
)
34 # create labels and lists
37 for i
in range(nlists
):
38 frame
= self
.frames
[i
]
39 label
= Label(frame
, text
=self
.subtitle(i
),
40 relief
="groove", borderwidth
=2)
42 self
.labels
.append(label
)
43 list = ScrolledList(frame
, width
=self
.width(i
),
44 height
=self
.height(i
))
45 self
.lists
.append(list)
47 lambda index
, i
=i
, self
=self
: self
.on_select(index
, i
)
49 lambda index
, i
=i
, self
=self
: self
.on_double(index
, i
)
50 # fill leftmost list (rest get filled on demand)
52 # XXX one after_idle isn't enough; two are...
53 top
.after_idle(self
.call_pack_propagate_1
)
55 def call_pack_propagate_1(self
):
56 self
.top
.after_idle(self
.call_pack_propagate
)
58 def call_pack_propagate(self
):
59 for frame
in self
.frames
:
60 frame
.pack_propagate(0)
62 def close(self
, event
=None):
66 short
= self
.shorttitle()
67 long = self
.longtitle()
69 title
= short
+ " - " + long
76 icon
= short
or long or title
77 self
.top
.wm_title(title
)
78 self
.top
.wm_iconname(icon
)
82 return "Multi Scrolled Lists"
96 def subtitle(self
, i
):
98 return "Column %d" % i
101 for k
in range(i
, self
.nlists
):
102 self
.lists
[k
].clear()
103 self
.labels
[k
].configure(text
=self
.subtitle(k
))
109 def on_select(self
, index
, i
):
110 item
= self
.lists
[i
].get(index
)
112 self
.path
.append(item
)
113 if i
+1 < self
.nlists
:
122 s
= self
.path
[i
-1] + "." + s
126 def on_double(self
, index
, i
):
132 quit
= Button(root
, text
="Exit", command
=root
.destroy
)
134 MultiScrolledLists(root
, 4)
137 if __name__
== "__main__":