- Timestamp:
- Feb 2, 2011 5:50:48 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:
- 6d3d5ff
- Parents:
- 4753fc2
- Location:
- guiframe
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/data_panel.py
r6db811e r52725d6 18 18 from sans.guiframe.dataFitting import Data1D 19 19 from sans.guiframe.dataFitting import Data2D 20 from sans.guiframe.panel_base import PanelBase 20 21 21 22 PANEL_WIDTH = 200 … … 31 32 self.root = self.AddRoot("Available Data") 32 33 33 class DataPanel(ScrolledPanel ):34 class DataPanel(ScrolledPanel, PanelBase): 34 35 """ 35 36 This panel displays data available in the application and widgets to … … 49 50 kwds['size']= size 50 51 ScrolledPanel.__init__(self, parent=parent, *args, **kwds) 52 PanelBase.__init__(self) 51 53 self.SetupScrolling() 52 54 -
guiframe/gui_manager.py
r4753fc2 r52725d6 130 130 #self._check_update(None) 131 131 # Register the close event so it calls our own method 132 wx.EVT_CLOSE(self, self. _onClose)132 wx.EVT_CLOSE(self, self.Close) 133 133 # Register to status events 134 134 self.Bind(EVT_STATUS, self._on_status_event) … … 463 463 id = wx.NewId() 464 464 m_name, m_hint, m_handler = item 465 self._file menu.Append(id, m_name, m_hint)465 self._file_menu.Append(id, m_name, m_hint) 466 466 wx.EVT_MENU(self, id, m_handler) 467 self._file menu.AppendSeparator()467 self._file_menu.AppendSeparator() 468 468 469 469 def _setup_menus(self): … … 647 647 """ 648 648 # File menu 649 self._file menu = wx.Menu()649 self._file_menu = wx.Menu() 650 650 # some menu of plugin to be seen under file menu 651 651 self._populate_file_menu() 652 652 id = wx.NewId() 653 self._file menu.Append(id, '&Save state into File',654 'Save project as a SansView (svs) file')655 wx.EVT_MENU(self, id, self._on_save )653 self._file_menu.Append(id, '&Save Application', 654 'Save state of the current active application') 655 wx.EVT_MENU(self, id, self._on_save_application) 656 656 id = wx.NewId() 657 self._filemenu.Append(id, '&Quit', 'Exit') 657 self._file_menu.Append(id, '&Save Project', 658 'Save the state of the whole application') 659 wx.EVT_MENU(self, id, self._on_save_project) 660 self._file_menu.AppendSeparator() 661 662 id = wx.NewId() 663 self._file_menu.Append(id, '&Quit', 'Exit') 658 664 wx.EVT_MENU(self, id, self.Close) 659 665 # Add sub menus 660 self._menubar.Append(self._file menu, '&File')666 self._menubar.Append(self._file_menu, '&File') 661 667 662 668 def _add_menu_data(self): … … 776 782 if path is None: 777 783 return 778 779 from data_loader import plot_data 780 from sans.perspectives import invariant 784 781 785 if path and os.path.isfile(path): 782 786 basename = os.path.basename(path) … … 797 801 self.on_close_welcome_panel() 798 802 799 def _on_save(self, event): 800 """ 801 Save state into a file 802 """ 803 # Ask the user the location of the file to write to. 804 803 def _on_save_application(self, event): 804 """ 805 save the state of the current active application 806 """ 805 807 ## Default file location for save 806 808 self._default_save_location = os.getcwd() 809 if self._current_perspective is None: 810 return 811 reader, ext = self._current_perspective.get_extensions() 807 812 path = None 808 813 dlg = wx.FileDialog(self, "Choose a file", 809 self._default_save_location, "", "*.svs", wx.SAVE)814 self._default_save_location, "", ext, wx.SAVE) 810 815 if dlg.ShowModal() == wx.ID_OK: 811 816 path = dlg.GetPath() … … 818 823 # default cansas xml doc 819 824 doc = None 820 for item in self.panels: 821 try: 822 if self.panels[item].window_name == 'Invariant': 823 data = self.panels[item]._data 824 if data != None: 825 state = self.panels[item].state 826 manager = self.panels[item]._manager 827 new_doc = manager.state_reader.write_toXML(data, state) 828 if hasattr(doc, "firstChild"): 829 child = new_doc.firstChild.firstChild 830 doc.firstChild.appendChild(child) 831 else: 832 doc = new_doc 833 elif self.panels[item].window_name == 'pr_control': 834 data = self.panels[item].manager.current_plottable 835 if data != None: 836 state = self.panels[item].get_state() 837 manager = self.panels[item].manager 838 new_doc = manager.state_reader.write_toXML(data, state) 839 if hasattr(doc, "firstChild"): 840 child = new_doc.firstChild.firstChild 841 doc.firstChild.appendChild(child) 842 else: 843 doc = new_doc 844 elif self.panels[item].window_name == 'Fit panel': 845 for index in range(self.panels[item].GetPageCount()): 846 selected_page = self.panels[item].GetPage(index) 847 if hasattr(selected_page,"get_data"): 848 data = selected_page.get_data() 849 state = selected_page.state 850 reader = selected_page.manager.state_reader 851 new_doc = reader.write_toXML(data, state) 852 if doc != None and hasattr(doc, "firstChild"): 853 child = new_doc.firstChild.firstChild 854 doc.firstChild.appendChild(child) 855 else: 856 doc = new_doc 857 except: 858 pass 825 for panel in self._current_perspective.get_perspective(): 826 doc = on_save_helper(doc, reader, panel, path) 827 828 def _on_save_project(self, event): 829 """ 830 save the state of the current active application 831 """ 832 ## Default file location for save 833 self._default_save_location = os.getcwd() 834 if self._current_perspective is None: 835 return 836 reader, ext = self._current_perspective.get_extensions() 837 path = None 838 dlg = wx.FileDialog(self, "Choose a file", 839 self._default_save_location, "", '.svs', wx.SAVE) 840 if dlg.ShowModal() == wx.ID_OK: 841 path = dlg.GetPath() 842 self._default_save_location = os.path.dirname(path) 843 else: 844 return None 845 dlg.Destroy() 846 if path is None: 847 return 848 # default cansas xml doc 849 doc = None 850 for panel in self.panels.values(): 851 doc = self.on_save_helper(doc, reader, panel, path) 852 853 854 def on_save_helper(self, doc, reader, panel, path): 855 """ 856 Save state into a file 857 """ 858 try: 859 data = panel.get_data() 860 state = panel.get_state() 861 if reader is not None: 862 if data is not None: 863 new_doc = reader.write_toXML(data, state) 864 if hasattr(doc, "firstChild"): 865 child = new_doc.firstChild.firstChild 866 doc.firstChild.appendChild(child) 867 else: 868 doc = new_doc 869 except: 870 raise 871 #pass 859 872 # Write the XML document 860 873 if doc != None: … … 863 876 fd.close() 864 877 else: 878 raise 865 879 #print "Nothing to save..." 866 raise RuntimeError, "%s is not a SansView (.svs) file..." % path 867 868 def _onClose(self, event): 869 """ 870 Store info to retrieve in xml before closing the application 871 """ 872 wx.Exit() 873 sys.exit() 874 880 #raise RuntimeError, "%s is not a SansView (.svs) file..." % path 881 return doc 882 875 883 def quit_guiframe(self): 876 884 """ … … 890 898 Quit the application 891 899 """ 892 flag = self.quit_guiframe() 893 if flag: 894 wx.Frame.Close(self) 900 #flag = self.quit_guiframe() 901 if True: 895 902 wx.Exit() 896 903 sys.exit() … … 1015 1022 self._mgr.Update() 1016 1023 1017 def choose_file(self, path=None):1018 """1019 Functionality that belongs elsewhere1020 Should add a hook to specify the preferred file type/extension.1021 """1022 #TODO: clean this up1023 from .data_loader import choose_data_file1024 # Choose a file path1025 if path == None:1026 path = choose_data_file(self, self._default_save_location)1027 if not path == None:1028 try:1029 self._default_save_location = os.path.dirname(path)1030 except:1031 pass1032 return path1033 1034 1024 def show_data_panel(self, event=None): 1035 1025 """ … … 1041 1031 self._mgr.Update() 1042 1032 1043 def add_data(self, data_list ):1033 def add_data(self, data_list, flag=False): 1044 1034 """ 1045 1035 receive a list of data . store them its data manager if possible … … 1052 1042 avalaible_data = self._data_manager.get_all_data() 1053 1043 1044 if flag: 1045 #reading a state file 1046 for plug in self.plugins: 1047 plug.on_set_state_helper(event=None) 1054 1048 style = self.__gui_style & GUIFRAME.MANAGER_ON 1055 1049 if style == GUIFRAME.MANAGER_ON: -
guiframe/local_perspectives/data_loader/data_loader.py
r52b8b74 r52725d6 17 17 from sans.guiframe.utils import parse_name 18 18 19 STATE_FILE_EXT = ['P(r) files (*.prv)|*.prv', 20 'P(r) files (*.sav)|*.sav', 21 'P(r) files (*.svs)|*.svs', 19 STATE_FILE_EXT = ['SansView files (*.svs)|*.svs', 20 'P(r) files (*.prv)|*.prv', 22 21 'Fitting files (*.fitv)|*.fitv', 23 'Fitting files (*.svs)|*.svs', 24 'Invariant files (*.inv)|*.inv', 25 'Invariant files (*.svs)|*.svs'] 26 EXTENSIONS = ['.svs', '.prv', '.inv', '.fitv'] 22 'Invariant files (*.inv)|*.inv'] 23 EXTENSIONS = ['.svs', '.prv','.fitv', '.inv'] 27 24 28 25 class Plugin(PluginBase): … … 195 192 temp = self.loader.load(p_file) 196 193 if temp.__class__.__name__ == "list": 194 print "list", temp 197 195 for item in temp: 198 196 data = self.create_data(item, p_file) 199 197 output.append(data) 200 198 else: 199 print "list", temp 201 200 data = self.create_data(temp, p_file) 202 201 output.append(data) … … 204 203 self.load_update(output=output, message=message) 205 204 except: 205 raise 206 206 error_message = "Error while loading: %s\n" % str(p_file) 207 207 error_message += str(sys.exc_value) + "\n" … … 211 211 message += log_msg 212 212 self.load_complete(output=output, error_message=error_message, 213 message=message, path=path )213 message=message, path=path, flag=flag) 214 214 215 215 … … 240 240 info="warning")) 241 241 242 def load_complete(self, output, message="", error_message="", path=None): 242 def load_complete(self, output, message="", error_message="", 243 path=None, flag=True): 243 244 """ 244 245 post message to status bar and return list of data … … 249 250 if error_message != "": 250 251 self.load_error(error_message) 251 self.parent.add_data(output )252 self.parent.add_data(output, flag=flag) 252 253 253 254 def create_data(self, data, path): -
guiframe/panel_base.py
r691643c r52725d6 28 28 Initialize some flag that Viewerframe used 29 29 """ 30 #panel manager 31 self._manager = None 32 30 33 self._print_flag = False 31 34 self._undo_flag = False … … 229 232 """ 230 233 231 234 def get_data(self): 235 """ 236 return list of current data 237 """ 238 return 239 240 def get_state(self): 241 """ 242 return the current state 243 """ 244 return 245 246 def set_manager(self, manager): 247 """ 248 """ 249 self._manager = manager 250 251 def get_manager(self): 252 """ 253 """ 254 return self._manager -
guiframe/plugin_base.py
rbf4402c3 r52725d6 41 41 ## Reference to the parent window. Filled by get_panels() below. 42 42 self.parent = None 43 43 #plugin state reader 44 self.state_reader = None 45 self._extensions = '' 44 46 ## List of panels that you would like to open in AUI windows 45 47 # for your plug-in. This defines your plug-in "perspective" 46 48 self.perspective = [] 47 49 50 def get_extensions(self): 51 """ 52 return state reader and its extensions 53 """ 54 return self.state_reader, self._extensions 55 48 56 def can_load_data(self): 49 57 """ … … 196 204 receive a list of data and use it in the current perspective 197 205 """ 206 def on_set_state_helper(self, event): 207 """ 208 update state 209 """ 210
Note: See TracChangeset
for help on using the changeset viewer.