Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / simulator / pgu-0.18 / examples / gui7.py
1 """<title>Custom Actions</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 class ColorDialog(gui.Dialog):
11     def __init__(self,value,**params):
12         self.value = list(gui.parse_color(value))
13         
14         title = gui.Label("Color Picker")
15         
16         main = gui.Table()
17         
18         main.tr()
19         
20         self.color = gui.Color(self.value,width=64,height=64)
21         main.td(self.color,rowspan=3,colspan=1)
22         
23         ##The sliders CHANGE events are connected to the adjust method.  The 
24         ##adjust method updates the proper color component based on the value
25         ##passed to the method.
26         ##::
27         main.td(gui.Label(' Red: '),1,0)
28         e = gui.HSlider(value=self.value[0],min=0,max=255,size=32,width=128,height=16)
29         e.connect(gui.CHANGE,self.adjust,(0,e))
30         main.td(e,2,0)
31         ##
32
33         main.td(gui.Label(' Green: '),1,1)
34         e = gui.HSlider(value=self.value[1],min=0,max=255,size=32,width=128,height=16)
35         e.connect(gui.CHANGE,self.adjust,(1,e))
36         main.td(e,2,1)
37
38         main.td(gui.Label(' Blue: '),1,2)
39         e = gui.HSlider(value=self.value[2],min=0,max=255,size=32,width=128,height=16)
40         e.connect(gui.CHANGE,self.adjust,(2,e))
41         main.td(e,2,2)
42                         
43         gui.Dialog.__init__(self,title,main)
44         
45     ##The custom adjust handler.
46     ##::
47     def adjust(self,value):
48         (num, slider) = value
49         self.value[num] = slider.value
50         self.color.repaint()
51         self.send(gui.CHANGE)
52     ##
53
54 if __name__ == '__main__':
55     app = gui.Desktop()
56     app.connect(gui.QUIT,app.quit,None)
57     
58     c = gui.Table(width=640,height=480)
59     
60     dialog = ColorDialog("#00ffff")
61             
62     e = gui.Button("Color")
63     e.connect(gui.CLICK,dialog.open,None)
64     c.tr()
65     c.td(e)
66     
67     app.run(c)
68

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