Changeset 71fa9028 in sasview for sansguiframe/src
- Timestamp:
- Sep 23, 2011 8:36:28 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:
- ebf422a
- Parents:
- 05efe88
- Location:
- sansguiframe/src/sans/guiframe
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sansguiframe/src/sans/guiframe/data_processor.py
rf4b37d1 r71fa9028 85 85 self.data_outputs = {} 86 86 self.data = None 87 self.details = "" 88 self.file_name = None 87 89 self._cols = 50 88 90 self._rows = 51 … … 172 174 slicerpop.AppendSubMenu(col_label_menu , 173 175 '&Insert Column', 'Insert Column') 174 hint = 'Insert empty column before the selected column' 175 id = wx.NewId() 176 col_label_menu.Append(id, '&Empty', hint) 177 wx.EVT_MENU(self, id, self.on_insert_column) 178 col_name = [self.GetCellValue(0, col) 179 for col in range(self.GetNumberCols())] 180 for label in self.data.keys(): 181 if label not in col_name: 182 id = wx.NewId() 183 hint = 'Insert %s column before the selected column' % str(label) 184 col_label_menu.Append(id, '&%s' % str(label), hint) 185 wx.EVT_MENU(self, id, self.on_insert_column) 176 col_name = [self.GetCellValue(0, c) 177 for c in range(self.GetNumberCols())] 178 row = 0 179 label = self.GetCellValue(row, col) 180 self.insert_col_menu(col_label_menu, label, self) 186 181 id = wx.NewId() 187 182 hint = 'Remove selected column %s' 188 slicerpop.Append(id, 189 '&Remove Column', hint) 183 slicerpop.Append(id, '&Remove Column', hint) 190 184 wx.EVT_MENU(self, id, self.on_remove_column) 191 185 … … 194 188 self.PopupMenu(slicerpop, pos) 195 189 196 def on_remove_column(self, event): 190 def insert_col_menu(self, menu, label, window): 191 """ 192 """ 193 id = wx.NewId() 194 title = "Empty" 195 hint = 'Insert empty column before %s' % str(label) 196 menu.Append(id, title, hint) 197 wx.EVT_MENU(window, id, self.on_insert_column) 198 col_name = [self.GetCellValue(0, col) 199 for col in range(self.GetNumberCols())] 200 for c_name in self.data.keys(): 201 if c_name not in col_name: 202 id = wx.NewId() 203 hint = "Insert %s column before the " % str(c_name) 204 hint += " %s column" % str(label) 205 menu.Append(id, '&%s' % str(c_name), hint) 206 wx.EVT_MENU(window, id, self.on_insert_column) 207 208 209 def on_remove_column(self, event=None): 197 210 """ 198 211 """ 199 212 if self.selected_cols is not None or len(self.selected_cols) > 0: 200 213 col = self.selected_cols[0] 201 # add data to the grid 202 row = 0 203 id = event.GetId() 204 col_name = self.GetCellValue(row, col) 205 self.data[col_name] = [] 206 for row in range(1, self.GetNumberRows() + 1): 207 if row < self.max_row_touse: 208 value = self.GetCellValue(row, col) 209 self.data[col_name].append(value) 210 for k , value_list in self.data.iteritems(): 211 if k != col_name: 212 length = len(value_list) 213 if length < self.max_row_touse: 214 diff = self.max_row_touse - length 215 for i in range(diff): 216 self.data[k].append("") 217 self.DeleteCols(pos=col, numCols=1, updateLabels=True) 218 self.AutoSize() 214 self.remove_column(col=col, numCols=1) 215 216 def remove_column(self, col, numCols=1): 217 """ 218 Remove column to the current grid 219 """ 220 # add data to the grid 221 row = 0 222 col_name = self.GetCellValue(row, col) 223 self.data[col_name] = [] 224 for row in range(1, self.GetNumberRows() + 1): 225 if row < self.max_row_touse: 226 value = self.GetCellValue(row, col) 227 self.data[col_name].append(value) 228 for k , value_list in self.data.iteritems(): 229 if k != col_name: 230 length = len(value_list) 231 if length < self.max_row_touse: 232 diff = self.max_row_touse - length 233 for i in range(diff): 234 self.data[k].append("") 235 self.DeleteCols(pos=col, numCols=numCols, updateLabels=True) 219 236 220 237 def on_insert_column(self, event): … … 227 244 id = event.GetId() 228 245 col_name = event.GetEventObject().GetLabelText(id) 229 self.InsertCols(pos=col, numCols=1, updateLabels=True) 230 if col_name.strip() != "Empty": 231 self.SetCellValue(row, col, str(col_name.strip())) 232 if col_name in self.data.keys(): 233 value_list = self.data[col_name] 234 cell_row = 1 235 for value in value_list: 236 self.SetCellValue(cell_row, col, str(value)) 237 cell_row += 1 238 self.AutoSize() 239 246 self.insert_column(col=col, col_name=col_name) 247 if not issubclass(event.GetEventObject().__class__ , wx.Menu): 248 col += 1 249 self.selected_cols[0] += 1 250 251 def insert_column(self, col, col_name): 252 """ 253 """ 254 255 row = 0 256 self.InsertCols(pos=col, numCols=1, updateLabels=True) 257 if col_name.strip() != "Empty": 258 self.SetCellValue(row, col, str(col_name.strip())) 259 if col_name in self.data.keys(): 260 value_list = self.data[col_name] 261 cell_row = 1 262 for value in value_list: 263 self.SetCellValue(cell_row, col, str(value)) 264 cell_row += 1 265 240 266 241 267 def on_set_x_axis(self, event): … … 249 275 self.panel.set_yaxis(y=self.axis_value, label=self.axis_label) 250 276 251 def set_data(self, data_inputs, data_outputs ):277 def set_data(self, data_inputs, data_outputs, details, file_name): 252 278 """ 253 279 Add data to the grid … … 255 281 :param data_ouputs: default columns deplayed 256 282 """ 283 self.file_name = file_name 284 self.details = details 285 257 286 if data_outputs is None: 258 287 data_outputs = {} 259 288 self.data_outputs = data_outputs 260 if self.data_inputs is None:289 if data_inputs is None: 261 290 data_inputs = {} 262 291 self.data_inputs = data_inputs … … 296 325 if cell_row > self.max_row_touse: 297 326 self.max_row_touse = cell_row 298 299 327 328 def get_grid_view(self): 329 """ 330 Return value contained in the grid 331 """ 332 grid_view = {} 333 for col in xrange(self.GetNumberCols()): 334 label = self.GetCellValue(row=0, col=col) 335 label = label.strip() 336 if label != "": 337 grid_view[label] = [] 338 for row in range(1, self.max_row_touse+1): 339 value = self.GetCellValue(row=row, col=col) 340 if value != "": 341 grid_view[label].append(value) 342 else: 343 grid_view[label].append(None) 344 return grid_view 345 300 346 class Notebook(nb, PanelBase): 301 347 """ … … 454 500 self.enable_close_button() 455 501 456 def set_data(self, data_inputs, data_outputs ):502 def set_data(self, data_inputs, data_outputs, details="", file_name=None): 457 503 if data_outputs is None or data_outputs == {}: 458 504 return … … 462 508 if grid.data is None: 463 509 #Found empty page 464 grid.set_data(data_inputs, data_outputs) 510 grid.set_data(data_inputs=data_inputs, 511 data_outputs=data_outputs, 512 details=details, 513 file_name=file_name) 465 514 self.SetSelection(pos) 466 515 return … … 477 526 grid.AppendCols(1, True) 478 527 479 def on_remove_column(self): 480 """ 481 Remove column to the current grid 482 """ 483 pos = self.GetSelection() 484 grid = self.GetPage(pos) 485 cols_pos = grid.GetSelectedCols() 486 for cpos in cols_pos: 487 grid.DeleteCols(cpos) 528 488 529 489 530 … … 517 558 self.layout_plotting_area() 518 559 self.SetSizer(self.vbox) 519 520 def set_data(self, data_inputs, data_outputs): 521 """ 522 """ 523 if self.notebook is not None: 524 self.notebook.set_data(data_inputs, data_outputs) 525 560 526 561 def set_xaxis(self, label="", x=None): 527 562 """ … … 738 773 menubar = wx.MenuBar() 739 774 self.SetMenuBar(menubar) 740 """ 741 edit = wx.Menu() 742 menubar.Append(edit, "&File") 743 save_menu = edit.Append(wx.NewId(), 'Save As', 'Save into File') 744 wx.EVT_MENU(self, save_menu.GetId(), self.on_save_column) 745 """ 775 776 self.curr_col = None 777 self.curr_grid = None 778 self.curr_col_name = "" 779 file = wx.Menu() 780 menubar.Append(file, "&File") 781 782 hint = "Open file containing batch results" 783 open_menu = file.Append(wx.NewId(), 'Open ', hint) 784 wx.EVT_MENU(self, open_menu.GetId(), self.on_open) 785 786 hint = "Open the the current grid into excel" 787 open_excel_menu = file.Append(wx.NewId(), 'Open with Excel', hint) 788 wx.EVT_MENU(self, open_excel_menu.GetId(), self.open_with_excel) 789 file.AppendSeparator() 790 save_menu = file.Append(wx.NewId(), 'Save As', 'Save into File') 791 wx.EVT_MENU(self, save_menu.GetId(), self.on_save_page) 792 793 self.edit = wx.Menu() 794 hint = "Insert column before the selected column" 795 self.insert_before_menu = wx.Menu() 796 self.insert_sub_menu = self.edit.AppendSubMenu(self.insert_before_menu, 797 'Insert Before', hint) 798 799 hint = "Remove the selected column" 800 self.remove_menu = self.edit.Append(-1, 'Remove Column', hint) 801 wx.EVT_MENU(self, self.remove_menu.GetId(), self.on_remove_column) 802 803 self.Bind(wx.EVT_MENU_OPEN, self.on_menu_open) 804 menubar.Append(self.edit, "&Edit") 746 805 self.Bind(wx.EVT_CLOSE, self.on_close) 747 806 748 def on_save_column(self, event): 749 """ 750 """ 751 self.panel.on_save_column(self.parent) 752 807 def GetLabelText(self, id): 808 """ 809 """ 810 for item in self.insert_before_menu.GetMenuItems(): 811 m_id = item.GetId() 812 if m_id == id: 813 return item.GetLabel() 814 815 def on_remove_column(self, event): 816 """ 817 """ 818 pos = self.panel.notebook.GetSelection() 819 grid = self.panel.notebook.GetPage(pos) 820 grid.on_remove_column(event=None) 821 822 def on_menu_open(self, event): 823 """ 824 825 """ 826 if self.edit == event.GetMenu(): 827 #get the selected column 828 pos = self.panel.notebook.GetSelection() 829 grid = self.panel.notebook.GetPage(pos) 830 col_list = grid.GetSelectedCols() 831 if len(col_list) > 0: 832 self.remove_menu.Enable(True) 833 else: 834 self.remove_menu.Enable(False) 835 if len(col_list)== 0 or len(col_list) > 1: 836 self.insert_sub_menu.Enable(False) 837 838 label = "Insert Column Before" 839 self.insert_sub_menu.SetText(label) 840 else: 841 self.insert_sub_menu.Enable(True) 842 843 col = col_list[0] 844 #GetColLabelValue(self, col) 845 col_name = grid.GetCellValue(row=0, col=col) 846 label = "Insert Column Before " + str(col_name) 847 self.insert_sub_menu.SetText(label) 848 for item in self.insert_before_menu.GetMenuItems(): 849 self.insert_before_menu.DeleteItem(item) 850 grid.insert_col_menu(menu=self.insert_before_menu, 851 label=col_name, window=self) 852 event.Skip() 853 854 855 856 def on_save_page(self, event): 857 """ 858 """ 859 if self.parent is not None: 860 pos = self.panel.notebook.GetSelection() 861 grid = self.panel.notebook.GetPage(pos) 862 reader, ext = os.path.splitext(grid.file_name) 863 path = None 864 if self.parent is not None: 865 location = os.path.dirname(grid.file_name) 866 dlg = wx.FileDialog(self, "Save Project file", 867 location, grid.file_name, ext, wx.SAVE) 868 path = None 869 if dlg.ShowModal() == wx.ID_OK: 870 path = dlg.GetPath() 871 dlg.Destroy() 872 if path != None: 873 if self.parent is not None: 874 data = grid.get_grid_view() 875 self.parent.write_batch_tofile(data=data, 876 file_name=path, 877 details=grid.details) 878 879 def on_open(self, event): 880 """ 881 Open file containg batch result 882 """ 883 if self.parent is not None: 884 self.parent.on_read_batch_tofile(event) 885 886 def open_with_excel(self, event): 887 """ 888 open excel and display batch result in Excel 889 """ 890 if self.parent is not None: 891 pos = self.panel.notebook.GetSelection() 892 grid = self.panel.notebook.GetPage(pos) 893 data = grid.get_grid_view() 894 self.parent.open_with_externalapp(data=data, 895 file_name=grid.file_name, 896 details=grid.details) 897 753 898 def on_close(self, event): 754 899 """ … … 756 901 self.Hide() 757 902 758 def on_remove_column(self, event): 759 """ 760 Remove the selected column to the grid 761 """ 762 self.panel.on_remove_column() 763 764 def on_insert_column(self, event): 765 """ 766 Insert a new column to the grid 767 """ 768 self.panel.insert_column() 769 903 770 904 def on_append_column(self, event): 771 905 """ … … 774 908 self.panel.add_column() 775 909 776 def set_data(self, data_inputs, data_outputs): 777 """ 778 """ 779 self.panel.set_data(data_inputs, data_outputs) 910 def set_data(self, data_inputs, data_outputs, details="", file_name=None): 911 """ 912 """ 913 pos = self.panel.notebook.GetSelection() 914 grid = self.panel.notebook.GetPage(pos) 915 grid.set_data(data_inputs=data_inputs, 916 file_name=file_name, 917 details=details, 918 data_outputs=data_outputs) 780 919 781 920 -
sansguiframe/src/sans/guiframe/gui_manager.py
r4c2c93f r71fa9028 306 306 file_name = "Batch_" + str(plugin_name)+ "_" + time_str + ext 307 307 file_name = self._default_save_location + str(file_name) 308 #Need to save configuration for later 309 """ 310 frame = BatchOutputFrame(parent=self, data_outputs=data_outputs, 311 data_inputs=data_inputs, 312 file_name=file_name, 313 details=details) 314 """ 315 self.open_with_localapp(data_inputs=data_inputs, 308 309 self.open_with_localapp(file_name=file_name, 310 details=details, 311 data_inputs=data_inputs, 316 312 data_outputs=data_outputs) 317 #frame.Show(True) 318 319 def open_with_localapp(self, data_inputs=None, data_outputs=None): 313 314 315 def open_with_localapp(self, data_inputs=None, details="", file_name=None, 316 data_outputs=None): 320 317 """ 321 318 Display value of data into the application grid 322 319 :param data: dictionary of string and list of items 323 320 """ 324 self.batch_frame.set_data(data_inputs, data_outputs) 321 self.batch_frame.set_data(data_inputs=data_inputs, 322 data_outputs=data_outputs, 323 details=details, 324 file_name=file_name) 325 325 self.batch_frame.Show(True) 326 326 … … 343 343 self._default_save_location = os.path.dirname(path) 344 344 dlg.Destroy() 345 346 345 self.read_batch_tofile(file_name=path) 347 346 … … 363 362 column_names_line = "" 364 363 index = None 364 details = "" 365 365 for index in range(len(lines)): 366 366 line = lines[index] 367 count = 0 367 368 if line.find(separator) != -1: 368 #found the first line containing the label 369 if line.count(separator) >= 2: 370 #found the first line containing the label 371 col_name_toks = line.split(separator) 372 for item in col_name_toks: 373 if item.strip() != "": 374 count += 1 375 else: 376 details += line 377 if count >= 2: 369 378 column_names_line = line 370 379 first_data_index = index 371 380 break 381 372 382 if column_names_line.strip() == "" or index is None: 373 383 return … … 380 390 for row in range(index + 1, len(lines)-1)] 381 391 c_index += 1 382 self.open_with_localapp(data_outputs=data) 392 393 394 self.open_with_localapp(data_outputs=data, data_inputs=None, 395 file_name=file_name, details=details) 383 396 384 397 def write_batch_tofile(self, data, file_name, details=""):
Note: See TracChangeset
for help on using the changeset viewer.