/Demo/tix/samples/NoteBook.py

http://unladen-swallow.googlecode.com/ · Python · 119 lines · 64 code · 22 blank · 33 comment · 3 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. # This file demonstrates the use of the tixNoteBook widget, which allows
  13. # you to lay out your interface using a "notebook" metaphore
  14. #
  15. import Tix
  16. def RunSample(w):
  17. global root
  18. root = w
  19. # We use these options to set the sizes of the subwidgets inside the
  20. # notebook, so that they are well-aligned on the screen.
  21. prefix = Tix.OptionName(w)
  22. if prefix:
  23. prefix = '*'+prefix
  24. else:
  25. prefix = ''
  26. w.option_add(prefix+'*TixControl*entry.width', 10)
  27. w.option_add(prefix+'*TixControl*label.width', 18)
  28. w.option_add(prefix+'*TixControl*label.anchor', Tix.E)
  29. w.option_add(prefix+'*TixNoteBook*tagPadX', 8)
  30. # Create the notebook widget and set its backpagecolor to gray.
  31. # Note that the -backpagecolor option belongs to the "nbframe"
  32. # subwidget.
  33. nb = Tix.NoteBook(w, name='nb', ipadx=6, ipady=6)
  34. nb['bg'] = 'gray'
  35. nb.nbframe['backpagecolor'] = 'gray'
  36. # Create the two tabs on the notebook. The -underline option
  37. # puts a underline on the first character of the labels of the tabs.
  38. # Keyboard accelerators will be defined automatically according
  39. # to the underlined character.
  40. nb.add('hard_disk', label="Hard Disk", underline=0)
  41. nb.add('network', label="Network", underline=0)
  42. nb.pack(expand=1, fill=Tix.BOTH, padx=5, pady=5 ,side=Tix.TOP)
  43. #----------------------------------------
  44. # Create the first page
  45. #----------------------------------------
  46. # Create two frames: one for the common buttons, one for the
  47. # other widgets
  48. #
  49. tab=nb.hard_disk
  50. f = Tix.Frame(tab)
  51. common = Tix.Frame(tab)
  52. f.pack(side=Tix.LEFT, padx=2, pady=2, fill=Tix.BOTH, expand=1)
  53. common.pack(side=Tix.RIGHT, padx=2, fill=Tix.Y)
  54. a = Tix.Control(f, value=12, label='Access time: ')
  55. w = Tix.Control(f, value=400, label='Write Throughput: ')
  56. r = Tix.Control(f, value=400, label='Read Throughput: ')
  57. c = Tix.Control(f, value=1021, label='Capacity: ')
  58. a.pack(side=Tix.TOP, padx=20, pady=2)
  59. w.pack(side=Tix.TOP, padx=20, pady=2)
  60. r.pack(side=Tix.TOP, padx=20, pady=2)
  61. c.pack(side=Tix.TOP, padx=20, pady=2)
  62. # Create the common buttons
  63. createCommonButtons(common)
  64. #----------------------------------------
  65. # Create the second page
  66. #----------------------------------------
  67. tab = nb.network
  68. f = Tix.Frame(tab)
  69. common = Tix.Frame(tab)
  70. f.pack(side=Tix.LEFT, padx=2, pady=2, fill=Tix.BOTH, expand=1)
  71. common.pack(side=Tix.RIGHT, padx=2, fill=Tix.Y)
  72. a = Tix.Control(f, value=12, label='Access time: ')
  73. w = Tix.Control(f, value=400, label='Write Throughput: ')
  74. r = Tix.Control(f, value=400, label='Read Throughput: ')
  75. c = Tix.Control(f, value=1021, label='Capacity: ')
  76. u = Tix.Control(f, value=10, label='Users: ')
  77. a.pack(side=Tix.TOP, padx=20, pady=2)
  78. w.pack(side=Tix.TOP, padx=20, pady=2)
  79. r.pack(side=Tix.TOP, padx=20, pady=2)
  80. c.pack(side=Tix.TOP, padx=20, pady=2)
  81. u.pack(side=Tix.TOP, padx=20, pady=2)
  82. createCommonButtons(common)
  83. def doDestroy():
  84. global root
  85. root.destroy()
  86. def createCommonButtons(master):
  87. ok = Tix.Button(master, name='ok', text='OK', width=6,
  88. command=doDestroy)
  89. cancel = Tix.Button(master, name='cancel',
  90. text='Cancel', width=6,
  91. command=doDestroy)
  92. ok.pack(side=Tix.TOP, padx=2, pady=2)
  93. cancel.pack(side=Tix.TOP, padx=2, pady=2)
  94. if __name__ == '__main__':
  95. root = Tix.Tk()
  96. RunSample(root)
  97. root.mainloop()