PageRenderTime 310ms CodeModel.GetById 117ms app.highlight 16ms RepoModel.GetById 84ms app.codeStats 0ms

/Demo/tix/samples/NoteBook.py

http://unladen-swallow.googlecode.com/
Python | 119 lines | 100 code | 3 blank | 16 comment | 1 complexity | 87eb1d5118fe81f78e333d636dc4d0f7 MD5 | raw file
  1# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2#
  3# $Id: NoteBook.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.
 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:
 26        prefix = '*'+prefix
 27    else:
 28        prefix = ''
 29    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'
 40
 41    # 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
 44    # to the underlined character.
 45    nb.add('hard_disk', label="Hard Disk", underline=0)
 46    nb.add('network', label="Network", underline=0)
 47
 48    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)
 59
 60    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)
 62
 63    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: ')
 67
 68    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)
 72
 73    # Create the common buttons
 74    createCommonButtons(common)
 75
 76    #----------------------------------------
 77    # Create the second page
 78    #----------------------------------------
 79
 80    tab = nb.network
 81
 82    f = Tix.Frame(tab)
 83    common = Tix.Frame(tab)
 84
 85    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)
 87
 88    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: ')
 93
 94    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)
 99
100    createCommonButtons(common)
101
102def doDestroy():
103    global root
104    root.destroy()
105
106def createCommonButtons(master):
107    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
113    ok.pack(side=Tix.TOP, padx=2, pady=2)
114    cancel.pack(side=Tix.TOP, padx=2, pady=2)
115
116if __name__ == '__main__':
117    root = Tix.Tk()
118    RunSample(root)
119    root.mainloop()