Changeset 75fbd17 in sasview
- Timestamp:
- Feb 9, 2011 2:04:24 AM (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:
- c83a5af
- Parents:
- 8240eab
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/data_manager.py
r6db811e r75fbd17 17 17 import logging 18 18 from sans.guiframe.data_state import DataState 19 from sans.guiframe.utils import parse_name 19 20 20 21 class DataManager(object): … … 33 34 self.stored_data = {} 34 35 self.message = "" 36 self.data_name_dict = {} 35 37 38 def rename(self, name): 39 """ 40 rename data 41 """ 42 ## name of the data allow to differentiate data when plotted 43 name = parse_name(name=name, expression="_") 44 45 max_char = name.find("[") 46 if max_char < 0: 47 max_char = len(name) 48 name = name[0:max_char] 49 50 if name not in self.data_name_dict: 51 self.data_name_dict[name] = 0 52 else: 53 self.data_name_dict[name] += 1 54 name = name + " [" + str(self.data_name_dict[name]) + "]" 55 return name 56 36 57 def add_data(self, data_list): 37 58 """ -
guiframe/gui_manager.py
r1b3a5a9 r75fbd17 47 47 from sans.guiframe.panel_base import PanelBase 48 48 from sans.guiframe.gui_toolbar import GUIToolBar 49 50 STATE_FILE_EXT = ['.inv', '.fitv', '.prv'] 51 DATA_MANAGER = False 52 AUTO_PLOT = False 53 AUTO_SET_DATA = True 49 from sans.guiframe.dataFitting import Data1D 50 from sans.guiframe.dataFitting import Data2D 51 from DataLoader.loader import Loader 52 53 from DataLoader.loader import Loader 54 import DataLoader.data_info as DataInfo 55 56 54 57 PLOPANEL_WIDTH = 400 55 58 PLOPANEL_HEIGTH = 400 … … 57 60 GUIFRAME_HEIGHT = 800 58 61 PROG_SPLASH_SCREEN = "images/danse_logo.png" 62 EXTENSIONS = ['.inv', '.fitv', '.prv', '.svs'] 59 63 60 64 class ViewerFrame(wx.Frame): … … 130 134 #panel on focus 131 135 self.panel_on_focus = None 136 self.loader = Loader() 132 137 #data manager 133 138 from data_manager import DataManager … … 479 484 return ID 480 485 481 def _populate_file_menu(self):482 """483 Insert menu item under file menu484 """485 for plugin in self.plugins:486 if len(plugin.populate_file_menu()) > 0:487 for item in plugin.populate_file_menu():488 id = wx.NewId()489 m_name, m_hint, m_handler = item490 self._file_menu.Append(id, m_name, m_hint)491 wx.EVT_MENU(self, id, m_handler)492 self._file_menu.AppendSeparator()493 494 486 def _setup_menus(self): 495 487 """ … … 723 715 if style == GUIFRAME.DATALOADER_ON: 724 716 # some menu of plugin to be seen under file menu 725 self._populate_file_menu() 717 hint_load_file = "Read state's files and load" 718 hint_load_file += " them into the application" 719 id = wx.NewId() 720 self._save_appl_menu = self._file_menu.Append(id, 721 '&Open State from File', hint_load_file) 722 wx.EVT_MENU(self, id, self._on_open_state) 726 723 id = wx.NewId() 727 724 self._save_appl_menu = self._file_menu.Append(id, … … 786 783 self.enable_edit_menu() 787 784 785 def get_style(self): 786 """ 787 """ 788 return self.__gui_style 789 788 790 def _add_menu_data(self): 789 791 """ 790 792 Add menu item item data to menu bar 791 793 """ 792 # Add menu data 793 self._data_menu = wx.Menu() 794 #menu for data files 795 data_file_id = wx.NewId() 796 data_file_hint = "load one or more data in the application" 797 self._data_menu.Append(data_file_id, 798 '&Load Data File(s)', data_file_hint) 799 wx.EVT_MENU(self, data_file_id, self._load_data) 800 style = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS 801 style1 = self.__gui_style & GUIFRAME.DATALOADER_ON 802 if style == GUIFRAME.MULTIPLE_APPLICATIONS: 803 #menu for data from folder 804 data_folder_id = wx.NewId() 805 data_folder_hint = "load multiple data in the application" 806 self._data_menu.Append(data_folder_id, 807 '&Load Data Folder', data_folder_hint) 808 wx.EVT_MENU(self, data_folder_id, self._load_folder) 809 self._menubar.Append(self._data_menu, '&Data') 810 elif style1 == GUIFRAME.DATALOADER_ON: 811 self._menubar.Append(self._data_menu, '&Data') 812 813 def _load_data(self, event): 814 """ 815 connect menu item load data with the first plugin that can load data 816 """ 817 for plug in self.plugins: 818 if plug.can_load_data(): 819 plug.load_data(event) 820 style = self.__gui_style & GUIFRAME.MANAGER_ON 821 if style == GUIFRAME.MANAGER_ON: 822 self.show_data_panel(event=None) 823 824 def _load_folder(self, event): 825 """ 826 connect menu item load data with the first plugin that can load data and 827 folder 828 """ 829 for plug in self.plugins: 830 if plug.can_load_data(): 831 plug.load_folder(event) 832 style = self.__gui_style & GUIFRAME.MANAGER_ON 833 if style == GUIFRAME.MANAGER_ON: 834 self.show_data_panel(event=None) 835 794 if self._data_plugin is not None: 795 menu_list = self._data_plugin.populate_menu(self) 796 if menu_list: 797 for (menu, name) in menu_list: 798 self._menubar.Append(menu, name) 799 836 800 def _on_hide_toolbar(self, event=None): 837 801 """ … … 911 875 self._mgr.GetPane(self.panels["default"].window_name).Hide() 912 876 self._mgr.Update() 913 914 def _on_open(self, event): 915 """ 916 """ 917 path = self.choose_file() 918 if path is None: 877 878 def clear_panel(self): 879 """ 880 """ 881 for item in self.panels: 882 try: 883 self.panels[item].clear_panel() 884 except: 885 pass 886 887 def create_gui_data(self, data, path=None): 888 """ 889 Receive data from loader and create a data to use for guiframe 890 """ 891 892 if issubclass(DataInfo.Data2D, data.__class__): 893 new_plot = Data2D(image=None, err_image=None) 894 else: 895 new_plot = Data1D(x=[], y=[], dx=None, dy=None) 896 897 new_plot.copy_from_datainfo(data) 898 data.clone_without_data(clone=new_plot) 899 #creating a name for data 900 name = "" 901 title = "" 902 file_name = "" 903 if path is not None: 904 file_name = os.path.basename(path) 905 if data.run: 906 name = data.run[0] 907 if name == "": 908 name = file_name 909 name = self._data_manager.rename(name) 910 #find title 911 if data.title.strip(): 912 title = data.title 913 if title.strip() == "": 914 title = file_name 915 916 if new_plot.filename.strip() == "": 917 new_plot.filename = file_name 918 919 new_plot.name = name 920 new_plot.title = title 921 ## allow to highlight data when plotted 922 new_plot.interactive = True 923 ## when 2 data have the same id override the 1 st plotted 924 new_plot.id = name 925 ##group_id specify on which panel to plot this data 926 new_plot.group_id = name 927 new_plot.is_data = True 928 new_plot.path = path 929 ##post data to plot 930 # plot data 931 return new_plot 932 933 def get_data(self, path, format=None): 934 """ 935 """ 936 message = "" 937 log_msg = '' 938 output = [] 939 error_message = "" 940 basename = os.path.basename(path) 941 root, extension = os.path.splitext(basename) 942 if extension.lower() not in EXTENSIONS: 943 log_msg = "File Loader cannot " 944 log_msg += "load: %s\n" % str(basename) 945 log_msg += "Try Data opening...." 946 logging.info(log_msg) 947 self.load_complete(output=output, error_message=error_message, 948 message=log_msg, path=path) 919 949 return 920 950 try: 951 temp = self.loader.load(path, extension) 952 if temp.__class__.__name__ == "list": 953 for item in temp: 954 data = self.create_gui_data(item, path) 955 output.append(data) 956 else: 957 data = self.create_gui_data(temp, path) 958 output.append(data) 959 message = "Loading File..." + str(basename) + "\n" 960 self.load_update(output=output, message=message) 961 except: 962 raise 963 error_message = "Error while loading: %s\n" % str(p_file) 964 error_message += str(sys.exc_value) + "\n" 965 self.load_update(output=output, message=error_message) 966 967 message = "Loading Complete! " 968 self.load_complete(output=output, error_message=error_message, 969 message=message, path=path, extension=extension) 970 971 def load_update(self, output=None, message=""): 972 """ 973 print update on the status bar 974 """ 975 if message != "": 976 wx.PostEvent(self, StatusEvent(status=message, 977 type="progress", 978 info="warning")) 979 980 def load_complete(self, output, message="", error_message="", 981 extension=None, path=None): 982 """ 983 post message to status bar and return list of data 984 """ 985 wx.PostEvent(self, StatusEvent(status=message, 986 info="warning", 987 type="stop")) 988 if error_message != "": 989 self.load_error(error_message) 990 #send a list of available data to plotting plugin 991 available_data = [] 992 if self._data_manager is not None: 993 self._data_manager.add_data(output) 994 temp = self._data_manager.get_selected_data() 995 for data_state in temp.values(): 996 available_data.append(data_state.data) 997 #reading a state file 998 for plug in self.plugins: 999 #plug.on_set_state_helper(event=None) 1000 _, ext = plug.get_extensions() 1001 if extension == ext: 1002 plug.set_state(state=None, datainfo=available_data) 1003 elif extension == '.svs': 1004 plug.set_state(state=None, datainfo=available_data) 1005 1006 style = self.__gui_style & GUIFRAME.MANAGER_ON 1007 if style == GUIFRAME.MANAGER_ON: 1008 if self._data_panel is not None: 1009 data_state = self._data_manager.get_selected_data() 1010 self._data_panel.load_data_list(data_state) 1011 self._mgr.GetPane(self._data_panel.window_name).Show(True) 1012 1013 def _on_open_state(self, event): 1014 """ 1015 """ 1016 path = None 1017 if self._default_save_location == None: 1018 self._default_save_location = os.getcwd() 1019 1020 wlist = ['SansView files (*.svs)|*.svs', 1021 'P(r) files (*.prv)|*.prv', 1022 'Fitting files (*.fitv)|*.fitv', 1023 'Invariant files (*.inv)|*.inv'] 1024 wlist = '|'.join(wlist) 1025 dlg = wx.FileDialog(self, 1026 "Choose a file", 1027 self._default_save_location, "", 1028 wlist) 1029 if dlg.ShowModal() == wx.ID_OK: 1030 path = dlg.GetPath() 1031 if path is not None: 1032 self._default_save_location = os.path.dirname(path) 1033 dlg.Destroy() 921 1034 if path and os.path.isfile(path): 922 1035 basename = os.path.basename(path) … … 928 1041 except: 929 1042 pass 930 #reset states and plot data 931 for item in STATE_FILE_EXT: 932 exec "plot_data(self, path,'%s')" % str(item) 933 else: 934 plot_data(self, path) 1043 self.get_data(path) 1044 935 1045 if self.defaultPanel is not None and \ 936 1046 self._mgr.GetPane(self.panels["default"].window_name).IsShown(): 937 1047 self.on_close_welcome_panel() 938 1048 939 1049 def _on_save_application(self, event): 940 1050 """ … … 954 1064 reader, ext = self._current_perspective.get_extensions() 955 1065 path = None 956 dlg = wx.FileDialog(self, " Choose afile",1066 dlg = wx.FileDialog(self, "Save Project file", 957 1067 self._default_save_location, "", '.svs', wx.SAVE) 958 1068 if dlg.ShowModal() == wx.ID_OK: … … 1144 1254 show the data panel 1145 1255 """ 1146 pane = self._mgr.GetPane(self.panels["data_panel"].window_name) 1147 #if not pane.IsShown(): 1148 pane.Show(True) 1149 self._mgr.Update() 1150 1151 def add_data(self, data_list, flag=False): 1256 style = self.__gui_style & GUIFRAME.MANAGER_ON 1257 if style == GUIFRAME.MANAGER_ON: 1258 pane = self._mgr.GetPane(self.panels["data_panel"].window_name) 1259 #if not pane.IsShown(): 1260 pane.Show(True) 1261 self._mgr.Update() 1262 1263 def add_data(self, data_list): 1152 1264 """ 1153 1265 receive a list of data . store them its data manager if possible … … 1159 1271 self._data_manager.add_data(data_list) 1160 1272 avalaible_data = self._data_manager.get_all_data() 1161 1162 if True: 1163 #reading a state file 1164 for plug in self.plugins: 1165 plug.on_set_state_helper(event=None) 1273 1166 1274 style = self.__gui_style & GUIFRAME.MANAGER_ON 1167 1275 if style == GUIFRAME.MANAGER_ON: … … 1259 1367 set the current active perspective 1260 1368 """ 1261 1369 print "set_current_perspective", perspective 1262 1370 self._current_perspective = perspective 1263 1371 name = "No current Application selected" -
guiframe/local_perspectives/data_loader/data_loader.py
rec489f5 r75fbd17 16 16 from sans.guiframe.dataFitting import Data2D 17 17 from sans.guiframe.utils import parse_name 18 from sans.guiframe.gui_style import GUIFRAME 18 19 19 STATE_FILE_EXT = ['SansView files (*.svs)|*.svs',20 'P(r) files (*.prv)|*.prv',21 'Fitting files (*.fitv)|*.fitv',22 'Invariant files (*.inv)|*.inv']23 20 EXTENSIONS = ['.svs', '.prv','.fitv', '.inv'] 24 21 … … 30 27 self._default_save_location = None 31 28 self.data_name_dict = {} 32 self.loader = Loader() 29 self.loader = Loader() 30 self._data_menu = None 33 31 34 def populate_ file_menu(self):32 def populate_menu(self, parent): 35 33 """ 36 get a menu item and append it under file menu of the application37 add load file menu item and load folder item38 34 """ 39 40 hint_load_file = "Read state's files and load them into the application" 41 return [["Open State from File", hint_load_file, self.load_file]] 42 43 def load_data(self, event): 35 # Add menu data 36 self._data_menu = wx.Menu() 37 #menu for data files 38 data_file_id = wx.NewId() 39 data_file_hint = "load one or more data in the application" 40 self._data_menu.Append(data_file_id, 41 '&Load Data File(s)', data_file_hint) 42 wx.EVT_MENU(self.parent, data_file_id, self._load_data) 43 gui_style = self.parent.get_style() 44 style = gui_style & GUIFRAME.MULTIPLE_APPLICATIONS 45 style1 = gui_style & GUIFRAME.DATALOADER_ON 46 if style == GUIFRAME.MULTIPLE_APPLICATIONS: 47 #menu for data from folder 48 data_folder_id = wx.NewId() 49 data_folder_hint = "load multiple data in the application" 50 self._data_menu.Append(data_folder_id, 51 '&Load Data Folder', data_folder_hint) 52 wx.EVT_MENU(self.parent, data_folder_id, self._load_folder) 53 54 return [(self._data_menu, 'Data')] 55 56 def _load_data(self, event): 44 57 """ 45 58 Load data 46 59 """ 47 flag = True 48 file_list = self.choose_data_file(flag) 60 if self._default_save_location == None: 61 self._default_save_location = os.getcwd() 62 63 cards = self.loader.get_wildcards() 64 wlist = '|'.join(cards) 65 style = wx.OPEN|wx.FD_MULTIPLE 66 dlg = wx.FileDialog(self.parent, 67 "Choose a file", 68 self._default_save_location, "", 69 wlist, 70 style=style) 71 if dlg.ShowModal() == wx.ID_OK: 72 file_list = dlg.GetPaths() 73 if len(file_list) >= 0 and not(file_list[0]is None): 74 self._default_save_location = os.path.dirname(file_list[0]) 75 dlg.Destroy() 76 49 77 if not file_list or file_list[0] is None: 50 78 return 51 self.get_data(file_list, flag=flag) 79 self.get_data(file_list) 80 self.parent.show_data_panel(event=None) 52 81 53 82 def can_load_data(self): … … 56 85 """ 57 86 return True 58 59 def load_file(self, event): 60 """ 61 Load sansview defined files 62 """ 63 flag = False 64 file_list = self.choose_data_file(flag) 65 if not file_list or file_list[0] is None: 66 return 67 self.get_state(file_list) 87 68 88 69 def load_folder(self, event):89 def _load_folder(self, event): 70 90 """ 71 91 Load entire folder 72 92 """ 73 flag = True74 path = self.choose_data_folder(flag)75 if path is None:76 return77 file_list = self.get_file_path(path)78 self.get_data(file_list, flag=flag)79 80 def get_wild_card(self, flag=True):81 """82 :param flag: is True load only data file, else load state file83 return wild cards84 """85 if flag:86 cards = self.loader.get_wildcards()87 for item in STATE_FILE_EXT:88 if item in cards:89 cards.remove(item)90 else:91 cards = STATE_FILE_EXT92 return '|'.join(cards)93 94 95 def choose_data_file(self, flag=True):96 """97 Open the file dialog to load file(s)98 """99 path = None100 93 if self._default_save_location == None: 101 94 self._default_save_location = os.getcwd() 102 103 cards = self.loader.get_wildcards()104 wlist = self.get_wild_card(flag)105 if flag:106 style = wx.OPEN|wx.FD_MULTIPLE107 else:108 style = wx.OPEN|wx.FD_DEFAULT_STYLE109 110 dlg = wx.FileDialog(self.parent,111 "Choose a file",112 self._default_save_location, "",113 wlist,114 style=style)115 if dlg.ShowModal() == wx.ID_OK:116 path = dlg.GetPaths()117 if len(path) >= 0 and not(path[0]is None):118 self._default_save_location = os.path.dirname(path[0])119 dlg.Destroy()120 return path121 122 def choose_data_folder(self, flag=True):123 """124 :param flag: is True load only data file, else load state file125 return a list of folder to read126 """127 path = None128 if self._default_save_location == None:129 self._default_save_location = os.getcwd()130 131 wlist = self.get_wild_card(flag)132 133 95 dlg = wx.DirDialog(self.parent, "Choose a directory", 134 96 self._default_save_location, … … 138 100 self._default_save_location = path 139 101 dlg.Destroy() 140 return path 141 102 if path is not None: 103 self._default_save_location = os.path.dirname(path) 104 else: 105 return 106 file_list = self.get_file_path(path) 107 self.get_data(file_list) 108 self.parent.show_data_panel(event=None) 109 110 142 111 def load_error(self, error=None): 143 112 """ … … 164 133 return [os.path.join(os.path.abspath(path), 165 134 file) for file in os.listdir(path)] 166 167 def get_state(self, path, format=None): 168 """ 169 read state 170 """ 171 output = [] 172 for p_file in path: 173 basename = os.path.basename(p_file) 174 root, extension = os.path.splitext(basename) 175 for extension in EXTENSIONS: 176 temp = self.loader.load(p_file, extension) 177 if temp.__class__.__name__ == "list": 178 for item in temp: 179 data = self.create_data(item, p_file) 180 else: 181 data = self.create_data(temp, p_file) 182 output.append(data) 183 self.load_complete(output=output, path=path) 184 185 def get_data(self, path, format=None, flag=True): 135 136 def get_data(self, path, format=None): 186 137 """ 187 138 """ … … 193 144 basename = os.path.basename(p_file) 194 145 root, extension = os.path.splitext(basename) 195 if flag: 196 if extension.lower() in EXTENSIONS: 197 log_msg = "Data Loader cannot " 198 log_msg += "load: %s\n" % str(p_file) 199 log_msg += "Try File -> open ...." 200 logging.info(log_msg) 201 continue 202 else: 203 if extension.lower() not in EXTENSIONS: 204 log_msg = "File Loader cannot" 205 log_msg += " load: %s\n" % str(p_file) 206 log_msg += "Try Data -> Load ...." 207 logging.info(log_msg) 208 continue 146 if extension.lower() in EXTENSIONS: 147 log_msg = "Data Loader cannot " 148 log_msg += "load: %s\n" % str(p_file) 149 log_msg += "Try File opening ...." 150 logging.info(log_msg) 151 continue 152 209 153 try: 210 154 temp = self.loader.load(p_file, format) 211 155 if temp.__class__.__name__ == "list": 212 print "list", temp213 156 for item in temp: 214 data = self. create_data(item, p_file)157 data = self.parent.create_gui_data(item, p_file) 215 158 output.append(data) 216 159 else: 217 print "not list", [temp] 218 data = self.create_data(temp, p_file) 160 data = self.parent.create_gui_data(temp, p_file) 219 161 output.append(data) 220 message = "Loading ..." + str(p_file) + "\n"162 message = "Loading Data..." + str(p_file) + "\n" 221 163 self.load_update(output=output, message=message) 222 164 except: 223 raise 224 error_message = "Error while loading: %s\n" % str(p_file) 165 error_message = "Error while loading Data: %s\n" % str(p_file) 225 166 error_message += str(sys.exc_value) + "\n" 226 167 self.load_update(output=output, message=error_message) 227 168 228 message = "Loading Complete! "169 message = "Loading Data Complete! " 229 170 message += log_msg 230 171 self.load_complete(output=output, error_message=error_message, 231 message=message, path=path , flag=flag)172 message=message, path=path) 232 173 233 234 174 def load_update(self, output=None, message=""): 235 175 """ … … 240 180 type="progress", 241 181 info="warning")) 242 243 def load_complete(self, output, message="", error_message="", 244 path=None, flag=True): 182 def load_complete(self, output, message="", error_message="", path=None): 245 183 """ 246 184 post message to status bar and return list of data … … 251 189 if error_message != "": 252 190 self.load_error(error_message) 253 self.parent.add_data(output, flag=flag) 191 self.parent.add_data(output) 192 193 254 194 255 def create_data(self, data, path): 256 """ 257 Receive data from loader and create a data to use for guiframe 258 """ 259 260 if issubclass(DataInfo.Data2D, data.__class__): 261 new_plot = Data2D(image=None, err_image=None) 262 else: 263 new_plot = Data1D(x=[], y=[], dx=None, dy=None) 264 265 new_plot.copy_from_datainfo(data) 266 data.clone_without_data(clone=new_plot) 267 #creating a name for data 268 name = "" 269 title = "" 270 file_name = "" 271 if path is not None: 272 file_name = os.path.basename(path) 273 if data.run: 274 name = data.run[0] 275 if name == "": 276 name = file_name 277 ## name of the data allow to differentiate data when plotted 278 name = parse_name(name=name, expression="_") 279 280 max_char = name.find("[") 281 if max_char < 0: 282 max_char = len(name) 283 name = name[0:max_char] 284 285 if name not in self.data_name_dict: 286 self.data_name_dict[name] = 0 287 else: 288 self.data_name_dict[name] += 1 289 name = name + " [" + str(self.data_name_dict[name]) + "]" 290 #find title 291 if data.title.strip(): 292 title = data.title 293 if title.strip() == "": 294 title = file_name 295 296 if new_plot.filename.strip() == "": 297 new_plot.filename = file_name 298 299 new_plot.name = name 300 new_plot.title = title 301 ## allow to highlight data when plotted 302 new_plot.interactive = True 303 ## when 2 data have the same id override the 1 st plotted 304 new_plot.id = name 305 ##group_id specify on which panel to plot this data 306 new_plot.group_id = name 307 new_plot.is_data = True 308 new_plot.path = path 309 ##post data to plot 310 # plot data 311 return new_plot 312 313 195 -
guiframe/panel_base.py
ra45037aa r75fbd17 24 24 #window_caption = "Welcome panel" 25 25 ## Flag to tell the AUI manager to put this panel in the center pane 26 #CENTER_PANE = True26 group_id = None 27 27 28 28 def __init__(self, parent=None): -
guiframe/plugin_base.py
r52725d6 r75fbd17 94 94 """ 95 95 return self._always_active 96 97 def populate_file_menu(self): 98 """ 99 get a menu item and append it under file menu of the application 100 return [[menu item name, menu_hint, menu handler]] 101 """ 102 return [] 103 96 104 97 def populate_menu(self, parent): 105 98 """ … … 133 126 # Return the list of panels 134 127 return [] 128 129 def clear_panel(self): 130 """ 131 reset all panels 132 """ 135 133 136 134 def get_tools(self): … … 171 169 return self.perspective 172 170 173 def on_perspective(self, event ):171 def on_perspective(self, event=None): 174 172 """ 175 173 Call back function for the perspective menu item. … … 200 198 return False 201 199 200 def set_state(self, state=None, datainfo=None): 201 """ 202 update state 203 """ 202 204 def set_data(self, data_list): 203 205 """ -
invariantview/perspectives/invariant/invariant.py
r27f3831 r75fbd17 27 27 from DataLoader.loader import Loader 28 28 from .invariant_panel import InvariantPanel 29 from sans.guiframe.events import EVT_INVSTATE_UPDATE29 #from sans.guiframe.events import EVT_INVSTATE_UPDATE 30 30 31 31 from sans.guiframe.plugin_base import PluginBase … … 82 82 #add error back to the data 83 83 self.parent.Bind(ERR_DATA, self._on_data_error) 84 self.parent.Bind(EVT_INVSTATE_UPDATE, self.on_set_state_helper)84 #self.parent.Bind(EVT_INVSTATE_UPDATE, self.on_set_state_helper) 85 85 86 86 self.invariant_panel = InvariantPanel(parent=self.parent) … … 195 195 data = dlg.get_data() 196 196 if issubclass(data.__class__, LoaderData1D): 197 self.compute_helper(data_list[0])198 197 wx.PostEvent(self.parent, NewPlotEvent(plot=data_list[0], 199 198 title=data_list[0].title)) 199 self.compute_helper(data_list[0]) 200 200 else: 201 201 msg = "invariant cannot be computed for data of " … … 205 205 elif len(data_list) == 1: 206 206 if issubclass(data_list[0].__class__, LoaderData1D): 207 self.compute_helper(data_list[0])208 207 wx.PostEvent(self.parent, NewPlotEvent(plot=data_list[0], 209 208 title=data_list[0].title)) 209 self.compute_helper(data_list[0]) 210 210 else: 211 211 msg = "invariant cannot be computed for" … … 245 245 raise RuntimeError, msg 246 246 247 def set_state(self, state , datainfo=None):247 def set_state(self, state=None, datainfo=None): 248 248 """ 249 249 Call-back method for the state reader. … … 254 254 self.temp_state = None 255 255 try: 256 257 if datainfo is None: 256 if datainfo.__class__.__name__ == 'list': 257 data = datainfo[0] 258 if data is None: 258 259 msg = "invariant.set_state: datainfo parameter cannot" 259 260 msg += " be None in standalone mode" 260 261 raise RuntimeError, msg 261 262 262 name = datainfo.meta_data['invstate'].file 263 datainfo.meta_data['invstate'].file = name 264 datainfo.name = name 265 datainfo.filename = name 266 self.__data = datainfo 267 self.__data.group_id = datainfo.filename 268 self.__data.id = datainfo.filename 269 270 temp_state = copy.deepcopy(state) 263 name = data.meta_data['invstate'].file 264 data.meta_data['invstate'].file = name 265 data.name = name 266 data.filename = name 267 #datainfo = self.parent.create_gui_data(datainfo,None) 268 #self.__data = datainfo 269 #self.__data.group_id = data.filename 270 #self.__data.id = datainfo.filename 271 self.__data = data 272 wx.PostEvent(self.parent, NewPlotEvent(plot=self.__data, 273 reset=True, title=self.__data.title)) 274 #temp_state = copy.deepcopy(state) 275 temp_state = self.state_reader.get_state() 271 276 # set state 272 277 self.invariant_panel.is_state_data = True 273 278 274 279 # Make sure the user sees the invariant panel after loading 275 self.parent.set_perspective(self.perspective) 280 #self.parent.set_perspective(self.perspective) 281 self.on_perspective(event=None) 276 282 # Load the invariant states 277 283 self.temp_state = temp_state 278 #self.invariant_panel.set_state(state=temp_state,data=self.__data)279 280 except: 284 self.invariant_panel.set_state(state=temp_state,data=self.__data) 285 286 except: 281 287 logging.error("invariant.set_state: %s" % sys.exc_value) 282 288 -
invariantview/perspectives/invariant/invariant_state.py
r68d48fa r75fbd17 2 2 """ 3 3 4 import time4 #import time 5 5 import os 6 6 import sys … … 252 252 """ 253 253 from xml.dom.minidom import getDOMImplementation 254 import time 254 255 timestamp = time.time() 255 256 # Check whether we have to write a standalone XML file … … 319 320 for name, value_list in self.bookmark_list.iteritems(): 320 321 element = newdoc.createElement('mark_'+ str(name)) 321 _,date,state,comp_state = value_list322 time,date,state,comp_state = value_list 322 323 time_element = newdoc.createElement('time') 323 324 time_element.appendChild(newdoc.createTextNode(str(value_list[0]))) … … 643 644 ## CanSAS format flag 644 645 self.cansas = cansas 646 self.state = None 645 647 646 648 def read(self, path): … … 742 744 elif len(output) == 1: 743 745 # Call back to post the new state 744 745 self.call_back(state=output[0].meta_data['invstate'],746 datainfo = output[0])746 self.state = output[0].meta_data['invstate'] 747 #self.call_back(state=output[0].meta_data['invstate'], 748 # datainfo = output[0]) 747 749 return output[0] 748 750 else: 749 751 return output 750 752 753 def get_state(self): 754 return self.state 751 755 752 756 def write(self, filename, datainfo=None, invstate=None): -
prview/perspectives/pr/inversion_state.py
r3e41f43 r75fbd17 374 374 ## CanSAS format flag 375 375 self.cansas = cansas 376 self.state = None 376 377 377 378 def read(self, path): … … 404 405 405 406 # Call back to post the new state 406 self.call_back(state) 407 self.state = state 408 #self.call_back(state) 407 409 return None 408 410 411 def get_state(self): 412 return self.state 409 413 def _parse_prstate(self, entry): 410 414 """ … … 482 486 elif len(output) == 1: 483 487 # Call back to post the new state 484 self.call_back(output[0].meta_data['prstate'], datainfo = output[0]) 488 #self.call_back(output[0].meta_data['prstate'], datainfo = output[0]) 489 self.state = output[0].meta_data['prstate'] 485 490 return output[0] 486 491 else: -
prview/perspectives/pr/pr.py
r6d3d5ff r75fbd17 121 121 return self.current_plottable 122 122 123 def set_state(self, state , datainfo=None):123 def set_state(self, state=None, datainfo=None): 124 124 """ 125 125 Call-back method for the inversion state reader. … … 131 131 """ 132 132 try: 133 if datainfo is None: 133 if datainfo.__class__.__name__ == 'list': 134 if len(datainfo) == 1: 135 data = datainfo[0] 136 if data is None: 134 137 raise RuntimeError, "Pr.set_state: datainfo parameter cannot be None in standalone mode" 135 138 """ 136 139 # Ensuring that plots are coordinated correctly 137 t = time.localtime(data info.meta_data['prstate'].timestamp)140 t = time.localtime(data.meta_data['prstate'].timestamp) 138 141 time_str = time.strftime("%b %d %H:%M", t) 139 142 140 143 # Check that no time stamp is already appended 141 max_char = data info.meta_data['prstate'].file.find("[")144 max_char = data.meta_data['prstate'].file.find("[") 142 145 if max_char < 0: 143 max_char = len(datainfo.meta_data['prstate'].file) 144 145 datainfo.meta_data['prstate'].file = datainfo.meta_data['prstate'].file[0:max_char] +' [' + time_str + ']' 146 datainfo.filename = datainfo.meta_data['prstate'].file 147 148 self.current_plottable = datainfo 149 self.current_plottable.group_id = datainfo.meta_data['prstate'].file 146 max_char = len(data.meta_data['prstate'].file) 147 148 data.meta_data['prstate'].file = data.meta_data['prstate'].file[0:max_char] +' [' + time_str + ']' 149 data.filename = data.meta_data['prstate'].file 150 """ 151 self.current_plottable = data 152 # self.current_plottable.group_id = data.meta_data['prstate'].file 153 154 # Make sure the user sees the P(r) panel after loading 155 #self.parent.set_perspective(self.perspective) 156 self.on_perspective(event=None) 150 157 151 158 # Load the P(r) results 159 state = self.state_reader.get_state() 160 wx.PostEvent(self.parent, NewPlotEvent(plot=self.current_plottable, 161 title=self.current_plottable.title)) 152 162 self.control_panel.set_state(state) 153 154 # Make sure the user sees the P(r) panel after loading155 self.parent.set_perspective(self.perspective)156 157 163 except: 158 logging.error("prview.set_state: %s" % sys.exc_value) 164 raise 165 #logging.error("prview.set_state: %s" % sys.exc_value) 159 166 160 167 … … 391 398 new_plot.title = "P(r) fit" 392 399 # Make sure that the plot is linear 393 new_plot.xtransform ="x"394 new_plot.ytransform ="y"400 new_plot.xtransform = "x" 401 new_plot.ytransform = "y" 395 402 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="P(r) fit")) 396 403 -
sansview/perspectives/fitting/fitting.py
r3cd5806 r75fbd17 131 131 #Menu for fitting 132 132 self.menu1 = wx.Menu() 133 #menu for model 134 menu2 = wx.Menu() 135 self.menu_mng.populate_menu(menu2, owner) 136 id2 = wx.NewId() 137 owner.Bind(models.EVT_MODEL,self._on_model_menu) 133 138 134 #Set park engine 139 135 id3 = wx.NewId() … … 156 152 wx.EVT_MENU(owner, id1, self.on_add_sim_page) 157 153 154 #menu for model 155 menu2 = wx.Menu() 156 self.menu_mng.populate_menu(menu2, owner) 157 id2 = wx.NewId() 158 owner.Bind(models.EVT_MODEL,self._on_model_menu) 159 158 160 self.fit_panel.set_owner(owner) 159 161 self.fit_panel.set_model_list(self.menu_mng.get_model_list()) … … 231 233 """ 232 234 self.parent = parent 233 self.parent.Bind(EVT_FITSTATE_UPDATE, self.on_set_state_helper)235 #self.parent.Bind(EVT_FITSTATE_UPDATE, self.on_set_state_helper) 234 236 # Creation of the fit panel 235 237 self.fit_panel = FitPanel(self.parent, -1) … … 251 253 #Create reader when fitting panel are created 252 254 self.state_reader = Reader(self.set_state) 253 254 255 #append that reader to list of available reader 255 256 loader = Loader() 256 257 loader.associate_file_reader(".fitv", self.state_reader) 257 258 loader.associate_file_reader(".svs", self.state_reader) 259 from sans.perspectives.calculator.sld_panel import SldPanel 258 260 #Send the fitting panel to guiframe 259 261 self.mypanels.append(self.fit_panel) 260 262 self.mypanels.append(SldPanel(parent=self.parent, base=self.parent)) 261 263 return self.mypanels 262 264 … … 286 288 wx.PostEvent(self.parent, NewPlotEvent(plot=data, 287 289 title=str(data.title))) 288 289 290 290 291 def set_state(self, state=None, datainfo=None, format=None): … … 296 297 : param datainfo: data 297 298 """ 299 state = self.state_reader.get_state() 298 300 if state != None: 299 301 # store fitting state in temp_state … … 305 307 # state file format 306 308 self.sfile_ext = format 307 308 def on_set_state_helper(self,event=None): 309 310 self.on_set_state_helper(event=None) 311 312 def on_set_state_helper(self,event=None): 309 313 """ 310 314 Set_state_helper. This actually sets state after plotting data from state file. … … 325 329 if state.formfactorcombobox != None: 326 330 #set state 331 data = self.parent.create_gui_data(state.data) 332 data.group_id = state.data.group_id 333 wx.PostEvent(self.parent, NewPlotEvent(plot=data, 334 title=data.title)) 327 335 page = self.fit_panel.set_state(state) 328 336 else: 337 wx.PostEvent(self.parent, NewPlotEvent(plot=data, 338 title=data.title)) 329 339 #just set data because set_state won't work 330 page_info = self.fit_panel.get_page_info(data=state.data) 340 data = self.parent.create_gui_data(state.data) 341 data.group_id = state.data.group_id 342 page_info = self.fit_panel.get_page_info(data=data) 331 343 panel = self.fit_panel.add_page(page_info) 332 self.store_page(page=panel, data= state.data)344 self.store_page(page=panel, data=data) 333 345 self.mypanels.append(panel) 334 346 347 335 348 # get ready for the next set_state 336 349 self.state_index += 1 … … 342 355 #self.state_index = 0 343 356 # Make sure the user sees the fitting panel after loading 344 self.parent.set_perspective(self.perspective) 357 #self.parent.set_perspective(self.perspective) 358 self.on_perspective(event=None) 345 359 except: 346 360 self.state_index==0 … … 1382 1396 return 1383 1397 x = data.x 1384 1385 if qmin == None : 1386 qmin == DEFAULT_QMIN 1387 1388 if qmax == None: 1389 qmax == DEFAULT_QMAX 1390 1398 if qmin == DEFAULT_QMIN : 1399 qmin = min(data.x) 1400 if qmax == DEFAULT_QMAX: 1401 qmax = max(data.x) 1391 1402 if not enable1D: 1392 1403 return -
sansview/perspectives/fitting/pagestate.py
rfb59ed9 r75fbd17 631 631 ## CanSAS format flag 632 632 self.cansas = cansas 633 self.state = None 634 def get_state(self): 635 return self.state 633 636 634 637 def read(self, path): … … 1170 1173 state.data.group_id = name 1171 1174 #store state in fitting 1172 self.call_back(state=state, datainfo=output[ind],format=ext) 1175 #self.call_back(state=state, datainfo=output[ind],format=ext) 1176 self.state= state 1173 1177 return output 1174 1178 1175 1179 except: 1176 self.call_back(format=ext) 1180 #self.call_back(format=ext) 1181 self.state= state 1177 1182 raise 1178 1183 -
sansview/sansview.py
r193416e r75fbd17 64 64 self.gui.add_perspective(pr_plug) 65 65 except: 66 logging.error("SansView: could not find P(r) plug-in module") 67 logging.error(sys.exc_value) 66 raise 67 #logging.error("SansView: could not find P(r) plug-in module") 68 #logging.error(sys.exc_value) 68 69 69 70 #Invariant perspective
Note: See TracChangeset
for help on using the changeset viewer.