Changeset 1106

Show
Ignore:
Timestamp:
11/10/08 14:57:18 (2 months ago)
Author:
bhimebau
Message:

context sensitive selection working

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • analog/pyeac/trunk/eeepc/controlpanel.py

    r1094 r1106  
    1919        
    2020        self.tr() 
    21         g = gui.Group(name="%s,type"%(params['pin']),value='V') 
    22         self.td(gui.Radio(g,value='V')) 
    23         self.td(gui.Radio(g,value='I')) 
    24         self.td(gui.Radio(g,value='L')) 
     21        self.type_selector = gui.Group(name="%s,type"%(params['pin']),value='V') 
     22        self.td(gui.Radio(self.type_selector,value='V')) 
     23        self.td(gui.Radio(self.type_selector,value='I')) 
     24        self.td(gui.Radio(self.type_selector,value='L')) 
    2525 
    2626        self.tr() 
    2727        self.td(gui.Label("",color=fg),align=0,width=50) 
    28         e = gui.HSlider(0,-200,200,size=8,width=50,height=16,name="%s,current"%(params['pin'])) 
    29         self.td(e
    30          
    31         e = gui.Input(value="1",name="%s,function"%(params['pin']),size=5) 
    32         self.td(e
     28        self.current_slider = gui.HSlider(0,-200,200,size=8,width=50,height=16,name="%s,current"%(params['pin'])) 
     29        self.td(self.current_slider
     30         
     31        self.lla_function_input = gui.Input(value="1",name="%s,function"%(params['pin']),size=5) 
     32        self.td(self.lla_function_input
    3333         
    3434class EacPanel(gui.Table): 
     
    9696            self.ledofff() 
    9797             
     98class Context_Sensitive_Panel(gui.Table): 
     99     
     100    def __init__(self, pin_grid, active_cell, **params): 
     101        gui.Table.__init__(self,**params) 
     102 
     103#         self.cc = CellControl(pin="1,1") 
     104        fg = (255,255,255) 
     105        self.id_label = gui.Label("%d,%d"%(active_cell),color=fg) 
     106        self.voltage_label = gui.Label("%4.3f"%(0.000),color=fg) 
     107        self.input_current_label = gui.Label("%4.3f" % (0.0),color=fg) 
     108        self.output_current_label = gui.Label("%4.3f" % (0.0),color=fg) 
     109        self.cell_type = gui.Select(value="voltage",name="cell_type") 
     110        self.cell_type.add("Voltage","voltage") 
     111        self.cell_type.add("Current","current") 
     112        self.cell_type.add("LLA","lla") 
     113        self.current_slider = gui.HSlider(0,-200,200,size=8,width=150,height=20,name="cslider") 
     114        self.current_input = gui.Input(value="0",name="ctext_box",size=10) 
     115        self.lla_function_input = gui.Input(value="1",name="lla_f_select",size=10,align=0) 
     116     
     117        if active_cell != (0,0): 
     118            gui.Table.__init__(self,**params) 
     119            self.tr() 
     120            self.td(gui.Label("Edit Cell = ",color=fg),align=-1) 
     121            self.td(self.id_label,align=-1) 
     122            self.tr() 
     123            self.td(gui.Label("Voltage = ",color=fg),align=-1) 
     124            self.td(self.voltage_label,align=-1) 
     125            self.tr() 
     126            self.td(gui.Label("Mode = ",color=fg),align=-1) 
     127            self.td(self.cell_type,align=-1) 
     128            self.tr() 
     129            self.td(gui.Label("Input Current = ",color=fg),align=-1) 
     130            self.td(self.input_current_label,align=-1) 
     131            self.tr() 
     132            self.td(gui.Label("Output Current = ",color=fg),align=-1) 
     133            self.td(self.output_current_label,align=-1) 
     134            self.tr() 
     135            self.td(gui.Label("Current Source/Sink = ",color=fg),align=-1) 
     136            self.td(self.current_slider,align=-1) 
     137            self.td(self.current_input,align=0) 
     138            self.tr() 
     139            self.td(gui.Label("LLA Function = ",color=fg),align=-1) 
     140            self.td(self.lla_function_input,align=-1) 
     141 
     142    def set_controls (self, pg, active_cell): 
     143        self.id_label.value = "%d,%d"%(active_cell) 
     144        (ax,ay) = active_cell 
     145 
     146        self.voltage_label.value = "%4.3f"%(float(pg.grid[ay-1][ax-1].voltage)) 
     147 
     148        if pg.grid[ay-1][ax-1].mode == "V": 
     149            self.input_current_label.value = "%d"%(0) 
     150            self.output_current_label.value = "%d"%(0) 
     151         
     152        elif pg.grid[ay-1][ax-1].mode == "S": 
     153            self.input_current_label.value = "%d"%(0) 
     154            if pg.grid[ay-1][ax-1].current_output != None: 
     155                self.output_current_label.value = "%d"%(int(pg.grid[ay-1][ax-1].current_output)) 
     156            else: 
     157                self.output_current_label.value = "%d"%(0) 
     158 
     159        elif pg.grid[ay-1][ax-1].mode == "L": 
     160            value = pg.lla_dict[pg.grid[ay-1][ax-1].lla_tag].input_current                         
     161            if value != None: 
     162                self.input_current_label.value = "%d"%(int(value))             
     163            value = pg.lla_dict[pg.grid[ay-1][ax-1].lla_tag].output_current             
     164 
     165            if value != None: 
     166                self.output_current_label.value = "%d"%(int(value))             
     167 
     168#         if pg.grid[ay-1][ax-1].current_input != None: 
     169#             self.input_current_label.value = "%d"%(int(pg.grid[ay-1][ax-1].current_input)) 
     170#         else: 
     171#             self.input_current_label.value = "%d"%(0) 
     172#  
     173#         if pg.grid[ay-1][ax-1].current_output != None: 
     174#             self.output_current_label.value = "%d"%(int(pg.grid[ay-1][ax-1].current_output)) 
     175#         else: 
     176#             self.output_current_label.value = "%d"%(0) 
     177 
     178      
     179    def update_selector_text(self, pg, active_cell): 
     180        (ax,ay) = active_cell 
     181        if pg.grid[ay-1][ax-1].mode == "V": 
     182            self.cell_type.value = "voltage" 
     183            self.current_slider.value = "0" 
     184            self.lla_function_input.value = "1" 
     185        elif pg.grid[ay-1][ax-1].mode == "S": 
     186            self.cell_type.value = "current" 
     187            self.current_slider.value = int(pg.grid[ay-1][ax-1].current_output) 
     188            self.lla_function_input.value = "1" 
     189        elif pg.grid[ay-1][ax-1].mode == "L": 
     190            self.cell_type.value = "lla" 
     191            self.current_slider.value = "0" 
     192            value = pg.lla_dict[pg.grid[ay-1][ax-1].lla_tag].function 
     193            self.lla_function_input.value = value 
     194 
    98195if __name__ == '__main__': 
    99196    screen = pygame.display.set_mode((1024,600)) 
  • analog/pyeac/trunk/eeepc/eac_physical.py

    r1104 r1106  
    193193        self.ueac.lon() 
    194194 
    195     def update(self, update_dict, full_form): 
    196         for key in update_dict.keys(): 
    197             (x,y,op) =  key.split(',') 
    198             x = int(x) 
    199             y = int(y) 
    200             value = update_dict[key] 
    201             if op == 'type': 
    202                 if value == 'V': 
    203                     self.set_voltage_input((x,y)) 
    204                 if value == 'I': 
    205                     current_value_key = "%s,%s,current"%(x,y) 
    206                     self.set_current_source((x,y),int(full_form[current_value_key])) 
    207                 if value == 'L': 
    208                     current_value_key = "%d,%d,function"%(x,y) 
    209                     value = int(full_form[current_value_key]) 
    210                     if value > 0 and value < 27: 
    211                         self.lla_add("L%d,%d"%(x,y),(x,y),(0,0),value,1) 
    212             elif op == 'function': 
    213                 if self.grid[y-1][x-1].mode == 'L': 
    214                     try: 
    215                         value = int(value) 
    216                         valid_value = True 
    217                     except ValueError: 
    218                         valid_value = False 
    219                      
    220                     if valid_value and value > 0 and value < 28: 
    221                         self.lla_add("L%d,%d"%(x,y),(x,y),(0,0),value,1) 
    222                  
    223             elif op == "current": 
    224                 if self.grid[y-1][x-1].mode == 'S': 
    225                     self.set_current_source((x,y),int(value)) 
     195    def update(self, form, active_cell): 
     196#         print form, active_cell 
     197        if form['cell_type'] == 'voltage': 
     198            self.set_voltage_input(active_cell) 
     199        elif form['cell_type'] == 'current': 
     200            self.set_current_source(active_cell,int(form['cslider'])) 
     201        elif form['cell_type'] == 'lla': 
     202            self.lla_add("L%d,%d"%(active_cell),active_cell,(0,0),int(form['lla_f_select']),1) 
     203 
     204#         for key in update_dict.keys(): 
     205#             (x,y,op) =  key.split(',') 
     206#             x = int(x) 
     207#             y = int(y) 
     208#             value = update_dict[key] 
     209#             if op == 'type': 
     210#                 if value == 'V': 
     211#                     self.set_voltage_input((x,y)) 
     212#                 if value == 'I': 
     213#                     current_value_key = "%s,%s,current"%(x,y) 
     214#                     self.set_current_source((x,y),int(full_form[current_value_key])) 
     215#                 if value == 'L': 
     216#                     current_value_key = "%d,%d,function"%(x,y) 
     217#                     value = int(full_form[current_value_key]) 
     218#                     if value > 0 and value < 27: 
     219#                         self.lla_add("L%d,%d"%(x,y),(x,y),(0,0),value,1) 
     220#             elif op == 'function': 
     221#                 if self.grid[y-1][x-1].mode == 'L': 
     222#                     try: 
     223#                         value = int(value) 
     224#                         valid_value = True 
     225#                     except ValueError: 
     226#                         valid_value = False 
     227#                      
     228#                     if valid_value and value > 0 and value < 28: 
     229#                         self.lla_add("L%d,%d"%(x,y),(x,y),(0,0),value,1) 
     230#                   
     231#             elif op == "current": 
     232#                 if self.grid[y-1][x-1].mode == 'S': 
     233#                     self.set_current_source((x,y),int(value)) 
    226234        
    227235 
  • analog/pyeac/trunk/eeepc/pyeac.py

    r1095 r1106  
    2222        return(None) 
    2323 
     24def get_grid_square(pos): 
     25    (gbx,gby) = (315,0) 
     26    (gsx,gsy) = (60,60) 
     27    (posx,posy) = pos 
     28 
     29    posnx = posx - gbx 
     30    posny = posy - gby 
     31     
     32    if posnx < 0 or posny < 0: 
     33        sq = (0,0) 
     34    elif posnx >= 300 or posny >= 300: 
     35        sq = (0,0) 
     36    else: 
     37        sq = (int(posnx/gsx) + 1, int(posny/gsy) + 1) 
     38    return sq 
     39     
     40def get_highlighted_square(grid_sq, color): 
     41    (gx,gy) = grid_sq 
     42    rx = (gx-1) * 60 
     43    ry = (gy-1) * 60 
     44    hlsurf = pygame.Surface((300,300)) 
     45    hlsurf.set_colorkey((0,0,0)) 
     46    hlsurf.fill((0,0,0)) 
     47    pygame.draw.rect(hlsurf, color, Rect(rx,ry,60,60), 3) 
     48    return hlsurf 
     49 
    2450if __name__ == '__main__': 
    2551    from visualizer import Visualizer 
     
    3157    import sys; sys.path.insert(0, ".")  
    3258    from pgu import gui 
    33     from controlpanel import EacPanel, ButtonPanel 
     59    from controlpanel import EacPanel, ButtonPanel, Context_Sensitive_Panel 
    3460    from raw_display import RawDisplay 
    3561 
     
    4975    form = gui.Form() 
    5076    app = gui.App() 
    51     ecc = EacPanel() 
     77#    ecc = EacPanel() 
    5278    bcc = ButtonPanel(pg.reset, pg.lon, pg.lof) 
    5379 
    5480    c = gui.Container(align=-1,valign=-1) 
    55     c.add(ecc,0,325) 
     81#    c.add(ecc,0,325) 
     82 
     83 
     84    csp = Context_Sensitive_Panel(pg, (1,1)) 
     85    c.add(csp,0,325) 
     86 
    5687    c.add(bcc,650,100) 
    5788 
     
    6293     
    6394    clock = pygame.time.Clock() 
     95    mousepos = (315,0) 
     96    mouseb1pressed = False 
     97 
     98    chl_grid = (3,3) 
     99    operating_grid = (3,3) 
     100    highlighted_surface = get_highlighted_square((3,3), (255,255,255)) 
     101    selected_square_surface = get_highlighted_square((3,3), (255,0,0)) 
     102    active_cell = (3,3) 
     103    loop_counter = 0 
     104 
    64105    while True: 
    65106        _form_last = _form 
    66107        _form = form.results() 
    67108        changes = diff_dict(_form_last,_form) 
     109 
    68110        if changes != None: 
    69             pg.update(changes,_form
     111            pg.update(_form,active_cell
    70112 
    71113        for event in pygame.event.get(): 
    72114            if event.type == QUIT: 
    73115                exit() 
     116            if event.type == MOUSEMOTION: 
     117                active_grid = get_grid_square(event.pos) 
     118                if active_grid != (0,0) and active_grid != chl_grid: 
     119                    chl_grid = active_grid 
     120                    highlighted_surface = get_highlighted_square(active_grid, (255,255,255)) 
     121                
     122            if event.type == MOUSEBUTTONDOWN: 
     123                if event.button == 1: 
     124                    selected_grid = get_grid_square(event.pos) 
     125                    if selected_grid != (0,0): 
     126                        selected_square_surface = get_highlighted_square(selected_grid, (255,0,0)) 
     127                        active_cell = selected_grid 
     128                        csp.update_selector_text(pg, active_cell) 
    74129            app.event(event) 
    75130 
     
    77132        phyeac_vis.update(pg) 
    78133        phyeac_raw.update(pg) 
     134        csp.set_controls(pg, active_cell) 
    79135 
    80136        screen.fill((0,0,0)) 
    81137        screen.blit(phyeac_vis.surface,(0,0)) 
    82138        screen.blit(phyeac_raw.master_surface,(315,0)) 
     139        screen.blit(highlighted_surface,(315,0)) 
     140        if selected_square_surface != None: 
     141            screen.blit(selected_square_surface,(315,0)) 
     142             
    83143 
    84144        app.paint(screen)