| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
import Tix, os |
| 18 |
|
| 19 |
def RunSample(w): |
| 20 |
top = Tix.Frame(w, relief=Tix.RAISED, bd=1) |
| 21 |
tree = Tix.Tree(top, options='separator "/"') |
| 22 |
tree.pack(expand=1, fill=Tix.BOTH, padx=10, pady=10, side=Tix.LEFT) |
| 23 |
tree['opencmd'] = lambda dir=None, w=tree: opendir(w, dir) |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
adddir(tree, "/") |
| 28 |
|
| 29 |
box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL) |
| 30 |
box.add('ok', text='Ok', underline=0, command=w.destroy, width=6) |
| 31 |
box.add('cancel', text='Cancel', underline=0, command=w.destroy, width=6) |
| 32 |
box.pack(side=Tix.BOTTOM, fill=Tix.X) |
| 33 |
top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1) |
| 34 |
|
| 35 |
def adddir(tree, dir): |
| 36 |
if dir == '/': |
| 37 |
text = '/' |
| 38 |
else: |
| 39 |
text = os.path.basename(dir) |
| 40 |
tree.hlist.add(dir, itemtype=Tix.IMAGETEXT, text=text, |
| 41 |
image=tree.tk.call('tix', 'getimage', 'folder')) |
| 42 |
try: |
| 43 |
os.listdir(dir) |
| 44 |
tree.setmode(dir, 'open') |
| 45 |
except os.error: |
| 46 |
|
| 47 |
pass |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
def opendir(tree, dir): |
| 58 |
entries = tree.hlist.info_children(dir) |
| 59 |
if entries: |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
for entry in entries: |
| 68 |
tree.hlist.show_entry(entry) |
| 69 |
files = os.listdir(dir) |
| 70 |
for file in files: |
| 71 |
if os.path.isdir(dir + '/' + file): |
| 72 |
adddir(tree, dir + '/' + file) |
| 73 |
else: |
| 74 |
tree.hlist.add(dir + '/' + file, itemtype=Tix.IMAGETEXT, text=file, |
| 75 |
image=tree.tk.call('tix', 'getimage', 'file')) |
| 76 |
|
| 77 |
if __name__ == '__main__': |
| 78 |
root = Tix.Tk() |
| 79 |
RunSample(root) |
| 80 |
root.mainloop() |