- Timestamp:
- Aug 6, 2010 7:36:07 PM (14 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:
- 028a0e8
- Parents:
- a93f525
- Location:
- guiframe
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/data_loader.py
raf47c8d rb35d3d1 150 150 type="stop")) 151 151 152 def plot_data(parent, path ):152 def plot_data(parent, path, format=None): 153 153 """ 154 154 Use the DataLoader loader to created data to plot. 155 155 156 156 :param path: the path of the data to load 157 157 : param format: file format (as file extension) 158 158 """ 159 159 from sans.guicomm.events import NewPlotEvent, StatusEvent … … 165 165 # Load data 166 166 try: 167 output = L.load(path )167 output = L.load(path, format) 168 168 except: 169 169 load_error(sys.exc_value) … … 235 235 i=1 236 236 for item in output: 237 msg = "Loading 1D data: %s"%str(item.run[0])238 wx.PostEvent(parent, StatusEvent(status=msg, info="info", type="stop"))239 237 try: 240 dx = item.dx 241 dxl = item.dxl 242 dxw = item.dxw 238 msg = "Loading 1D data: %s"%str(item.run[0]) 239 wx.PostEvent(parent, StatusEvent(status=msg, info="info", type="stop")) 240 try: 241 dx = item.dx 242 dxl = item.dxl 243 dxw = item.dxw 244 except: 245 dx = None 246 dxl = None 247 dxw = None 248 249 new_plot = Data1D(x=item.x,y=item.y,dx=dx,dy=item.dy) 250 new_plot.copy_from_datainfo(item) 251 item.clone_without_data(clone=new_plot) 252 new_plot.dxl = dxl 253 new_plot.dxw = dxw 254 255 name = parse_name(name=str(item.run[0]), expression="_") 256 #if not name in parent.indice_load_data.keys(): 257 # parent.indice_load_data[name] = 0 258 #else: 259 ## create a copy of the loaded data 260 261 #TODO: this is a very annoying feature. We should make this 262 # an option. Excel doesn't do this. Why should we? 263 # What is the requirement for this feature, and are the 264 # counter arguments stronger? Is this feature developed 265 # to please at least 80% of the users or a special few? 266 #parent.indice_load_data[name] += 1 267 #name = name + "(copy %i)"%parent.indice_load_data[name] 268 269 new_plot.name = name 270 new_plot.interactive = True 271 new_plot.group_id = name 272 new_plot.id = name 273 new_plot.is_data = True 274 275 if hasattr(item,"title"): 276 title = item.title.lstrip().rstrip() 277 if title == "": 278 title = str(name) 279 else: 280 title = name 281 if hasattr(parent, "panel_on_focus") and not(parent.panel_on_focus is None): 282 existing_panel = parent.panel_on_focus 283 panel_name = existing_panel.window_caption 284 data_name = new_plot.name 285 if enable_add_data(existing_panel, new_plot): 286 if open_dialog_append_data(panel_name, data_name): 287 #add this plot the an existing panel 288 new_plot.group_id = existing_panel.group_id 289 wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=str(title))) 290 i+=1 243 291 except: 244 dx = None 245 dxl = None 246 dxw = None 247 248 new_plot = Data1D(x=item.x,y=item.y,dx=dx,dy=item.dy) 249 new_plot.copy_from_datainfo(item) 250 item.clone_without_data(clone=new_plot) 251 new_plot.dxl = dxl 252 new_plot.dxw = dxw 253 254 name = parse_name(name=str(item.run[0]), expression="_") 255 #if not name in parent.indice_load_data.keys(): 256 # parent.indice_load_data[name] = 0 257 #else: 258 ## create a copy of the loaded data 259 260 #TODO: this is a very annoying feature. We should make this 261 # an option. Excel doesn't do this. Why should we? 262 # What is the requirement for this feature, and are the 263 # counter arguments stronger? Is this feature developed 264 # to please at least 80% of the users or a special few? 265 #parent.indice_load_data[name] += 1 266 #name = name + "(copy %i)"%parent.indice_load_data[name] 267 268 new_plot.name = name 269 new_plot.interactive = True 270 new_plot.group_id = name 271 new_plot.id = name 272 new_plot.is_data = True 273 274 if hasattr(item,"title"): 275 title = item.title.lstrip().rstrip() 276 if title == "": 277 title = str(name) 278 else: 279 title = name 280 if hasattr(parent, "panel_on_focus") and not(parent.panel_on_focus is None): 281 existing_panel = parent.panel_on_focus 282 panel_name = existing_panel.window_caption 283 data_name = new_plot.name 284 if enable_add_data(existing_panel, new_plot): 285 if open_dialog_append_data(panel_name, data_name): 286 #add this plot the an existing panel 287 new_plot.group_id = existing_panel.group_id 288 wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=str(title))) 289 i+=1 290 292 raise -
guiframe/gui_manager.py
raf47c8d rb35d3d1 537 537 538 538 id = wx.NewId() 539 self.filemenu.Append(id, '& Load Data', 'Load data file into the application')539 self.filemenu.Append(id, '&Open', 'Load data file into the application') 540 540 wx.EVT_MENU(self, id, self._on_open) 541 #self.filemenu.AppendSeparator() 542 543 id = wx.NewId() 544 self.filemenu.Append(id, '&Save', 'Save project as a SanaView (svs) file') 545 wx.EVT_MENU(self, id, self._on_save) 541 546 #self.filemenu.AppendSeparator() 542 547 … … 711 716 from data_loader import plot_data 712 717 if path and os.path.isfile(path): 713 plot_data(self, path) 718 basename = os.path.basename(path) 719 if basename.endswith('.svs'): 720 plot_data(self, path,'.inv') 721 plot_data(self, path,'.prv') 722 plot_data(self, path,'.fitv') 723 else: plot_data(self,path) 714 724 if self.defaultPanel is not None and \ 715 725 self._mgr.GetPane(self.panels["default"].window_name).IsShown(): 716 726 self.on_close_welcome_panel() 727 728 def _on_save(self, event): 729 """ 730 Save state into a file 731 """ 732 # Ask the user the location of the file to write to. 733 734 ## Default file location for save 735 self._default_save_location = os.getcwd() 736 path = None 737 dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, "", "*.svs", wx.SAVE) 738 if dlg.ShowModal() == wx.ID_OK: 739 path = dlg.GetPath() 740 self._default_save_location = os.path.dirname(path) 741 else: 742 return None 743 744 dlg.Destroy() 745 if path is None: 746 return 747 # default cansas xml doc 748 doc = None 749 for item in self.panels: 750 try: 751 if self.panels[item].window_name == 'Invariant' or self.panels[item].window_name == 'pr_control' or self.panels[item].window_name == 'Fit panel': 752 if self.panels[item].window_name == 'Invariant': 753 data = self.panels[item]._data 754 state = self.panels[item].state 755 new_doc =self.panels[item]._manager.state_reader.write_toXML(data,state) 756 if hasattr(doc, "firstChild"): 757 doc.firstChild.appendChild (new_doc.firstChild.firstChild) 758 else: 759 doc = new_doc 760 elif self.panels[item].window_name == 'pr_control': 761 data = self.panels[item].manager.current_plottable 762 state = self.panels[item].get_state() 763 new_doc =self.panels[item].manager.state_reader.write_toXML(data,state) 764 if hasattr(doc, "firstChild"): 765 doc.firstChild.appendChild (new_doc.firstChild.firstChild) 766 else: 767 doc = new_doc 768 elif self.panels[item].window_name == 'Fit panel': 769 for index in range(self.panels[item].GetPageCount()): 770 selected_page = self.panels[item].GetPage(index) 771 if hasattr(selected_page,"get_data"): 772 data = selected_page.get_data() 773 state = selected_page.state 774 new_doc =selected_page.manager.state_reader.write_toXML(data,state) 775 if doc != None and hasattr(doc, "firstChild"): 776 doc.firstChild.appendChild (new_doc.firstChild.firstChild) 777 else: 778 doc = new_doc 779 780 except: 781 pass 782 783 # Write the XML document 784 if doc != None: 785 fd = open(path, 'w') 786 fd.write(doc.toprettyxml()) 787 fd.close() 788 else: 789 raise RuntimeError, "%s is not a SansView (.svs) file..." % path 790 717 791 718 792 def _onClose(self, event):
Note: See TracChangeset
for help on using the changeset viewer.