Changeset 1082

Show
Ignore:
Timestamp:
10/31/08 08:56:20 (2 months ago)
Author:
bhimebau
Message:

interconnection between visualizer and the control panel still needed

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • analog/pyeac/branches/pyeac_pygame/controlpanel.py

    r1081 r1082  
    1111from pgu import gui 
    1212 
    13 screen = pygame.display.set_mode((1024,600),SWSURFACE) 
    14 form = gui.Form() 
    15  
    16  
    1713class CellControl(gui.Table): 
    1814    def __init__(self,**params): 
     
    2117        
    2218        self.tr() 
    23         g = gui.Group(name="%s-type"%(params['pin']),value='V') 
     19        g = gui.Group(name="%s,type"%(params['pin']),value='V') 
    2420        self.td(gui.Radio(g,value='V')) 
    2521        self.td(gui.Radio(g,value='I')) 
     
    2824        self.tr() 
    2925        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'])) 
    3127        self.td(e) 
    3228         
    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) 
    3430        self.td(e) 
    3531         
     
    3834        gui.Table.__init__(self,**params) 
    3935        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) 
    4541 
    4642        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) 
    5248 
    5349        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) 
    5955 
    6056        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) 
    6662 
    6763        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 
     70class 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     
    7381 
    7482 
    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) 
     83if __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) 
    8091 
    81 _form = form.results() 
    82 _quit = 0 
    83 while not _quit: 
    8492    _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  
    88__license__ = "GPL v3" 
    99 
     10 
     11def 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 
    1024if __name__ == '__main__': 
    1125    from visualizer import Visualizer 
     
    1529    import random 
    1630    from pygame.locals import *     
     31    from pgu import gui 
     32    from controlpanel import EacPanel, TableBorder 
     33 
    1734 
    1835    phyeac = ueac(ueac_device='/dev/ttyUSB0')  # Connect to the uEAC device 
     
    3047         
    3148    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)
    3451    pygame.display.set_caption("EAC Framework") 
    3552    pygame.display.set_icon(pygame.image.load('uEAC_icon.png')) 
    3653 
     54 
    3755    phyeac_vis = Visualizer((0,0,100)) 
     56    phyeac_vis.update(phyeac.voltage_values) 
     57 
    3858    simeac_vis = Visualizer() 
     59    simeac_vis.update(simeac.evaluate()) 
    3960 
     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() 
    4074    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 
    4182        for event in pygame.event.get(): 
    4283            if event.type == QUIT: 
    4384                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) 
    4786 
    48         screen.blit(phyeac_vis.surface,(0,0)) 
    49         screen.blit(simeac_vis.surface,(524,0)) 
    50          
    51         simeac_vis.update(simeac.evaluate()) 
    5287        phyeac.read_v() 
    5388        phyeac_vis.update(phyeac.voltage_values) 
    5489 
    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) 
    5694 
    57      
     95        pygame.display.flip() 
     96#        print clock.tick() 
    5897 
    5998 
  • analog/pyeac/branches/pyeac_pygame/visualizer.py

    r1078 r1082  
    1111    def __init__(self, fill_color=(100,0,0)): 
    1212        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)) 
    1515        for y in range(5): 
    1616            for x in range(5): 
    1717                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) 
    2020     
    2121    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)) 
    2323        self.surface.fill(color,fill_window) 
    2424                 
    2525    def set_all(self,color): 
    26         fill_window = Rect((0,0),(500,500)) 
     26        fill_window = Rect((0,0),(300,300)) 
    2727        self.surface.fill(color,fill_window) 
    2828