Merge branch 'master' of git.ucc.asn.au:/matches/honours
[matches/honours.git] / research / transmission_spectroscopy / simulator / pgu-0.18 / examples / gui16.py
1 """and example of how to implement tabs"""
2
3 import pygame
4 from pygame.locals import *
5
6 # the following line is not needed if pgu is installed
7 import sys; sys.path.insert(0, "..")
8
9 from pgu import gui
10 from pgu import html
11
12 app = gui.Desktop()
13
14 #####################################
15 c = gui.Container(width=240,height=120)
16
17 def i_disable(value):
18     item.disabled = True
19     item.blur()
20     item.chsize()
21
22 item = gui.Button(gui.Label('Disable'))
23 item.connect(gui.CLICK,i_disable,None)
24
25 def c_add(value):
26     w = value
27     c.add(item,120,45)
28     w.value = gui.Label('Remove')
29     w.connect(gui.CLICK,c_remove,w)
30     
31 def c_remove(value):
32     w = value
33     c.remove(item)
34     w.value = gui.Label('Add')
35     w.connect(gui.CLICK,c_add,w)
36
37
38 w = gui.Button("Add")
39 w.connect(gui.CLICK,c_add,w)
40 c.add(w,10,45)
41
42 #################################
43 t = gui.Table(width=240,height=120)
44
45 tn = 0
46 tw = []
47 def t_add(value):
48     global tn
49     if (tn%6)==0: t.tr()
50     w = gui.Label(str(tn))
51     tw.append(w)
52     t.td(w)
53     tn+=1
54     
55 def t_remove(value):
56     if len(tw):
57         w = tw.pop()
58         t.remove(w)
59
60 t.tr()
61 w = gui.Button('Add')
62 w.connect(gui.CLICK,t_add,None)
63 t.td(w,colspan=3)
64
65 w = gui.Button('Remove')
66 w.connect(gui.CLICK,t_remove,None)
67 t.td(w,colspan=3)
68
69 #####################################
70 d = gui.Document(width=240,height=120)
71
72 dn = 0
73 dw = []
74 def d_add(value):
75     global dn
76     w = gui.Label("%d "%dn)
77     dw.append(w)
78     d.add(w)
79     dn+=1
80     
81 def d_remove(value):
82     if len(dw):
83         w = dw.pop()
84         d.remove(w)
85
86 w = gui.Button('Add')
87 w.connect(gui.CLICK,d_add,None)
88 d.add(w)
89 d.space((8,8))
90
91 w = gui.Button('Remove')
92 w.connect(gui.CLICK,d_remove,None)
93 d.add(w)
94 d.space((8,8))
95 #######################################
96
97 def tab():
98     box.widget = g.value
99     
100
101 g = gui.Group()
102 g.connect(gui.CHANGE,tab)
103
104 tt = gui.Table()
105 tt.tr()
106
107 b = gui.Tool(g,gui.Label("Container"),c)
108 tt.td(b)
109 b = gui.Tool(g,gui.Label("Table"),t)
110 tt.td(b)
111 b = gui.Tool(g,gui.Label("Document"),d)
112 tt.td(b)
113
114 tt.tr()
115 spacer = gui.Spacer(240,120)
116 box = gui.ScrollArea(spacer,height=120)
117 tt.td(box,style={'border':1},colspan=3)
118
119 app.connect(gui.QUIT,app.quit,None)
120 app.run(tt)

UCC git Repository :: git.ucc.asn.au