Changeset 36ce0b5 in sasview


Ignore:
Timestamp:
Jul 20, 2011 10:26:53 AM (13 years ago)
Author:
Gervaise Alina <gervyh@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
be98b3d
Parents:
075526b
Message:

working on data grid

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guiframe/data_processor.py

    rcb26857 r36ce0b5  
    106106        self.manager = manager 
    107107        self.data = data 
    108         self.grid = GridPage(self, panel=self.parent) 
    109         self.AddPage(self.grid, "Batch") 
    110         self.grid.SetFocus() 
    111108         
    112109    def set_data(self, data): 
    113110        if data is None: 
    114             data = {} 
    115         pos = self.GetSelection() 
    116         if pos != -1: 
    117             selected_page = self.GetPage(pos) 
    118             selected_page.set_data(data)   
    119111            return 
    120         if  len(data) > 0: 
    121             self.data = data 
    122             self.col_names = data.keys() 
    123             self.col_names.sort()  
    124             self._cols = len(self.data.keys())  
    125             self._rows = max([len(v) for v in self.data.values()])  
    126             selected_page.SetNumberRows(int(self._rows)) 
    127             selected_page.SetNumberCols(int(self._cols)) 
    128             for index  in range(len(self.col_names)): 
    129                 self.SetColLabelValue(index, str(self.col_names[index])) 
    130         return 
    131          
    132         if  len(data) > 0: 
    133             self.data = data 
    134             self.col_names = data.keys() 
    135             self.col_names.sort()  
    136             self._cols = len(self.data.keys())  
    137             self._rows = max([len(v) for v in self.data.values()])  
    138             for index in xrange(self._rows): 
    139                 self.row_names.append( str(index)) 
    140                 self.AppendRows(index)   
    141                 self.SetColLabelValue(index) 
    142           
    143             #AppendCols(self, numCols, updateLabels) 
    144             #SetColLabelValue(int col, const wxString& value) 
    145             #AppendRows(self, numRows, updateLabels)     
    146         
    147  
    148 class TableBase(Grid.PyGridTableBase): 
    149     """ 
    150      grid receiving dictionary data structure as input 
    151     """ 
    152     def __init__(self, data=None): 
    153         """data is a dictionary of key=column_name , value list of row value. 
    154          
    155         :Note: the value stored in the list will be append to the grid in the same order . 
    156         :example:data = {col_1:[value1, value2], col_2:[value11, value22]} 
    157         +--------++--------++--------+ 
    158         | Index  | col_1    | col2   | 
    159         +--------++--------++--------+ 
    160         | Index1 | value1  | value2  | 
    161         +--------++--------++--------+ 
    162         | Index2 | value11  | value22| 
    163         +--------++--------++--------+ 
    164         """ 
    165         # The base class must be initialized *first* 
    166         Grid.PyGridTableBase.__init__(self) 
    167         self.data = {} 
    168         self._rows = 0 
    169         self._cols = 0 
    170         self.col_names = [] 
    171         self.row_names = [] 
    172          
    173         if data is None: 
    174             data = {} 
    175         self.set_data(data) 
    176          
    177     def set_data(self, data): 
    178         if  len(data) > 0: 
    179             self.data = data 
    180             self.col_names = data.keys() 
    181             self.col_names.sort()  
    182             self._cols = len(self.data.keys())  
    183             self._rows = max([len(v) for v in self.data.values()])  
    184             for index in xrange(self._rows): 
    185                 self.row_names.append( str(index)) 
    186           
    187      
    188            
    189     def GetNumberCols(self): 
    190         return self._cols 
    191  
    192     def GetNumberRows(self): 
    193         return self._rows 
    194  
    195     def GetColLabelValue(self, col): 
    196         if len(self.col_names) > col: 
    197             return self.col_names[col] 
    198          
    199     def GetRowLabelValue(self, row): 
    200         if len(self.row_names) > row: 
    201             return self.row_names[row] 
    202  
    203     def GetValue(self, row, col): 
    204         pos = int(row) 
    205         if len(self.data[self.col_names[col]]) > pos: 
    206             return str(self.data[self.col_names[col]][pos]) 
    207  
    208     def GetRawValue(self, row, col): 
    209         pos = int(row) 
    210         if len(self.data[self.col_names[col]]) > pos: 
    211             return self.data[self.col_names[col]][row] 
    212  
    213     def SetValue(self, row, col, value): 
    214         if len(self.data) == 0: 
    215             return 
    216         pos = int(row) 
    217         if len(self.data[self.col_names[col]]) > pos: 
    218             self.data[self.col_names[col]][row] = value 
    219              
    220     def getRaw(self, row): 
    221         pos = int(row) 
    222         row_value = [] 
    223         for col in xrange(self.data.values()): 
    224             if len(col) < pos: 
    225                 row_value.append(None) 
    226             else: 
    227                 row_value.append(col[pos]) 
    228         return row_value 
    229              
    230  
    231 class Table(Grid.Grid): 
    232     def __init__(self, parent, data=None): 
    233         """ 
    234         """ 
    235         Grid.Grid.__init__(self, parent, -1) 
    236         self._table = TableBase(data=data) 
    237         self.SetTable(self._table) 
    238         self.Bind(Grid.EVT_GRID_LABEL_RIGHT_CLICK, self.on_context_menu) 
    239          
    240     def on_context_menu(self, event): 
    241         row, col = event.GetRow(), event.GetCol() 
    242         print "right click", row, col 
    243          
    244     def set_data(self, data): 
    245         self._table.set_data(data) 
     112             
     113        grid = GridPage(self, panel=self.parent) 
     114        grid.set_data(data)   
     115        self.AddPage(grid, "Batch") 
     116      
    246117         
    247118class SPanel(ScrolledPanel): 
Note: See TracChangeset for help on using the changeset viewer.