Changeset 656d65d in sasview for sansguiframe/src/sans
- Timestamp:
- Sep 12, 2011 6:15:37 PM (13 years ago)
- 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:
- 8d57bdb
- Parents:
- 13382fc7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansguiframe/src/sans/guiframe/data_processor.py
r2073eb7 r656d65d 75 75 self.data_inputs = {} 76 76 self.data_outputs = {} 77 self.data = {} 77 78 self._cols = 50 78 79 self._rows = 51 79 80 col_with = 30 80 81 row_height = 20 82 self.max_row_touse = 0 81 83 self.axis_value = [] 82 84 self.axis_label = "" … … 90 92 self.Bind(wx.grid.EVT_GRID_LABEL_RIGHT_CLICK, self.on_right_click) 91 93 self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.on_selected_cell) 94 self.Bind(wx.grid.EVT_GRID_CMD_CELL_CHANGE, self.on_edit_cell) 95 96 def on_edit_cell(self, event): 97 """ 98 """ 99 row, col = event.GetRow(), event.GetCol() 100 if row > self.max_row_touse: 101 self.max_row_touse = row 102 event.Skip() 92 103 93 104 def on_selected_cell(self, event): … … 118 129 flag = event.CmdDown() or event.ControlDown() 119 130 col = event.GetCol() 120 if not flag:121 self.selected_cols = []122 self.axis_value = []123 self.axis_label = ""124 if col not in self.selected_cols:125 self.selected_cols.append(col)126 if not flag :127 for row in range(2, self.GetNumberRows()+ 1):128 self.axis_value.append(self.GetCellValue(row, col))129 row = 1130 self.axis_label = self.GetCellValue(row, col)131 131 event.Skip() 132 132 … … 135 135 Catch the right click mouse 136 136 """ 137 137 138 col = event.GetCol() 138 if col != -1 and len(self.col_names) > col: 139 label = self.col_names[int(col)] 140 self.axis_label = label 141 if label in self.data.keys(): 142 col_val = self.data[label] 143 self.axis_value = col_val 139 self.selected_cols = [] 140 self.selected_cols.append(col) 144 141 # Slicer plot popup menu 145 142 slicerpop = wx.Menu() 143 col_label_menu = wx.Menu() 144 slicerpop.AppendSubMenu(col_label_menu , 145 '&Insert Column', 'Insert Column') 146 hint = 'Insert empty column before the selected column' 146 147 id = wx.NewId() 147 slicerpop.Append(id, '&Set X axis', 'Set X axis') 148 wx.EVT_MENU(self, id, self.on_set_x_axis) 149 150 id = wx.NewId() 151 slicerpop.Append(id, '&Set Y axis', 'Set Y axis') 152 wx.EVT_MENU(self, id, self.on_set_y_axis) 153 pos = event.GetPosition() 148 col_label_menu.Append(id, '&Empty', hint) 149 wx.EVT_MENU(self, id, self.on_insert_column) 150 col_name = [self.GetCellValue(0, col) 151 for col in range(self.GetNumberCols())] 152 for label in self.data.keys(): 153 if label not in col_name: 154 id = wx.NewId() 155 hint = 'Insert %s column before the selected column' % str(label) 156 col_label_menu.Append(id, '&%s' % str(label), hint) 157 wx.EVT_MENU(self, id, self.on_insert_column) 158 id = wx.NewId() 159 hint = 'Remove selected column %s' 160 slicerpop.Append(id, 161 '&Remove Column', hint) 162 wx.EVT_MENU(self, id, self.on_remove_column) 163 164 pos = wx.GetMousePosition() 154 165 pos = self.ScreenToClient(pos) 155 166 self.PopupMenu(slicerpop, pos) 167 168 def on_remove_column(self, event): 169 """ 170 """ 171 if self.selected_cols is not None or len(self.selected_cols) > 0: 172 col = self.selected_cols[0] 173 # add data to the grid 174 row = 0 175 id = event.GetId() 176 col_name = self.GetCellValue(row, col) 177 self.data[col_name] = [] 178 for row in range(1, self.GetNumberRows()): 179 if row <= self.max_row_touse: 180 value = self.GetCellValue(row, col) 181 self.data[col_name].append(value) 182 for k , value_list in self.data.iteritems(): 183 if k != col_name: 184 length = len(value_list) 185 if length < self.max_row_touse: 186 diff = self.max_row_touse - length 187 for i in range(diff): 188 self.data[k].append("") 189 self.DeleteCols(pos=col, numCols=1, updateLabels=True) 190 self.AutoSize() 191 192 def on_insert_column(self, event): 193 """ 194 """ 195 if self.selected_cols is not None or len(self.selected_cols) > 0: 196 col = self.selected_cols[0] 197 # add data to the grid 198 row = 0 199 id = event.GetId() 200 col_name = event.GetEventObject().GetLabelText(id) 201 self.InsertCols(pos=col, numCols=1, updateLabels=True) 202 if col_name.strip() != "Empty": 203 self.SetCellValue(row, col, str(col_name.strip())) 204 if col_name in self.data.keys(): 205 value_list = self.data[col_name] 206 cell_row = 1 207 for value in value_list: 208 self.SetCellValue(cell_row, col, str(value)) 209 cell_row += 1 210 self.AutoSize() 211 156 212 157 213 def on_set_x_axis(self, event): … … 175 231 data_inputs = {} 176 232 self.data_inputs = data_inputs 177 233 self.data = {} 234 for item in (self.data_outputs, self.data_inputs): 235 self.data.update(item) 178 236 if len(self.data_outputs) > 0: 179 237 self._cols = self.GetNumberCols() … … 206 264 cell_row += 1 207 265 cell_col += 1 266 if cell_row > self.max_row_touse: 267 self.max_row_touse = cell_row 208 268 self.AutoSize() 209 269 … … 444 504 return axis 445 505 506 def on_save_column(self, parent): 507 """ 508 """ 509 pos = self.notebook.GetSelection() 510 grid = self.notebook.GetPage(pos) 511 if parent is not None and self.data is not None: 512 parent.write_batch_tofile(data=grid.data, 513 file_name=path, 514 details=self.details) 515 446 516 def on_plot(self, event): 447 517 """ … … 604 674 menubar = wx.MenuBar() 605 675 self.SetMenuBar(menubar) 676 """ 606 677 edit = wx.Menu() 607 menubar.Append(edit, "&Edit") 678 menubar.Append(edit, "&File") 679 save_menu = edit.Append(wx.NewId(), 'Save As', 'Save into File') 680 wx.EVT_MENU(self, save_menu.GetId(), self.on_save_column) 681 """ 608 682 self.Bind(wx.EVT_CLOSE, self.on_close) 609 683 610 add_col_menu = edit.Append(wx.NewId(), 'Add Column', 'Add column') 611 wx.EVT_MENU(self, add_col_menu.GetId(), self.on_add_column) 612 remove_col_menu = edit.Append(wx.NewId(), 'Remove Column', 613 'Remove Column') 614 wx.EVT_MENU(self, remove_col_menu.GetId(), self.on_remove_column) 684 def on_save_column(self, event): 685 """ 686 """ 687 self.panel.on_save_column(self.parent) 615 688 616 689 def on_close(self, event): … … 625 698 self.panel.on_remove_column() 626 699 627 def on_add_column(self, event): 700 def on_insert_column(self, event): 701 """ 702 Insert a new column to the grid 703 """ 704 self.panel.insert_column() 705 706 def on_append_column(self, event): 628 707 """ 629 708 Append a new column to the grid … … 781 860 j += 1 782 861 data["index"+str(i)] = [i/j, i*j, i, i+j] 783 784 frame = GridFrame(data_outputs=data, data_inputs=data) 862 863 data_input = copy.deepcopy(data) 864 data_input["index5"] = [10,20,40, 50] 865 frame = GridFrame(data_outputs=data, data_inputs=data_input) 785 866 frame.Show(True) 786 867 except:
Note: See TracChangeset
for help on using the changeset viewer.