Merge branch 'master' of git.ucc.asn.au:/matches/honours
[matches/honours.git] / research / transmission_spectroscopy / simulator / pgu-0.18 / examples / html4.py
1 """<title>an example of a custom html dialog with python connections</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 from pgu import html
10
11 from gui7 import ColorDialog
12
13 class NewDialog(gui.Dialog):
14     def __init__(self,**params):
15         title = gui.Label("New Picture...")
16         
17         ##Note how the global variables are set for the scripting of HTML
18         ##::        
19         picker = ColorDialog("#ffffff")
20         doc = html.HTML(globals={'gui':gui,'dialog':self,'picker':picker},data="""
21 <form id='form'>
22
23 <table>
24
25 <tr><td colspan='2' align='center'>
26 Size
27 <tr><td colspan='2' align='center'>
28 <table>
29 <tr><td align=right>Width: <td><input type='text' size='4' value='256' name='width'>
30 <tr><td align=right>Height: <td><input type='text' size='4' value='256' name='height'>
31 </table>
32
33 <tr><td>Format<td>Background
34
35 <tr><td>
36 <input type='radio' name='format' value='rgb' checked> RGB<br>
37 <input type='radio' name='format' value='bw'> Grayscale
38 <td>
39 <input type='radio' name='background' value='#000000'> Black<br>
40 <input type='radio' name='background' value='#ffffff' checked> White<br>
41 <input type='radio' name='background' value='custom'> <object type='gui.Color' width=48 height=16 value='#ffffff' name='custom' border=1 onclick='picker.open()'>
42
43 <tr><td colspan=2><input type='button' value='Okay' onclick='dialog.send(gui.CHANGE)'> <input type='button' value='Cancel' onclick='dialog.close()'>
44
45 </table>
46
47 """)
48         gui.Dialog.__init__(self,title,doc)
49         
50         picker.connect(gui.CHANGE,gui.action_setvalue,(picker,doc['form']['custom']))
51         ##
52         
53         self.value = doc['form']
54
55
56
57 if __name__ == '__main__':
58     app = gui.Desktop()
59     app.connect(gui.QUIT,app.quit,None)
60     
61     c = gui.Table(width=640,height=480)
62     
63     dialog = NewDialog()
64     
65     ##The dialog's CHANGE event is connected to this function that will display the form values.
66     ##::
67     def onchange(value):
68         print('-----------')
69         for k,v in value.value.items():
70             print(k,v)
71         value.close()
72     
73     dialog.connect(gui.CHANGE,onchange,dialog)
74     ##
75             
76     e = gui.Button("New")
77     e.connect(gui.CLICK,dialog.open,None)
78     c.tr()
79     c.td(e)
80     
81     app.run(c)
82     #import profile
83     #profile.run('app.run(c)')

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