~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Demo/tix/samples/SHList1.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
 
2
#
 
3
# $Id: SHList1.py 68309 2009-01-04 18:53:28Z benjamin.peterson $
 
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 tixScrolledHList widget.
 
14
#
 
15
 
 
16
import tkinter.tix
 
17
 
 
18
TCL_ALL_EVENTS          = 0
 
19
 
 
20
def RunSample (root):
 
21
    shlist = DemoSHList(root)
 
22
    shlist.mainloop()
 
23
    shlist.destroy()
 
24
 
 
25
class DemoSHList:
 
26
    def __init__(self, w):
 
27
        self.root = w
 
28
        self.exit = -1
 
29
 
 
30
        z = w.winfo_toplevel()
 
31
        z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
 
32
 
 
33
        # We create the frame and the ScrolledHList widget
 
34
        # at the top of the dialog box
 
35
        #
 
36
        top = tkinter.tix.Frame( w, relief=tkinter.tix.RAISED, bd=1)
 
37
 
 
38
        # Put a simple hierachy into the HList (two levels). Use colors and
 
39
        # separator widgets (frames) to make the list look fancy
 
40
        #
 
41
        top.a = tkinter.tix.ScrolledHList(top)
 
42
        top.a.pack( expand=1, fill=tkinter.tix.BOTH, padx=10, pady=10, side=tkinter.tix.TOP)
 
43
 
 
44
        # This is our little relational database
 
45
        #
 
46
        bosses = [
 
47
            ('jeff',  'Jeff Waxman'),
 
48
            ('john',  'John Lee'),
 
49
            ('peter', 'Peter Kenson')
 
50
        ]
 
51
 
 
52
        employees = [
 
53
            ('alex',  'john',  'Alex Kellman'),
 
54
            ('alan',  'john',  'Alan Adams'),
 
55
            ('andy',  'peter', 'Andreas Crawford'),
 
56
            ('doug',  'jeff',  'Douglas Bloom'),
 
57
            ('jon',   'peter', 'Jon Baraki'),
 
58
            ('chris', 'jeff',  'Chris Geoffrey'),
 
59
            ('chuck', 'jeff',  'Chuck McLean')
 
60
        ]
 
61
 
 
62
        hlist=top.a.hlist
 
63
 
 
64
        # Let configure the appearance of the HList subwidget
 
65
        #
 
66
        hlist.config( separator='.', width=25, drawbranch=0, indent=10)
 
67
 
 
68
        count=0
 
69
        for boss,name in bosses :
 
70
            if count :
 
71
                f=tkinter.tix.Frame(hlist, name='sep%d' % count, height=2, width=150,
 
72
                    bd=2, relief=tkinter.tix.SUNKEN )
 
73
 
 
74
                hlist.add_child( itemtype=tkinter.tix.WINDOW,
 
75
                    window=f, state=tkinter.tix.DISABLED )
 
76
 
 
77
            hlist.add(boss, itemtype=tkinter.tix.TEXT, text=name)
 
78
            count = count+1
 
79
 
 
80
 
 
81
        for person,boss,name in employees :
 
82
            # '.' is the separator character we chose above
 
83
            #
 
84
            key= boss    + '.'     + person
 
85
            #    ^^^^                ^^^^^^
 
86
            #    parent entryPath /  child's name
 
87
 
 
88
            hlist.add( key, text=name )
 
89
 
 
90
            # [Hint] Make sure the keys (e.g. 'boss.person') you choose
 
91
            #    are unique names. If you cannot be sure of this (because of
 
92
            #    the structure of your database, e.g.) you can use the
 
93
            #    "add_child" command instead:
 
94
            #
 
95
            #  hlist.addchild( boss,  text=name)
 
96
            #                  ^^^^
 
97
            #                  parent entryPath
 
98
 
 
99
 
 
100
        # Use a ButtonBox to hold the buttons.
 
101
        #
 
102
        box= tkinter.tix.ButtonBox(top, orientation=tkinter.tix.HORIZONTAL )
 
103
        box.add( 'ok',  text='Ok', underline=0,  width=6,
 
104
            command = self.okcmd)
 
105
 
 
106
        box.add( 'cancel', text='Cancel', underline=0, width=6,
 
107
            command = self.quitcmd)
 
108
 
 
109
        box.pack( side=tkinter.tix.BOTTOM, fill=tkinter.tix.X)
 
110
        top.pack( side=tkinter.tix.TOP,    fill=tkinter.tix.BOTH, expand=1 )
 
111
 
 
112
    def okcmd (self):
 
113
        self.quitcmd()
 
114
 
 
115
    def quitcmd (self):
 
116
        self.exit = 0
 
117
 
 
118
    def mainloop(self):
 
119
        while self.exit < 0:
 
120
            self.root.tk.dooneevent(TCL_ALL_EVENTS)
 
121
 
 
122
    def destroy (self):
 
123
        self.root.destroy()
 
124
 
 
125
 
 
126
# This "if" statement makes it possible to run this script file inside or
 
127
# outside of the main demo program "tixwidgets.py".
 
128
#
 
129
if __name__== '__main__' :
 
130
    root=tkinter.tix.Tk()
 
131
    RunSample(root)