| 1 | # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
|
|---|
| 2 | #
|
|---|
| 3 | # $Id: DirTree.py 36560 2004-07-18 06:16:08Z tim_one $
|
|---|
| 4 | #
|
|---|
| 5 | # Tix Demostration Program
|
|---|
| 6 | #
|
|---|
| 7 | # This sample program is structured in such a way so that it can be
|
|---|
| 8 | # executed from the Tix demo program "tixwidgets.py": it must have a
|
|---|
| 9 | # procedure called "RunSample". It should also have the "if" statment
|
|---|
| 10 | # at the end of this file so that it can be run as a standalone
|
|---|
| 11 | # program using tixwish.
|
|---|
| 12 |
|
|---|
| 13 | # This file demonstrates the use of the tixDirTree widget -- you can
|
|---|
| 14 | # use it for the user to select a directory. For example, an installation
|
|---|
| 15 | # program can use the tixDirTree widget to ask the user to select the
|
|---|
| 16 | # installation directory for an application.
|
|---|
| 17 | #
|
|---|
| 18 |
|
|---|
| 19 | import Tix, os, copy
|
|---|
| 20 | from Tkconstants import *
|
|---|
| 21 |
|
|---|
| 22 | TCL_ALL_EVENTS = 0
|
|---|
| 23 |
|
|---|
| 24 | def RunSample (root):
|
|---|
| 25 | dirtree = DemoDirTree(root)
|
|---|
| 26 | dirtree.mainloop()
|
|---|
| 27 | dirtree.destroy()
|
|---|
| 28 |
|
|---|
| 29 | class DemoDirTree:
|
|---|
| 30 | def __init__(self, w):
|
|---|
| 31 | self.root = w
|
|---|
| 32 | self.exit = -1
|
|---|
| 33 |
|
|---|
| 34 | z = w.winfo_toplevel()
|
|---|
| 35 | z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
|
|---|
| 36 |
|
|---|
| 37 | # Create the tixDirTree and the tixLabelEntry widgets on the on the top
|
|---|
| 38 | # of the dialog box
|
|---|
| 39 |
|
|---|
| 40 | # bg = root.tk.eval('tix option get bg')
|
|---|
| 41 | # adding bg=bg crashes Windows pythonw tk8.3.3 Python 2.1.0
|
|---|
| 42 |
|
|---|
| 43 | top = Tix.Frame( w, relief=RAISED, bd=1)
|
|---|
| 44 |
|
|---|
| 45 | # Create the DirTree widget. By default it will show the current
|
|---|
| 46 | # directory
|
|---|
| 47 | #
|
|---|
| 48 | #
|
|---|
| 49 | top.dir = Tix.DirTree(top)
|
|---|
| 50 | top.dir.hlist['width'] = 40
|
|---|
| 51 |
|
|---|
| 52 | # When the user presses the ".." button, the selected directory
|
|---|
| 53 | # is "transferred" into the entry widget
|
|---|
| 54 | #
|
|---|
| 55 | top.btn = Tix.Button(top, text = " >> ", pady = 0)
|
|---|
| 56 |
|
|---|
| 57 | # We use a LabelEntry to hold the installation directory. The user
|
|---|
| 58 | # can choose from the DirTree widget, or he can type in the directory
|
|---|
| 59 | # manually
|
|---|
|
|---|