Changeset 82d88d5 in sasview for src/sas/sasgui/guiframe
- Timestamp:
- Mar 6, 2019 6:18:09 PM (6 years ago)
- Branches:
- master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1249
- Children:
- f923967
- Parents:
- cb64d86 (diff), f205d3a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- src/sas/sasgui/guiframe
- Files:
-
- 35 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/gui_manager.py
r5251ec6 r82d88d5 48 48 from sas.sasgui.guiframe.CategoryManager import CategoryManager 49 49 from sas.sascalc.dataloader.loader import Loader 50 from sas.sascalc.file_converter.nxcansas_writer import NXcanSASWriter 50 51 from sas.sasgui.guiframe.proxy import Connection 51 52 … … 64 65 SPLASH_SCREEN_HEIGHT = config.SPLASH_SCREEN_HEIGHT 65 66 SS_MAX_DISPLAY_TIME = config.SS_MAX_DISPLAY_TIME 66 if not WELCOME_PANEL_ON: 67 WELCOME_PANEL_SHOW = False 67 68 def custom_value(name, default=None): 69 """ 70 Fetch a config value from custom_config. Fallback to config, and then 71 to default if it doesn't exist in config. 72 """ 73 default = getattr(config, name, default) 74 return getattr(custom_config, name, default) 75 76 # Custom config values in the order they appear. 77 DATAPANEL_WIDTH = custom_value('DATAPANEL_WIDTH', -1) 78 CLEANUP_PLOT = custom_value('CLEANUP_PLOT', False) 79 FIXED_PANEL = custom_value('FIXED_PANEL', True) 80 PLOPANEL_WIDTH = custom_value('PLOPANEL_WIDTH', -1) 81 DATALOADER_SHOW = custom_value('DATALOADER_SHOW', True) 82 GUIFRAME_HEIGHT = custom_value('GUIFRAME_HEIGHT', -1) 83 GUIFRAME_WIDTH = custom_value('GUIFRAME_WIDTH', -1) 84 CONTROL_WIDTH = custom_value('CONTROL_WIDTH', -1) 85 CONTROL_HEIGHT = custom_value('CONTROL_HEIGHT', -1) 86 open_folder = custom_value('DEFAULT_OPEN_FOLDER', None) 87 if open_folder is not None and os.path.isdir(open_folder): 88 DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder) 68 89 else: 69 WELCOME_PANEL_SHOW = True70 try:71 DATALOADER_SHOW = custom_config.DATALOADER_SHOW72 TOOLBAR_SHOW = custom_config.TOOLBAR_SHOW73 FIXED_PANEL = custom_config.FIXED_PANEL74 if WELCOME_PANEL_ON:75 WELCOME_PANEL_SHOW = custom_config.WELCOME_PANEL_SHOW76 PLOPANEL_WIDTH = custom_config.PLOPANEL_WIDTH77 DATAPANEL_WIDTH = custom_config.DATAPANEL_WIDTH78 GUIFRAME_WIDTH = custom_config.GUIFRAME_WIDTH79 GUIFRAME_HEIGHT = custom_config.GUIFRAME_HEIGHT80 CONTROL_WIDTH = custom_config.CONTROL_WIDTH81 CONTROL_HEIGHT = custom_config.CONTROL_HEIGHT82 DEFAULT_PERSPECTIVE = custom_config.DEFAULT_PERSPECTIVE83 CLEANUP_PLOT = custom_config.CLEANUP_PLOT84 # custom open_path85 open_folder = custom_config.DEFAULT_OPEN_FOLDER86 if open_folder is not None and os.path.isdir(open_folder):87 DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder)88 else:89 DEFAULT_OPEN_FOLDER = get_app_dir()90 SAS_OPENCL = custom_config.SAS_OPENCL91 except:92 DATALOADER_SHOW = True93 TOOLBAR_SHOW = True94 FIXED_PANEL = True95 WELCOME_PANEL_SHOW = False96 PLOPANEL_WIDTH = config.PLOPANEL_WIDTH97 DATAPANEL_WIDTH = config.DATAPANEL_WIDTH98 GUIFRAME_WIDTH = config.GUIFRAME_WIDTH99 GUIFRAME_HEIGHT = config.GUIFRAME_HEIGHT100 CONTROL_WIDTH = -1101 CONTROL_HEIGHT = -1102 DEFAULT_PERSPECTIVE = None103 CLEANUP_PLOT = False104 90 DEFAULT_OPEN_FOLDER = get_app_dir() 105 DEFAULT_OPEN_FOLDER = PATH_APP 106 SAS_OPENCL = None 91 WELCOME_PANEL_SHOW = (custom_value('WELCOME_PANEL_SHOW', False) 92 if WELCOME_PANEL_ON else False) 93 TOOLBAR_SHOW = custom_value('TOOLBAR_SHOW', True) 94 DEFAULT_PERSPECTIVE = custom_value('DEFAULT_PERSPECTIVE', 'Fitting') 95 SAS_OPENCL = custom_value('SAS_OPENCL', 'None') 96 107 97 DEFAULT_STYLE = config.DEFAULT_STYLE 108 109 98 PLUGIN_STATE_EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS 110 99 OPEN_SAVE_MENU = config.OPEN_SAVE_PROJECT_MENU … … 2420 2409 default_name = fname 2421 2410 wildcard = "Text files (*.txt)|*.txt|"\ 2422 "CanSAS 1D files(*.xml)|*.xml" 2423 path = None 2411 "CanSAS 1D files (*.xml)|*.xml|"\ 2412 "NXcanSAS files (*.h5)|*.h5|" 2413 options = [".txt", ".xml",".h5"] 2424 2414 dlg = wx.FileDialog(self, "Choose a file", 2425 2415 self._default_save_location, … … 2431 2421 # This is MAC Fix 2432 2422 ext_num = dlg.GetFilterIndex() 2433 if ext_num == 0: 2434 ext_format = '.txt' 2435 else: 2436 ext_format = '.xml' 2423 2424 ext_format = options[ext_num] 2437 2425 path = os.path.splitext(path)[0] + ext_format 2438 2426 mypath = os.path.basename(path) 2439 2440 # Instantiate a loader 2441 loader = Loader() 2442 ext_format = ".txt" 2443 if os.path.splitext(mypath)[1].lower() == ext_format: 2427 fName = os.path.splitext(path)[0] + ext_format 2428 2429 if os.path.splitext(mypath)[1].lower() == options[0]: 2444 2430 # Make sure the ext included in the file name 2445 2431 # especially on MAC 2446 fName = os.path.splitext(path)[0] + ext_format2447 2432 self._onsaveTXT(data, fName) 2448 ext_format = ".xml" 2449 if os.path.splitext(mypath)[1].lower() == ext_format: 2433 elif os.path.splitext(mypath)[1].lower() == options[1]: 2450 2434 # Make sure the ext included in the file name 2451 2435 # especially on MAC 2452 fName = os.path.splitext(path)[0] + ext_format 2436 # Instantiate a loader 2437 loader = Loader() 2453 2438 loader.save(fName, data, ext_format) 2439 elif os.path.splitext(mypath)[1].lower() == options[2]: 2440 nxcansaswriter = NXcanSASWriter() 2441 nxcansaswriter.write([data], fName) 2454 2442 try: 2455 2443 self._default_save_location = os.path.dirname(path) … … 2478 2466 if has_errors: 2479 2467 if data.dx is not None and data.dx != []: 2480 out.write("<X> <Y> <dY><dX>\n")2468 out.write("<X>\t<Y>\t<dY>\t<dX>\n") 2481 2469 else: 2482 out.write("<X> <Y><dY>\n")2470 out.write("<X>\t<Y>\t<dY>\n") 2483 2471 else: 2484 out.write("<X> 2472 out.write("<X>\t<Y>\n") 2485 2473 2486 2474 for i in range(len(data.x)): … … 2526 2514 text += 'dY_min = %s: dY_max = %s\n' % (min(data.dy), max(data.dy)) 2527 2515 text += '\nData Points:\n' 2528 x_st = "X" 2516 text += "<index> \t<X> \t<Y> \t<dY> " 2517 text += "\t<dXl> \t<dXw>\n" if(data.dxl is not None and 2518 data.dxw is not None) else "\t<dX>\n" 2529 2519 for index in range(len(data.x)): 2530 2520 if data.dy is not None and len(data.dy) > index: … … 2537 2527 dx_val = 0.0 2538 2528 if data.dxl is not None and len(data.dxl) > index: 2539 if index == 0:2540 x_st = "Xl"2541 2529 dx_val = data.dxl[index] 2542 elif data.dxw is not None and len(data.dxw) > index: 2543 if index == 0: 2544 x_st = "Xw" 2545 dx_val = data.dxw[index] 2546 2547 if index == 0: 2548 text += "<index> \t<X> \t<Y> \t<dY> \t<d%s>\n" % x_st 2530 if data.dxw is not None and len(data.dxw) > index: 2531 dx_val = "%s \t%s" % (data.dxl[index], data.dxw[index]) 2532 2549 2533 text += "%s \t%s \t%s \t%s \t%s\n" % (index, 2550 2534 data.x[index], … … 2563 2547 """ 2564 2548 default_name = fname 2565 wildcard = "IGOR/DAT 2D file in Q_map (*.dat)|*.DAT" 2549 wildcard = "IGOR/DAT 2D file in Q_map (*.dat)|*.DAT|"\ 2550 "NXcanSAS files (*.h5)|*.h5|" 2566 2551 dlg = wx.FileDialog(self, "Choose a file", 2567 2552 self._default_save_location, … … 2575 2560 if ext_num == 0: 2576 2561 ext_format = '.dat' 2562 elif ext_num == 1: 2563 ext_format = '.h5' 2577 2564 else: 2578 2565 ext_format = '' … … 2582 2569 # Instantiate a loader 2583 2570 loader = Loader() 2584 2585 ext_format = ".dat" 2586 if os.path.splitext(mypath)[1].lower() == ext_format: 2571 ext = os.path.splitext(mypath)[1].lower() 2572 if ext == '.dat': 2587 2573 # Make sure the ext included in the file name 2588 2574 # especially on MAC 2589 2575 fileName = os.path.splitext(path)[0] + ext_format 2590 2576 loader.save(fileName, data, ext_format) 2577 elif ext == '.h5': 2578 # Make sure the ext included in the file name 2579 # especially on MAC 2580 fileName = os.path.splitext(path)[0] + ext_format 2581 nxcansaswriter = NXcanSASWriter() 2582 nxcansaswriter.write([data], fileName) 2591 2583 try: 2592 2584 self._default_save_location = os.path.dirname(path) -
src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py
r5251ec6 r82d88d5 205 205 except NoKnownLoaderException as e: 206 206 exception_occurred = True 207 error_message = "Loading data failed! " + e.message207 error_message = "Loading data failed!\n" + e.message 208 208 file_errors[basename] = [error_message] 209 209 except Exception as e: … … 224 224 for message in error_array: 225 225 error_message += message + "\n" 226 error_message = error_message[:-1] 226 227 self.load_complete(output=output, 227 228 message=error_message, … … 231 232 self.load_complete(output=output, message="Loading data complete!", 232 233 info="info") 233 else:234 self.load_complete(output=None, message=error_message, info="error")235 234 236 235 def load_update(self, message="", info="warning"): -
src/sas/sasgui/guiframe/CategoryInstaller.py
ra26f67f rcb64d86 20 20 21 21 logger = logging.getLogger(__name__) 22 23 if sys.version_info[0] > 2: 24 def json_dump(obj, filename): 25 with open(filename, 'w', newline='\n') as fd: 26 json.dump(obj, fd) 27 else: # CRUFT: python 2.7 support 28 def json_dump(obj, filename): 29 with open(filename, 'wb') as fd: 30 json.dump(obj, fd) 22 31 23 32 class CategoryInstaller(object): … … 121 130 """ 122 131 _model_dict = {model.name: model for model in model_list} 123 _model_list = _model_dict.keys()132 _model_list = list(_model_dict.keys()) 124 133 125 134 serialized_file = None … … 146 155 by_model_dict.pop(model_name) 147 156 model_enabled_dict.pop(model_name) 148 except Exception :149 logger.error("CategoryInstaller: %s", sys.exc_value)157 except Exception as exc: 158 logger.error("CategoryInstaller: %s", exc) 150 159 else: 151 160 add_list.remove(model_name) … … 171 180 model_enabled_dict) 172 181 173 json .dump(master_category_dict, open(serialized_file, 'wb'))182 json_dump(master_category_dict, serialized_file) -
src/sas/sasgui/guiframe/CategoryManager.py
r463e7ffc r5251ec6 230 230 231 231 for model in model_name_list: 232 index = self.cat_list.InsertStringItem(sys.max int, model)232 index = self.cat_list.InsertStringItem(sys.maxsize, model) 233 233 self.cat_list.SetStringItem(index, 1, \ 234 234 str(self.by_model_dict[model]).\ … … 384 384 """ 385 385 cat_list = list() 386 for category in self.master_category_dict. iterkeys():386 for category in self.master_category_dict.keys(): 387 387 if not category == 'Uncategorized': 388 388 cat_list.append(category) -
src/sas/sasgui/guiframe/custom_pstats.py
r959eb01 r5251ec6 36 36 width = self.max_name_len 37 37 if self.fcn_list: 38 list= self.fcn_list[:]38 stats = self.fcn_list[:] 39 39 temp_msg = " Ordered by: " + self.sort_type + '\n' 40 40 else: 41 list = self.stats.keys()41 stats = list(self.stats.keys()) 42 42 temp_msg = " Random listing order was used\n" 43 43 44 44 for selection in amount: 45 list, temp_msg = self.eval_print_amount(selection, list, temp_msg)45 stats, temp_msg = self.eval_print_amount(selection, stats, temp_msg) 46 46 47 count = len( list)47 count = len(stats) 48 48 49 if not list:50 width , list = 0, list49 if not stats: 50 width = 0 51 51 else: 52 msg += 52 msg += str(temp_msg) + '\n' 53 53 if count < len(self.stats): 54 54 width = 0 55 for func in list:55 for func in stats: 56 56 if len(func_std_string(func)) > width: 57 57 width = len(func_std_string(func)) 58 58 59 width , list = width+2, list60 if list:59 width = width+2 60 if stats: 61 61 msg += ' ncalls tottime percall cumtime percall' 62 62 msg += ' filename:lineno(function)' + "\n" 63 for func in list:63 for func in stats: 64 64 cc, nc, tt, ct, callers = self.stats[func] 65 65 c = str(nc) -
src/sas/sasgui/guiframe/data_manager.py
r959eb01 r5251ec6 51 51 _str += "No of states is %s \n" % str(len(self.stored_data)) 52 52 n_count = 0 53 for 53 for value in self.stored_data.values(): 54 54 n_count += 1 55 55 _str += "State No %s \n" % str(n_count) … … 134 134 receive a list of 135 135 """ 136 for id, data in data_list.ite ritems():136 for id, data in data_list.items(): 137 137 if id in self.stored_data: 138 138 msg = "Data manager already stores %s" % str(data.name) … … 150 150 """ 151 151 """ 152 if prev_data.id not in self.stored_data .keys():152 if prev_data.id not in self.stored_data: 153 153 return None, {} 154 154 data_state = self.stored_data[prev_data.id] 155 155 self.stored_data[new_data.id] = data_state.clone() 156 156 self.stored_data[new_data.id].data = new_data 157 if prev_data.id in self.stored_data .keys():157 if prev_data.id in self.stored_data: 158 158 del self.stored_data[prev_data.id] 159 159 return prev_data.id, {new_data.id: self.stored_data[new_data.id]} … … 165 165 if data_id is None and theory is not None: 166 166 uid = theory.id 167 if uid in self.stored_data .keys():167 if uid in self.stored_data: 168 168 data_state = self.stored_data[uid] 169 169 else: … … 195 195 if search_id == d_id: 196 196 _selected_data[search_id] = data 197 if search_id in theory_list .keys():197 if search_id in theory_list: 198 198 _selected_theory_list[search_id] = theory_list[search_id] 199 199 … … 204 204 """ 205 205 """ 206 return self.freeze_theory( self.stored_data.keys(), theory_id)206 return self.freeze_theory(list(self.stored_data.keys()), theory_id) 207 207 208 208 def freeze_theory(self, data_id, theory_id): … … 215 215 theory_list = data_state.get_theory() 216 216 for t_id in theory_id: 217 if t_id in theory_list .keys():217 if t_id in theory_list: 218 218 theory_data, theory_state = theory_list[t_id] 219 219 new_theory = copy.deepcopy(theory_data) … … 235 235 """ 236 236 for d_id in data_id: 237 if d_id in self.stored_data .keys():237 if d_id in self.stored_data: 238 238 data_state = self.stored_data[d_id] 239 239 if data_state.data.name in self.data_name_dict: … … 253 253 data_state = self.stored_data[d_id] 254 254 theory_list = data_state.get_theory() 255 if theory_id in theory_list .keys():255 if theory_id in theory_list: 256 256 del theory_list[theory_id] 257 257 #del pure theory … … 273 273 _selected_data = {} 274 274 for selected_name in name_list: 275 for id, data_state in self.stored_data.ite ritems():275 for id, data_state in self.stored_data.items(): 276 276 if data_state.data.name == selected_name: 277 277 _selected_data[id] = data_state.data … … 283 283 """ 284 284 for selected_name in name_list: 285 for id, data_state in self.stored_data.ite ritems():285 for id, data_state in self.stored_data.items(): 286 286 if data_state.data.name == selected_name: 287 287 del self.stored_data[id] … … 293 293 _selected_data_state = {} 294 294 for id in data_id: 295 if id in self.stored_data .keys():295 if id in self.stored_data: 296 296 _selected_data_state[id] = self.stored_data[id] 297 297 return _selected_data_state … … 303 303 return self.stored_data 304 304 305 306 -
src/sas/sasgui/guiframe/data_panel.py
rb963b20 r5251ec6 13 13 from __future__ import print_function 14 14 15 import sys 16 15 17 import wx 16 from wx.build import build_options17 18 import sys19 18 from wx.lib.scrolledpanel import ScrolledPanel 20 19 import wx.lib.agw.customtreectrl as CT 20 #from wx.build import build_options 21 21 22 from sas.sasgui.guiframe.dataFitting import Data1D 22 23 from sas.sasgui.guiframe.dataFitting import Data2D … … 444 445 self.parent.get_data_manager().get_by_id(id_list=[id]) 445 446 if data_list: 446 data = data_list.values()[0]447 data = list(data_list.values())[0] 447 448 if data is None: 448 data = theory_list.values()[0][0]449 data = list(theory_list.values())[0][0] 449 450 return data 450 451 … … 667 668 """ 668 669 if list: 669 for state_id, dstate in list.ite ritems():670 for state_id, dstate in list.items(): 670 671 data = dstate.get_data() 671 672 theory_list = dstate.get_theory() … … 764 765 if not theory_list: 765 766 return 766 if state_id not in self.list_cb_data .keys():767 if state_id not in self.list_cb_data: 767 768 root = self.tree_ctrl_theory.root 768 769 tree = self.tree_ctrl_theory … … 783 784 Append theory helper 784 785 """ 785 if state_id in self.list_cb_theory .keys():786 if state_id in self.list_cb_theory: 786 787 # update current list of theory for this data 787 788 theory_list_ctrl = self.list_cb_theory[state_id] 788 789 789 for theory_id, item in theory_list.ite ritems():790 for theory_id, item in theory_list.items(): 790 791 theory_data, _ = item 791 792 if theory_data is None: … … 828 829 # data didn't have a theory associated it before 829 830 theory_list_ctrl = {} 830 for theory_id, item in theory_list.ite ritems():831 for theory_id, item in theory_list.items(): 831 832 theory_data, _ = item 832 833 if theory_data is not None: … … 868 869 869 870 for theory_dict in self.list_cb_theory.values(): 870 for _, value in theory_dict.ite ritems():871 for _, value in theory_dict.items(): 871 872 item, _, _ = value 872 873 if item.IsChecked(): … … 924 925 theory_key = [] 925 926 # remove data from treectrl 926 for d_key, item in self.list_cb_data.ite ritems():927 for d_key, item in self.list_cb_data.items(): 927 928 data_c, _, _, _, _, _, _, _ = item 928 929 if data_c.IsChecked(): 929 930 self.tree_ctrl.Delete(data_c) 930 931 data_key.append(d_key) 931 if d_key in self.list_cb_theory .keys():932 if d_key in self.list_cb_theory: 932 933 theory_list_ctrl = self.list_cb_theory[d_key] 933 theory_to_remove += theory_list_ctrl.keys()934 theory_to_remove += list(theory_list_ctrl.keys()) 934 935 # Remove theory from treectrl 935 for _, theory_dict in self.list_cb_theory.ite ritems():936 for key, value in theory_dict.ite ritems():936 for _, theory_dict in self.list_cb_theory.items(): 937 for key, value in theory_dict.items(): 937 938 item, _, _ = value 938 939 if item.IsChecked(): … … 950 951 # remove theory references independently of data 951 952 for key in theory_key: 952 for _, theory_dict in self.list_cb_theory.ite ritems():953 for _, theory_dict in self.list_cb_theory.items(): 953 954 if key in theory_dict: 954 for key, value in theory_dict.ite ritems():955 for key, value in theory_dict.items(): 955 956 item, _, _ = value 956 957 if item.IsChecked(): … … 1047 1048 if self.cb_plotpanel and self.cb_plotpanel.IsBeingDeleted(): 1048 1049 return 1049 for _, value in self.parent.plot_panels.ite ritems():1050 for _, value in self.parent.plot_panels.items(): 1050 1051 name_plot_panel = str(value.window_caption) 1051 1052 if name_plot_panel not in self.cb_plotpanel.GetItems(): … … 1129 1130 #import documentation window here to avoid circular imports 1130 1131 #if put at top of file with rest of imports. 1131 from documentation_window import DocumentationWindow1132 from .documentation_window import DocumentationWindow 1132 1133 1133 1134 _TreeLocation = "user/sasgui/guiframe/data_explorer_help.html" … … 1499 1500 window.Show(True) 1500 1501 window.load_data_list(list=temp_data_list) 1501 except :1502 except Exception as exc: 1502 1503 # raise 1503 print("error", sys.exc_value)1504 print("error", exc) 1504 1505 1505 1506 app.MainLoop() -
src/sas/sasgui/guiframe/data_processor.py
r20fa5fe r5251ec6 234 234 # overriden in this subclassn - actually we have currently 235 235 # disabled the on_context_menu that would override the OnRightClick 236 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnCellChange) 236 try: 237 EVT_GRID_CELL_CHANGED = wx.grid.EVT_GRID_CELL_CHANGED 238 except AttributeError: 239 # CRUFT: wx 3.x uses CHANGE rather than CHANGING/CHANGED 240 EVT_GRID_CELL_CHANGED = wx.grid.EVT_GRID_CELL_CHANGE 241 self.Bind(EVT_GRID_CELL_CHANGED, self.OnCellChange) 237 242 self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnLeftClick) 238 243 self.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnRightClick) … … 561 566 value = self.GetCellValue(row, col) 562 567 self.data[col_name].append(value) 563 for k, value_list in self.data.ite ritems():568 for k, value_list in self.data.items(): 564 569 if k != col_name: 565 570 length = len(value_list) … … 621 626 if col_name.strip() != "Empty": 622 627 self.SetCellValue(row, col, str(col_name.strip())) 623 if col_name in self.data .keys():628 if col_name in self.data: 624 629 value_list = self.data[col_name] 625 630 cell_row = 1 … … 674 679 self._cols = self.GetNumberCols() 675 680 self._rows = self.GetNumberRows() 676 self.col_names = self.data_outputs.keys()681 self.col_names = list(self.data_outputs.keys()) 677 682 self.col_names.sort() 678 683 nbr_user_cols = len(self.col_names) … … 682 687 self.AppendCols(new_col_nbr, True) 683 688 #Add more rows to the grid if necessary 684 nbr_user_row = len( self.data_outputs.values()[0])689 nbr_user_row = len(list(self.data_outputs.values())[0]) 685 690 if nbr_user_row > self._rows + 1: 686 691 new_row_nbr = nbr_user_row - self._rows + 1 … … 909 914 msg = "Edit axis doesn't understand this selection.\n" 910 915 msg += "Please select only one column" 911 raise ValueError , msg916 raise ValueError(msg) 912 917 for (_, cell_col) in grid.selected_cells: 913 918 if cell_col != col: … … 915 920 msg += "this operation.\n" 916 921 msg += "Please select elements of the same col.\n" 917 raise ValueError , msg922 raise ValueError(msg) 918 923 919 924 # Finally check the highlighted cell if any cells missing … … 922 927 msg = "No item selected.\n" 923 928 msg += "Please select only one column or one cell" 924 raise ValueError , msg929 raise ValueError(msg) 925 930 return grid.selected_cells 926 931 … … 1326 1331 if sentence.strip() == "": 1327 1332 msg = "Select column values for x axis" 1328 raise ValueError , msg1333 raise ValueError(msg) 1329 1334 except: 1330 1335 msg = "X axis value error." … … 1345 1350 if sentence.strip() == "": 1346 1351 msg = "select value for y axis" 1347 raise ValueError , msg1352 raise ValueError(msg) 1348 1353 except: 1349 1354 msg = "Y axis value error." … … 1440 1445 """ 1441 1446 1442 for tok, (col_name, list) in dict.ite ritems():1447 for tok, (col_name, list) in dict.items(): 1443 1448 col = column_names[col_name] 1444 1449 axis = self.get_plot_axis(col, list) … … 1446 1451 return None 1447 1452 sentence = sentence.replace(tok, "numpy.array(%s)" % str(axis)) 1448 for key, value in FUNC_DICT.ite ritems():1453 for key, value in FUNC_DICT.items(): 1449 1454 sentence = sentence.replace(key.lower(), value) 1450 1455 return sentence … … 1546 1551 cell_list = self.notebook.on_edit_axis() 1547 1552 label, title = self.create_axis_label(cell_list) 1548 except :1549 msg = str( sys.exc_value)1553 except Exception as exc: 1554 msg = str(exc) 1550 1555 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 1551 1556 return … … 2036 2041 frame = GridFrame(data_outputs=data, data_inputs=data_input) 2037 2042 frame.Show(True) 2038 except :2039 print( sys.exc_value)2043 except Exception as exc: 2044 print(exc) 2040 2045 2041 2046 app.MainLoop() -
src/sas/sasgui/guiframe/data_state.py
r959eb01 r5251ec6 37 37 _str += "Theories available: %s \n" % len(self.theory_list) 38 38 if self.theory_list: 39 for id, item in self.theory_list.ite ritems():39 for id, item in self.theory_list.items(): 40 40 theory_data, theory_state = item 41 41 _str += "Theory name : %s \n" % str(theory_data.name) … … 53 53 obj.message = self.message 54 54 obj.id = self.id 55 for id, item in self.theory_list.ite ritems():55 for id, item in self.theory_list.items(): 56 56 theory_data, theory_state = item 57 57 state = None … … 95 95 """ 96 96 self.theory_list[theory_data.id] = [theory_data, theory_state] 97 data, state = self.theory_list.values()[0]97 data, state = list(self.theory_list.values())[0] 98 98 99 99 def get_theory(self): … … 106 106 return self.message 107 107 108 -
src/sas/sasgui/guiframe/gui_statusbar.py
r463e7ffc r5251ec6 86 86 wx.ART_TOOLBAR) 87 87 self.msg_txt.Newline() 88 self.msg_txt.WriteBitmap(icon_bmp) 88 # wx 3 has WriteImage and WriteBitmap; not sure if there 89 # is any difference between them. wx 4 has only WriteImage. 90 self.msg_txt.WriteImage(icon_bmp) 89 91 self.msg_txt.BeginTextColour(color) 90 92 self.msg_txt.WriteText("\t") -
src/sas/sasgui/guiframe/gui_style.py
ra1b8fee r5251ec6 58 58 DRAG_ID_PATH = os.path.join(PATH, 'drag_hand.png') 59 59 RESET_ID_PATH = os.path.join(PATH, 'reset.png') 60 PREVIEW_ID_PATH = os.path.join(PATH, 'report.png') 60 REPORT_ID_PATH = os.path.join(PATH, 'report.png') 61 PREVIEW_ID_PATH = os.path.join(PATH, 'preview.png') 61 62 PRINT_ID_PATH = os.path.join(PATH, 'printer.png') 62 63 HIDE_ID_PATH = os.path.join(PATH, 'hide.png') 63 64 64 65 SAVE_ICON = wx.Image(os.path.join(PATH, 'save.png')) 66 UNDO_ICON = wx.Image(os.path.join(PATH, 'undo.png')) 67 REDO_ICON = wx.Image(os.path.join(PATH, 'redo.png')) 68 COPY_ICON = wx.Image(os.path.join(PATH, 'copy.png')) 69 PASTE_ICON = wx.Image(os.path.join(PATH, 'paste.png')) 70 BOOKMARK_ICON = wx.Image(os.path.join(PATH, 'bookmark.png')) 71 ZOOM_IN_ICON = wx.Image(os.path.join(PATH, 'zoom_in.png')) 72 ZOOM_OUT_ICON = wx.Image(os.path.join(PATH, 'zoom_out.png')) 73 ZOOM_ICON = wx.Image(os.path.join(PATH, 'search_pan.png')) 74 DRAG_ICON = wx.Image(os.path.join(PATH, 'drag_hand.png')) 75 RESET_ICON = wx.Image(os.path.join(PATH, 'reset.png')) 76 REPORT_ICON = wx.Image(os.path.join(PATH, 'report.png')) 77 PREVIEW_ICON = wx.Image(os.path.join(PATH, 'preview.png')) 78 PRINT_ICON = wx.Image(os.path.join(PATH, 'printer.png')) 79 HIDE_ICON = wx.Image(os.path.join(PATH, 'hide.png')) 65 # Note: wx 4 requires that the app be defined before 66 # the images are loaded, so they can't be processed 67 # at module load time. Instead, need to load icons 68 # when the app is created. 69 @classmethod 70 def load_icons(cls): 71 cls.SAVE_ICON = wx.Image(cls.SAVE_ICON_PATH) 72 cls.UNDO_ICON = wx.Image(cls.UNDO_ICON_PATH) 73 cls.REDO_ICON = wx.Image(cls.REDO_ICON_PATH) 74 cls.COPY_ICON = wx.Image(cls.COPY_ICON_PATH) 75 cls.PASTE_ICON = wx.Image(cls.PASTE_ICON_PATH) 76 cls.BOOKMARK_ICON = wx.Image(cls.BOOKMARK_ICON_PATH) 77 cls.ZOOM_IN_ICON = wx.Image(cls.ZOOM_IN_ID_PATH) 78 cls.ZOOM_OUT_ICON = wx.Image(cls.ZOOM_OUT_ID_PATH) 79 cls.ZOOM_ICON = wx.Image(cls.ZOOM_ID_PATH) 80 cls.DRAG_ICON = wx.Image(cls.DRAG_ID_PATH) 81 cls.RESET_ICON = wx.Image(cls.RESET_ID_PATH) 82 cls.REPORT_ICON = wx.Image(cls.REPORT_ID_PATH) 83 cls.PREVIEW_ICON = wx.Image(cls.PREVIEW_ID_PATH) 84 cls.PRINT_ICON = wx.Image(cls.PRINT_ID_PATH) 85 cls.HIDE_ICON = wx.Image(cls.HIDE_ID_PATH) 80 86 81 87 if __name__ == "__main__": -
src/sas/sasgui/guiframe/local_perspectives/data_loader/load_thread.py
r959eb01 r5251ec6 72 72 if self.updatefn is not None: 73 73 self.updatefn(output=output, message=message) 74 except :74 except Exception as exc: 75 75 error_message = "Error while loading: %s\n" % str(path) 76 error_message += str( sys.exc_value) + "\n"76 error_message += str(exc) + "\n" 77 77 self.updatefn(output=output, message=error_message) 78 78 -
src/sas/sasgui/guiframe/local_perspectives/plotting/AnnulusSlicer.py
r7432acb r5251ec6 7 7 8 8 import math 9 # from copy import deepcopy 10 9 11 import wx 10 # from copy import deepcopy 11 # Debug printout 12 12 13 from sas.sasgui.guiframe.events import NewPlotEvent 13 14 from sas.sasgui.guiframe.events import StatusEvent 14 15 from sas.sasgui.guiframe.events import SlicerParameterEvent 15 16 from sas.sasgui.guiframe.events import EVT_SLICER_PARS 16 from BaseInteractor import _BaseInteractor17 17 from sas.sasgui.guiframe.dataFitting import Data1D 18 19 from .BaseInteractor import _BaseInteractor 18 20 19 21 class AnnulusInteractor(_BaseInteractor): -
src/sas/sasgui/guiframe/local_perspectives/plotting/Arc.py
r7432acb r5251ec6 4 4 import math 5 5 6 from BaseInteractor import _BaseInteractor7 6 from sas.sasgui.guiframe.events import SlicerParameterEvent 7 8 from .BaseInteractor import _BaseInteractor 8 9 9 10 class ArcInteractor(_BaseInteractor): -
src/sas/sasgui/guiframe/local_perspectives/plotting/AzimutSlicer.py
rd85c194 r5251ec6 5 5 # 6 6 import math 7 7 8 import wx 8 from BaseInteractor import _BaseInteractor 9 9 10 from sas.sasgui.guiframe.events import NewPlotEvent 10 11 from sas.sasgui.guiframe.events import EVT_SLICER_PARS 12 13 from .BaseInteractor import _BaseInteractor 11 14 12 15 class SectorInteractor(_BaseInteractor): … … 29 32 30 33 # Inner circle 31 from Arc import ArcInteractor34 from .Arc import ArcInteractor 32 35 self.inner_circle = ArcInteractor(self, self.base.subplot, 33 36 zorder=zorder, … … 43 46 self.outer_circle.qmax = self.qmax * 1.2 44 47 # self.outer_circle.set_cursor(self.base.qmax/1.8, 0) 45 from Edge import RadiusInteractor48 from .Edge import RadiusInteractor 46 49 self.right_edge = RadiusInteractor(self, self.base.subplot, 47 50 zorder=zorder + 1, -
src/sas/sasgui/guiframe/local_perspectives/plotting/Edge.py
r7432acb r5251ec6 1 1 import math 2 from BaseInteractor import _BaseInteractor 2 3 from .BaseInteractor import _BaseInteractor 3 4 4 5 -
src/sas/sasgui/guiframe/local_perspectives/plotting/Plotter1D.py
r2469df7 r5251ec6 11 11 12 12 13 import wx14 13 import sys 15 14 import math 15 import logging 16 17 import wx 16 18 import numpy as np 17 import logging 19 18 20 from sas.sasgui.plottools.PlotPanel import PlotPanel 19 21 from sas.sasgui.guiframe.events import StatusEvent … … 22 24 from sas.sasgui.guiframe.panel_base import PanelBase 23 25 from sas.sasgui.guiframe.gui_style import GUIFRAME_ICON 24 from appearanceDialog import appearanceDialog 25 from graphAppearance import graphAppearance 26 27 from .appearanceDialog import appearanceDialog 28 from .graphAppearance import graphAppearance 26 29 27 30 logger = logging.getLogger(__name__) … … 36 39 def find_key(dic, val): 37 40 """return the key of dictionary dic given the value""" 38 return [k for k, v in dic.ite ritems() if v == val][0]41 return [k for k, v in dic.items() if v == val][0] 39 42 40 43 class ModelPanel1D(PlotPanel, PanelBase): … … 220 223 if hasattr(event, 'is_corfunc'): 221 224 self.is_corfunc = event.is_corfunc 222 if event.id in self.plots .keys():225 if event.id in self.plots: 223 226 ctrl = event.ctrl 224 227 self.cursor_id = event.id … … 243 246 if position is not None and not self.is_corfunc: 244 247 wx.PostEvent(self.parent, StatusEvent(status=position)) 245 except :246 logger.error( sys.exc_value)248 except Exception as exc: 249 logger.error(exc) 247 250 if not event.leftdown: 248 251 # text event … … 256 259 if is_moved: 257 260 self.canvas.draw() 258 except :259 logger.error( sys.exc_value)261 except Exception as exc: 262 logger.error(exc) 260 263 event.Skip() 261 264 return … … 410 413 self.canvas.draw() 411 414 self.q_ctrl[vl_ind].SetValue(str(pos_x)) 412 except :413 logger.error( sys.exc_value)415 except Exception as exc: 416 logger.error(exc) 414 417 415 418 def set_resizing(self, resizing=False): … … 431 434 Remove data from plot 432 435 """ 433 if id in self.plots .keys():436 if id in self.plots: 434 437 data = self.plots[id] 435 438 self.graph.delete(data) … … 437 440 data_list, theory_list = data_manager.get_by_id(id_list=[id]) 438 441 439 if id in data_list .keys():442 if id in data_list: 440 443 data = data_list[id] 441 if id in theory_list .keys():444 if id in theory_list: 442 445 data = theory_list[id] 443 446 … … 457 460 if data.__class__.__name__ == 'Data2D': 458 461 return 459 plot_keys = self.plots.keys()462 plot_keys = list(self.plots.keys()) 460 463 if data.id in plot_keys: 461 464 # Recover panel prop.s … … 476 479 try: 477 480 self._onEVT_FUNC_PROPERTY() 478 except Exception ,exc:481 except Exception as exc: 479 482 wx.PostEvent(self.parent, 480 483 StatusEvent(status="Plotting Error: %s" % str(exc), info="error")) … … 493 496 # MAC: forcing to plot 2D avg 494 497 self.canvas._onDrawIdle() 495 except Exception ,exc:498 except Exception as exc: 496 499 wx.PostEvent(self.parent, StatusEvent(status=\ 497 500 "Plotting Error: %s" % str(exc), info="error")) … … 567 570 self.set_selected_from_menu(menu, event_id) 568 571 ## Check if there is a selected graph to remove 569 if self.graph.selected_plottable in self.plots .keys():572 if self.graph.selected_plottable in self.plots: 570 573 graph_id = self.graph.selected_plottable 571 574 self.remove_data_by_id(graph_id) … … 603 606 plot_menu = wx.Menu() 604 607 if self.graph.selected_plottable: 605 if not self.graph.selected_plottable in self.plots .keys():608 if not self.graph.selected_plottable in self.plots: 606 609 continue 607 610 if plot != self.plots[self.graph.selected_plottable]: … … 623 626 plot_menu.Append(wx_id, item[0], name) 624 627 wx.EVT_MENU(self, wx_id, item[2]) 625 except :628 except Exception as exc: 626 629 msg = "ModelPanel1D.onContextMenu: " 627 msg += "bad menu item %s" % sys.exc_value630 msg += "bad menu item %s" % exc 628 631 wx.PostEvent(self.parent, StatusEvent(status=msg)) 629 632 plot_menu.AppendSeparator() -
src/sas/sasgui/guiframe/local_perspectives/plotting/Plotter2D.py
r3e5648b r5251ec6 11 11 12 12 13 import wx14 13 import sys 15 14 import math 15 import logging 16 17 import wx 16 18 import numpy as np 17 import logging 19 from matplotlib.font_manager import FontProperties 20 18 21 from sas.sasgui.plottools.PlotPanel import PlotPanel 19 22 from sas.sasgui.plottools.plottables import Graph … … 24 27 from sas.sasgui.guiframe.events import SlicerEvent 25 28 from sas.sasgui.guiframe.utils import PanelMenu 26 from sas.sasgui.guiframe.local_perspectives.plotting.binder import BindArtist 27 from Plotter1D import ModelPanel1D 29 from sas.sasgui.guiframe.local_perspectives.plotting.binder import BindArtist 28 30 from sas.sasgui.plottools.toolbar import NavigationToolBar 29 from matplotlib.font_manager import FontProperties 30 from graphAppearance import graphAppearance 31 32 from .Plotter1D import ModelPanel1D 33 from .graphAppearance import graphAppearance 34 31 35 (InternalEvent, EVT_INTERNAL) = wx.lib.newevent.NewEvent() 32 36 … … 41 45 def find_key(dic, val): 42 46 """return the key of dictionary dic given the value""" 43 return [k for k, v in dic.ite ritems() if v == val][0]47 return [k for k, v in dic.items() if v == val][0] 44 48 45 49 … … 200 204 ## Update self.data2d with the current plot 201 205 self.data2D = data 202 if data.id in self.plots .keys():206 if data.id in self.plots: 203 207 #replace 204 208 xlo, xhi = self.subplot.get_xlim() … … 326 330 slicerpop.Append(wx_id, item[0], item[1]) 327 331 wx.EVT_MENU(self, wx_id, item[2]) 328 except :332 except Exception as exc: 329 333 msg = "ModelPanel1D.onContextMenu: " 330 msg += "bad menu item %s" % sys.exc_value334 msg += "bad menu item %s" % exc 331 335 wx.PostEvent(self.parent, StatusEvent(status=msg)) 332 336 slicerpop.AppendSeparator() … … 447 451 448 452 """ 449 import detector_dialog453 from . import detector_dialog 450 454 dialog = detector_dialog.DetectorDialog(self, -1, base=self.parent, 451 455 reset_zmin_ctl=self.default_zmin_ctl, … … 630 634 """ 631 635 if self.slicer is not None: 632 from parameters_panel_slicer import SlicerParameterPanel636 from .parameters_panel_slicer import SlicerParameterPanel 633 637 dialog = SlicerParameterPanel(self, -1, "Slicer Parameters") 634 638 dialog.set_slicer(self.slicer.__class__.__name__, … … 641 645 Perform sector averaging on Q and draw sector slicer 642 646 """ 643 from SectorSlicer import SectorInteractor647 from .SectorSlicer import SectorInteractor 644 648 self.onClearSlicer(event) 645 649 wx.PostEvent(self, InternalEvent(slicer=SectorInteractor)) … … 649 653 Perform sector averaging on Phi and draw annulus slicer 650 654 """ 651 from AnnulusSlicer import AnnulusInteractor655 from .AnnulusSlicer import AnnulusInteractor 652 656 self.onClearSlicer(event) 653 657 wx.PostEvent(self, InternalEvent(slicer=AnnulusInteractor)) … … 657 661 """ 658 662 from sas.sasgui.guiframe.gui_manager import MDIFrame 659 from boxSum import BoxSum663 from .boxSum import BoxSum 660 664 self.onClearSlicer(event) 661 665 self.slicer_z += 1 … … 668 672 params = self.slicer.get_params() 669 673 ## Create a new panel to display results of summation of Data2D 670 from parameters_panel_boxsum import SlicerPanel674 from .parameters_panel_boxsum import SlicerPanel 671 675 win = MDIFrame(self.parent, None, 'None', (100, 200)) 672 676 new_panel = SlicerPanel(parent=win, id=-1, … … 699 703 :param event: wx.menu event 700 704 """ 701 from boxSlicer import BoxInteractorX705 from .boxSlicer import BoxInteractorX 702 706 self.onClearSlicer(event) 703 707 wx.PostEvent(self, InternalEvent(slicer=BoxInteractorX)) … … 711 715 712 716 """ 713 from boxSlicer import BoxInteractorY717 from .boxSlicer import BoxInteractorY 714 718 self.onClearSlicer(event) 715 719 wx.PostEvent(self, InternalEvent(slicer=BoxInteractorY)) -
src/sas/sasgui/guiframe/local_perspectives/plotting/SectorSlicer.py
r8de66b6 r5251ec6 3 3 """ 4 4 import math 5 5 6 import wx 6 from BaseInteractor import _BaseInteractor 7 7 8 from sas.sasgui.guiframe.events import NewPlotEvent 8 9 from sas.sasgui.guiframe.events import StatusEvent … … 10 11 from sas.sasgui.guiframe.events import EVT_SLICER_PARS 11 12 from sas.sasgui.guiframe.dataFitting import Data1D 13 14 from .BaseInteractor import _BaseInteractor 12 15 13 16 … … 238 241 msg = "Phi left and phi right are different" 239 242 msg += " %f, %f" % (self.left_line.phi, self.right_line.phi) 240 raise ValueError , msg243 raise ValueError(msg) 241 244 params["Phi [deg]"] = self.main_line.theta * 180 / math.pi 242 245 params["Delta_Phi [deg]"] = math.fabs(self.left_line.phi * 180 / math.pi) -
src/sas/sasgui/guiframe/local_perspectives/plotting/appearanceDialog.py
rd85c194 r5251ec6 153 153 Populate Symbols 154 154 """ 155 self.sorted_symbo_labels = sorted(self.symbo_labels.ite ritems(),155 self.sorted_symbo_labels = sorted(self.symbo_labels.items(), 156 156 key=operator.itemgetter(1)) 157 157 self.sorted_sym_dic = {} … … 166 166 Populate Colors 167 167 """ 168 sortedcolor_labels = sorted(self.color_labels.ite ritems(),168 sortedcolor_labels = sorted(self.color_labels.items(), 169 169 key=operator.itemgetter(1)) 170 170 for color in sortedcolor_labels: … … 197 197 Find key 198 198 """ 199 return [k for k, v in dic.ite ritems() if v == val][0]199 return [k for k, v in dic.items() if v == val][0] 200 200 201 201 def get_current_values(self): -
src/sas/sasgui/guiframe/local_perspectives/plotting/binder.py
r20fa5fe r5251ec6 2 2 Extension to MPL to support the binding of artists to key/mouse events. 3 3 """ 4 from __future__ import print_function 5 6 import sys 4 7 import logging 5 import sys6 8 7 9 logger = logging.getLogger(__name__) … … 16 18 artist = None 17 19 prop = {} 20 18 21 def __init__(self, artist=None, prop={}): 19 22 self.artist, self.prop = artist, self.prop … … 25 28 return self.artist is not other.artist 26 29 27 def __ nonzero__(self):30 def __bool__(self): 28 31 return self.artist is not None 32 33 __nonzero__ = __bool__ 34 29 35 30 36 class BindArtist(object): 31 37 """ 32 Track keyboard modifiers for events. 33 TODO: Move keyboard modifier support into the backend. We cannot 34 TODO: properly support it from outside the windowing system since there 35 TODO: is no way to recognized whether shift is held down when the mouse 36 TODO: first clicks on the the application window. 38 Track keyboard modifiers for events. 37 39 """ 40 # TODO: Move keyboard modifier support into the backend. We cannot 41 # TODO: properly support it from outside the windowing system since there 42 # TODO: is no way to recognized whether shift is held down when the mouse 43 # TODO: first clicks on the the application window. 38 44 control, shift, alt, meta = False, False, False, False 39 45 … … 46 52 'scroll', 'key', 'keyup'] 47 53 # TODO: Need our own event structure 54 48 55 def __init__(self, figure): 49 56 canvas = figure.canvas 57 50 58 # Link to keyboard/mouse 51 59 try: … … 59 67 ] 60 68 except: 61 # print "bypassing scroll_event: wrong matplotlib version"69 logger.warn("bypassing scroll_event: wrong matplotlib version") 62 70 self._connections = [ 63 71 canvas.mpl_connect('motion_notify_event', self._onMotion), … … 67 75 canvas.mpl_connect('key_release_event', self._onKeyRelease), 68 76 ] 77 69 78 # Turn off picker if it hasn't already been done 70 79 try: 71 80 canvas.mpl_disconnect(canvas.button_pick_id) 72 81 canvas.mpl_disconnect(canvas.scroll_pick_id) 73 except: 74 logger.error(sys.exc_value) 82 except Exception as exc: 83 logger.error(exc) 84 85 self._current = None 86 self._actions = {} 75 87 self.canvas = canvas 76 88 self.figure = figure … … 83 95 84 96 Use clearall() to reset all connections. 85 86 97 """ 87 98 for h in artists: … … 108 119 for action in self.events: 109 120 self._actions[action] = {} 121 110 122 # Need activity state 111 123 self._artists = [] … … 121 133 for cid in self._connections: 122 134 self.canvas.mpl_disconnect(cid) 123 except :124 pass135 except Exception as exc: 136 logger.error("Error disconnection canvas: %s" % exc) 125 137 self._connections = [] 126 138 … … 169 181 sure it applies. E.g., the callback for 'press' might be: 170 182 if event.button == 1 and event.shift: process Shift-click 171 172 :TODO: Only receive events with the correct modifiers (e.g., S-click, 173 :TODO: or *-click for any modifiers). 174 :TODO: Only receive button events for the correct button (e.g., click1 175 :TODO: release3, or dclick* for any button) 176 :TODO: Support virtual artist, so that and artist can be flagged as 177 :TODO: having a tag list and receive the correct events 178 :TODO: Support virtual events for binding to button-3 vs shift button-1 179 :TODO: without changing callback code 180 :TODO: Attach multiple callbacks to the same event? 181 :TODO: Clean up interaction with toolbar modes 182 :TODO: push/pushclear/pop context so that binding changes 183 for the duration 184 :TODO: e.g., to support ? context sensitive help 185 186 """ 183 """ 184 #TODO: Only receive events with the correct modifiers (e.g., S-click, 185 #TODO: or *-click for any modifiers). 186 #TODO: Only receive button events for the correct button (e.g., click1 187 #TODO: release3, or dclick* for any button) 188 #TODO: Support virtual artist, so that and artist can be flagged as 189 #TODO: having a tag list and receive the correct events 190 #TODO: Support virtual events for binding to button-3 vs shift button-1 191 #TODO: without changing callback code 192 #TODO: Attach multiple callbacks to the same event? 193 #TODO: Clean up interaction with toolbar modes 194 #TODO: push/pushclear/pop context so that binding changes for the duration 195 #TODO: e.g., to support ? context sensitive help 196 187 197 # Check that the trigger is valid 188 198 if trigger not in self._actions: 189 raise ValueError, "%s invalid --- valid triggers are %s" \ 190 % (trigger, ", ".join(self.events)) 199 raise ValueError("%s invalid --- valid triggers are %s" 200 % (trigger, ", ".join(self.events))) 201 191 202 # Register the trigger callback 192 203 self._actions[trigger][artist] = action 193 # print "==> added",artist,[artist],"to",trigger,":", 194 # self._actions[trigger].keys() 204 195 205 # Maintain a list of all artists 196 206 if artist not in self._artists: … … 203 213 """ 204 214 if action not in self.events: 205 raise ValueError, "Trigger expects " + ", ".join(self.events) 215 raise ValueError("Trigger expects " + ", ".join(self.events)) 216 206 217 # Tag the event with modifiers 207 218 for mod in ('alt', 'control', 'shift', 'meta'): … … 210 221 setattr(ev, 'action', action) 211 222 setattr(ev, 'prop', {}) 223 212 224 # Fallback scheme. If the event does not return false, pass to parent. 213 225 processed = False … … 233 245 """ 234 246 # TODO: sort by zorder of axes then by zorder within axes 235 self._artists.sort(cmp=lambda x, y: cmp(y.zorder, x.zorder)) 236 # print "search"," ".join([str(h) for h in self._artists]) 247 self._artists.sort(key=lambda x: x.zorder, reverse=True) 237 248 found = Selection() 238 # print "searching in",self._artists239 249 for artist in self._artists: 240 250 # TODO: should contains() return false if invisible? … … 250 260 found.artist, found.prop = artist, prop 251 261 break 252 # print "found",found.artist253 262 254 263 # TODO: how to check if prop is equal? … … 257 266 self.trigger(found, 'enter', event) 258 267 self._current = found 268 259 269 return found 260 270 … … 274 284 275 285 transform = self._hasclick.artist.get_transform() 276 # 286 #x,y = event.xdata,event.ydata 277 287 x, y = event.x, event.y 278 288 try: 279 289 x, y = transform.inverted().transform_point((x, y)) 280 281 except: 290 except: # CRUFT: matplotlib-0.91 support 282 291 x, y = transform.inverse_xy_tup((x, y)) 292 283 293 event.xdata, event.ydata = x, y 284 294 self.trigger(self._hasclick, 'drag', event) 285 295 else: 286 296 found = self._find_current(event) 287 # print "found",found.artist288 297 self.trigger(found, 'motion', event) 289 298 … … 296 305 # Check for double-click 297 306 event_time = time.time() 298 # print event_time,self._last_time,self.dclick_threshhold299 # print (event_time > self._last_time + self.dclick_threshhold)300 # print event.button,self._last_button301 307 if (event.button != self._last_button) or \ 302 308 (event_time > self._last_time + self.dclick_threshhold): … … 381 387 setattr(self, event.key, False) 382 388 return 389 383 390 if self._haskey: 384 391 self.trigger(self._haskey, 'keyup', event) … … 391 398 found = self._find_current(event) 392 399 self.trigger(found, 'scroll', event) 393 -
src/sas/sasgui/guiframe/local_perspectives/plotting/boxMask.py
r7432acb r5251ec6 1 1 import math 2 from BaseInteractor import _BaseInteractor3 from boxSum import PointInteractor4 from boxSum import VerticalDoubleLine5 from boxSum import HorizontalDoubleLine2 from .BaseInteractor import _BaseInteractor 3 from .boxSum import PointInteractor 4 from .boxSum import VerticalDoubleLine 5 from .boxSum import HorizontalDoubleLine 6 6 7 7 -
src/sas/sasgui/guiframe/local_perspectives/plotting/boxSlicer.py
r20fa5fe r5251ec6 1 import math 2 1 3 import wx 2 import math3 4 import numpy as np 5 4 6 from sas.sasgui.guiframe.events import NewPlotEvent 5 7 from sas.sasgui.guiframe.events import StatusEvent 6 8 from sas.sasgui.guiframe.events import SlicerParameterEvent 7 9 from sas.sasgui.guiframe.events import EVT_SLICER_PARS 8 from BaseInteractor import _BaseInteractor9 10 from sas.sasgui.guiframe.dataFitting import Data1D 11 12 from .BaseInteractor import _BaseInteractor 10 13 11 14 … … 152 155 if new_slab is None: 153 156 msg = "post data:cannot average , averager is empty" 154 raise ValueError , msg157 raise ValueError(msg) 155 158 self.averager = new_slab 156 159 if self.direction == "X": … … 168 171 else: 169 172 msg = "post data:no Box Average direction was supplied" 170 raise ValueError , msg173 raise ValueError(msg) 171 174 # # Average data2D given Qx or Qy 172 175 box = self.averager(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max, -
src/sas/sasgui/guiframe/local_perspectives/plotting/boxSum.py
r7432acb r5251ec6 4 4 """ 5 5 import math 6 6 7 import wx 7 from BaseInteractor import _BaseInteractor 8 8 9 from sas.sasgui.guiframe.events import SlicerParamUpdateEvent 9 10 from sas.sasgui.guiframe.events import EVT_SLICER_PARS 10 11 from sas.sasgui.guiframe.events import StatusEvent 12 13 from .BaseInteractor import _BaseInteractor 11 14 12 15 -
src/sas/sasgui/guiframe/local_perspectives/plotting/detector_dialog.py
r7432acb r5251ec6 99 99 self.cmap_selector.SetStringSelection("jet") 100 100 self._on_select_cmap(event=None) 101 except :102 msg = "error occurs while resetting Detector: %s" % sys.exc_value101 except Exception as exc: 102 msg = "error occurs while resetting Detector: %s" % exc 103 103 wx.PostEvent(self.parent, StatusEvent(status=msg)) 104 104 -
src/sas/sasgui/guiframe/local_perspectives/plotting/masking.py
r20fa5fe r5251ec6 18 18 19 19 # #Todo: cleaning up, improving the maskplotpanel initialization, and testing. 20 import wx21 20 import sys 22 21 import time 23 import matplotlib.cm as cm24 22 import math 25 23 import copy 24 from functools import partial 25 26 import wx 26 27 import numpy as np 28 import matplotlib.cm as cm 29 27 30 from sas.sasgui.plottools.PlotPanel import PlotPanel 28 31 from sas.sasgui.plottools.plottables import Graph 29 from binder import BindArtist30 32 from sas.sasgui.guiframe.dataFitting import Data1D, Data2D 31 from boxMask import BoxMask32 from sector_mask import SectorMask33 from AnnulusSlicer import CircularMask34 35 33 from sas.sasgui.guiframe.events import SlicerEvent 36 34 from sas.sasgui.guiframe.events import StatusEvent 37 from functools import partial 35 36 from .binder import BindArtist 37 from .boxMask import BoxMask 38 from .sector_mask import SectorMask 39 from .AnnulusSlicer import CircularMask 40 38 41 39 42 (InternalEvent, EVT_INTERNAL) = wx.lib.newevent.NewEvent() -
src/sas/sasgui/guiframe/local_perspectives/plotting/parameters_panel_boxsum.py
r37d461c r5251ec6 1 1 import wx 2 2 import wx.lib.newevent 3 from parameters_panel_slicer import SlicerParameterPanel 3 4 4 from sas.sasgui.guiframe.utils import format_number 5 5 from sas.sasgui.guiframe.panel_base import PanelBase … … 7 7 EVT_SLICER) 8 8 9 from .parameters_panel_slicer import SlicerParameterPanel 9 10 10 11 class SlicerPanel(wx.Panel, PanelBase): … … 64 65 n = 1 65 66 self.parameters = [] 66 keys = params.keys() 67 keys.sort() 67 keys = list(sorted(params.keys())) 68 68 for item in keys: 69 69 if not item.lower() in ["num_points", "avg", "avg_error", "sum", -
src/sas/sasgui/guiframe/local_perspectives/plotting/parameters_panel_slicer.py
ra20a255 r5251ec6 2 2 3 3 import os 4 4 5 import wx 5 6 import wx.lib.newevent 7 6 8 from sas.sascalc.dataloader.readers.cansas_reader import Reader 7 9 from sas.sasgui.guiframe.utils import format_number 8 10 from sas.sasgui.guiframe.events import EVT_SLICER_PARS, EVT_SLICER 9 11 from sas.sasgui.guiframe.events import SlicerParameterEvent, StatusEvent 10 from Plotter2D import ModelPanel2D 12 13 from .Plotter2D import ModelPanel2D 14 11 15 apply_params, EVT_APPLY_PARAMS = wx.lib.newevent.NewEvent() 12 16 save_files, EVT_AUTO_SAVE = wx.lib.newevent.NewEvent() … … 100 104 iy = 1 101 105 self.parameters = [] 102 keys = params.keys() 103 keys.sort() 106 keys = list(sorted(params.keys())) 104 107 for item in keys: 105 108 ix = 0 … … 127 130 self.bck.Add(text, (iy, ix), (1, 1), 128 131 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 129 options = BINNING_OPTIONS.keys()132 options = list(BINNING_OPTIONS.keys()) 130 133 self.bin_ctl = wx.ComboBox(parent=self, choices=options) 131 134 hint_msg = "Modify the value of %s to change" % item … … 325 328 326 329 # Find desired 2D data panels 327 for key, mgr in spp.plot_panels.ite ritems():330 for key, mgr in spp.plot_panels.items(): 328 331 if mgr.graph.prop['title'] in self.data_list.CheckedStrings: 329 332 apply_to_list.append(mgr) … … 377 380 self.loaded_data = [] 378 381 # Iterate over the loaded plots and find all 2D panels 379 for key, value in self.main_window.plot_panels.ite ritems():382 for key, value in self.main_window.plot_panels.items(): 380 383 if isinstance(value, ModelPanel2D): 381 384 self.loaded_data.append(value.data2D.name) … … 453 456 454 457 # Find the correct plots to save 455 for key, plot in self.main_window.plot_panels.ite ritems():458 for key, plot in self.main_window.plot_panels.items(): 456 459 if not hasattr(plot, "data2D"): 457 460 for item in plot.plots: … … 461 464 462 465 # Save files as Text 463 for item, data1d in data_dic.ite ritems():466 for item, data1d in data_dic.items(): 464 467 base = '.'.join(item.split('.')[:-1]) 465 468 file_name = base + append + ".txt" -
src/sas/sasgui/guiframe/local_perspectives/plotting/plotting.py
r2d9526d r5251ec6 12 12 ################################################################################ 13 13 14 import wx15 14 import sys 16 15 from copy import deepcopy 16 17 import wx 18 17 19 from sas.sasgui.guiframe.events import EVT_NEW_PLOT 18 20 from sas.sasgui.guiframe.events import EVT_PLOT_QRANGE … … 23 25 from sas.sasgui.guiframe.dataFitting import Data2D 24 26 from sas.sasgui.guiframe.gui_manager import MDIFrame 27 25 28 DEFAULT_MENU_ITEM_LABEL = "No graph available" 26 29 DEFAULT_MENU_ITEM_ID = wx.NewId() … … 91 94 if event is None: 92 95 return 93 if event.id in self.plot_panels .keys():96 if event.id in self.plot_panels: 94 97 panel = self.plot_panels[event.id] 95 elif event.group_id in self.plot_panels .keys():98 elif event.group_id in self.plot_panels: 96 99 panel = self.plot_panels[event.group_id] 97 100 else: … … 102 105 if event is None: 103 106 return 104 if event.id in self.plot_panels .keys():107 if event.id in self.plot_panels: 105 108 panel = self.plot_panels[event.id] 106 elif event.group_id in self.plot_panels .keys():109 elif event.group_id in self.plot_panels: 107 110 panel = self.plot_panels[event.group_id] 108 111 else: … … 123 126 """ 124 127 125 if group_id in self.plot_panels .keys():128 if group_id in self.plot_panels: 126 129 panel = self.plot_panels[group_id] 127 130 panel.remove_data_by_id(id=id) … … 134 137 Clear and Hide all plot panels, and remove them from menu 135 138 """ 136 for group_id in self.plot_panels .keys():139 for group_id in self.plot_panels: 137 140 self.clear_panel_by_id(group_id) 138 141 self.plot_panels = {} … … 142 145 clear the graph 143 146 """ 144 if group_id in self.plot_panels .keys():147 if group_id in self.plot_panels: 145 148 panel = self.plot_panels[group_id] 146 149 for plottable in panel.graph.plottables.keys(): … … 184 187 # Create a new plot panel if none was available 185 188 if issubclass(data.__class__, Data1D): 186 from Plotter1D import ModelPanel1D189 from .Plotter1D import ModelPanel1D 187 190 ## get the data representation label of the data to plot 188 191 ## when even the user select "change scale" … … 200 203 201 204 msg = "1D Panel of group ID %s could not be created" % str(group_id) 202 raise ValueError , msg205 raise ValueError(msg) 203 206 204 207 def create_2d_panel(self, data, group_id): … … 207 210 if issubclass(data.__class__, Data2D): 208 211 ##Create a new plotpanel for 2D data 209 from Plotter2D import ModelPanel2D212 from .Plotter2D import ModelPanel2D 210 213 scale = data.scale 211 214 win = MDIFrame(self.parent, None, 'None', (200, 150)) … … 218 221 return new_panel 219 222 msg = "2D Panel of group ID %s could not be created" % str(group_id) 220 raise ValueError , msg223 raise ValueError(msg) 221 224 222 225 def update_panel(self, data, panel): … … 238 241 msg += " to panel %s\n" % str(panel.window_caption) 239 242 msg += "Please edit %s's units, labels" % str(data.name) 240 raise ValueError , msg243 raise ValueError(msg) 241 244 else: 242 245 if panel.group_id not in data.list_group_id: … … 247 250 """ 248 251 """ 249 if group_id in self.plot_panels .keys():252 if group_id in self.plot_panels: 250 253 panel = self.plot_panels[group_id] 251 254 uid = panel.uid … … 254 257 caption=panel.window_caption)) 255 258 del self.plot_panels[group_id] 256 if uid in self.parent.plot_panels .keys():259 if uid in self.parent.plot_panels: 257 260 del self.parent.plot_panels[uid] 258 261 panel.frame.Destroy() … … 280 283 for data in event.plots: 281 284 for panel in self.plot_panels.values(): 282 if data.id in panel.plots .keys():285 if data.id in panel.plots: 283 286 plot_exists = True 284 287 # Pass each panel it's own copy of the data … … 310 313 data = event.plot 311 314 group_id = data.group_id 312 if group_id in self.plot_panels .keys():315 if group_id in self.plot_panels: 313 316 if action_check: 314 317 # Check if the plot already exist. if it does, do nothing. 315 if data.id in self.plot_panels[group_id].plots .keys():318 if data.id in self.plot_panels[group_id].plots: 316 319 return 317 320 #update a panel graph … … 327 330 for p_group_id in self.plot_panels.keys(): 328 331 p_plot = self.plot_panels[p_group_id] 329 if data.id in p_plot.plots .keys():332 if data.id in p_plot.plots: 330 333 p_plot.plots[data.id] = data 331 334 self.plot_panels[group_id] = p_plot -
src/sas/sasgui/guiframe/local_perspectives/plotting/sector_mask.py
r7432acb r5251ec6 3 3 """ 4 4 import math 5 5 6 import wx 6 #from copy import deepcopy 7 from BaseInteractor import _BaseInteractor 8 from SectorSlicer import SideInteractor 9 from SectorSlicer import LineInteractor 7 10 8 from sas.sasgui.guiframe.events import SlicerParameterEvent 9 10 from .BaseInteractor import _BaseInteractor 11 from .SectorSlicer import SideInteractor 12 from .SectorSlicer import LineInteractor 11 13 12 14 class SectorMask(_BaseInteractor): … … 175 177 msg += "different %f, %f" % (self.left_line.phi, 176 178 self.right_line.phi) 177 raise ValueError , msg179 raise ValueError(msg) 178 180 params["Phi"] = self.main_line.theta 179 181 params["Delta_Phi"] = math.fabs(self.left_line.phi) -
src/sas/sasgui/guiframe/plugin_base.py
r20fa5fe r5251ec6 112 112 Load data 113 113 """ 114 raise NotImplementedError 114 raise NotImplementedError() 115 115 116 116 def load_folder(self, event): … … 118 118 Load entire folder 119 119 """ 120 raise NotImplementedError 120 raise NotImplementedError() 121 121 122 122 def set_is_active(self, active=False): … … 277 277 """ 278 278 msg = "%s plugin: does not support import theory" % str(self.sub_menu) 279 raise ValueError , msg279 raise ValueError(msg) 280 280 281 281 def on_set_state_helper(self, event): -
src/sas/sasgui/guiframe/proxy.py
r20fa5fe r5251ec6 3 3 from __future__ import print_function 4 4 5 import urllib26 5 import sys 7 6 import json … … 9 8 import re 10 9 10 try: 11 # CRUFT: python 3 uses urllib.request instead of urllib2 12 import urllib2 13 except ImportError: 14 from urllib import request as urllib2 11 15 12 16 logger = logging.getLogger(__name__) … … 50 54 this_name, this_val, this_type = winreg.EnumValue(net, i) 51 55 subkeys[this_name] = this_val 52 if 'AutoConfigURL' in subkeys .keys()and len(subkeys['AutoConfigURL']) > 0:56 if 'AutoConfigURL' in subkeys and len(subkeys['AutoConfigURL']) > 0: 53 57 pac_files.append(subkeys['AutoConfigURL']) 54 58 elif sys.platform == 'darwin': … … 61 65 # the first part is a long identifier 62 66 net_key, network = network 63 if 'ProxyAutoConfigURLString' in network['Proxies'] .keys():67 if 'ProxyAutoConfigURLString' in network['Proxies']: 64 68 pac_files.append( 65 69 network['Proxies']['ProxyAutoConfigURLString']) … … 127 131 logger.debug("Trying Direct connection to %s..."%self.url) 128 132 response = urllib2.urlopen(req, timeout=self.timeout) 129 except Exception , e:133 except Exception as exc: 130 134 logger.debug("Failed!") 131 logger.debug(e )135 logger.debug(exc) 132 136 try: 133 137 logger.debug("Trying to use system proxy if it exists...") 134 138 self._set_proxy() 135 139 response = urllib2.urlopen(req, timeout=self.timeout) 136 except Exception , e:140 except Exception as exc: 137 141 logger.debug("Failed!") 138 logger.debug(e )142 logger.debug(exc) 139 143 pac_urls = self._get_addresses_of_proxy_pac() 140 144 proxy_urls = self._parse_proxy_pac(pac_urls) … … 144 148 self._set_proxy(proxy) 145 149 response = urllib2.urlopen(req, timeout=self.timeout) 146 except Exception , e:150 except Exception as exc: 147 151 logger.debug("Failed!") 148 logger.debug(e )152 logger.debug(exc) 149 153 if response is not None: 150 154 logger.debug("The connection to %s was successful."%self.url) -
src/sas/sasgui/guiframe/report_dialog.py
rd0ce666f r5251ec6 147 147 self.Update() 148 148 return pisaStatus.err 149 except Exception :150 logger.error("Error creating pdf: %s" % sys.exc_value)149 except Exception as exc: 150 logger.error("Error creating pdf: %s" % exc) 151 151 return False -
src/sas/sasgui/guiframe/startup_configuration.py
rb963b20 r5251ec6 197 197 with open(path, 'w') as out_f: 198 198 out_f.write("#Application appearance custom configuration\n") 199 for key, item in self.return_string.ite ritems():199 for key, item in self.return_string.items(): 200 200 if (key == 'DEFAULT_PERSPECTIVE') or \ 201 201 (key == 'DEFAULT_OPEN_FOLDER' and item != None): -
src/sas/sasgui/guiframe/utils.py
r7432acb r5251ec6 208 208 self.id_list = id_list 209 209 self.index = -1 210 def next(self):210 def __next__(self): 211 211 self.index += 1 212 212 return self.id_list[self.index] 213 213 # CRUFT: python 2 uses next rather than __next__ for iterator 214 next = __next__ 215
Note: See TracChangeset
for help on using the changeset viewer.