1 from Tkinter import *
2 import Pmw
3
6 optiondefs = (
7
8 ('doublecommand', None, None),
9 ('rowselectcommand', None, None),
10 ('colselectcommand', None, None),
11 )
12 self.defineoptions(kw, optiondefs)
13 Pmw.MegaWidget.__init__(self, master)
14 self.lists = []
15 for label,width in lists:
16 self.addList(label,width)
17 frame = Frame(self.component('hull'))
18 frame.pack(side='right', fill=Y)
19 Label(frame, borderwidth=1, relief='raised').pack(fill=X)
20 sb = Scrollbar(frame, orient='vertical', command=self._scroll)
21 sb.pack(expand='yes', fill='y')
22 self.lists[0]['yscrollcommand']=sb.set
23
25 """dp"""
26 try:
27 frame = self.createcomponent('frame %s' % (label),(),None,Frame,
28 (self.component('hull'),))
29 except ValueError:
30
31 return
32 frame.pack(side='left', expand='yes', fill='both')
33 widget = self.createcomponent('label %s' % (label),(),label,Label,
34 (frame, ),
35 text=label, borderwidth=1,
36 anchor='w',height=1,width=width,
37 relief='raised',wraplength=0)
38 widget.bind('<Button-1>', lambda e,s=self,l=label:s.selectColumn(e,l))
39 widget.pack(fill='x')
40 lb = self.createcomponent('list %s' % (label),(),label,Listbox,
41 (frame, ),
42 width=width, borderwidth=0,
43 selectborderwidth=0,
44 relief='flat', exportselection='false')
45 lb.pack(expand='yes', fill='both')
46 self.lists.append(lb)
47 lb.bind('<Double-ButtonRelease-1>', lambda e, s=self: s._double(e))
48 lb.bind('<B1-Motion>', lambda e, s=self: s._select(e.y))
49 lb.bind('<Button-1>', lambda e, s=self: s._select(e.y))
50 lb.bind('<Shift-1>', lambda e, s=self: s._select(e.y,'shift'))
51 lb.bind('<Control-1>', lambda e, s=self: s._select(e.y,'ctrl'))
52 lb.bind('<Leave>', lambda e: 'break')
53 lb.bind('<B2-Motion>', lambda e, s=self: s._b2motion(e.x, e.y))
54 lb.bind('<Button-2>', lambda e, s=self: s._button2(e.x, e.y))
55
57 """dp"""
58 widget = self.component('list %s' % (label))
59 for index in range(len(self.lists)):
60 if self.lists[index] is widget:
61 break
62 else:
63 raise UserWarning,'Unable to find list %s to delete' % (label)
64 del self.lists[index]
65 self.destroycomponent('list %s' % (label))
66 self.destroycomponent('label %s' % (label))
67 self.destroycomponent('frame %s' % (label))
68
70 """dp"""
71 self.selection_clear(0,'end')
72 widget = self.component('list %s' % (label))
73 widget.selection_set(0,'end')
74 if self['colselectcommand']:
75 self['colselectcommand'](label)
76
77 - def _select(self, y,modifier=None):
91
92 - def _double(self,event,modifier=None):
93 """dp"""
94 row = self.lists[0].nearest(event.y)
95 if self['doublecommand']:
96 self['doublecommand'](row,event)
97 return 'break'
98
102
104 for l in self.lists: l.scan_dragto(x, y)
105 return 'break'
106
110
113
114 - def delete(self, first, last=None):
117
118 - def get(self, first, last=None):
119 result = []
120 for l in self.lists:
121 result.append(l.get(first,last))
122 if last: return apply(map, [None] + result)
123 return result
124
127
128 - def insert(self, index, *elements):
129 for e in elements:
130 i = 0
131 for l in self.lists:
132 l.insert(index, e[i])
133 i = i + 1
134
136 return self.lists[0].size()
137
138 - def see(self, index):
139 for l in self.lists:
140 l.see(index)
141
145
149
152
156
157 if __name__ == '__main__':
158 tk = Tk()
159 Label(tk, text='MultiListbox').pack()
160 mlb = MultiListbox(tk, (('Subject', 40), ('Sender', 20), ('Date', 10)))
161 for i in range(1000):
162 mlb.insert(END, ('Important Message: %d' % i, 'John Doe', '10/10/%04d' % (1900+i)))
163 mlb.pack(expand=YES,fill=BOTH)
164 tk.mainloop()
165