Changeset 42d27f2 in sasview
- Timestamp:
- Apr 13, 2009 11:43:41 AM (16 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:
- 309ccaf
- Parents:
- f31701c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/local_perspectives/plotting/Plotter1D.py
r3cc533e r42d27f2 204 204 name = plot.name 205 205 206 slicerpop.Append(id, "&Save %s points" % name)206 slicerpop.Append(id, "&Save points" ) 207 207 self.action_ids[str(id)] = plot 208 208 wx.EVT_MENU(self, id, self._onSave) 209 210 id = wx.NewId() 211 slicerpop.Append(id, "&Save %s canSAS XML" % name) 212 self.action_ids[str(id)] = plot 213 wx.EVT_MENU(self, id, self._onSaveXML) 209 #wx.EVT_MENU(self, id, self._onSaveXML) 214 210 215 211 id = wx.NewId() … … 361 357 362 358 363 def _onSaveXML(self, evt):359 def _onSaveXML(self, path): 364 360 """ 365 361 Save 1D Data to XML file 362 @param evt: Menu event 363 """ 364 if not path == None: 365 out = open(path, 'w') 366 from DataLoader.readers import cansas_reader 367 reader = cansas_reader.Reader() 368 datainfo= self.plots[self.graph.selected_plottable].info 369 reader.write( path, datainfo) 370 return 371 372 373 def _onsaveTXT(self, path): 374 """ 375 Save file as txt 376 """ 377 data = self.plots[self.graph.selected_plottable] 378 379 if not path == None: 380 out = open(path, 'w') 381 has_errors = True 382 if data.dy==None or data.dy==[]: 383 has_errors = False 384 385 # Sanity check 386 if has_errors: 387 try: 388 if len(data.y) != len(data.dy): 389 390 has_errors = False 391 except: 392 has_errors = False 393 394 if has_errors: 395 out.write("<X> <Y> <dY>\n") 396 else: 397 out.write("<X> <Y>\n") 398 399 for i in range(len(data.x)): 400 if has_errors: 401 out.write("%g %g %g\n" % (data.x[i], 402 data.y[i], 403 data.dy[i])) 404 else: 405 out.write("%g %g\n" % (data.x[i], 406 data.y[i])) 407 408 out.close() 409 410 411 def _onSave(self, evt): 412 """ 413 Save a data set to a text file 366 414 @param evt: Menu event 367 415 """ … … 369 417 id = str(evt.GetId()) 370 418 if id in self.action_ids: 419 371 420 path = None 372 dlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "", "*.xml", wx.SAVE) 421 wildcard = "Text files (*.txt)|*.txt|CanSAS 1D files (*.xml)|*.xml|" 422 423 dlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "",wildcard , wx.SAVE) 424 373 425 if dlg.ShowModal() == wx.ID_OK: 374 426 path = dlg.GetPath() 375 427 mypath = os.path.basename(path) 428 376 429 dlg.Destroy() 377 378 if not path == None: 379 out = open(path, 'w') 380 from DataLoader.readers import cansas_reader 381 reader = cansas_reader.Reader() 382 datainfo= self.plots[self.graph.selected_plottable].info 383 reader.write( path, datainfo) 384 return 385 386 387 388 def _onSave(self, evt): 389 """ 390 Save a data set to a text file 391 @param evt: Menu event 392 """ 393 import os 394 id = str(evt.GetId()) 395 if id in self.action_ids: 396 397 path = None 398 dlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "", "*.txt", wx.SAVE) 399 if dlg.ShowModal() == wx.ID_OK: 400 path = dlg.GetPath() 401 mypath = os.path.basename(path) 402 403 dlg.Destroy() 404 405 if not path == None: 406 out = open(path, 'w') 407 has_errors = True 408 if self.action_ids[id].dy==None or self.action_ids[id].dy==[]: 409 has_errors = False 410 411 # Sanity check 412 if has_errors: 413 try: 414 if len(self.action_ids[id].y) != len(self.action_ids[id].dy): 415 416 has_errors = False 417 except: 418 has_errors = False 419 420 if has_errors: 421 out.write("<X> <Y> <dY>\n") 422 else: 423 out.write("<X> <Y>\n") 424 425 for i in range(len(self.action_ids[id].x)): 426 if has_errors: 427 out.write("%g %g %g\n" % (self.action_ids[id].x[i], 428 self.action_ids[id].y[i], 429 self.action_ids[id].dy[i])) 430 else: 431 out.write("%g %g\n" % (self.action_ids[id].x[i], 432 self.action_ids[id].y[i])) 433 434 out.close() 435 436 437 430 if os.path.splitext(mypath)[1].lower() ==".txt": 431 self._onsaveTXT(path) 432 if os.path.splitext(mypath)[1].lower() ==".xml": 433 self._onSaveXML(path) 434 return 435 436 437 438
Note: See TracChangeset
for help on using the changeset viewer.