symbian-qemu-0.9.1-12/python-2.6.1/Demo/tix/samples/SHList1.py
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
       
     2 #
       
     3 # $Id: SHList1.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 tixScrolledHList widget.
       
    14 #
       
    15 
       
    16 import 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 = Tix.Frame( w, relief=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 = Tix.ScrolledHList(top)
       
    42         top.a.pack( expand=1, fill=Tix.BOTH, padx=10, pady=10, side=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=Tix.Frame(hlist, name='sep%d' % count, height=2, width=150,
       
    72                     bd=2, relief=Tix.SUNKEN )
       
    73 
       
    74                 hlist.add_child( itemtype=Tix.WINDOW,
       
    75                     window=f, state=Tix.DISABLED )
       
    76 
       
    77             hlist.add(boss, itemtype=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= Tix.ButtonBox(top, orientation=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=Tix.BOTTOM, fill=Tix.X)
       
   110         top.pack( side=Tix.TOP,    fill=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=Tix.Tk()
       
   131     RunSample(root)