Changeset b9dbd6b in sasview
- Timestamp:
- Mar 5, 2015 11:51:04 AM (10 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:
- 824e488
- Parents:
- 3477478
- Location:
- src/sas/guiframe/local_perspectives
- Files:
-
- 2 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/local_perspectives/data_loader/data_loader.py
r8729965 rb9dbd6b 9 9 10 10 from sas.dataloader.loader import Loader 11 import sas.dataloader.data_info as DataInfo12 11 from sas.guiframe.plugin_base import PluginBase 13 12 from sas.guiframe.events import StatusEvent 14 from sas.guiframe.events import NewPlotEvent15 from sas.guiframe.dataFitting import Data1D16 from sas.guiframe.dataFitting import Data2D17 from sas.guiframe.utils import parse_name18 13 from sas.guiframe.gui_style import GUIFRAME 19 14 from sas.guiframe.gui_manager import DEFAULT_OPEN_FOLDER … … 25 20 (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))): 26 21 fObj, path, descr = imp.find_module('local_config', [path]) 27 config = imp.load_module('local_config', fObj, path, descr) 22 config = imp.load_module('local_config', fObj, path, descr) 28 23 else: 29 24 # Try simply importing local_config 30 25 import local_config as config 31 26 except: 32 # Didn't find local config, load the default 27 # Didn't find local config, load the default 33 28 import sas.guiframe.config as config 34 29 35 30 if config is None: 36 31 import sas.guiframe.config as config 37 38 32 33 39 34 extension_list = [] 40 35 if config.APPLICATION_STATE_EXTENSION is not None: 41 36 extension_list.append(config.APPLICATION_STATE_EXTENSION) 42 EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS + extension_list 37 EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS + extension_list 43 38 PLUGINS_WLIST = config.PLUGINS_WLIST 44 39 APPLICATION_WLIST = config.APPLICATION_WLIST 45 40 46 41 class Plugin(PluginBase): 47 42 48 43 def __init__(self, standalone=False): 49 44 PluginBase.__init__(self, name="DataLoader", standalone=standalone) 50 # Default location45 # Default location 51 46 self._default_save_location = DEFAULT_OPEN_FOLDER 52 self.loader = Loader() 53 self._data_menu = None 54 55 def help(self, evt): 56 """ 57 Show a general help dialog. 58 """ 59 # from documentation_window import DocumentationWindow 60 # _sphinx_doc_viewer = DocumentationWindow(self, -1, "/user/guiframe/ \ 61 # data_explorer_help.html", "DataLoader Help") 62 # from help_panel import HelpWindow 63 # frame = HelpWindow(None, -1) 64 # if hasattr(frame, "IsIconized"): 65 # if not frame.IsIconized(): 66 # try: 67 # icon = self.parent.GetIcon() 68 # frame.SetIcon(icon) 69 # except: 70 # pass 71 # frame.Show(True) 72 47 self.loader = Loader() 48 self._data_menu = None 49 73 50 def populate_file_menu(self): 74 51 """ … … 76 53 add load file menu item and load folder item 77 54 """ 78 # menu for data files55 # menu for data files 79 56 menu_list = [] 80 57 data_file_hint = "load one or more data in the application" … … 84 61 style1 = gui_style & GUIFRAME.DATALOADER_ON 85 62 if style == GUIFRAME.MULTIPLE_APPLICATIONS: 86 # menu for data from folder63 # menu for data from folder 87 64 data_folder_hint = "load multiple data in the application" 88 menu_list.append(('&Load Data Folder', data_folder_hint, 65 menu_list.append(('&Load Data Folder', data_folder_hint, 89 66 self._load_folder)) 90 67 return menu_list 91 92 68 93 69 def load_data(self, event): … … 99 75 if self._default_save_location == None: 100 76 self._default_save_location = os.getcwd() 101 77 102 78 cards = self.loader.get_wildcards() 103 79 temp = [APPLICATION_WLIST] + PLUGINS_WLIST … … 105 81 if item in cards: 106 82 cards.remove(item) 107 wlist = 108 style = wx.OPEN |wx.FD_MULTIPLE109 dlg = wx.FileDialog(self.parent, 110 "Choose a file", 83 wlist = '|'.join(cards) 84 style = wx.OPEN | wx.FD_MULTIPLE 85 dlg = wx.FileDialog(self.parent, 86 "Choose a file", 111 87 self._default_save_location, "", 112 113 88 wlist, 89 style=style) 114 90 if dlg.ShowModal() == wx.ID_OK: 115 91 file_list = dlg.GetPaths() 116 if len(file_list) >= 0 and not (file_list[0]is None):92 if len(file_list) >= 0 and not file_list[0] is None: 117 93 self._default_save_location = os.path.dirname(file_list[0]) 118 94 path = self._default_save_location 119 95 dlg.Destroy() 120 96 121 97 if path is None or not file_list or file_list[0] is None: 122 98 return 123 99 self.parent._default_save_location = self._default_save_location 124 100 self.get_data(file_list) 125 126 101 102 127 103 def can_load_data(self): 128 104 """ … … 130 106 """ 131 107 return True 132 133 108 109 134 110 def _load_folder(self, event): 135 111 """ … … 140 116 if self._default_save_location == None: 141 117 self._default_save_location = os.getcwd() 142 dlg = wx.DirDialog(self.parent, "Choose a directory", 118 dlg = wx.DirDialog(self.parent, "Choose a directory", 143 119 self._default_save_location, 144 120 style=wx.DD_DEFAULT_STYLE) 145 121 if dlg.ShowModal() == wx.ID_OK: 146 122 path = dlg.GetPath() … … 150 126 self._default_save_location = os.path.dirname(path) 151 127 else: 152 return 128 return 153 129 file_list = self.get_file_path(path) 154 130 self.get_data(file_list) 155 131 self.parent._default_save_location = self._default_save_location 156 132 157 133 def load_error(self, error=None): 158 134 """ 159 135 Pop up an error message. 160 136 161 137 :param error: details error message to be displayed 162 138 """ 163 139 if error is not None or str(error).strip() != "": 164 140 dial = wx.MessageDialog(self.parent, str(error), 'Error Loading File', 165 wx.OK | wx.ICON_EXCLAMATION)166 dial.ShowModal() 167 141 wx.OK | wx.ICON_EXCLAMATION) 142 dial.ShowModal() 143 168 144 def get_file_path(self, path): 169 145 """ … … 171 147 """ 172 148 if os.path.isdir(path): 173 return [os.path.join(os.path.abspath(path), 174 file) for file in os.listdir(path)] 175 149 return [os.path.join(os.path.abspath(path), filename) for filename in os.listdir(path)] 150 176 151 def _process_data_and_errors(self, item, p_file, output, message): 177 152 """ … … 186 161 output[data.id] = data 187 162 return output, message, data_error 188 163 189 164 def get_data(self, path, format=None): 190 165 """ … … 198 173 for p_file in path: 199 174 info = "info" 200 basename 175 basename = os.path.basename(p_file) 201 176 _, extension = os.path.splitext(basename) 202 177 if extension.lower() in EXTENSIONS: … … 209 184 logging.info(log_msg) 210 185 continue 211 186 212 187 try: 213 188 message = "Loading Data... " + str(p_file) + "\n" 214 189 self.load_update(output=output, message=message, info=info) 215 temp = 190 temp = self.loader.load(p_file, format) 216 191 if temp.__class__.__name__ == "list": 217 192 for item in temp: 218 193 output, error_message, data_error = \ 219 self._process_data_and_errors(item, 220 p_file, 221 output, 194 self._process_data_and_errors(item, 195 p_file, 196 output, 222 197 error_message) 223 198 else: 224 199 output, error_message, data_error = \ 225 self._process_data_and_errors(temp, 226 p_file, 227 output, 200 self._process_data_and_errors(temp, 201 p_file, 202 output, 228 203 error_message) 229 204 except: … … 243 218 error_message = base_message + error_message 244 219 else: 245 error_message += "%s\n" % str(p_file)220 error_message += "%s\n" % str(p_file) 246 221 info = "error" 247 self.load_update(output=output, message=error_message, 248 info=info) 249 222 self.load_update(output=output, message=error_message, info=info) 223 250 224 else: 251 225 message = "Loading Data Complete! " 252 226 message += log_msg 253 227 self.load_complete(output=output, error_message=error_message, 254 message=message, path=path, info=info)255 228 message=message, path=path, info=info) 229 256 230 def load_update(self, output=None, message="", info="warning"): 257 231 """ … … 259 233 """ 260 234 if message != "": 261 wx.PostEvent(self.parent, StatusEvent(status=message, info='info', 235 wx.PostEvent(self.parent, StatusEvent(status=message, info='info', 262 236 type="progress")) 263 def load_complete(self, output, message="", error_message="", path=None, 237 def load_complete(self, output, message="", error_message="", path=None, 264 238 info="warning"): 265 239 """ 266 240 post message to status bar and return list of data 267 241 """ 268 wx.PostEvent(self.parent, StatusEvent(status=message, 242 wx.PostEvent(self.parent, StatusEvent(status=message, 269 243 info=info, 270 244 type="stop")) 271 # if error_message != "":245 # if error_message != "": 272 246 # self.load_error(error_message) 273 247 self.parent.add_data(data_list=output) 274 275 276 277 248 249 250 -
src/sas/guiframe/local_perspectives/data_loader/load_thread.py
r79492222 rb9dbd6b 1 1 """ 2 Loading thread 3 """ 2 4 import time 3 5 import sys … … 6 8 from sas.data_util.calcthread import CalcThread 7 9 8 10 9 11 EXTENSIONS = ['.svs', '.prv', '.inv', '.fitv'] 10 12 … … 17 19 transform_data=None, 18 20 completefn=None, 19 updatefn = None, 20 yieldtime = 0.01, 21 worktime = 0.01 22 ): 21 updatefn=None, 22 yieldtime=0.01, 23 worktime=0.01): 23 24 CalcThread.__init__(self, completefn, 24 updatefn,25 yieldtime,26 worktime)25 updatefn, 26 yieldtime, 27 worktime) 27 28 self.load_state_flag = flag 28 29 self.transform_data = transform_data 29 30 self.list_path = path 30 # Instantiate a loader31 # Instantiate a loader 31 32 self.loader = loader 32 33 self.message = "" 33 self.starttime = 0 34 self.starttime = 0 34 35 self.updatefn = updatefn 35 36 36 37 def isquit(self): 37 38 """ … … 41 42 CalcThread.isquit(self) 42 43 except KeyboardInterrupt: 43 raise KeyboardInterrupt 44 45 44 raise KeyboardInterrupt 45 46 46 def compute(self): 47 47 """ … … 52 52 error_message = "" 53 53 for path in self.list_path: 54 basename 55 root, extension = os.path.splitext(basename)54 basename = os.path.basename(path) 55 _, extension = os.path.splitext(basename) 56 56 if self.load_state_flag: 57 57 if extension.lower() in EXTENSIONS: … … 61 61 pass 62 62 try: 63 temp = self.loader.load(path) 64 elapsed = time.time() - self.starttime 63 temp = self.loader.load(path) 65 64 if temp.__class__.__name__ == "list": 66 65 for item in temp: … … 77 76 error_message += str(sys.exc_value) + "\n" 78 77 self.updatefn(output=output, message=error_message) 79 78 80 79 message = "Loading Complete!" 81 80 self.complete(output=output, error_message=error_message, 82 message=message, path=self.list_path) 83 84 85 81 message=message, path=self.list_path) -
src/sas/guiframe/local_perspectives/plotting/plotting.py
r79492222 rb9dbd6b 335 335 self.create_panel_helper(new_panel, data, group_id, title) 336 336 return 337 338 def help(self, evt):339 """340 Show a general help dialog.341 """342 from help_panel import HelpWindow343 frame = HelpWindow(None, -1)344 if hasattr(frame, "IsIconized"):345 if not frame.IsIconized():346 try:347 icon = self.parent.GetIcon()348 frame.SetIcon(icon)349 except:350 pass351 337 frame.Show(True)
Note: See TracChangeset
for help on using the changeset viewer.