blob: 1e0da3e76a6f37aed71b65e2a60dfd1b3e788678 [file] [log] [blame]
Martin v. Löwis8ec03e02002-03-17 18:19:13 +00001# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
Tim Peters182b5ac2004-07-18 06:16:08 +00002#
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00003# $Id$
4#
5# Tix Demostration Program
6#
7# This sample program is structured in such a way so that it can be
Martin v. Löwis8ec03e02002-03-17 18:19:13 +00008# executed from the Tix demo program "tixwidgets.py": it must have a
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00009# 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.
12
13# This file demonstrates the use of the tixNoteBook widget, which allows
14# you to lay out your interface using a "notebook" metaphore
15#
16import Tix
17
18def RunSample(w):
19 global root
20 root = w
21
22 # We use these options to set the sizes of the subwidgets inside the
23 # notebook, so that they are well-aligned on the screen.
24 prefix = Tix.OptionName(w)
25 if prefix:
Tim Peters182b5ac2004-07-18 06:16:08 +000026 prefix = '*'+prefix
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000027 else:
Tim Peters182b5ac2004-07-18 06:16:08 +000028 prefix = ''
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000029 w.option_add(prefix+'*TixControl*entry.width', 10)
30 w.option_add(prefix+'*TixControl*label.width', 18)
31 w.option_add(prefix+'*TixControl*label.anchor', Tix.E)
32 w.option_add(prefix+'*TixNoteBook*tagPadX', 8)
33
34 # Create the notebook widget and set its backpagecolor to gray.
35 # Note that the -backpagecolor option belongs to the "nbframe"
36 # subwidget.
37 nb = Tix.NoteBook(w, name='nb', ipadx=6, ipady=6)
38 nb['bg'] = 'gray'
39 nb.nbframe['backpagecolor'] = 'gray'
Tim Peters182b5ac2004-07-18 06:16:08 +000040
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000041 # Create the two tabs on the notebook. The -underline option
42 # puts a underline on the first character of the labels of the tabs.
43 # Keyboard accelerators will be defined automatically according
Tim Peters182b5ac2004-07-18 06:16:08 +000044 # to the underlined character.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000045 nb.add('hard_disk', label="Hard Disk", underline=0)
46 nb.add('network', label="Network", underline=0)
Tim Peters182b5ac2004-07-18 06:16:08 +000047
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000048 nb.pack(expand=1, fill=Tix.BOTH, padx=5, pady=5 ,side=Tix.TOP)
49
50 #----------------------------------------
51 # Create the first page
52 #----------------------------------------
53 # Create two frames: one for the common buttons, one for the
54 # other widgets
55 #
56 tab=nb.hard_disk
57 f = Tix.Frame(tab)
58 common = Tix.Frame(tab)
Tim Peters182b5ac2004-07-18 06:16:08 +000059
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000060 f.pack(side=Tix.LEFT, padx=2, pady=2, fill=Tix.BOTH, expand=1)
61 common.pack(side=Tix.RIGHT, padx=2, fill=Tix.Y)
Tim Peters182b5ac2004-07-18 06:16:08 +000062
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000063 a = Tix.Control(f, value=12, label='Access time: ')
64 w = Tix.Control(f, value=400, label='Write Throughput: ')
65 r = Tix.Control(f, value=400, label='Read Throughput: ')
66 c = Tix.Control(f, value=1021, label='Capacity: ')
Tim Peters182b5ac2004-07-18 06:16:08 +000067
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000068 a.pack(side=Tix.TOP, padx=20, pady=2)
69 w.pack(side=Tix.TOP, padx=20, pady=2)
70 r.pack(side=Tix.TOP, padx=20, pady=2)
71 c.pack(side=Tix.TOP, padx=20, pady=2)
Tim Peters182b5ac2004-07-18 06:16:08 +000072
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000073 # Create the common buttons
74 createCommonButtons(common)
Tim Peters182b5ac2004-07-18 06:16:08 +000075
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000076 #----------------------------------------
Tim Peters182b5ac2004-07-18 06:16:08 +000077 # Create the second page
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000078 #----------------------------------------
Tim Peters182b5ac2004-07-18 06:16:08 +000079
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000080 tab = nb.network
81
82 f = Tix.Frame(tab)
83 common = Tix.Frame(tab)
Tim Peters182b5ac2004-07-18 06:16:08 +000084
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000085 f.pack(side=Tix.LEFT, padx=2, pady=2, fill=Tix.BOTH, expand=1)
86 common.pack(side=Tix.RIGHT, padx=2, fill=Tix.Y)
Tim Peters182b5ac2004-07-18 06:16:08 +000087
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000088 a = Tix.Control(f, value=12, label='Access time: ')
89 w = Tix.Control(f, value=400, label='Write Throughput: ')
90 r = Tix.Control(f, value=400, label='Read Throughput: ')
91 c = Tix.Control(f, value=1021, label='Capacity: ')
92 u = Tix.Control(f, value=10, label='Users: ')
Tim Peters182b5ac2004-07-18 06:16:08 +000093
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000094 a.pack(side=Tix.TOP, padx=20, pady=2)
95 w.pack(side=Tix.TOP, padx=20, pady=2)
96 r.pack(side=Tix.TOP, padx=20, pady=2)
97 c.pack(side=Tix.TOP, padx=20, pady=2)
98 u.pack(side=Tix.TOP, padx=20, pady=2)
Tim Peters182b5ac2004-07-18 06:16:08 +000099
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000100 createCommonButtons(common)
Tim Peters182b5ac2004-07-18 06:16:08 +0000101
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000102def doDestroy():
103 global root
104 root.destroy()
105
106def createCommonButtons(master):
Tim Peters182b5ac2004-07-18 06:16:08 +0000107 ok = Tix.Button(master, name='ok', text='OK', width=6,
108 command=doDestroy)
109 cancel = Tix.Button(master, name='cancel',
110 text='Cancel', width=6,
111 command=doDestroy)
112
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000113 ok.pack(side=Tix.TOP, padx=2, pady=2)
Tim Peters182b5ac2004-07-18 06:16:08 +0000114 cancel.pack(side=Tix.TOP, padx=2, pady=2)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000115
116if __name__ == '__main__':
117 root = Tix.Tk()
118 RunSample(root)
119 root.mainloop()