Changeset 5251ec6 in sasview for src/sas/sasgui/perspectives
- Timestamp:
- Oct 11, 2018 12:20:56 PM (6 years ago)
- Branches:
- master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1249
- Children:
- 98b9f32
- Parents:
- 67ed543
- Location:
- src/sas/sasgui/perspectives
- Files:
-
- 48 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/calculator/__init__.py
r5a405bd r5251ec6 2 2 import os 3 3 from distutils.filelist import findall 4 from calculator import *4 from .calculator import * 5 5 N_DIR = 12 6 6 def get_data_path(media): -
src/sas/sasgui/perspectives/calculator/calculator.py
r61bfd36 r5251ec6 12 12 ################################################################################ 13 13 14 import logging 15 14 16 import wx 17 15 18 from sas.sasgui.guiframe.plugin_base import PluginBase 16 19 from sas.sasgui.perspectives.calculator.data_operator import DataOperatorWindow … … 26 29 from sas.sasgui.perspectives.calculator.image_viewer import ImageView 27 30 from sas.sasgui.perspectives.calculator.pyconsole import PyConsole 28 import logging29 31 30 32 logger = logging.getLogger(__name__) -
src/sas/sasgui/perspectives/calculator/collimation_editor.py
r959eb01 r5251ec6 1 1 """ 2 2 """ 3 import wx4 3 import sys 5 4 from copy import deepcopy 5 6 import wx 7 6 8 from sas.sascalc.dataloader.loader import Loader 7 9 from sas.sascalc.dataloader.data_info import Aperture, Collimation 8 from aperture_editor import ApertureDialog9 10 10 from sas.sasgui.guiframe.utils import check_float 11 12 from .aperture_editor import ApertureDialog 13 11 14 _BOX_WIDTH = 60 12 15 -
src/sas/sasgui/perspectives/calculator/data_editor.py
r235f514 r5251ec6 7 7 from sas.sascalc.dataloader.loader import Loader 8 8 from sas.sascalc.dataloader.data_info import Data2D 9 from detector_editor import DetectorDialog10 from collimation_editor import CollimationDialog11 from console import ConsoleDialog12 9 13 10 from sas.sasgui.guiframe.events import StatusEvent 11 12 from .detector_editor import DetectorDialog 13 from .collimation_editor import CollimationDialog 14 from .console import ConsoleDialog 15 14 16 15 17 … … 397 399 if data is None: 398 400 return 399 from sample_editor import SampleDialog401 from .sample_editor import SampleDialog 400 402 dlg = SampleDialog(parent=self, sample=data.sample) 401 403 dlg.set_manager(self) … … 409 411 if data is None: 410 412 return 411 from source_editor import SourceDialog413 from .source_editor import SourceDialog 412 414 dlg = SourceDialog(parent=self, source=data.source) 413 415 dlg.set_manager(self) … … 426 428 wlist = '|'.join(cards) 427 429 428 dlg = wx.FileDialog(self, "Choose a file", location, "", wlist, wx. OPEN)430 dlg = wx.FileDialog(self, "Choose a file", location, "", wlist, wx.FD_OPEN) 429 431 if dlg.ShowModal() == wx.ID_OK: 430 432 path = dlg.GetPath() … … 527 529 try: 528 530 #Load data 529 from load_thread import DataReader531 from .load_thread import DataReader 530 532 ## If a thread is already started, stop it 531 533 if self.reader is not None and self.reader.isrunning(): … … 535 537 updatefn=None) 536 538 self.reader.queue() 537 except :538 msg = "Data Editor: %s" % (sys.exc_value)539 except Exception as exc: 540 msg = "Data Editor: %s" % exc 539 541 load_error(msg) 540 542 return -
src/sas/sasgui/perspectives/calculator/data_operator.py
r7432acb r5251ec6 202 202 else: 203 203 text = name 204 state_list = self.get_datalist().values()205 204 name_list = [] 206 for state in s tate_list:205 for state in self.get_datalist().values(): 207 206 if state.data is None: 208 207 theory_list = state.get_theory() 209 theory, _ = theory_list.values()[0]208 theory, _ = list(theory_list.values())[0] 210 209 d_name = str(theory.name) 211 210 else: … … 393 392 try: 394 393 self.output = self.make_data_out(data1, data2) 395 except :394 except Exception as exc: 396 395 self._check_newname() 397 396 self._set_textctrl_color(self.data1_cbox, 'pink') 398 397 self._set_textctrl_color(self.data2_cbox, 'pink') 399 msg = "DataOperation: %s" % sys.exc_value398 msg = "DataOperation: %s" % exc 400 399 self.send_warnings(msg, 'error') 401 400 self.output = None … … 411 410 operator = self.operator_cbox.GetClientData(pos) 412 411 try: 413 exec "output = data1 %s data2" % operator 412 output = eval("data1 %s data2" % operator, 413 {"data1": data1, "data2": data2}) 414 414 except: 415 415 raise … … 532 532 self.data2_cbox.SetClientData(pos3, val) 533 533 dnames = [] 534 ids = self._data.keys() 535 for id in ids: 534 for id in self._data.keys(): 536 535 if id is not None: 537 536 if self._data[id].data is not None: … … 539 538 else: 540 539 theory_list = self._data[id].get_theory() 541 theory, _ = theory_list.values()[0]540 theory, _ = list(theory_list.values())[0] 542 541 dnames.append(theory.name) 543 542 ind = np.argsort(dnames) 544 543 if len(ind) > 0: 545 val_list = np.array( self._data.values())[ind]544 val_list = np.array(list(self._data.values()))[ind] 546 545 for datastate in val_list: 547 546 data = datastate.data … … 588 587 self.send_warnings('') 589 588 self.data_namectr.SetBackgroundColour('white') 590 state_list = self.get_datalist().values()591 589 name = self.data_namectr.GetValue().strip() 592 590 name_list = [] 593 for state in s tate_list:591 for state in self.get_datalist().values(): 594 592 if state.data is None: 595 593 theory_list = state.get_theory() 596 theory, _ = theory_list.values()[0]594 theory, _ = list(theory_list.values())[0] 597 595 d_name = str(theory.name) 598 596 else: … … 889 887 def _onProperties(self, event): 890 888 """ 891 when clicking on Properties on context menu , 892 The Property dialog is displayed 893 The user selects a transformation for x or y value and 894 a new plot is displayed 895 """ 896 list = [] 897 list = self.graph.returnPlottable() 898 if len(list.keys()) > 0: 899 first_item = list.keys()[0] 889 When clicking on Properties on context menu, the 890 Property dialog is displayed the user selects a 891 transformation for x or y value and a new plot is displayed 892 """ 893 plottables = self.graph.returnPlottable() 894 if plottables: 895 # TODO: key order is random prior to py 3.7 896 first_item = list(plottables.keys())[0] 900 897 if first_item.x != []: 901 898 from sas.sasgui.plottools.PropertyDialog import Properties … … 929 926 and set the scale 930 927 """ 931 list = []932 list = self.graph.returnPlottable()933 928 # Changing the scale might be incompatible with 934 929 # currently displayed data (for instance, going … … 940 935 _xscale = 'linear' 941 936 _yscale = 'linear' 942 for item in list:937 for item in self.graph.returnPlottable(): 943 938 item.setLabel(self.xLabel, self.yLabel) 944 939 # control axis labels from the panel itself -
src/sas/sasgui/perspectives/calculator/density_panel.py
r7432acb r5251ec6 362 362 self.molar_mass_ctl.SetValue(str(self._format_number(molar_mass))) 363 363 self.output_ctl.SetValue(str(output)) 364 except :364 except Exception as exc: 365 365 if self.base is not None: 366 msg = "Density/Volume Calculator: %s" % (sys.exc_value)366 msg = "Density/Volume Calculator: %s" % exc 367 367 wx.PostEvent(self.base, StatusEvent(status=msg)) 368 368 if event is not None: -
src/sas/sasgui/perspectives/calculator/detector_editor.py
ra1b8fee r5251ec6 34 34 self._do_layout() 35 35 self.set_values() 36 except :37 print("error", sys.exc_value)36 except Exception as exc: 37 print("error", exc) 38 38 39 39 def _define_structure(self): -
src/sas/sasgui/perspectives/calculator/gen_scatter_panel.py
r20fa5fe r5251ec6 228 228 sizer.Add(unit_title, (iy, ix), (1, 1), \ 229 229 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 230 key_list = params.keys() 231 key_list.sort() 232 for param in key_list: 230 for param in sorted(params.keys()): 233 231 iy += 1 234 232 ix = 0 … … 341 339 ix = 0 342 340 iy = 0 343 #key_list.sort()344 341 name = wx.StaticText(self, -1, 'No. of Qx (Qy) bins: ') 345 342 sizer.Add(name, (iy, ix), (1, 1), \ … … 509 506 wildcard = '|'.join(wildcard) 510 507 dlg = wx.FileDialog(self, "Choose a file", location, 511 "", wildcard, wx. OPEN)508 "", wildcard, wx.FD_OPEN) 512 509 if dlg.ShowModal() == wx.ID_OK: 513 510 path = dlg.GetPath() … … 556 553 self.reader.queue() 557 554 #self.load_update() 558 except :555 except Exception as exc: 559 556 self.ext = None 560 557 if self.parent.parent is None: 561 558 return 562 msg = "Generic SAS Calculator: %s" % (sys.exc_value)559 msg = "Generic SAS Calculator: %s" % exc 563 560 wx.PostEvent(self.parent.parent, 564 561 StatusEvent(status=msg, type='stop')) … … 774 771 if output.pix_type == 'atom': 775 772 # Get atom names not in the list 776 a_names = [symb for symb in pix_symbol \777 if symb not in color_dic .keys()]773 a_names = [symb for symb in pix_symbol 774 if symb not in color_dic] 778 775 a_name = a_names[0] 779 776 for name in a_names: … … 898 895 cal_out.queue() 899 896 900 except :901 msg = "%s." % sys.exc_value897 except Exception as exc: 898 msg = "%s." % exc 902 899 status_type = 'stop' 903 900 self._status_info(msg, status_type) … … 1344 1341 self.sld_data.is_data = False 1345 1342 self.sld_data.filename = "Default SLD Profile" 1346 except :1347 msg = "OMF Panel: %s" % sys.exc_value1343 except Exception as exc: 1344 msg = "OMF Panel: %s" % exc 1348 1345 infor = 'Error' 1349 1346 #logger.error(msg) … … 1441 1438 raise 1442 1439 sld_key_list = self._get_slds_key_list(omfdata) 1443 # Dic is not sorted1444 key_list = [key for key in sld_key_list.keys()]1445 # Sort here1446 key_list.sort()1447 1440 is_data = self.sld_data.is_data 1448 1441 sizer = wx.GridBagSizer(2, 3) 1449 1442 ix = 0 1450 1443 iy = -1 1451 for key in key_list: 1452 value = sld_key_list[key] 1444 for key, value in sorted(sld_key_list.items()): 1453 1445 iy += 1 1454 1446 ix = 0 … … 1485 1477 ix = 0 1486 1478 iy = -1 1487 for key, value in key_list.iteritems():1479 for key, value in sorted(key_list.items()): 1488 1480 iy += 1 1489 1481 ix = 0 … … 1520 1512 ix = 0 1521 1513 iy = -1 1522 #key_list.sort() 1523 for key, value in key_list.iteritems(): 1514 for key, value in sorted(key_list.items()): 1524 1515 iy += 1 1525 1516 ix = 0 -
src/sas/sasgui/perspectives/calculator/image_viewer.py
r412e9e8b r5251ec6 95 95 if location is None: 96 96 location = os.getcwd() 97 wildcard="Images (*.bmp;*.gif;*jpeg,*jpg;*.png;*tif;*.tiff)|*bmp;\ 98 *.gif; *.jpg; *.jpeg;*png;*.png;*.tif;*.tiff|"\ 99 "Bitmap (*.bmp)|*.bmp|"\ 100 "GIF (*.gif)|*.gif|"\ 101 "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|"\ 102 "PNG (*.png)|*.png|"\ 103 "TIFF (*.tif;*.tiff)|*.tif;*tiff|"\ 104 "All Files (*.*)|*.*|" 97 wildcard="|".join(( 98 "Images (*.bmp;*.gif;*jpeg,*jpg;*.png;*tif;*.tiff)" 99 "|*bmp;*.gif;*.jpg;*.jpeg;*png;*.png;*.tif;*.tiff", 100 "Bitmap (*.bmp)|*.bmp", 101 "GIF (*.gif)|*.gif", 102 "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg", 103 "PNG (*.png)|*.png", 104 "TIFF (*.tif;*.tiff)|*.tif;*tiff", 105 "All Files (*.*)|*.*", 106 )) 105 107 106 108 dlg = wx.FileDialog(self.parent, "Image Viewer: Choose an image file", -
src/sas/sasgui/perspectives/calculator/kiessig_calculator_panel.py
r7432acb r5251ec6 12 12 import sys 13 13 14 from sas.sascalc.calculator.kiessig_calculator import KiessigThicknessCalculator 14 15 from sas.sasgui.guiframe.panel_base import PanelBase 15 from sas.sascalc.calculator.kiessig_calculator import KiessigThicknessCalculator16 from calculator_widgets import OutputTextCtrl17 from calculator_widgets import InputTextCtrl18 16 from sas.sasgui.perspectives.calculator import calculator_widgets as widget 19 17 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 18 from .calculator_widgets import OutputTextCtrl 19 from .calculator_widgets import InputTextCtrl 20 20 21 21 _BOX_WIDTH = 77 -
src/sas/sasgui/perspectives/calculator/model_editor.py
r9bf40e7 r5251ec6 578 578 self.base = base 579 579 self.path = path 580 self.font = wx.SystemSettings _GetFont(wx.SYS_SYSTEM_FONT)580 self.font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT) 581 581 self.font.SetPointSize(10) 582 582 self.reader = None … … 781 781 if item.count("_") < 1: 782 782 try: 783 exec "float(math.%s)" % item783 exec("float(math.%s)" % item) 784 784 self.math_combo.Append(str(item)) 785 785 except Exception: -
src/sas/sasgui/perspectives/calculator/resolcal_thread.py
r20fa5fe r5251ec6 46 46 executing computation 47 47 """ 48 self.image = map(self.func, self.qx, self.qy,49 self.qx_min, self.qx_max,50 self.qy_min, self.qy_max)[0]48 self.image = list(map(self.func, self.qx, self.qy, 49 self.qx_min, self.qx_max, 50 self.qy_min, self.qy_max))[0] 51 51 elapsed = time.time() - self.starttime 52 52 -
src/sas/sasgui/perspectives/calculator/resolution_calculator_panel.py
r1cf490b6 r5251ec6 148 148 # Custom sorting 149 149 source_list = [] 150 for key, _ in self.source_mass.ite ritems():150 for key, _ in self.source_mass.items(): 151 151 name_source = str(key) 152 152 source_list.append(name_source) … … 667 667 Execute the computation of resolution 668 668 """ 669 # Clone the event before CallAfter; the event seems 670 # to delete the event when it is done processing, so 671 # the original will not be available when the call 672 # after method starts. 673 if event is not None: 674 event = event.Clone() 669 675 wx.CallAfter(self.on_compute_call, event) 670 676 … … 753 759 wx.MessageBox(msg, 'Warning') 754 760 return 755 #raise ValueError , "Invalid Q Input..."761 #raise ValueError("Invalid Q Input...") 756 762 757 763 # Validate the q inputs … … 934 940 def _sigma_strings(self): 935 941 """ 936 Recode sigmas as strin s942 Recode sigmas as strings 937 943 """ 938 944 sigma_r = self.format_number(self.resolution.sigma_1) … … 1082 1088 msg = "The numbers must be one or two (separated by ',')..." 1083 1089 self._status_info(msg, 'stop') 1084 raise RuntimeError , msg1090 raise RuntimeError(msg) 1085 1091 1086 1092 return new_string … … 1099 1105 value = float(string_split[ind]) 1100 1106 new_string.append(value) 1101 except :1102 logger.error( sys.exc_value)1107 except Exception as exc: 1108 logger.error(exc) 1103 1109 1104 1110 return new_string … … 1141 1147 out = self._string2inputlist(string) 1142 1148 return out 1143 except :1144 logger.error( sys.exc_value)1149 except Exception as exc: 1150 logger.error(exc) 1145 1151 1146 1152 def _on_xy_coordinate(self, event=None): … … 1269 1275 try: 1270 1276 basename = os.path.basename(path) 1271 if basename not in self.spectrum_dic .keys():1277 if basename not in self.spectrum_dic: 1272 1278 self.spectrum_cb.Append(basename) 1273 1279 self.spectrum_dic[basename] = self._read_file(path) … … 1286 1292 dlg = wx.FileDialog(self, 1287 1293 "Choose a wavelength spectrum file: Intensity vs. wavelength", 1288 self.parent.parent.get_save_location() , "", "*.*", wx. OPEN)1294 self.parent.parent.get_save_location() , "", "*.*", wx.FD_OPEN) 1289 1295 path = None 1290 1296 if dlg.ShowModal() == wx.ID_OK: … … 1318 1324 wavelength.append(wave) 1319 1325 intensity.append(intens) 1320 except :1326 except Exception as exc: 1321 1327 # Skip non-data lines 1322 logger.error( sys.exc_value)1328 logger.error(exc) 1323 1329 1324 1330 return [wavelength, intensity] -
src/sas/sasgui/perspectives/calculator/sld_panel.py
r2d220dd r5251ec6 363 363 364 364 """ 365 # TODO: use periodictable.elements object 366 # energy = xray_energy(periodictable.elements[element].K_alpha) 367 # TODO: code is very similar to sld helper 365 368 myformula = formula(str(element)) 366 369 if len(myformula.atoms) != 1: 367 370 return 368 element = myformula.atoms.keys()[0]371 element = list(myformula.atoms.keys())[0] 369 372 energy = xray_energy(element.K_alpha) 370 373 … … 413 416 msg += "Error for wavelength value :expect float" 414 417 elif (self.xray_source == 'Element'): 418 # TODO: use periodictable.elements instead of exec() hacks 419 # if self.xray_source_input not in periodictable.elements: 420 # ... 415 421 try: 416 422 import periodictable … … 447 453 448 454 """ 455 # TODO: use periodictable.elements object 456 # energy = xray_energy(periodictable.elements[element].K_alpha) 449 457 element_formula = formula(str(element)) 450 458 if len(element_formula.atoms) != 1: 451 459 return 452 element = element_formula.atoms.keys()[0]460 element = list(element_formula.atoms.keys())[0] 453 461 energy = xray_energy(element.K_alpha) 462 454 463 atom = molecule_formula.atoms 455 464 return xray_sld_from_atoms(atom, density=density, energy=energy) … … 505 514 #self.wavelength_ctl.SetValue(str(self.wavelength)) 506 515 #self.wavelength_ctl.SetValue(str(self.wavelength)) 507 except :516 except Exception as exc: 508 517 if self.base is not None: 509 msg = "SLD Calculator: %s" % (sys.exc_value)518 msg = "SLD Calculator: %s" % exc 510 519 wx.PostEvent(self.base, StatusEvent(status=msg)) 511 520 if event is not None: -
src/sas/sasgui/perspectives/calculator/slit_length_calculator_panel.py
rd788619 r5251ec6 17 17 from sas.sasgui.guiframe.events import StatusEvent 18 18 from sas.sascalc.calculator.slit_length_calculator import SlitlengthCalculator 19 from calculator_widgets import OutputTextCtrl20 from calculator_widgets import InterActiveOutputTextCtrl21 19 from sas.sasgui.perspectives.calculator import calculator_widgets as widget 22 20 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 21 from .calculator_widgets import OutputTextCtrl 22 from .calculator_widgets import InterActiveOutputTextCtrl 23 23 24 24 _BOX_WIDTH = 76 … … 163 163 164 164 dlg = wx.FileDialog(self, "Choose a file", location, 165 "", wildcard, wx. OPEN)165 "", wildcard, wx.FD_OPEN) 166 166 if dlg.ShowModal() == wx.ID_OK: 167 167 path = dlg.GetPath() … … 223 223 self.reader.queue() 224 224 self.load_update() 225 except :225 except Exception as exc: 226 226 if self.parent.parent is None: 227 227 return 228 msg = "Slit Length Calculator: %s" % (sys.exc_value)228 msg = "Slit Length Calculator: %s" % exc 229 229 wx.PostEvent(self.parent.parent, 230 230 StatusEvent(status=msg, type='stop')) … … 264 264 if x == [] or x is None or y == [] or y is None: 265 265 msg = "The current data is empty please check x and y" 266 raise ValueError , msg266 raise ValueError(msg) 267 267 slit_length_calculator = SlitlengthCalculator() 268 268 slit_length_calculator.set_data(x=x, y=y) 269 269 slit_length = slit_length_calculator.calculate_slit_length() 270 except :270 except Exception as exc: 271 271 if self.parent.parent is None: 272 272 return 273 msg = "Slit Size Calculator: %s" % (sys.exc_value)273 msg = "Slit Size Calculator: %s" % exc 274 274 wx.PostEvent(self.parent.parent, 275 275 StatusEvent(status=msg, type='stop')) -
src/sas/sasgui/perspectives/corfunc/__init__.py
rc23f303 r5251ec6 1 1 PLUGIN_ID = "Corfunc Plug-In 0.1" 2 from corfunc import *2 from .corfunc import * -
src/sas/sasgui/perspectives/corfunc/corfunc.py
r9b90bf8 r5251ec6 18 18 from sas.sascalc.dataloader.loader import Loader 19 19 import sas.sascalc.dataloader 20 from plot_labels import *20 from .plot_labels import * 21 21 22 22 logger = logging.getLogger(__name__) … … 148 148 self.data_id = data.id 149 149 self.corfunc_panel.set_data(data) 150 except :151 msg = "Corfunc set_data: " + str( sys.exc_value)150 except Exception as exc: 151 msg = "Corfunc set_data: " + str(exc) 152 152 wx.PostEvent(self.parent, StatusEvent(status=msg, 153 153 info='error')) -
src/sas/sasgui/perspectives/corfunc/corfunc_panel.py
r5652efc r5251ec6 17 17 from sas.sascalc.corfunc.corfunc_calculator import CorfuncCalculator 18 18 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 19 from plot_labels import *19 from .plot_labels import * 20 20 21 21 OUTPUT_STRINGS = { … … 396 396 output.SetValue('-') 397 397 return 398 for key, value in params.ite ritems():398 for key, value in params.items(): 399 399 output = self._extrapolation_outputs[key] 400 400 rounded = self._round_sig_figs(value, 6) … … 417 417 # Not all parameters were calculated 418 418 error = True 419 for key, value in params.ite ritems():419 for key, value in params.items(): 420 420 rounded = self._round_sig_figs(value, 6) 421 421 self._output_boxes[key].SetValue(rounded) … … 549 549 wx.CENTER | wx.ADJUST_MINSIZE, 15) 550 550 551 file_sizer.AddSpacer((1, 25), pos=(0,2))551 #file_sizer.AddSpacer((1, 25), pos=(0,2)) 552 552 databox_sizer.Add(file_sizer, wx.TOP, 15) 553 553 … … 713 713 self._output_boxes = dict() 714 714 i = 0 715 for key, value in OUTPUT_STRINGS.ite ritems():715 for key, value in OUTPUT_STRINGS.items(): 716 716 # Create a label and a text box for each poperty 717 717 label = wx.StaticText(self, -1, value) -
src/sas/sasgui/perspectives/corfunc/corfunc_state.py
r5652efc r5251ec6 74 74 if self.outputs != {} and self.outputs is not None: 75 75 state += "\nOutputs:\n" 76 for key, value in self.outputs.ite ritems():76 for key, value in self.outputs.items(): 77 77 name = output_list[key][1] 78 78 state += "{}: {}\n".format(name, str(value)) … … 158 158 state = new_doc.createElement("state") 159 159 top_element.appendChild(state) 160 for name, value in self.saved_state.ite ritems():160 for name, value in self.saved_state.items(): 161 161 element = new_doc.createElement(name) 162 162 element.appendChild(new_doc.createTextNode(str(value))) … … 181 181 output = new_doc.createElement("output") 182 182 top_element.appendChild(output) 183 for key, value in self.outputs.ite ritems():183 for key, value in self.outputs.items(): 184 184 element = new_doc.createElement(key) 185 185 element.appendChild(new_doc.createTextNode(str(value))) … … 214 214 try: 215 215 self.timestamp = (entry.get('epoch')) 216 except :216 except Exception as exc: 217 217 msg = ("CorfuncState.fromXML: Could not read timestamp", 218 "\n{}").format( sys.exc_value)218 "\n{}").format(exc) 219 219 logger.error(msg) 220 220 … … 222 222 entry = get_content('ns:state', node) 223 223 if entry is not None: 224 for item in DEFAULT_STATE. iterkeys():224 for item in DEFAULT_STATE.keys(): 225 225 input_field = get_content("ns:{}".format(item), entry) 226 226 if input_field is not None: … … 283 283 root, ext = os.path.splitext(basename) 284 284 if not ext.lower() in self.ext: 285 raise IOError , "{} is not a supported file type".format(ext)285 raise IOError("{} is not a supported file type".format(ext)) 286 286 tree = etree.parse(path, parser=etree.ETCompatXMLParser()) 287 287 root = tree.getroot() … … 299 299 # File not found 300 300 msg = "{} is not a valid file path or doesn't exist".format(path) 301 raise IOError , msg301 raise IOError(msg) 302 302 303 303 if len(output) == 0: … … 323 323 msg = ("The CanSAS writer expects a Data1D instance. {} was " 324 324 "provided").format(datainfo.__class__.__name__) 325 raise RuntimeError , msg325 raise RuntimeError(msg) 326 326 if datainfo.title is None or datainfo.title == '': 327 327 datainfo.title = datainfo.name … … 358 358 state = CorfuncState() 359 359 state.fromXML(nodes[0]) 360 except :360 except Exception as exc: 361 361 msg = "XML document does not contain CorfuncState information\n{}" 362 msg.format( sys.exc_value)362 msg.format(exc) 363 363 logger.info(msg) 364 364 return state -
src/sas/sasgui/perspectives/file_converter/__init__.py
r77d92cd r5251ec6 1 1 PLUGIN_ID = "File-Converter Plug-In 1.0" 2 from file_converter import *2 from .file_converter import * -
src/sas/sasgui/perspectives/file_converter/converter_panel.py
ra26f67f r5251ec6 112 112 [group_path, group_name] = os.path.split(filepath) 113 113 ext = "." + group_name.split('.')[-1] # File extension 114 for frame_number, frame_data in frame_data.ite ritems():114 for frame_number, frame_data in frame_data.items(): 115 115 # Append frame number to base filename 116 116 filename = group_name.replace(ext, str(frame_number)+ext) … … 155 155 # If lines end with comma or semi-colon, trim the last character 156 156 if end_char == ',' or end_char == ';': 157 data = map(lambda s: s[0:-1], data)157 data = [s[0:-1] for s in data] 158 158 else: 159 159 msg = ("Error reading {}: Lines must end with a digit, comma " … … 275 275 else: 276 276 return { 'frames': [], 'inc': None, 'file': single_file } 277 frames = range(first_frame, last_frame + 1, increment)277 frames = list(range(first_frame, last_frame + 1, increment)) 278 278 return { 'frames': frames, 'inc': increment, 'file': single_file } 279 279 … … 335 335 if single_file: 336 336 # Only need to set metadata on first Data1D object 337 frame_data = frame_data.values() # Don't need to know frame numbers337 frame_data = list(frame_data.values()) # Don't need to know frame numbers 338 338 frame_data[0].filename = output_path.split('\\')[-1] 339 for key, value in metadata.ite ritems():339 for key, value in metadata.items(): 340 340 setattr(frame_data[0], key, value) 341 341 else: … … 343 343 for datainfo in frame_data.values(): 344 344 datainfo.filename = output_path.split('\\')[-1] 345 for key, value in metadata.ite ritems():345 for key, value in metadata.items(): 346 346 setattr(datainfo, key, value) 347 347 … … 355 355 def convert_2d_data(self, dataset): 356 356 metadata = self.get_metadata() 357 for key, value in metadata.ite ritems():357 for key, value in metadata.items(): 358 358 setattr(dataset[0], key, value) 359 359 -
src/sas/sasgui/perspectives/file_converter/converter_widgets.py
r0e11ec7 r5251ec6 54 54 v = Vector() 55 55 if not self.Validate(): return v 56 for direction, control in self._inputs.ite ritems():56 for direction, control in self._inputs.items(): 57 57 try: 58 58 value = float(control.GetValue()) -
src/sas/sasgui/perspectives/fitting/__init__.py
r12d3e0e r5251ec6 1 1 PLUGIN_ID = "Fitting plug-in 1.0" 2 2 import os 3 from fitting import *4 3 from distutils.filelist import findall 4 from .fitting import * 5 5 def get_data_path(media): 6 6 """ -
src/sas/sasgui/perspectives/fitting/basepage.py
r5323490 r5251ec6 12 12 import logging 13 13 import traceback 14 from Queue import Queue 14 try: 15 from Queue import Queue 16 except ImportError: 17 from queue import Queue 15 18 from threading import Thread 16 19 from collections import defaultdict … … 66 69 FONT_VARIANT = 1 67 70 ON_MAC = True 71 if sys.version_info[0] >= 3: 72 unicode = str 68 73 69 74 CUSTOM_MODEL = 'Plugin Models' … … 115 120 # Q range for data set 116 121 self.qmin_data_set = np.inf 117 self.qmax_data_set = None122 self.qmax_data_set = -np.inf 118 123 self.npts_data_set = 0 119 124 # Q range … … 624 629 if self.model is not None: 625 630 self.m_name = self.model.name 626 if name in self.saved_states .keys():631 if name in self.saved_states: 627 632 previous_state = self.saved_states[name] 628 633 # reset state of checkbox,textcrtl and regular parameters value … … 893 898 894 899 if len(self._disp_obj_dict) > 0: 895 for k, v in self._disp_obj_dict.ite ritems():900 for k, v in self._disp_obj_dict.items(): 896 901 self.state.disp_obj_dict[k] = v.type 897 902 … … 960 965 961 966 if len(self.disp_cb_dict) > 0: 962 for k, v in self.disp_cb_dict.ite ritems():967 for k, v in self.disp_cb_dict.items(): 963 968 if v is None: 964 969 self.state.disp_cb_dict[k] = v … … 969 974 self.state.disp_cb_dict[k] = None 970 975 if len(self._disp_obj_dict) > 0: 971 for k, v in self._disp_obj_dict.ite ritems():976 for k, v in self._disp_obj_dict.items(): 972 977 self.state.disp_obj_dict[k] = v.type 973 978 … … 1097 1102 1098 1103 else: 1099 keys = self.model.getParamList() 1100 for item in keys: 1104 for item in self.model.getParamList(): 1101 1105 if item in self.disp_list and \ 1102 1106 item not in self.model.details: … … 1142 1146 :return: combo_box_position 1143 1147 """ 1144 for key, value in self.master_category_dict.ite ritems():1148 for key, value in self.master_category_dict.items(): 1145 1149 formfactor = state.formfactorcombobox.split(":") 1146 1150 if isinstance(formfactor, list): … … 1318 1322 Help to rest page for dispersions 1319 1323 """ 1320 keys = self.model.getParamList() 1321 for item in keys: 1324 for item in self.model.getParamList(): 1322 1325 if item in self.disp_list and \ 1323 1326 item not in self.model.details: 1324 1327 self.model.details[item] = ["", None, None] 1325 # for k,v in self.state.disp_cb_dict.ite ritems():1328 # for k,v in self.state.disp_cb_dict.items(): 1326 1329 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1327 1330 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) … … 1329 1332 self.weights = copy.deepcopy(state.weights) 1330 1333 1331 for key, disp_type in state.disp_obj_dict.ite ritems():1334 for key, disp_type in state.disp_obj_dict.items(): 1332 1335 # disp_model = disp 1333 1336 disp_model = POLYDISPERSITY_MODELS[disp_type]() … … 1378 1381 dlg = wx.FileDialog(self, "Choose a weight file", 1379 1382 self._default_save_location, "", 1380 "*.*", wx. OPEN)1383 "*.*", wx.FD_OPEN) 1381 1384 path = None 1382 1385 if dlg.ShowModal() == wx.ID_OK: … … 1390 1393 """ 1391 1394 ids = iter(self._id_pool) # Reusing ids for context menu 1392 for name, _ in self.state.saved_states.ite ritems():1395 for name, _ in self.state.saved_states.items(): 1393 1396 self.number_saved_state += 1 1394 1397 # Add item in the context menu … … 1919 1922 else: 1920 1923 tcrtl.SetBackgroundColour("pink") 1921 msg = "Model Error: wrong value entered: %s" % \1922 sys.exc_info()[1]1924 _, exc, _ = sys.exc_info() 1925 msg = "Model Error: wrong value entered: %s" % exc 1923 1926 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1924 1927 return 1925 except Exception :1928 except Exception as exc: 1926 1929 tcrtl.SetBackgroundColour("pink") 1927 msg = "Model Error: wrong value entered: %s" % sys.exc_info()[1]1930 msg = "Model Error: wrong value entered: %s" % exc 1928 1931 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1929 1932 return … … 1976 1979 else: 1977 1980 tcrtl.SetBackgroundColour("pink") 1978 msg = "Model Error: wrong value entered: %s" % \1979 sys.exc_info()[1]1981 _, exc, _ = sys.exc_info() 1982 msg = "Model Error: wrong value entered: %s" % exc 1980 1983 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1981 1984 return 1982 except Exception :1985 except Exception as exc: 1983 1986 tcrtl.SetBackgroundColour("pink") 1984 msg = "Model Error: wrong value entered: %s" % sys.exc_info()[1]1987 msg = "Model Error: wrong value entered: %s" % exc 1985 1988 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1986 1989 return … … 2291 2294 value_ctrl.SetValue(format_number(value)) 2292 2295 2293 if name not in self.model.details .keys():2296 if name not in self.model.details: 2294 2297 self.model.details[name] = ["", None, None] 2295 2298 old_low, old_high = self.model.details[name][1:3] … … 2750 2753 gui_manager = self._manager.parent 2751 2754 # loops through the panels [dic] 2752 for _, item2 in gui_manager.plot_panels.ite ritems():2755 for _, item2 in gui_manager.plot_panels.items(): 2753 2756 data_title = self.data.group_id 2754 2757 # try to get all plots belonging to this control panel … … 3324 3327 if self.data.__class__.__name__ == "Data2D": 3325 3328 name = item[1] 3326 if name in content .keys():3329 if name in content: 3327 3330 values = content[name] 3328 3331 check = values[0] … … 3373 3376 if not item[1] in orient_param: 3374 3377 name = item[1] 3375 if name in content .keys():3378 if name in content: 3376 3379 check = content[name][0] 3377 3380 # Avoid changing combox content … … 3480 3483 self.state.weights = self.weights 3481 3484 3482 except Exception :3485 except Exception as exc: 3483 3486 logger.error(traceback.format_exc()) 3484 print("Error in BasePage._paste_poly_help: %s" % \ 3485 sys.exc_info()[1]) 3487 print("Error in BasePage._paste_poly_help: %s" % exc) 3486 3488 3487 3489 def _set_disp_cb(self, isarray, item): … … 3548 3550 3549 3551 self.categorybox.Clear() 3550 cat_list = sorted(self.master_category_dict.keys())3552 cat_list = list(sorted(self.master_category_dict.keys())) 3551 3553 if uncat_str not in cat_list: 3552 3554 cat_list.append(uncat_str) -
src/sas/sasgui/perspectives/fitting/fit_thread.py
rba8d326 r5251ec6 12 12 13 13 def map_apply(arguments): 14 return apply(arguments[0], arguments[1:]) 14 fn, args = arguments[0], arguments[1:] 15 return fn(*args) 15 16 16 17 class FitThread(CalcThread): … … 50 51 except KeyboardInterrupt: 51 52 msg = "Fitting: terminated by the user." 52 raise KeyboardInterrupt , msg53 raise KeyboardInterrupt(msg) 53 54 54 55 def compute(self): … … 76 77 list_q, list_q, list_handler, list_curr_thread, 77 78 list_reset_flag) 78 result = map(map_apply, inputs)79 result = list(map(map_apply, inputs)) 79 80 80 81 self.complete(result=result, … … 85 86 elapsed=time.time() - self.starttime) 86 87 87 except KeyboardInterrupt ,msg:88 except KeyboardInterrupt as msg: 88 89 # Thread was interrupted, just proceed and re-raise. 89 90 # Real code should not print, but this is an example... -
src/sas/sasgui/perspectives/fitting/fitpage.py
rba1c145 r5251ec6 766 766 disp_box = wx.ComboBox(self, wx.ID_ANY, size=(65, -1), 767 767 style=wx.CB_READONLY, name='%s' % name1) 768 for key, value in POLYDISPERSITY_MODELS.ite ritems():768 for key, value in POLYDISPERSITY_MODELS.items(): 769 769 name_disp = str(key) 770 770 disp_box.Append(name_disp, value) … … 930 930 disp_box = wx.ComboBox(self, wx.ID_ANY, size=(65, -1), 931 931 style=wx.CB_READONLY, name='%s' % name1) 932 for key, value in POLYDISPERSITY_MODELS.ite ritems():932 for key, value in POLYDISPERSITY_MODELS.items(): 933 933 name_disp = str(key) 934 934 disp_box.Append(name_disp, value) … … 1372 1372 self._check_value_enter(self.fittable_param) 1373 1373 self._check_value_enter(self.parameters) 1374 except :1374 except Exception as exc: 1375 1375 tcrtl.SetBackgroundColour("pink") 1376 msg = "Model Error:wrong value entered : %s" % sys.exc_value1376 msg = "Model Error:wrong value entered : %s" % exc 1377 1377 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1378 1378 return … … 1486 1486 else: 1487 1487 tcrtl.SetBackgroundColour("pink") 1488 msg = "Model Error:wrong value entered : %s" % sys.exc_value 1488 _, exc, _ = sys.exc_info() 1489 msg = "Model Error:wrong value entered : %s" % exc 1489 1490 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1490 1491 return 1491 except :1492 except Exception as exc: 1492 1493 tcrtl.SetBackgroundColour("pink") 1493 msg = "Model Error:wrong value entered : %s" % sys.exc_value1494 msg = "Model Error:wrong value entered : %s" % exc 1494 1495 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1495 1496 return … … 1859 1860 wx.PostEvent(self._manager.parent, StatusEvent(status=msg, 1860 1861 info="error")) 1861 raise ValueError , msg1862 raise ValueError(msg) 1862 1863 1863 1864 else: … … 1871 1872 wx.PostEvent(self._manager.parent, StatusEvent(status=msg, 1872 1873 info="error")) 1873 raise ValueError , msg1874 raise ValueError(msg) 1874 1875 # Maximum value of data 1875 1876 qmax = math.sqrt(x * x + y * y) … … 2113 2114 self._on_fit_complete() 2114 2115 if out is None or not np.isfinite(chisqr): 2115 raise ValueError , "Fit error occured..."2116 raise ValueError("Fit error occured...") 2116 2117 2117 2118 is_modified = False … … 2188 2189 i += 1 2189 2190 else: 2190 raise ValueError , "onsetValues: Invalid parameters..."2191 raise ValueError("onsetValues: Invalid parameters...") 2191 2192 # Show error title when any errors displayed 2192 2193 if has_error: … … 2947 2948 # type can be either Guassian or Array 2948 2949 if len(self.model.dispersion.values()) > 0: 2949 type = self.model.dispersion.values()[0]["type"]2950 dist_type = list(self.model.dispersion.values())[0]["type"] 2950 2951 else: 2951 type = "Gaussian"2952 dist_type = "Gaussian" 2952 2953 2953 2954 iy += 1 … … 3008 3009 3009 3010 # For Gaussian only 3010 if type.lower() != "array":3011 if dist_type.lower() != "array": 3011 3012 for item in self.model.orientation_params: 3012 3013 if not self.magnetic_on: -
src/sas/sasgui/perspectives/fitting/fitpanel.py
r69363c7 r5251ec6 94 94 batch_state = self.sim_page.set_state() 95 95 96 for uid, page in self.opened_pages.ite ritems():96 for uid, page in self.opened_pages.items(): 97 97 data = page.get_data() 98 98 # state must be cloned … … 135 135 if uid not in self.opened_pages: 136 136 msg = "Fitpanel cannot find ID: %s in self.opened_pages" % str(uid) 137 raise ValueError , msg137 raise ValueError(msg) 138 138 else: 139 139 return self.opened_pages[uid] … … 217 217 page_is_opened = False 218 218 if state is not None: 219 for uid, panel in self.opened_pages.ite ritems():219 for uid, panel in self.opened_pages.items(): 220 220 # Don't return any panel is the exact same page is created 221 221 if uid == panel.uid and panel.data == state.data: … … 396 396 """ 397 397 if data.__class__.__name__ != "list": 398 raise ValueError , "Fitpanel delete_data expect list of id"398 raise ValueError("Fitpanel delete_data expect list of id") 399 399 else: 400 400 for page in self.opened_pages.values(): … … 592 592 if selected_page in page_finder: 593 593 # Delete the name of the page into the list of open page 594 for uid, list in self.opened_pages.ite ritems():594 for uid, list in self.opened_pages.items(): 595 595 # Don't return any panel is the exact same page is created 596 596 if flag and selected_page.uid == uid: … … 600 600 601 601 # Delete the name of the page into the list of open page 602 for uid, list in self.opened_pages.ite ritems():602 for uid, list in self.opened_pages.items(): 603 603 # Don't return any panel is the exact same page is created 604 604 if selected_page.uid == uid: -
src/sas/sasgui/perspectives/fitting/fitproblem.py
r20fa5fe r5251ec6 545 545 return fitproblem contained in this dictionary 546 546 """ 547 return self.values()547 return list(self.values()) 548 548 549 549 def set_result(self, result, fid): -
src/sas/sasgui/perspectives/fitting/fitting.py
raba4559 r5251ec6 147 147 Given an ID create a fitproblem container 148 148 """ 149 if page_id in self.page_finder .iterkeys():149 if page_id in self.page_finder: 150 150 del self.page_finder[page_id] 151 151 … … 356 356 # categories, the updated plugin may be in either the form factor 357 357 # or the structure factor combo boxes 358 for uid, page in self.fit_panel.opened_pages.ite ritems():358 for uid, page in self.fit_panel.opened_pages.items(): 359 359 pbox = getattr(page, "formfactorbox", None) 360 360 sbox = getattr(page, "structurebox", None) … … 417 417 self.fit_panel.SetSelection(current_page_index) 418 418 419 except Exception :420 logger.error("update_custom_combo: %s", sys.exc_value)419 except Exception as exc: 420 logger.error("update_custom_combo: %s", exc) 421 421 422 422 def set_edit_menu(self, owner): … … 642 642 data.list_group_id.append(group_id) 643 643 self.add_fit_page(data=[data]) 644 except :645 msg = "Fitting set_data: " + str( sys.exc_value)644 except Exception as exc: 645 msg = "Fitting set_data: " + str(exc) 646 646 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 647 647 … … 654 654 _, theory_state = item 655 655 self.fit_panel.set_model_state(theory_state) 656 except Exception :656 except Exception as exc: 657 657 msg = "Fitting: cannot deal with the theory received" 658 658 evt = StatusEvent(status=msg, info="error") 659 logger.error("set_theory " + msg + "\n" + str( sys.exc_value))659 logger.error("set_theory " + msg + "\n" + str(exc)) 660 660 wx.PostEvent(self.parent, evt) 661 661 … … 780 780 if fid is None: 781 781 return 782 if uid in self.page_finder .keys():782 if uid in self.page_finder: 783 783 self.page_finder[uid].set_weight(flag=flag, is2d=is2d) 784 784 … … 793 793 :param qmax: maximum value of the fit range 794 794 """ 795 if uid in self.page_finder .keys():795 if uid in self.page_finder: 796 796 self.page_finder[uid].set_range(qmin=qmin, qmax=qmax, fid=fid) 797 797 … … 804 804 :param uid: the id related to a page containing fitting information 805 805 """ 806 if uid in self.page_finder .keys():806 if uid in self.page_finder: 807 807 self.page_finder[uid].schedule_tofit(value) 808 808 … … 823 823 """ 824 824 sim_page_id = self.sim_page.uid 825 for uid, value in self.page_finder.ite ritems():825 for uid, value in self.page_finder.items(): 826 826 if uid != sim_page_id and uid != self.batch_page.uid: 827 827 model_list = value.get_model() … … 888 888 Stop the fit 889 889 """ 890 if uid in self.fit_thread_list .keys():890 if uid in self.fit_thread_list: 891 891 calc_fit = self.fit_thread_list[uid] 892 892 if calc_fit is not None and calc_fit.isrunning(): … … 900 900 batch_flag = self.batch_page is not None and uid == self.batch_page.uid 901 901 if sim_flag or batch_flag: 902 for uid, value in self.page_finder.ite ritems():902 for uid, value in self.page_finder.items(): 903 903 if value.get_scheduled() == 1: 904 if uid in self.fit_panel.opened_pages .keys():904 if uid in self.fit_panel.opened_pages: 905 905 panel = self.fit_panel.opened_pages[uid] 906 906 panel._on_fit_complete() … … 919 919 :param draw: Determine if the theory needs to be plot 920 920 """ 921 if uid not in self.page_finder .keys():921 if uid not in self.page_finder: 922 922 return 923 923 self.page_finder[uid].enable_smearing(flag=enable_smearer) … … 930 930 msg += "Got data = %s .\n" % str(data) 931 931 return 932 #raise ValueError , msg932 #raise ValueError(msg) 933 933 model = self.page_finder[uid].get_model(fid=fid) 934 934 if model is None: … … 1032 1032 list_page_id = [] 1033 1033 fit_id = 0 1034 for page_id, page_info in self.page_finder.ite ritems():1034 for page_id, page_info in self.page_finder.items(): 1035 1035 # For simulfit (uid give with None), do for-loop 1036 1036 # if uid is specified (singlefit), do it only on the page. … … 1059 1059 1060 1060 pars = [str(element[1]) for element in page.param_toFit] 1061 fitproblem_list = page_info.values() 1062 for fitproblem in fitproblem_list: 1061 for fitproblem in page_info.values(): 1063 1062 if sim_fitter is None: 1064 1063 fitter = Fit() … … 1079 1078 wx.PostEvent(self.parent, evt) 1080 1079 return True 1081 except :1080 except Exception as exc: 1082 1081 raise 1083 msg = "Fitting error: %s" % str(sys.exc_value)1082 msg = "Fitting error: %s" % exc 1084 1083 evt = StatusEvent(status=msg, info="error", type="stop") 1085 1084 wx.PostEvent(self.parent, evt) … … 1138 1137 :param fid: the id of the fitproblem(data, model, range,etc) 1139 1138 """ 1140 if uid not in self.page_finder .keys():1139 if uid not in self.page_finder: 1141 1140 return 1142 1141 fitproblemList = self.page_finder[uid].get_fit_problem(fid) … … 1183 1182 evt = StatusEvent(status=msg, info="warning") 1184 1183 wx.PostEvent(self.parent, evt) 1185 except Exception :1186 msg = "Creating Fit page: %s" % sys.exc_value1184 except Exception as exc: 1185 msg = "Creating Fit page: %s" % exc 1187 1186 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 1188 1187 … … 1264 1263 # case that uid is not specified 1265 1264 if uid is None: 1266 for page_id in self.page_finder .keys():1265 for page_id in self.page_finder: 1267 1266 self.page_finder[page_id].schedule_tofit(value) 1268 1267 # when uid is given 1269 1268 else: 1270 if uid in self.page_finder .keys():1269 if uid in self.page_finder: 1271 1270 self.page_finder[uid].schedule_tofit(value) 1272 1271 … … 1302 1301 panel = self.plot_panel 1303 1302 if panel is None: 1304 raise ValueError , "Fitting:_onSelect: NonType panel"1303 raise ValueError("Fitting:_onSelect: NonType panel") 1305 1304 Plugin.on_perspective(self, event=event) 1306 1305 self.select_data(panel) … … 1335 1334 """ 1336 1335 uid = page_id[0] 1337 if uid in self.fit_thread_list .keys():1336 if uid in self.fit_thread_list: 1338 1337 del self.fit_thread_list[uid] 1339 1338 … … 1361 1360 #get all fittable parameters of the current model 1362 1361 for param in model.getParamList(): 1363 if param not in batch_outputs .keys():1362 if param not in batch_outputs: 1364 1363 batch_outputs[param] = [] 1365 1364 for param in model.getDispParamList(): 1366 1365 if not model.is_fittable(param) and \ 1367 param in batch_outputs .keys():1366 param in batch_outputs: 1368 1367 del batch_outputs[param] 1369 1368 # Add fitted parameters and their error 1370 1369 for param in res.param_list: 1371 if param not in batch_outputs .keys():1370 if param not in batch_outputs: 1372 1371 batch_outputs[param] = [] 1373 1372 err_param = "error on %s" % str(param) 1374 if err_param not in batch_inputs .keys():1373 if err_param not in batch_inputs: 1375 1374 batch_inputs[err_param] = [] 1376 1375 msg = "" … … 1526 1525 model = fitproblem.get_model() 1527 1526 #fill batch result information 1528 if "Data" not in batch_outputs .keys():1527 if "Data" not in batch_outputs: 1529 1528 batch_outputs["Data"] = [] 1530 1529 cell = BatchCell() … … 1555 1554 cell.object = [data, theory_data] 1556 1555 batch_outputs["Data"].append(cell) 1557 for key, value in data.meta_data.ite ritems():1558 if key not in batch_inputs .keys():1556 for key, value in data.meta_data.items(): 1557 if key not in batch_inputs: 1559 1558 batch_inputs[key] = [] 1560 1559 #if key.lower().strip() != "loader": … … 1562 1561 param = "temperature" 1563 1562 if hasattr(data.sample, param): 1564 if param not in batch_inputs .keys():1563 if param not in batch_inputs: 1565 1564 batch_inputs[param] = [] 1566 1565 batch_inputs[param].append(data.sample.temperature) … … 1633 1632 wx.PostEvent(self.parent, evt) 1634 1633 1635 except Exception: 1636 msg = ("Fit completed but the following error occurred: %s" 1637 % sys.exc_value) 1634 except Exception as exc: 1635 msg = "Fit completed but the following error occurred: %s" % exc 1638 1636 #msg = "\n".join((traceback.format_exc(), msg)) 1639 1637 evt = StatusEvent(status=msg, info="warning", type="stop") … … 1723 1721 if model is None: 1724 1722 return 1725 if uid not in self.page_finder .keys():1723 if uid not in self.page_finder: 1726 1724 return 1727 1725 # save the name containing the data name with the appropriate model … … 2080 2078 source=source) 2081 2079 self.calc_1D.queue() 2082 except :2080 except Exception as exc: 2083 2081 msg = " Error occurred when drawing %s Model 1D: " % model.name 2084 msg += " %s" % sys.exc_value2082 msg += " %s" % exc 2085 2083 wx.PostEvent(self.parent, StatusEvent(status=msg)) 2086 2084 -
src/sas/sasgui/perspectives/fitting/model_thread.py
r69363c7 r5251ec6 65 65 if self.data is None: 66 66 msg = "Compute Calc2D receive data = %s.\n" % str(self.data) 67 raise ValueError , msg67 raise ValueError(msg) 68 68 69 69 # Define matrix where data will be plotted -
src/sas/sasgui/perspectives/fitting/resultpanel.py
r959eb01 r5251ec6 59 59 def on_plot_results(self, event): 60 60 self.frame.Show(True) 61 result = event.result[0][0]61 result = list(event.result[0])[0] 62 62 filename = result.data.sas_data.filename 63 63 current_time = datetime.datetime.now().strftime("%I:%M%p, %B %d, %Y") -
src/sas/sasgui/perspectives/fitting/simfitpage.py
r20fa5fe r5251ec6 168 168 i = 0 169 169 for model in self.model_list: 170 model_id = self._format_id( model[1].keys()[0])170 model_id = self._format_id(list(model[1].keys())[0]) 171 171 for saved_model in sim_state.model_list: 172 172 save_id = saved_model.pop('name') … … 328 328 sizer.Add(tab_used, (iy, ix), (1, 1), 329 329 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 330 for id, value in self.page_finder.ite ritems():330 for id, value in self.page_finder.items(): 331 331 if id not in self.parent.opened_pages: 332 332 continue … … 757 757 self.set_button.Disable() 758 758 759 for id, model in self.constraint_dict.ite ritems():759 for id, model in self.constraint_dict.items(): 760 760 # check if all parameters have been selected for constraint 761 761 # then do not allow add constraint on parameters 762 762 self.model_cbox_left.Append(str(model.name), model) 763 763 self.model_cbox_left.Select(0) 764 for id, model in self.constraint_dict.ite ritems():764 for id, model in self.constraint_dict.items(): 765 765 # check if all parameters have been selected for constraint 766 766 # then do not allow add constraint on parameters … … 814 814 model_right = self.model_cbox_right.GetValue() 815 815 model_b = self.model_cbox_right.GetClientData(selection_b) 816 for id, dic_model in self.constraint_dict.ite ritems():816 for id, dic_model in self.constraint_dict.items(): 817 817 if model == dic_model: 818 818 param_list = self.page_finder[id].get_param2fit() … … 857 857 if len(self.constraints_list) != 0: 858 858 nb_fit_param = 0 859 for id, model in self.constraint_dict.ite ritems():859 for id, model in self.constraint_dict.items(): 860 860 nb_fit_param += len(self.page_finder[id].get_param2fit()) 861 861 # Don't add anymore … … 879 879 model_cbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 880 880 model_cbox.Clear() 881 for id, model in self.constraint_dict.ite ritems():881 for id, model in self.constraint_dict.items(): 882 882 # check if all parameters have been selected for constraint 883 883 # then do not allow add constraint on parameters … … 931 931 hide buttons related constraint 932 932 """ 933 for id in self.page_finder. iterkeys():933 for id in self.page_finder.keys(): 934 934 self.page_finder[id].clear_model_param() 935 935 … … 969 969 model = model_cbox.GetClientData(n) 970 970 param_list = [] 971 for id, dic_model in self.constraint_dict.ite ritems():971 for id, dic_model in self.constraint_dict.items(): 972 972 if model == dic_model: 973 973 param_list = self.page_finder[id].get_param2fit() … … 1056 1056 msg += " in combobox to set constraint! " 1057 1057 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1058 for id, value in self.constraint_dict.ite ritems():1058 for id, value in self.constraint_dict.items(): 1059 1059 if model == value: 1060 1060 if constraint == "": … … 1080 1080 return False 1081 1081 1082 for fid in self.page_finder[id]. iterkeys():1082 for fid in self.page_finder[id].keys(): 1083 1083 # wrap in param/constraint in str() to remove unicode 1084 1084 self.page_finder[id].set_model_param(str(param), -
src/sas/sasgui/perspectives/invariant/__init__.py
r5a405bd r5251ec6 3 3 4 4 from distutils.filelist import findall 5 from invariant import *5 from .invariant import * 6 6 7 7 def get_data_path(media): -
src/sas/sasgui/perspectives/invariant/invariant.py
r7432acb r5251ec6 133 133 name = data.__class__.__name__ 134 134 msg = "Invariant use only Data1D got: [%s] " % str(name) 135 raise ValueError , msg135 raise ValueError(msg) 136 136 self.compute_helper(data=data) 137 137 … … 144 144 if data_list is None: 145 145 data_list = [] 146 else: 147 data_list = list(data_list) # force iterator to list 146 148 if len(data_list) >= 1: 147 149 if len(data_list) == 1: … … 190 192 try: 191 193 self.compute_helper(data) 192 except :193 msg = "Invariant Set_data: " + str( sys.exc_value)194 except Exception as exc: 195 msg = "Invariant Set_data: " + str(exc) 194 196 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 195 197 else: … … 240 242 msg = "invariant.save_file: the data being saved is" 241 243 msg += " not a sas.sascalc.dataloader.data_info.Data1D object" 242 raise RuntimeError , msg244 raise RuntimeError(msg) 243 245 244 246 def set_state(self, state=None, datainfo=None): … … 258 260 msg = "invariant.set_state: datainfo parameter cannot" 259 261 msg += " be None in standalone mode" 260 raise RuntimeError , msg262 raise RuntimeError(msg) 261 263 # Make sure the user sees the invariant panel after loading 262 264 # self.parent.set_perspective(self.perspective) … … 281 283 self.on_set_state_helper(None) 282 284 283 except :284 logger.error("invariant.set_state: %s" % sys.exc_value)285 except Exception as exc: 286 logger.error("invariant.set_state: %s" % exc) 285 287 286 288 def on_set_state_helper(self, event=None): … … 320 322 else: 321 323 msg = "Scale can not be zero." 322 raise ValueError , msg324 raise ValueError(msg) 323 325 if len(new_plot.x) == 0: 324 326 return -
src/sas/sasgui/perspectives/invariant/invariant_details.py
r20fa5fe r5251ec6 2 2 Invariant panel 3 3 """ 4 import sys 5 4 6 import wx 5 import sys6 7 7 8 from sas.sasgui.guiframe.utils import format_number 8 from invariant_widgets import OutputTextCtrl 9 from .invariant_widgets import OutputTextCtrl 10 9 11 # Dimensions related to chart 10 12 RECTANGLE_WIDTH = 400.0 … … 33 35 34 36 35 class InvariantContainer (wx.Object):37 class InvariantContainer: 36 38 """ 37 39 This class stores some values resulting resulting from invariant -
src/sas/sasgui/perspectives/invariant/invariant_panel.py
r44e8f48 r5251ec6 319 319 background = self.background_tcl.GetValue().lstrip().rstrip() 320 320 if background == "": 321 raise ValueError , "Need a background"321 raise ValueError("Need a background") 322 322 if check_float(self.background_tcl): 323 323 return float(background) 324 324 else: 325 325 msg = "Receive invalid value for background : %s" % (background) 326 raise ValueError , msg326 raise ValueError(msg) 327 327 328 328 def get_scale(self): … … 332 332 scale = self.scale_tcl.GetValue().lstrip().rstrip() 333 333 if scale == "": 334 raise ValueError , "Need a background"334 raise ValueError("Need a background") 335 335 if check_float(self.scale_tcl): 336 336 if float(scale) <= 0.0: … … 338 338 self.scale_tcl.Refresh() 339 339 msg = "Receive invalid value for scale: %s" % (scale) 340 raise ValueError , msg340 raise ValueError(msg) 341 341 return float(scale) 342 342 else: 343 raise ValueError , "Receive invalid value for scale : %s" % (scale)343 raise ValueError("Receive invalid value for scale : %s" % (scale)) 344 344 345 345 def get_contrast(self): … … 386 386 self.volume_tcl.SetValue(format_number(v)) 387 387 self.volume_err_tcl.SetValue(format_number(dv)) 388 except :388 except Exception as exc: 389 389 self.volume_tcl.SetValue(format_number(None)) 390 390 self.volume_err_tcl.SetValue(format_number(None)) 391 391 msg = "Error occurred computing volume " 392 msg += " fraction: %s" % sys.exc_value392 msg += " fraction: %s" % exc 393 393 wx.PostEvent(self.parent, StatusEvent(status=msg, 394 394 info="error", … … 406 406 self.surface_tcl.SetValue(format_number(s)) 407 407 self.surface_err_tcl.SetValue(format_number(ds)) 408 except :408 except Exception as exc: 409 409 self.surface_tcl.SetValue(format_number(None)) 410 410 self.surface_err_tcl.SetValue(format_number(None)) 411 411 msg = "Error occurred computing " 412 msg += "specific surface: %s" % sys.exc_value412 msg += "specific surface: %s" % exc 413 413 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", 414 414 type="stop")) … … 426 426 self.inv_container.qstar_total = qstar_total 427 427 self.inv_container.qstar_total_err = qstar_total_err 428 except :428 except Exception as exc: 429 429 self.inv_container.qstar_total = "Error" 430 430 self.inv_container.qstar_total_err = "Error" … … 432 432 self.invariant_total_err_tcl.SetValue(format_number(None)) 433 433 msg = "Error occurred computing invariant using" 434 msg += " extrapolation: %s" % sys.exc_value434 msg += " extrapolation: %s" % exc 435 435 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 436 436 … … 450 450 self._manager.plot_theory(data=extrapolated_data, 451 451 name="Low-Q extrapolation") 452 except :452 except Exception as exc: 453 453 self.inv_container.qstar_low = "ERROR" 454 454 self.inv_container.qstar_low_err = "ERROR" 455 455 self._manager.plot_theory(name="Low-Q extrapolation") 456 456 msg = "Error occurred computing low-Q " 457 msg += "invariant: %s" % sys.exc_value457 msg += "invariant: %s" % exc 458 458 wx.PostEvent(self.parent, 459 459 StatusEvent(status=msg, type="stop")) … … 462 462 try: 463 463 self._manager.plot_theory(name="Low-Q extrapolation") 464 except :465 logger.error( sys.exc_value)464 except Exception as exc: 465 logger.error(exc) 466 466 467 467 def get_high_qstar(self, inv, high_q=False): … … 483 483 self._manager.plot_theory(data=high_out_data, 484 484 name="High-Q extrapolation") 485 except :485 except Exception as exc: 486 486 #raise 487 487 self.inv_container.qstar_high = "ERROR" … … 489 489 self._manager.plot_theory(name="High-Q extrapolation") 490 490 msg = "Error occurred computing high-Q " 491 msg += "invariant: %s" % sys.exc_value491 msg += "invariant: %s" % exc 492 492 wx.PostEvent(self.parent, StatusEvent(status=msg, 493 493 type="stop")) … … 496 496 try: 497 497 self._manager.plot_theory(name="High-Q extrapolation") 498 except :499 logger.error( sys.exc_value)498 except Exception as exc: 499 logger.error(exc) 500 500 501 501 def get_qstar(self, inv): … … 625 625 background = self.get_background() 626 626 scale = self.get_scale() 627 except :628 msg = "Invariant Error: %s" % (sys.exc_value)627 except Exception as exc: 628 msg = "Invariant Error: %s" % exc 629 629 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 630 630 return … … 641 641 inv, npts_low = self.set_extrapolation_low(inv=inv, low_q=low_q) 642 642 inv, npts_high = self.set_extrapolation_high(inv=inv, high_q=high_q) 643 except :644 msg = "Error occurred computing invariant: %s" % sys.exc_value643 except Exception as exc: 644 msg = "Error occurred computing invariant: %s" % exc 645 645 wx.PostEvent(self.parent, StatusEvent(status=msg, 646 646 info="warning", type="stop")) … … 652 652 try: 653 653 self.get_qstar(inv=inv) 654 except :655 msg = "Error occurred computing invariant: %s" % sys.exc_value654 except Exception as exc: 655 msg = "Error occurred computing invariant: %s" % exc 656 656 wx.PostEvent(self.parent, StatusEvent(status=msg, 657 657 info="warning", … … 674 674 porod_const = self.get_porod_const() 675 675 contrast = self.get_contrast() 676 except: 677 msg = r_msg + "Error occurred computing invariant: %s" % \ 678 sys.exc_value 676 except Exception as exc: 677 msg = r_msg + "Error occurred computing invariant: %s" % exc 679 678 wx.PostEvent(self.parent, StatusEvent(status=msg, 680 679 info="error", … … 685 684 extrapolation=extrapolation) 686 685 #compute surface and set value to txtcrtl 687 except :688 msg = "Error occurred computing invariant: %s" % sys.exc_value686 except Exception as exc: 687 msg = "Error occurred computing invariant: %s" % exc 689 688 wx.PostEvent(self.parent, StatusEvent(status=msg, 690 689 info="warning", … … 695 694 extrapolation=extrapolation) 696 695 697 except :698 msg = "Error occurred computing invariant: %s" % sys.exc_value696 except Exception as exc: 697 msg = "Error occurred computing invariant: %s" % exc 699 698 wx.PostEvent(self.parent, StatusEvent(status=msg, 700 699 info="warning", … … 845 844 if attr.__class__.__name__ == "StaticText": 846 845 return 847 if value in ["True", "False", True, False]: 848 value = bool(value) 846 if value in ["True", True]: 847 value = 1 848 elif value in ["False", False]: 849 value = 0 849 850 else: 850 851 value = str(value) 851 852 attr.SetValue(value) 852 except :853 logger.error("Invariant state: %s", sys.exc_value)853 except Exception as exc: 854 logger.error("Invariant state: %s", exc) 854 855 855 856 def get_bookmark_by_num(self, num=None): … … 867 868 try: 868 869 _, _, current_state, comp_state = self.state.bookmark_list[int(num)] 869 except :870 logger.error( sys.exc_value)871 raise ValueError , "No such bookmark exists"870 except Exception as exc: 871 logger.error(exc) 872 raise ValueError("No such bookmark exists") 872 873 873 874 # set the parameters … … 962 963 self.state.state_list[str(self.state.state_num)] = \ 963 964 self.state.clone_state() 964 except :965 logger.error( sys.exc_value)965 except Exception as exc: 966 logger.error(exc) 966 967 967 968 self._set_undo_flag(True) … … 1006 1007 try: 1007 1008 del self.state.state_list[str(i)] 1008 except :1009 logger.error( sys.exc_value)1009 except Exception as exc: 1010 logger.error(exc) 1010 1011 # Enable the undo button if it was not 1011 1012 self._set_undo_flag(True) … … 1071 1072 try: 1072 1073 del self.state.state_list[str(i)] 1073 except :1074 logger.error( sys.exc_value)1074 except Exception as exc: 1075 logger.error(exc) 1075 1076 1076 1077 # try to add new state of the text changes in the state_list … … 1086 1087 self.state.state_num = self.state.saved_state['state_num'] 1087 1088 self.state.state_list[str(self.state.state_num)] = self.state.clone_state() 1088 except :1089 logger.error( sys.exc_value)1089 except Exception as exc: 1090 logger.error(exc) 1090 1091 1091 1092 self._set_undo_flag(True) … … 1108 1109 self.state.saved_state[name] = str(value) 1109 1110 self.state.state_list[str(self.state.state_num)] = self.state.clone_state() 1110 except :1111 logger.error( sys.exc_value)1111 except Exception as exc: 1112 logger.error(exc) 1112 1113 1113 1114 def _get_input_list(self): … … 1118 1119 compute_num = self.state.saved_state['compute_num'] 1119 1120 # find values and put into the input list 1120 for key1, value1 in self.state.state_list[str(compute_num)].ite ritems():1121 for key, _ in self.state.input_list.ite ritems():1121 for key1, value1 in self.state.state_list[str(compute_num)].items(): 1122 for key, _ in self.state.input_list.items(): 1122 1123 if key == key1: 1123 1124 self.state.input_list[key] = value1 -
src/sas/sasgui/perspectives/invariant/invariant_state.py
re9920cd r5251ec6 2 2 State class for the invariant UI 3 3 """ 4 from __future__ import print_function 4 5 5 6 # import time … … 140 141 141 142 # text ctl general inputs ( excluding extrapolation text ctl) 142 for key, value in self.input_list.ite ritems():143 for key, value in self.input_list.items(): 143 144 if value == '': 144 145 continue … … 166 167 low_off = False 167 168 high_off = False 168 for key, value in self.input_list.ite ritems():169 for key, value in self.input_list.items(): 169 170 key_split = key.split('_') 170 171 max_ind = len(key_split) - 1 … … 216 217 # other outputs than Q* 217 218 name = item[0] + "_tcl" 218 if name in self.saved_state .keys():219 if name in self.saved_state: 219 220 value = self.saved_state[name] 220 221 … … 301 302 top_element.appendChild(state) 302 303 303 for name, value in self.saved_state.ite ritems():304 for name, value in self.saved_state.items(): 304 305 element = newdoc.createElement(str(name)) 305 306 element.appendChild(newdoc.createTextNode(str(value))) … … 310 311 top_element.appendChild(history) 311 312 312 for name, value in self.state_list.ite ritems():313 for name, value in self.state_list.items(): 313 314 history_element = newdoc.createElement('state_' + str(name)) 314 for state_name, state_value in value.ite ritems():315 for state_name, state_value in value.items(): 315 316 state_element = newdoc.createElement(str(state_name)) 316 317 child = newdoc.createTextNode(str(state_value)) … … 325 326 top_element.appendChild(bookmark) 326 327 item_list = ['time', 'date', 'state', 'comp_state'] 327 for name, value_list in self.bookmark_list.ite ritems():328 for name, value_list in self.bookmark_list.items(): 328 329 element = newdoc.createElement('mark_' + str(name)) 329 330 _, date, state, comp_state = value_list … … 334 335 state_list_element = newdoc.createElement('state') 335 336 comp_state_list_element = newdoc.createElement('comp_state') 336 for state_name, state_value in value_list[2].ite ritems():337 for state_name, state_value in value_list[2].items(): 337 338 state_element = newdoc.createElement(str(state_name)) 338 339 child = newdoc.createTextNode(str(state_value)) 339 340 state_element.appendChild(child) 340 341 state_list_element.appendChild(state_element) 341 for comp_name, comp_value in value_list[3].ite ritems():342 for comp_name, comp_value in value_list[3].items(): 342 343 comp_element = newdoc.createElement(str(comp_name)) 343 344 comp_element.appendChild(newdoc.createTextNode(str(comp_value))) … … 368 369 msg = "InvariantSate no longer supports non-CanSAS" 369 370 msg += " format for invariant files" 370 raise RuntimeError , msg371 raise RuntimeError(msg) 371 372 372 373 if node.get('version')\ … … 383 384 try: 384 385 timestamp = (entry.get('epoch')) 385 except :386 except Exception as exc: 386 387 msg = "InvariantSate.fromXML: Could not read" 387 msg += " timestamp\n %s" % sys.exc_value388 msg += " timestamp\n %s" % exc 388 389 logger.error(msg) 389 390 … … 453 454 Get the values (strings) from __str__ for report 454 455 """ 455 strings = self.__str__()456 457 456 # default string values 458 for num in range(1, 19): 459 exec "s_%s = 'NA'" % str(num) 460 lines = strings.split('\n') 457 s = {num: 'NA' for num in range(1, 19)} 461 458 # get all string values from __str__() 462 for line in range(0, len(lines)): 463 if line == 1: 464 s_1 = lines[1] 465 elif line == 2: 466 s_2 = lines[2] 459 lines = str(self).split('\n') 460 for line_num, line in enumerate(lines): 461 if line_num == 1: 462 s[1] = line 463 elif line_num == 2: 464 s[2] = line 467 465 else: 468 item = line s[line].split(':')466 item = line.split(':') 469 467 item[0] = item[0].strip() 470 468 if item[0] == "scale": 471 s _3= item[1]469 s[3] = item[1] 472 470 elif item[0] == "porod constant": 473 s _4= item[1]471 s[4] = item[1] 474 472 elif item[0] == "background": 475 s _5= item[1]473 s[5] = item[1] 476 474 elif item[0] == "contrast": 477 s _6= item[1]475 s[6] = item[1] 478 476 elif item[0] == "Extrapolation": 479 477 extra = item[1].split(";") 480 478 bool_0 = extra[0].split("=") 481 479 bool_1 = extra[1].split("=") 482 s _8= " " + bool_0[0] + "Q region = " + bool_0[1]483 s _7= " " + bool_1[0] + "Q region = " + bool_1[1]480 s[8] = " " + bool_0[0] + "Q region = " + bool_0[1] 481 s[7] = " " + bool_1[0] + "Q region = " + bool_1[1] 484 482 elif item[0] == "npts low": 485 s _9= item[1]483 s[9] = item[1] 486 484 elif item[0] == "npts high": 487 s _10= item[1]485 s[10] = item[1] 488 486 elif item[0] == "volume fraction": 489 487 val = item[1].split("+-")[0].strip() 490 488 error = item[1].split("+-")[1].strip() 491 s _17= val + " ± " + error489 s[17] = val + " ± " + error 492 490 elif item[0] == "specific surface": 493 491 val = item[1].split("+-")[0].strip() 494 492 error = item[1].split("+-")[1].strip() 495 s _18= val + " ± " + error493 s[18] = val + " ± " + error 496 494 elif item[0].split("(")[0].strip() == "power low": 497 s _11= item[0] + " =" + item[1]495 s[11] = item[0] + " =" + item[1] 498 496 elif item[0].split("(")[0].strip() == "power high": 499 s _12= item[0] + " =" + item[1]497 s[12] = item[0] + " =" + item[1] 500 498 elif item[0].split("[")[0].strip() == "Q* from low Q extrapolation": 501 499 # looks messy but this way the symbols +_ and % work on html … … 504 502 err = error.split("%")[0].strip() 505 503 percent = error.split("%")[1].strip() 506 s _13= val + " ± " + err + "%" + percent504 s[13] = val + " ± " + err + "%" + percent 507 505 elif item[0].split("[")[0].strip() == "Q* from data": 508 506 val = item[1].split("+-")[0].strip() … … 510 508 err = error.split("%")[0].strip() 511 509 percent = error.split("%")[1].strip() 512 s _14= val + " ± " + err + "%" + percent510 s[14] = val + " ± " + err + "%" + percent 513 511 elif item[0].split("[")[0].strip() == "Q* from high Q extrapolation": 514 512 val = item[1].split("+-")[0].strip() … … 516 514 err = error.split("%")[0].strip() 517 515 percent = error.split("%")[1].strip() 518 s _15= val + " ± " + err + "%" + percent516 s[15] = val + " ± " + err + "%" + percent 519 517 elif item[0].split("[")[0].strip() == "total Q*": 520 518 val = item[1].split("+-")[0].strip() 521 519 error = item[1].split("+-")[1].strip() 522 s _16= val + " ± " + error520 s[16] = val + " ± " + error 523 521 else: 524 522 continue 525 523 526 s _1 = self._check_html_format(s_1)524 s[1] = self._check_html_format(s[1]) 527 525 file_name = self._check_html_format(self.file) 528 526 … … 530 528 self.set_plot_state(extra_high=bool_0[1], extra_low=bool_1[1]) 531 529 # get ready for report with setting all the html strings 532 self.report_str = str(self.template_str) % (s_1, s_2, 533 s_3, s_4, s_5, s_6, s_7, s_8, 534 s_9, s_10, s_11, s_12, s_13, s_14, s_15, 535 s_16, s_17, s_18, file_name, "%s") 530 self.report_str = str(self.template_str) % ( 531 s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], 532 s[12], s[13], s[14], s[15], s[16], s[17], s[18], file_name, "%s") 536 533 537 534 def _check_html_format(self, name): … … 692 689 state = InvariantState() 693 690 state.fromXML(node=nodes[0]) 694 except :691 except Exception as exc: 695 692 msg = "XML document does not contain invariant" 696 msg += " information.\n %s" % sys.exc_value693 msg += " information.\n %s" % exc 697 694 logger.info(msg) 698 695 return state … … 736 733 output.append(sas_entry) 737 734 else: 738 raise RuntimeError , "%s is not a file" % path735 raise RuntimeError("%s is not a file" % path) 739 736 740 737 # Return output consistent with the loader's api … … 782 779 msg = "The cansas writer expects a Data1D" 783 780 msg += " instance: %s" % str(datainfo.__class__.__name__) 784 raise RuntimeError , msg781 raise RuntimeError(msg) 785 782 # make sure title and data run is filled up. 786 783 if datainfo.title is None or datainfo.title == '': -
src/sas/sasgui/perspectives/invariant/report_dialog.py
rd0ce666f r5251ec6 92 92 # Mac 93 93 os.system("open %s" % fName) 94 except :94 except Exception as exc: 95 95 # DO not open 96 logger.error("Could not open file: %s" % sys.exc_value)96 logger.error("Could not open file: %s" % exc) 97 97 # delete image file 98 98 os.remove(pic_fname) -
src/sas/sasgui/perspectives/pr/__init__.py
r959eb01 r5251ec6 1 1 PLUGIN_ID = "P(r) plug-in 1.0" 2 from pr import *2 from .pr import * -
src/sas/sasgui/perspectives/pr/explore_dialog.py
r20fa5fe r5251ec6 35 35 from sas.sasgui.plottools.plottables import Graph 36 36 37 from pr_widgets import PrTextCtrl37 from .pr_widgets import PrTextCtrl 38 38 39 39 # Default number of points on the output plot … … 416 416 results.pos_err.append(pos_err) 417 417 results.osc.append(osc) 418 except :418 except Exception as exc: 419 419 # This inversion failed, skip this D_max value 420 420 msg = "ExploreDialog: inversion failed " 421 msg += "for D_max=%s\n%s" % (str(d), sys.exc_value)421 msg += "for D_max=%s\n%s" % (str(d), exc) 422 422 logger.error(msg) 423 423 -
src/sas/sasgui/perspectives/pr/inversion_panel.py
rcb62bd5 r5251ec6 5 5 __revision__ = "$Revision: 1193 $" 6 6 7 import wx8 7 import os 9 8 import sys 10 9 import logging 10 11 import wx 11 12 from wx.lib.scrolledpanel import ScrolledPanel 13 12 14 from sas.sasgui.guiframe.events import StatusEvent 13 15 from sas.sasgui.guiframe.panel_base import PanelBase 14 from inversion_state import InversionState15 from pr_widgets import PrTextCtrl16 from pr_widgets import DataFileTextCtrl17 from pr_widgets import OutputTextCtrl18 16 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 17 18 from .inversion_state import InversionState 19 from .pr_widgets import PrTextCtrl 20 from .pr_widgets import DataFileTextCtrl 21 from .pr_widgets import OutputTextCtrl 19 22 20 23 logger = logging.getLogger(__name__) … … 752 755 except ValueError: 753 756 logger.error("InversionControl._on_accept_alpha got a value that was not a number: %s" % alpha ) 754 except :757 except Exception as exc: 755 758 # No estimate or bad estimate, either do nothing 756 logger.error("InversionControl._on_accept_alpha: %s" % sys.exc_value)759 logger.error("InversionControl._on_accept_alpha: %s" % exc) 757 760 758 761 def _on_accept_nterms(self, evt): … … 768 771 except ValueError: 769 772 logger.error("InversionControl._on_accept_nterms got a value that was not a number: %s" % nterms ) 770 except :773 except Exception as exc: 771 774 # No estimate or bad estimate, either do nothing 772 logger.error("InversionControl._on_accept_nterms: %s" % sys.exc_value)775 logger.error("InversionControl._on_accept_nterms: %s" % exc) 773 776 774 777 def clear_panel(self): … … 901 904 message += "than the number of points" 902 905 wx.PostEvent(self._manager.parent, StatusEvent(status=message)) 903 raise ValueError , message906 raise ValueError(message) 904 907 self.nfunc_ctl.SetBackgroundColour(wx.WHITE) 905 908 self.nfunc_ctl.Refresh() … … 957 960 Invoke the d_max exploration dialog 958 961 """ 959 from explore_dialog import ExploreDialog962 from .explore_dialog import ExploreDialog 960 963 if self._manager._last_pr is not None: 961 964 pr = self._manager._create_plot_pr() … … 1008 1011 self._on_invert(None) 1009 1012 self._set_analysis(True) 1010 except :1011 msg = "InversionControl._change_file: %s" % sys.exc_value1013 except Exception as exc: 1014 msg = "InversionControl._change_file: %s" % exc 1012 1015 logger.error(msg) 1013 1016 -
src/sas/sasgui/perspectives/pr/inversion_state.py
r2469df7 r5251ec6 18 18 import logging 19 19 from lxml import etree 20 20 21 from sas.sasgui.guiframe.dataFitting import Data1D 21 22 from sas.sascalc.dataloader.readers.cansas_reader import Reader as CansasReader … … 238 239 msg = "InversionState no longer supports non-CanSAS" 239 240 msg += " format for P(r) files" 240 raise RuntimeError , msg241 raise RuntimeError(msg) 241 242 242 243 if node.get('version') and node.get('version') == '1.0': … … 252 253 try: 253 254 self.timestamp = float(entry.get('epoch')) 254 except :255 except Exception as exc: 255 256 msg = "InversionState.fromXML: Could not read " 256 msg += "timestamp\n %s" % sys.exc_value257 msg += "timestamp\n %s" % exc 257 258 logger.error(msg) 258 259 … … 432 433 state = InversionState() 433 434 state.fromXML(node=nodes[0]) 434 except :435 except Exception as exc: 435 436 msg = "XML document does not contain P(r) " 436 msg += "information.\n %s" % sys.exc_value437 msg += "information.\n %s" % exc 437 438 logger.info(msg) 438 439 … … 481 482 output.append(sas_entry) 482 483 else: 483 raise RuntimeError , "%s is not a file" % path484 raise RuntimeError("%s is not a file" % path) 484 485 485 486 # Return output consistent with the loader's api … … 525 526 msg = "The cansas writer expects a Data1D " 526 527 msg += "instance: %s" % str(datainfo.__class__.__name__) 527 raise RuntimeError , msg528 raise RuntimeError(msg) 528 529 529 530 # Create basic XML document -
src/sas/sasgui/perspectives/pr/pr.py
r2469df7 r5251ec6 18 18 19 19 import sys 20 import wx21 20 import logging 22 21 import time 23 22 import math 23 24 import wx 24 25 import numpy as np 25 26 import pylab 27 26 28 from sas.sasgui.guiframe.gui_manager import MDIFrame 27 29 from sas.sasgui.guiframe.dataFitting import Data1D … … 33 35 import sas.sascalc.dataloader 34 36 35 from pr_widgets import load_error36 37 from sas.sasgui.guiframe.plugin_base import PluginBase 38 39 from .inversion_state import Reader # .prv file reader 40 from .inversion_panel import InversionControl 41 #from .inversion_panel import HelpDialog 42 from .inversion_panel import PrDistDialog 43 from .pr_thread import CalcPr 44 from .pr_thread import EstimatePr 45 from .pr_thread import EstimateNT 46 from .pr_widgets import load_error 47 from .pr_widgets import DataDialog 37 48 38 49 logger = logging.getLogger(__name__) … … 106 117 self.list_plot_id = [] 107 118 108 # Associate the inversion state reader with .prv files109 from inversion_state import Reader110 111 119 # Create a CanSAS/Pr reader 112 120 self.state_reader = Reader(self.set_state) … … 151 159 msg = "Pr.set_state: datainfo parameter cannot " 152 160 msg += "be None in standalone mode" 153 raise RuntimeError , msg161 raise RuntimeError(msg) 154 162 155 163 # Ensuring that plots are coordinated correctly … … 184 192 title=self.current_plottable.title)) 185 193 self.control_panel.set_state(state) 186 except :187 logger.error("prview.set_state: %s" % sys.exc_value)194 except Exception as exc: 195 logger.error("prview.set_state: %s" % exc) 188 196 189 197 … … 195 203 196 204 """ 197 from inversion_panel import HelpDialog198 205 dialog = HelpDialog(None, -1) 199 206 if dialog.ShowModal() == wx.ID_OK: … … 369 376 Redisplay P(r) with a different number of points 370 377 """ 371 from inversion_panel import PrDistDialog372 378 dialog = PrDistDialog(None, -1) 373 379 dialog.set_content(self._pr_npts) … … 452 458 # Notify the user if we could not read the file 453 459 if dataread is None: 454 raise RuntimeError , "Invalid data"460 raise RuntimeError("Invalid data") 455 461 456 462 x = None … … 472 478 if dataread is None: 473 479 return x, y, err 474 raise RuntimeError , "This tool can only read 1D data"480 raise RuntimeError("This tool can only read 1D data") 475 481 476 482 self._current_file_data.x = x … … 511 517 data_y = np.append(data_y, y) 512 518 data_err = np.append(data_err, err) 513 except :514 logger.error( sys.exc_value)519 except Exception as exc: 520 logger.error(exc) 515 521 516 522 if scale is not None: … … 562 568 data_y = np.append(data_y, y) 563 569 data_err = np.append(data_err, err) 564 except :565 logger.error( sys.exc_value)570 except Exception as exc: 571 logger.error(exc) 566 572 elif line.find("The 6 columns") >= 0: 567 573 data_started = True … … 720 726 Start a calculation thread 721 727 """ 722 from pr_thread import CalcPr723 724 728 # If a thread is already started, stop it 725 729 if self.calc_thread is not None and self.calc_thread.isrunning(): … … 849 853 try: 850 854 pr = self._create_file_pr(data) 851 except :852 status = "Problem reading data: %s" % sys.exc_value855 except Exception as exc: 856 status = "Problem reading data: %s" % exc 853 857 wx.PostEvent(self.parent, StatusEvent(status=status)) 854 raise RuntimeError , status858 raise RuntimeError(status) 855 859 856 860 # If the file contains nothing, just return 857 861 if pr is None: 858 raise RuntimeError , "Loaded data is invalid"862 raise RuntimeError("Loaded data is invalid") 859 863 860 864 self.pr = pr … … 906 910 msg = "pr.save_data: the data being saved is not a" 907 911 msg += " sas.data_info.Data1D object" 908 raise RuntimeError , msg912 raise RuntimeError(msg) 909 913 910 914 def setup_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, … … 928 932 self.pr = pr 929 933 self.perform_inversion() 930 except :931 wx.PostEvent(self.parent, StatusEvent(status= sys.exc_value))934 except Exception as exc: 935 wx.PostEvent(self.parent, StatusEvent(status=exc)) 932 936 933 937 def estimate_plot_inversion(self, alpha, nfunc, d_max, … … 952 956 self.pr = pr 953 957 self.perform_estimate() 954 except :955 wx.PostEvent(self.parent, StatusEvent(status= sys.exc_value))958 except Exception as exc: 959 wx.PostEvent(self.parent, StatusEvent(status=exc)) 956 960 957 961 def _create_plot_pr(self, estimate=False): … … 1033 1037 self.pr = pr 1034 1038 self.perform_inversion() 1035 except :1036 wx.PostEvent(self.parent, StatusEvent(status= sys.exc_value))1039 except Exception as exc: 1040 wx.PostEvent(self.parent, StatusEvent(status=exc)) 1037 1041 1038 1042 def estimate_file_inversion(self, alpha, nfunc, d_max, data, … … 1056 1060 self.pr = pr 1057 1061 self.perform_estimate() 1058 except :1059 wx.PostEvent(self.parent, StatusEvent(status= sys.exc_value))1062 except Exception as exc: 1063 wx.PostEvent(self.parent, StatusEvent(status=exc)) 1060 1064 1061 1065 def _create_file_pr(self, data): … … 1085 1089 self._current_file_data.err = data.dy 1086 1090 x, y, err = data.x, data.y, data.dy 1087 except :1088 load_error( sys.exc_value)1091 except Exception as exc: 1092 load_error(exc) 1089 1093 return None 1090 1094 … … 1124 1128 pr.slit_width = self.slit_width 1125 1129 return pr 1126 except :1127 load_error( sys.exc_value)1130 except Exception as exc: 1131 load_error(exc) 1128 1132 return None 1129 1133 … … 1132 1136 Perform parameter estimation 1133 1137 """ 1134 from pr_thread import EstimatePr1135 1136 1138 # If a thread is already started, stop it 1137 1139 if self.estimation_thread is not None and \ … … 1162 1164 Perform parameter estimation 1163 1165 """ 1164 from pr_thread import EstimateNT1165 1166 1166 # If a thread is already started, stop it 1167 1167 if self.estimation_thread is not None and self.estimation_thread.isrunning(): … … 1239 1239 Create and return a list of panel objects 1240 1240 """ 1241 from inversion_panel import InversionControl1242 1243 1241 self.parent = parent 1244 1242 self.frame = MDIFrame(self.parent, None, 'None', (100, 200)) … … 1262 1260 if data_list is None: 1263 1261 data_list = [] 1262 else: 1263 data_list = list(data_list) # force iterator to list 1264 1264 if len(data_list) >= 1: 1265 1265 if len(data_list) == 1: … … 1287 1287 msg += "Please select one.\n" 1288 1288 if len(data_list) > 1: 1289 from pr_widgets import DataDialog1290 1289 dlg = DataDialog(data_list=data_1d_list, text=msg) 1291 1290 if dlg.ShowModal() == wx.ID_OK: … … 1306 1305 self.data_id = data.id 1307 1306 self.control_panel._change_file(evt=None, data=data) 1308 except :1309 msg = "Prview Set_data: " + str( sys.exc_value)1307 except Exception as exc: 1308 msg = "Prview Set_data: " + str(exc) 1310 1309 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 1311 1310 else: -
src/sas/sasgui/perspectives/pr/pr_thread.py
rac07a3a r5251ec6 41 41 # Thread was interrupted, just proceed 42 42 pass 43 except :43 except Exception as exc: 44 44 if self.error_func is not None: 45 self.error_func("CalcPr.compute: %s" % sys.exc_value)45 self.error_func("CalcPr.compute: %s" % exc) 46 46 47 47 class EstimatePr(CalcThread): … … 69 69 # Thread was interrupted, just proceed 70 70 pass 71 except :71 except Exception as exc: 72 72 if self.error_func is not None: 73 self.error_func("EstimatePr.compute: %s" % sys.exc_value)73 self.error_func("EstimatePr.compute: %s" % exc) 74 74 75 75 class EstimateNT(CalcThread): … … 109 109 # Thread was interrupted, just proceed 110 110 pass 111 except :111 except Exception as exc: 112 112 if self.error_func is not None: 113 self.error_func("EstimatePr2.compute: %s" % sys.exc_value)113 self.error_func("EstimatePr2.compute: %s" % exc) -
src/sas/sasgui/perspectives/simulation/ShapeAdapter.py
r959eb01 r5251ec6 87 87 self.sim_canvas._model_changed() 88 88 else: 89 raise ValueError , "SimShapeVisitor: Wrong class for visited object"89 raise ValueError("SimShapeVisitor: Wrong class for visited object") 90 90 91 91 … … 115 115 self.sim_canvas._model_changed() 116 116 else: 117 raise ValueError , "SimShapeVisitor: Wrong class for visited object"117 raise ValueError("SimShapeVisitor: Wrong class for visited object") 118 118 119 119 … … 130 130 shape.accept_update(self) 131 131 else: 132 raise ValueError , "ShapeAdapter: Shape [%s] not in list" % shape.name132 raise ValueError("ShapeAdapter: Shape [%s] not in list" % shape.name) 133 133 -
src/sas/sasgui/perspectives/simulation/ShapeParameters.py
ra1b8fee r5251ec6 10 10 from __future__ import print_function 11 11 12 import sys 13 from copy import deepcopy 14 12 15 import wx 13 import sys14 16 import wx.lib.newevent 15 from copy import deepcopy 16 import SimCanvas17 18 from . import SimCanvas 17 19 18 20 (CreateShapeEvent, EVT_ADD_SHAPE) = wx.lib.newevent.NewEvent() … … 201 203 n = 1 202 204 self.parameters = [] 203 keys = shape.params.keys() 204 keys.sort() 205 206 for item in keys: 205 206 for item in sorted(shape.params.keys()): 207 207 if item in ['contrast', 'order']: 208 208 continue … … 393 393 if not tmp==None: 394 394 self.current_shape.params[item[0]] = tmp 395 except :395 except Exception as exc: 396 396 print("Could not create") 397 print( sys.exc_value)397 print(exc) 398 398 399 399 def _onCreate(self, evt): … … 489 489 print("NOT YET IMPLMENTED") 490 490 print("renaming", self.shape_listbox.GetString(indices[0])) 491 -
src/sas/sasgui/perspectives/simulation/__init__.py
r959eb01 r5251ec6 1 1 PLUGIN_ID = "Simulation plug-in 1.0" 2 from simulation import *2 from .simulation import * -
src/sas/sasgui/perspectives/simulation/simulation.py
r7432acb r5251ec6 15 15 16 16 # Application imports 17 import SimCanvas 18 import ShapeParameters 19 import ShapeAdapter 17 from sas.sascalc.realspace import VolumeCanvas 18 from sas.sascalc.data_util.calcthread import CalcThread 20 19 from sas.sasgui.guiframe.dataFitting import Data1D 21 # Real-space simulation import22 import sas.sascalc.realspace.VolumeCanvas as VolumeCanvas23 24 from sas.sascalc.data_util.calcthread import CalcThread25 20 from sas.guicomm.events import NewPlotEvent, StatusEvent 21 22 from . import SimCanvas 23 from . import ShapeParameters 24 from . import ShapeAdapter 26 25 27 26 logger = logging.getLogger(__name__)
Note: See TracChangeset
for help on using the changeset viewer.