Changeset 176fbf1 in sasview for sansguiframe/src/sans/guiframe/local_perspectives/plotting
- Timestamp:
- Dec 30, 2011 3:33:16 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:
- c067d12
- Parents:
- 2365c0b
- Location:
- sansguiframe/src/sans/guiframe/local_perspectives/plotting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sansguiframe/src/sans/guiframe/local_perspectives/plotting/Plotter1D.py
r45b6bfb r176fbf1 608 608 #self.graph.render(self) 609 609 #self.subplot.figure.canvas.draw_idle() 610 611 612 613 def _onsaveTXT(self, path): 614 """ 615 Save file as txt 616 617 :TODO: Refactor and remove this method. See TODO in _onSave. 610 611 def _onSave(self, evt): 612 """ 613 Save a data set to a text file 614 615 :param evt: Menu event 618 616 619 617 """ 620 618 data = self.plots[self.graph.selected_plottable] 621 622 if not path == None: 623 out = open(path, 'w') 624 has_errors = True 625 if data.dy == None or data.dy == []: 626 has_errors = False 627 # Sanity check 628 if has_errors: 629 try: 630 if len(data.y) != len(data.dy): 631 has_errors = False 632 except: 633 has_errors = False 634 if has_errors: 635 if data.dx != None and data.dx != []: 636 out.write("<X> <Y> <dY> <dX>\n") 637 else: 638 out.write("<X> <Y> <dY>\n") 639 else: 640 out.write("<X> <Y>\n") 641 642 for i in range(len(data.x)): 643 if has_errors: 644 if data.dx != None and data.dx != []: 645 out.write("%g %g %g %g\n" % (data.x[i], 646 data.y[i], 647 data.dy[i], 648 data.dx[i])) 649 else: 650 out.write("%g %g %g\n" % (data.x[i], 651 data.y[i], 652 data.dy[i])) 653 else: 654 out.write("%g %g\n" % (data.x[i], 655 data.y[i])) 656 out.close() 657 try: 658 self._default_save_location = os.path.dirname(path) 659 self.parent._default_save_location = self._default_save_location 660 except: 661 pass 662 663 def _onSave(self, evt): 664 """ 665 Save a data set to a text file 666 667 :param evt: Menu event 668 669 """ 670 671 path = None 672 wildcard = "Text files (*.txt)|*.txt|"\ 673 "CanSAS 1D files(*.xml)|*.xml" 674 default_name = self.plots[self.graph.selected_plottable].label 619 default_name = data.label 675 620 if default_name.count('.') > 0: 676 621 default_name = default_name.split('.')[0] 677 622 default_name += "_out" 678 623 if self.parent != None: 679 self._default_save_location = self.parent._default_save_location 680 dlg = wx.FileDialog(self, "Choose a file", 681 self._default_save_location, 682 default_name, wildcard , wx.SAVE) 683 684 if dlg.ShowModal() == wx.ID_OK: 685 path = dlg.GetPath() 686 # ext_num = 0 for .txt, ext_num = 1 for .xml 687 # This is MAC Fix 688 ext_num = dlg.GetFilterIndex() 689 if ext_num == 0: 690 format = '.txt' 691 else: 692 format = '.xml' 693 path = os.path.splitext(path)[0] + format 694 mypath = os.path.basename(path) 695 696 #TODO: This is bad design. The DataLoader is designed 697 #to recognize extensions. 698 # It should be a simple matter of calling the . 699 #save(file, data, '.xml') method 700 # of the sans.dataloader.loader.Loader class. 701 from sans.dataloader.loader import Loader 702 #Instantiate a loader 703 loader = Loader() 704 data = self.plots[self.graph.selected_plottable] 705 format = ".txt" 706 if os.path.splitext(mypath)[1].lower() == format: 707 # Make sure the ext included in the file name 708 # especially on MAC 709 fName = os.path.splitext(path)[0] + format 710 self._onsaveTXT(fName) 711 format = ".xml" 712 if os.path.splitext(mypath)[1].lower() == format: 713 # Make sure the ext included in the file name 714 # especially on MAC 715 fName = os.path.splitext(path)[0] + format 716 loader.save(fName, data, format) 717 try: 718 self._default_save_location = os.path.dirname(path) 719 self.parent._default_save_location = self._default_save_location 720 except: 721 pass 722 dlg.Destroy() 624 self.parent.save_data1d(data, default_name) 723 625 724 626 def _add_more_tool(self): -
sansguiframe/src/sans/guiframe/local_perspectives/plotting/Plotter2D.py
rb837e1f r176fbf1 757 757 default_name += "_out" 758 758 if id in self.action_ids: 759 760 759 path = None 761 wildcard = "IGOR/DAT 2D file in Q_map (*.dat)|*.DAT" 762 dlg = wx.FileDialog(self, "Choose a file", 763 self._default_save_location, 764 default_name, wildcard , wx.SAVE) 765 766 if dlg.ShowModal() == wx.ID_OK: 767 path = dlg.GetPath() 768 # ext_num = 0 for .txt, ext_num = 1 for .xml 769 # This is MAC Fix 770 ext_num = dlg.GetFilterIndex() 771 if ext_num == 0: 772 format = '.dat' 773 else: 774 format = '' 775 path = os.path.splitext(path)[0] + format 776 mypath = os.path.basename(path) 777 778 #TODO: This is bad design. The DataLoader is designed 779 #to recognize extensions. 780 # It should be a simple matter of calling the . 781 #save(file, data, '.xml') method 782 # of the DataLoader.loader.Loader class. 783 from sans.dataloader.loader import Loader 784 #Instantiate a loader 785 loader = Loader() 786 data = self.data2D 787 788 format = ".dat" 789 if os.path.splitext(mypath)[1].lower() == format: 790 # Make sure the ext included in the file name 791 # especially on MAC 792 fName = os.path.splitext(path)[0] + format 793 loader.save(fName, data, format) 794 try: 795 self._default_save_location = os.path.dirname(path) 796 self.parent._default_save_location = \ 797 self._default_save_location 798 except: 799 pass 800 dlg.Destroy() 760 self.parent.save_data2d(self.data2D, default_name) 761
Note: See TracChangeset
for help on using the changeset viewer.