Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / simulator / pgu-0.18 / examples / gui14.py
1 """an example of add, remove for several container types"""
2
3 #this example contains a bit of a HACK
4 #when something is added/removed, chsize() may need to be called
5 #to ensure proper refresh of the screen, etc
6 #this may be fixed in the future, but for now, chsize must be called
7 #by hand
8
9 import pygame
10 from pygame.locals import *
11
12 # the following line is not needed if pgu is installed
13 import sys; sys.path.insert(0, "..")
14
15 from pgu import gui
16 from pgu import html
17
18 app = gui.Desktop()
19
20 c = gui.Container(width=240,height=120)
21
22 def i_disable(value):
23     item.disabled = True
24     item.blur()
25     item.chsize()
26
27 item = gui.Button(gui.Label('Disable'))
28 item.connect(gui.CLICK,i_disable,None)
29
30 def c_add(value):
31     w = value
32     c.add(item,120,45)
33     w.value = gui.Label('Remove')
34     # Note - we need to disconnect the old signal handler first
35     w.disconnect(gui.CLICK)
36     w.connect(gui.CLICK,c_remove,w)
37     
38 def c_remove(value):
39     w = value
40     c.remove(item)
41     w.value = gui.Label('Add')
42     # Note - we need to disconnect the old signal handler first
43     w.disconnect(gui.CLICK)
44     w.connect(gui.CLICK,c_add,w)
45
46
47 w = gui.Button("Add")
48 w.connect(gui.CLICK,c_add,w)
49 c.add(w,10,45)
50
51
52 t = gui.Table(width=240,height=120)
53
54 tn = 0
55 tw = []
56 def t_add(value):
57     global tn
58     if (tn%6)==0: t.tr()
59     w = gui.Label(str(tn))
60     tw.append(w)
61     t.td(w)
62     tn+=1
63     
64 def t_remove(value):
65     if len(tw):
66         w = tw.pop()
67         t.remove(w)
68
69 t.tr()
70 w = gui.Button('Add')
71 w.connect(gui.CLICK,t_add,None)
72 t.td(w,colspan=3)
73
74 w = gui.Button('Remove')
75 w.connect(gui.CLICK,t_remove,None)
76 t.td(w,colspan=3)
77
78 d = gui.Document(width=240,height=120)
79
80 dn = 0
81 dw = []
82 def d_add(value):
83     global dn
84     w = gui.Label("%d "%dn)
85     dw.append(w)
86     d.add(w)
87     dn+=1
88     
89 def d_remove(value):
90     if len(dw):
91         w = dw.pop()
92         d.remove(w)
93
94 w = gui.Button('Add')
95 w.connect(gui.CLICK,d_add,None)
96 d.add(w)
97 d.space((8,8))
98
99 w = gui.Button('Remove')
100 w.connect(gui.CLICK,d_remove,None)
101 d.add(w)
102 d.space((8,8))
103
104
105 tt = gui.Table()
106 tt.tr()
107 tt.td(gui.Label("Container"))
108 tt.tr()
109 tt.td(c,style={'border':1})
110
111 tt.tr()
112 tt.td(gui.Label("Table"))
113 tt.tr()
114 tt.td(t,style={'border':1})
115
116 tt.tr()
117 tt.td(gui.Label("Document"))
118 tt.tr()
119 tt.td(d,style={'border':1})
120
121 app.connect(gui.QUIT,app.quit,None)
122 app.run(tt)

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