Ignore:
Timestamp:
Oct 11, 2018 2:20:56 PM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1249
Children:
98b9f32
Parents:
67ed543
Message:

improved support for py37 in sasgui

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/pr/pr.py

    r2469df7 r5251ec6  
    1818 
    1919import sys 
    20 import wx 
    2120import logging 
    2221import time 
    2322import math 
     23 
     24import wx 
    2425import numpy as np 
    2526import pylab 
     27 
    2628from sas.sasgui.guiframe.gui_manager import MDIFrame 
    2729from sas.sasgui.guiframe.dataFitting import Data1D 
     
    3335import sas.sascalc.dataloader 
    3436 
    35 from pr_widgets import load_error 
    3637from sas.sasgui.guiframe.plugin_base import PluginBase 
     38 
     39from .inversion_state import Reader  # .prv file reader 
     40from .inversion_panel import InversionControl 
     41#from .inversion_panel import HelpDialog 
     42from .inversion_panel import PrDistDialog 
     43from .pr_thread import CalcPr 
     44from .pr_thread import EstimatePr 
     45from .pr_thread import EstimateNT 
     46from .pr_widgets import load_error 
     47from .pr_widgets import DataDialog 
    3748 
    3849logger = logging.getLogger(__name__) 
     
    106117        self.list_plot_id = [] 
    107118 
    108         # Associate the inversion state reader with .prv files 
    109         from inversion_state import Reader 
    110  
    111119        # Create a CanSAS/Pr reader 
    112120        self.state_reader = Reader(self.set_state) 
     
    151159                msg = "Pr.set_state: datainfo parameter cannot " 
    152160                msg += "be None in standalone mode" 
    153                 raise RuntimeError, msg 
     161                raise RuntimeError(msg) 
    154162 
    155163            # Ensuring that plots are coordinated correctly 
     
    184192                                                   title=self.current_plottable.title)) 
    185193            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) 
    188196 
    189197 
     
    195203 
    196204        """ 
    197         from inversion_panel import HelpDialog 
    198205        dialog = HelpDialog(None, -1) 
    199206        if dialog.ShowModal() == wx.ID_OK: 
     
    369376        Redisplay P(r) with a different number of points 
    370377        """ 
    371         from inversion_panel import PrDistDialog 
    372378        dialog = PrDistDialog(None, -1) 
    373379        dialog.set_content(self._pr_npts) 
     
    452458        # Notify the user if we could not read the file 
    453459        if dataread is None: 
    454             raise RuntimeError, "Invalid data" 
     460            raise RuntimeError("Invalid data") 
    455461 
    456462        x = None 
     
    472478                if dataread is None: 
    473479                    return x, y, err 
    474                 raise RuntimeError, "This tool can only read 1D data" 
     480                raise RuntimeError("This tool can only read 1D data") 
    475481 
    476482        self._current_file_data.x = x 
     
    511517                    data_y = np.append(data_y, y) 
    512518                    data_err = np.append(data_err, err) 
    513                 except: 
    514                     logger.error(sys.exc_value) 
     519                except Exception as exc: 
     520                    logger.error(exc) 
    515521 
    516522        if scale is not None: 
     
    562568                        data_y = np.append(data_y, y) 
    563569                        data_err = np.append(data_err, err) 
    564                     except: 
    565                         logger.error(sys.exc_value) 
     570                    except Exception as exc: 
     571                        logger.error(exc) 
    566572                elif line.find("The 6 columns") >= 0: 
    567573                    data_started = True 
     
    720726            Start a calculation thread 
    721727        """ 
    722         from pr_thread import CalcPr 
    723  
    724728        # If a thread is already started, stop it 
    725729        if self.calc_thread is not None and self.calc_thread.isrunning(): 
     
    849853            try: 
    850854                pr = self._create_file_pr(data) 
    851             except: 
    852                 status = "Problem reading data: %s" % sys.exc_value 
     855            except Exception as exc: 
     856                status = "Problem reading data: %s" % exc 
    853857                wx.PostEvent(self.parent, StatusEvent(status=status)) 
    854                 raise RuntimeError, status 
     858                raise RuntimeError(status) 
    855859 
    856860            # If the file contains nothing, just return 
    857861            if pr is None: 
    858                 raise RuntimeError, "Loaded data is invalid" 
     862                raise RuntimeError("Loaded data is invalid") 
    859863 
    860864            self.pr = pr 
     
    906910            msg = "pr.save_data: the data being saved is not a" 
    907911            msg += " sas.data_info.Data1D object" 
    908             raise RuntimeError, msg 
     912            raise RuntimeError(msg) 
    909913 
    910914    def setup_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, 
     
    928932                self.pr = pr 
    929933                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)) 
    932936 
    933937    def estimate_plot_inversion(self, alpha, nfunc, d_max, 
     
    952956                self.pr = pr 
    953957                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)) 
    956960 
    957961    def _create_plot_pr(self, estimate=False): 
     
    10331037                self.pr = pr 
    10341038                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)) 
    10371041 
    10381042    def estimate_file_inversion(self, alpha, nfunc, d_max, data, 
     
    10561060                self.pr = pr 
    10571061                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)) 
    10601064 
    10611065    def _create_file_pr(self, data): 
     
    10851089            self._current_file_data.err = data.dy 
    10861090            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) 
    10891093            return None 
    10901094 
     
    11241128            pr.slit_width = self.slit_width 
    11251129            return pr 
    1126         except: 
    1127             load_error(sys.exc_value) 
     1130        except Exception as exc: 
     1131            load_error(exc) 
    11281132        return None 
    11291133 
     
    11321136            Perform parameter estimation 
    11331137        """ 
    1134         from pr_thread import EstimatePr 
    1135  
    11361138        # If a thread is already started, stop it 
    11371139        if self.estimation_thread is not None and \ 
     
    11621164            Perform parameter estimation 
    11631165        """ 
    1164         from pr_thread import EstimateNT 
    1165  
    11661166        # If a thread is already started, stop it 
    11671167        if self.estimation_thread is not None and self.estimation_thread.isrunning(): 
     
    12391239            Create and return a list of panel objects 
    12401240        """ 
    1241         from inversion_panel import InversionControl 
    1242  
    12431241        self.parent = parent 
    12441242        self.frame = MDIFrame(self.parent, None, 'None', (100, 200)) 
     
    12621260        if data_list is None: 
    12631261            data_list = [] 
     1262        else: 
     1263            data_list = list(data_list)  # force iterator to list 
    12641264        if len(data_list) >= 1: 
    12651265            if len(data_list) == 1: 
     
    12871287                msg += "Please select one.\n" 
    12881288                if len(data_list) > 1: 
    1289                     from pr_widgets import DataDialog 
    12901289                    dlg = DataDialog(data_list=data_1d_list, text=msg) 
    12911290                    if dlg.ShowModal() == wx.ID_OK: 
     
    13061305                    self.data_id = data.id 
    13071306                    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) 
    13101309                    wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 
    13111310            else: 
Note: See TracChangeset for help on using the changeset viewer.