5b580422609ebf5fc969d2a5bf7442c788ef8e38
[matches/honours.git] / research / transmission_spectroscopy / simulator / pgu-0.18 / examples / gui8.py
1 """<title>Forms</title>"""
2 import pygame
3 from pygame.locals import *
4
5 # the following line is not needed if pgu is installed
6 import sys; sys.path.insert(0, "..")
7
8 from pgu import gui
9
10 from gui7 import ColorDialog
11
12 class NewDialog(gui.Dialog):
13     def __init__(self,**params):
14         title = gui.Label("New Picture...")
15         
16         ##Once a form is created, all the widgets that are added with a name
17         ##are added to that form.
18         ##::
19         self.value = gui.Form()
20         
21         t = gui.Table()
22         
23         t.tr()
24         t.td(gui.Label("Size"),align=0,colspan=2)
25         
26         tt = gui.Table()
27         tt.tr()
28         tt.td(gui.Label("Width: "),align=1)
29         tt.td(gui.Input(name="width",value=256,size=4))
30         tt.tr()
31         tt.td(gui.Label("Height: "),align=1)
32         tt.td(gui.Input(name="height",value=256,size=4))
33         t.tr()
34         t.td(tt,colspan=2)
35         ##
36         
37         t.tr()
38         t.td(gui.Spacer(width=8,height=8))
39         t.tr()
40         t.td(gui.Label("Format",align=0))
41         t.td(gui.Label("Background",align=0))
42
43         t.tr()        
44         g = gui.Group(name="format",value="rgb")
45         tt = gui.Table()
46         tt.tr()
47         tt.td(gui.Radio(g,value="rgb"))
48         tt.td(gui.Label(" RGB"),align=-1)
49         tt.tr()
50         tt.td(gui.Radio(g,value="bw"))
51         tt.td(gui.Label(" Grayscale"),align=-1)
52         t.td(tt,colspan=1)
53         
54         g = gui.Group(name="color",value="#ffffff")
55         tt = gui.Table()
56         tt.tr()
57         tt.td(gui.Radio(g,value="#000000"))
58         tt.td(gui.Label(" Black"),align=-1)
59         tt.tr()
60         tt.td(gui.Radio(g,value="#ffffff"))
61         tt.td(gui.Label(" White"),align=-1)
62         tt.tr()
63         
64         default = "#ffffff"
65         radio = gui.Radio(g,value="custom")
66         color = gui.Color(default,width=40,height=16,name="custom")
67         picker = ColorDialog(default)
68         
69         color.connect(gui.CLICK,gui.action_open,{'container':t,'window':picker})
70         picker.connect(gui.CHANGE,gui.action_setvalue,(picker,color))
71
72         tt.td(radio)
73         tt.td(color)
74         
75         t.td(tt,colspan=1)
76         
77         t.tr()
78         t.td(gui.Spacer(width=8,height=8))
79         
80         ##The okay button CLICK event is connected to the Dailog's 
81         ##send event method.  It will send a gui.CHANGE event.
82         ##::
83         t.tr()
84         e = gui.Button("Okay")
85         e.connect(gui.CLICK,self.send,gui.CHANGE)
86         t.td(e)
87         ##
88         
89         e = gui.Button("Cancel")
90         e.connect(gui.CLICK,self.close,None)
91         t.td(e)
92         
93         gui.Dialog.__init__(self,title,t)
94
95 if __name__ == '__main__':
96     app = gui.Desktop()
97     app.connect(gui.QUIT,app.quit,None)
98     
99     c = gui.Table(width=640,height=480)
100     
101     dialog = NewDialog()
102     
103     ##The dialog's CHANGE event is connected to this function that will display the form values.
104     ##::
105     def onchange(value):
106         print('-----------')
107         for k,v in value.value.items():
108             print(k,v)
109         value.close()
110     
111     dialog.connect(gui.CHANGE,onchange,dialog)
112     ##
113             
114     e = gui.Button("New")
115     e.connect(gui.CLICK,dialog.open,None)
116     c.tr()
117     c.td(e)
118     
119     app.run(c)
120     #import profile
121     #profile.run('app.run(c)')

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