Changeset 1082
- Timestamp:
- 10/31/08 08:56:20 (2 months ago)
- Files:
-
- analog/pyeac/branches/pyeac_pygame/controlpanel.py (modified) (4 diffs)
- analog/pyeac/branches/pyeac_pygame/main.py (modified) (3 diffs)
- analog/pyeac/branches/pyeac_pygame/visualizer.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
analog/pyeac/branches/pyeac_pygame/controlpanel.py
r1081 r1082 11 11 from pgu import gui 12 12 13 screen = pygame.display.set_mode((1024,600),SWSURFACE)14 form = gui.Form()15 16 17 13 class CellControl(gui.Table): 18 14 def __init__(self,**params): … … 21 17 22 18 self.tr() 23 g = gui.Group(name="%s -type"%(params['pin']),value='V')19 g = gui.Group(name="%s,type"%(params['pin']),value='V') 24 20 self.td(gui.Radio(g,value='V')) 25 21 self.td(gui.Radio(g,value='I')) … … 28 24 self.tr() 29 25 self.td(gui.Label("",color=fg),align=0,width=50) 30 e = gui.HSlider(0,-200,200,size=8,width=50,height=16,name="%s -current"%(params['pin']))26 e = gui.HSlider(0,-200,200,size=8,width=50,height=16,name="%s,current"%(params['pin'])) 31 27 self.td(e) 32 28 33 e = gui.Input(value="f1",name="%s -function"%(params['pin']),size=5)29 e = gui.Input(value="f1",name="%s,function"%(params['pin']),size=5) 34 30 self.td(e) 35 31 … … 38 34 gui.Table.__init__(self,**params) 39 35 self.tr() 40 self.td(CellControl(pin='1 _1'),align=0)41 self.td(CellControl(pin='2 _1'),align=0)42 self.td(CellControl(pin='3 _1'),align=0)43 self.td(CellControl(pin='4 _1'),align=0)44 self.td(CellControl(pin='5 _1'),align=0)36 self.td(CellControl(pin='1,1'),align=0) 37 self.td(CellControl(pin='2,1'),align=0) 38 self.td(CellControl(pin='3,1'),align=0) 39 self.td(CellControl(pin='4,1'),align=0) 40 self.td(CellControl(pin='5,1'),align=0) 45 41 46 42 self.tr() 47 self.td(CellControl(pin='1 _2'),align=0)48 self.td(CellControl(pin='2 _2'),align=0)49 self.td(CellControl(pin='3 _2'),align=0)50 self.td(CellControl(pin='4 _2'),align=0)51 self.td(CellControl(pin='5 _2'),align=0)43 self.td(CellControl(pin='1,2'),align=0) 44 self.td(CellControl(pin='2,2'),align=0) 45 self.td(CellControl(pin='3,2'),align=0) 46 self.td(CellControl(pin='4,2'),align=0) 47 self.td(CellControl(pin='5,2'),align=0) 52 48 53 49 self.tr() 54 self.td(CellControl(pin='1 _3'),align=0)55 self.td(CellControl(pin='2 _3'),align=0)56 self.td(CellControl(pin='3 _3'),align=0)57 self.td(CellControl(pin='4 _3'),align=0)58 self.td(CellControl(pin='5 _3'),align=0)50 self.td(CellControl(pin='1,3'),align=0) 51 self.td(CellControl(pin='2,3'),align=0) 52 self.td(CellControl(pin='3,3'),align=0) 53 self.td(CellControl(pin='4,3'),align=0) 54 self.td(CellControl(pin='5,3'),align=0) 59 55 60 56 self.tr() 61 self.td(CellControl(pin='1 _4'),align=0)62 self.td(CellControl(pin='2 _4'),align=0)63 self.td(CellControl(pin='3 _4'),align=0)64 self.td(CellControl(pin='4 _4'),align=0)65 self.td(CellControl(pin='5 _4'),align=0)57 self.td(CellControl(pin='1,4'),align=0) 58 self.td(CellControl(pin='2,4'),align=0) 59 self.td(CellControl(pin='3,4'),align=0) 60 self.td(CellControl(pin='4,4'),align=0) 61 self.td(CellControl(pin='5,4'),align=0) 66 62 67 63 self.tr() 68 self.td(CellControl(pin='1_4'),align=0) 69 self.td(CellControl(pin='2_4'),align=0) 70 self.td(CellControl(pin='3_4'),align=0) 71 self.td(CellControl(pin='4_4'),align=0) 72 self.td(CellControl(pin='5_4'),align=0) 64 self.td(CellControl(pin='1,4'),align=0) 65 self.td(CellControl(pin='2,4'),align=0) 66 self.td(CellControl(pin='3,4'),align=0) 67 self.td(CellControl(pin='4,4'),align=0) 68 self.td(CellControl(pin='5,4'),align=0) 69 70 class TableBorder(): 71 72 def __init__(self): 73 self.surface = pygame.Surface((200,200)) 74 self.cellrect = pygame.Rect((0,0),(50,20)) 75 self.get_border() 76 77 def get_border(self): 78 pygame.draw.rect(self.surface,(255,255,255),self.cellrect,1) 79 return (self.surface) 80 73 81 74 82 75 app = gui.App() 76 ecc = EacPanel(border="1") 77 c = gui.Container(align=-1,valign=-1) 78 c.add(ecc,0,200) 79 app.init(c) 83 if __name__ == '__main__': 84 screen = pygame.display.set_mode((1024,600)) 85 form = gui.Form() 86 app = gui.App() 87 ecc = EacPanel() 88 c = gui.Container(align=-1,valign=-1) 89 c.add(ecc,0,325) 90 app.init(c) 80 91 81 _form = form.results()82 _quit = 083 while not _quit:84 92 _form = form.results() 85 # print _form 86 screen.fill((0,0,0)) #clear the screen 87 for e in pygame.event.get(): 88 if e.type is QUIT: _quit = 1 89 if e.type is KEYDOWN and e.key == K_ESCAPE: _quit = 1 90 app.event(e) 91 app.paint(screen) 92 pygame.display.flip() 93 _quit = 0 94 while not _quit: 95 _form = form.results() 96 # print _form 97 screen.fill((0,0,0)) #clear the screen 98 for e in pygame.event.get(): 99 if e.type is QUIT: _quit = 1 100 if e.type is KEYDOWN and e.key == K_ESCAPE: _quit = 1 101 app.event(e) 102 app.paint(screen) 103 pygame.display.flip() analog/pyeac/branches/pyeac_pygame/main.py
r1080 r1082 8 8 __license__ = "GPL v3" 9 9 10 11 def diff_dict(before,after): 12 changed = 0 13 diff_dict = {} 14 bkeys = before.keys() 15 for key in bkeys: 16 if before[key] != after[key]: 17 diff_dict[key] = after[key] 18 changed = 1 19 if changed: 20 return(diff_dict) 21 else: 22 return(None) 23 10 24 if __name__ == '__main__': 11 25 from visualizer import Visualizer … … 15 29 import random 16 30 from pygame.locals import * 31 from pgu import gui 32 from controlpanel import EacPanel, TableBorder 33 17 34 18 35 phyeac = ueac(ueac_device='/dev/ttyUSB0') # Connect to the uEAC device … … 30 47 31 48 pygame.init() 32 window_size = (1024,600)33 screen = pygame.display.set_mode(window_size,RESIZABLE,32)49 screen = pygame.display.set_mode((1000,550)) 50 screen.set_colorkey((0,0,0)) 34 51 pygame.display.set_caption("EAC Framework") 35 52 pygame.display.set_icon(pygame.image.load('uEAC_icon.png')) 36 53 54 37 55 phyeac_vis = Visualizer((0,0,100)) 56 phyeac_vis.update(phyeac.voltage_values) 57 38 58 simeac_vis = Visualizer() 59 simeac_vis.update(simeac.evaluate()) 39 60 61 form = gui.Form() 62 app = gui.App() 63 ecc = EacPanel() 64 c = gui.Container(align=-1,valign=-1) 65 c.add(ecc,0,325) 66 app.init(c) 67 68 _form = form.results() 69 _quit = 0 70 71 tb = TableBorder() 72 73 clock = pygame.time.Clock() 40 74 while True: 75 _form_last = _form 76 _form = form.results() 77 changes = diff_dict(_form_last,_form) 78 if changes != None: 79 print changes 80 simeac_vis.update(simeac.evaluate()) 81 41 82 for event in pygame.event.get(): 42 83 if event.type == QUIT: 43 84 exit() 44 if event.type == VIDEORESIZE: 45 window_size = event.size 46 screen = pygame.display.set_mode(window_size,RESIZABLE,32) 85 app.event(event) 47 86 48 screen.blit(phyeac_vis.surface,(0,0))49 screen.blit(simeac_vis.surface,(524,0))50 51 simeac_vis.update(simeac.evaluate())52 87 phyeac.read_v() 53 88 phyeac_vis.update(phyeac.voltage_values) 54 89 55 pygame.display.update() 90 screen.fill((0,0,0)) 91 screen.blit(phyeac_vis.surface,(0,0)) 92 screen.blit(simeac_vis.surface,(485,0)) 93 app.paint(screen) 56 94 57 95 pygame.display.flip() 96 # print clock.tick() 58 97 59 98 analog/pyeac/branches/pyeac_pygame/visualizer.py
r1078 r1082 11 11 def __init__(self, fill_color=(100,0,0)): 12 12 self.fill_color = fill_color 13 self.surface = pygame.Surface(( 500,500))14 fill_window = Rect((0,0),( 100,100))13 self.surface = pygame.Surface((300,300)) 14 fill_window = Rect((0,0),(60,60)) 15 15 for y in range(5): 16 16 for x in range(5): 17 17 self.surface.fill(fill_color,fill_window) 18 fill_window = fill_window.move( 100,0)19 fill_window = fill_window.move(- 500,100)18 fill_window = fill_window.move(60,0) 19 fill_window = fill_window.move(-300,60) 20 20 21 21 def set_block(self, pos, color): 22 fill_window = Rect((pos[0]* 100,pos[1]*100),(100,100))22 fill_window = Rect((pos[0]*60,pos[1]*60),(60,60)) 23 23 self.surface.fill(color,fill_window) 24 24 25 25 def set_all(self,color): 26 fill_window = Rect((0,0),( 500,500))26 fill_window = Rect((0,0),(300,300)) 27 27 self.surface.fill(color,fill_window) 28 28
