Ignore:
Timestamp:
Oct 11, 2018 2:20:56 PM (5 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

Location:
src/sas/sasgui/perspectives/calculator
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/calculator/__init__.py

    r5a405bd r5251ec6  
    22import os 
    33from distutils.filelist import findall 
    4 from calculator import * 
     4from .calculator import * 
    55N_DIR = 12 
    66def get_data_path(media): 
  • src/sas/sasgui/perspectives/calculator/calculator.py

    r61bfd36 r5251ec6  
    1212################################################################################ 
    1313 
     14import logging 
     15 
    1416import wx 
     17 
    1518from sas.sasgui.guiframe.plugin_base import PluginBase 
    1619from sas.sasgui.perspectives.calculator.data_operator import DataOperatorWindow 
     
    2629from sas.sasgui.perspectives.calculator.image_viewer import ImageView 
    2730from sas.sasgui.perspectives.calculator.pyconsole import PyConsole 
    28 import logging 
    2931 
    3032logger = logging.getLogger(__name__) 
  • src/sas/sasgui/perspectives/calculator/collimation_editor.py

    r959eb01 r5251ec6  
    11""" 
    22""" 
    3 import wx 
    43import sys 
    54from copy import deepcopy 
     5 
     6import wx 
     7 
    68from sas.sascalc.dataloader.loader import Loader 
    79from sas.sascalc.dataloader.data_info import Aperture, Collimation 
    8 from aperture_editor import ApertureDialog 
    9  
    1010from sas.sasgui.guiframe.utils import check_float 
     11 
     12from .aperture_editor import ApertureDialog 
     13 
    1114_BOX_WIDTH = 60 
    1215 
  • src/sas/sasgui/perspectives/calculator/data_editor.py

    r235f514 r5251ec6  
    77from sas.sascalc.dataloader.loader import Loader 
    88from sas.sascalc.dataloader.data_info import Data2D 
    9 from detector_editor import DetectorDialog 
    10 from collimation_editor import CollimationDialog 
    11 from console import ConsoleDialog 
    129 
    1310from sas.sasgui.guiframe.events import StatusEvent 
     11 
     12from .detector_editor import DetectorDialog 
     13from .collimation_editor import CollimationDialog 
     14from .console import ConsoleDialog 
     15 
    1416 
    1517 
     
    397399        if data is None: 
    398400            return 
    399         from sample_editor import SampleDialog 
     401        from .sample_editor import SampleDialog 
    400402        dlg = SampleDialog(parent=self, sample=data.sample) 
    401403        dlg.set_manager(self) 
     
    409411        if data is None: 
    410412            return 
    411         from source_editor import SourceDialog 
     413        from .source_editor import SourceDialog 
    412414        dlg = SourceDialog(parent=self, source=data.source) 
    413415        dlg.set_manager(self) 
     
    426428        wlist = '|'.join(cards) 
    427429 
    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) 
    429431        if dlg.ShowModal() == wx.ID_OK: 
    430432            path = dlg.GetPath() 
     
    527529        try: 
    528530            #Load data 
    529             from load_thread import DataReader 
     531            from .load_thread import DataReader 
    530532            ## If a thread is already started, stop it 
    531533            if self.reader is not None and self.reader.isrunning(): 
     
    535537                                    updatefn=None) 
    536538            self.reader.queue() 
    537         except: 
    538             msg = "Data Editor: %s" % (sys.exc_value) 
     539        except Exception as exc: 
     540            msg = "Data Editor: %s" % exc 
    539541            load_error(msg) 
    540542            return 
  • src/sas/sasgui/perspectives/calculator/data_operator.py

    r7432acb r5251ec6  
    202202        else: 
    203203            text = name 
    204         state_list = self.get_datalist().values() 
    205204        name_list = [] 
    206         for state in state_list: 
     205        for state in self.get_datalist().values(): 
    207206            if state.data is None: 
    208207                theory_list = state.get_theory() 
    209                 theory, _ = theory_list.values()[0] 
     208                theory, _ = list(theory_list.values())[0] 
    210209                d_name = str(theory.name) 
    211210            else: 
     
    393392        try: 
    394393            self.output = self.make_data_out(data1, data2) 
    395         except: 
     394        except Exception as exc: 
    396395            self._check_newname() 
    397396            self._set_textctrl_color(self.data1_cbox, 'pink') 
    398397            self._set_textctrl_color(self.data2_cbox, 'pink') 
    399             msg = "DataOperation: %s" % sys.exc_value 
     398            msg = "DataOperation: %s" % exc 
    400399            self.send_warnings(msg, 'error') 
    401400            self.output = None 
     
    411410        operator = self.operator_cbox.GetClientData(pos) 
    412411        try: 
    413             exec "output = data1 %s data2" % operator 
     412            output = eval("data1 %s data2" % operator, 
     413                          {"data1": data1, "data2": data2}) 
    414414        except: 
    415415            raise 
     
    532532        self.data2_cbox.SetClientData(pos3, val) 
    533533        dnames = [] 
    534         ids = self._data.keys() 
    535         for id in ids: 
     534        for id in self._data.keys(): 
    536535            if id is not None: 
    537536                if self._data[id].data is not None: 
     
    539538                else: 
    540539                    theory_list = self._data[id].get_theory() 
    541                     theory, _ = theory_list.values()[0] 
     540                    theory, _ = list(theory_list.values())[0] 
    542541                    dnames.append(theory.name) 
    543542        ind = np.argsort(dnames) 
    544543        if len(ind) > 0: 
    545             val_list = np.array(self._data.values())[ind] 
     544            val_list = np.array(list(self._data.values()))[ind] 
    546545            for datastate in val_list: 
    547546                data = datastate.data 
     
    588587        self.send_warnings('') 
    589588        self.data_namectr.SetBackgroundColour('white') 
    590         state_list = self.get_datalist().values() 
    591589        name = self.data_namectr.GetValue().strip() 
    592590        name_list = [] 
    593         for state in state_list: 
     591        for state in self.get_datalist().values(): 
    594592            if state.data is None: 
    595593                theory_list = state.get_theory() 
    596                 theory, _ = theory_list.values()[0] 
     594                theory, _ = list(theory_list.values())[0] 
    597595                d_name = str(theory.name) 
    598596            else: 
     
    889887    def _onProperties(self, event): 
    890888        """ 
    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] 
    900897            if first_item.x != []: 
    901898                from sas.sasgui.plottools.PropertyDialog import Properties 
     
    929926        and set the scale 
    930927        """ 
    931         list = [] 
    932         list = self.graph.returnPlottable() 
    933928        # Changing the scale might be incompatible with 
    934929        # currently displayed data (for instance, going 
     
    940935        _xscale = 'linear' 
    941936        _yscale = 'linear' 
    942         for item in list: 
     937        for item in self.graph.returnPlottable(): 
    943938            item.setLabel(self.xLabel, self.yLabel) 
    944939            # control axis labels from the panel itself 
  • src/sas/sasgui/perspectives/calculator/density_panel.py

    r7432acb r5251ec6  
    362362            self.molar_mass_ctl.SetValue(str(self._format_number(molar_mass))) 
    363363            self.output_ctl.SetValue(str(output)) 
    364         except: 
     364        except Exception as exc: 
    365365            if self.base is not None: 
    366                 msg = "Density/Volume Calculator: %s" % (sys.exc_value) 
     366                msg = "Density/Volume Calculator: %s" % exc 
    367367                wx.PostEvent(self.base, StatusEvent(status=msg)) 
    368368        if event is not None: 
  • src/sas/sasgui/perspectives/calculator/detector_editor.py

    ra1b8fee r5251ec6  
    3434            self._do_layout() 
    3535            self.set_values() 
    36         except: 
    37             print("error", sys.exc_value) 
     36        except Exception as exc: 
     37            print("error", exc) 
    3838 
    3939    def _define_structure(self): 
  • src/sas/sasgui/perspectives/calculator/gen_scatter_panel.py

    r20fa5fe r5251ec6  
    228228        sizer.Add(unit_title, (iy, ix), (1, 1), \ 
    229229                            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()): 
    233231            iy += 1 
    234232            ix = 0 
     
    341339        ix = 0 
    342340        iy = 0 
    343         #key_list.sort() 
    344341        name = wx.StaticText(self, -1, 'No. of Qx (Qy) bins: ') 
    345342        sizer.Add(name, (iy, ix), (1, 1), \ 
     
    509506        wildcard = '|'.join(wildcard) 
    510507        dlg = wx.FileDialog(self, "Choose a file", location, 
    511                             "", wildcard, wx.OPEN) 
     508                            "", wildcard, wx.FD_OPEN) 
    512509        if dlg.ShowModal() == wx.ID_OK: 
    513510            path = dlg.GetPath() 
     
    556553            self.reader.queue() 
    557554            #self.load_update() 
    558         except: 
     555        except Exception as exc: 
    559556            self.ext = None 
    560557            if self.parent.parent is None: 
    561558                return 
    562             msg = "Generic SAS Calculator: %s" % (sys.exc_value) 
     559            msg = "Generic SAS Calculator: %s" % exc 
    563560            wx.PostEvent(self.parent.parent, 
    564561                          StatusEvent(status=msg, type='stop')) 
     
    774771            if output.pix_type == 'atom': 
    775772                # 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] 
    778775                a_name = a_names[0] 
    779776                for name in a_names: 
     
    898895            cal_out.queue() 
    899896 
    900         except: 
    901             msg = "%s." % sys.exc_value 
     897        except Exception as exc: 
     898            msg = "%s." % exc 
    902899            status_type = 'stop' 
    903900            self._status_info(msg, status_type) 
     
    13441341            self.sld_data.is_data = False 
    13451342            self.sld_data.filename = "Default SLD Profile" 
    1346         except: 
    1347             msg = "OMF Panel: %s" % sys.exc_value 
     1343        except Exception as exc: 
     1344            msg = "OMF Panel: %s" % exc 
    13481345            infor = 'Error' 
    13491346            #logger.error(msg) 
     
    14411438            raise 
    14421439        sld_key_list = self._get_slds_key_list(omfdata) 
    1443         # Dic is not sorted 
    1444         key_list = [key for key in sld_key_list.keys()] 
    1445         # Sort here 
    1446         key_list.sort() 
    14471440        is_data = self.sld_data.is_data 
    14481441        sizer = wx.GridBagSizer(2, 3) 
    14491442        ix = 0 
    14501443        iy = -1 
    1451         for key in key_list: 
    1452             value = sld_key_list[key] 
     1444        for key, value in sorted(sld_key_list.items()): 
    14531445            iy += 1 
    14541446            ix = 0 
     
    14851477        ix = 0 
    14861478        iy = -1 
    1487         for key, value in key_list.iteritems(): 
     1479        for key, value in sorted(key_list.items()): 
    14881480            iy += 1 
    14891481            ix = 0 
     
    15201512        ix = 0 
    15211513        iy = -1 
    1522         #key_list.sort() 
    1523         for key, value in key_list.iteritems(): 
     1514        for key, value in sorted(key_list.items()): 
    15241515            iy += 1 
    15251516            ix = 0 
  • src/sas/sasgui/perspectives/calculator/image_viewer.py

    r412e9e8b r5251ec6  
    9595        if location is None: 
    9696            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            )) 
    105107 
    106108        dlg = wx.FileDialog(self.parent, "Image Viewer: Choose an image file", 
  • src/sas/sasgui/perspectives/calculator/kiessig_calculator_panel.py

    r7432acb r5251ec6  
    1212import sys 
    1313 
     14from sas.sascalc.calculator.kiessig_calculator import KiessigThicknessCalculator 
    1415from sas.sasgui.guiframe.panel_base import PanelBase 
    15 from sas.sascalc.calculator.kiessig_calculator import KiessigThicknessCalculator 
    16 from calculator_widgets import OutputTextCtrl 
    17 from calculator_widgets import InputTextCtrl 
    1816from sas.sasgui.perspectives.calculator import calculator_widgets as widget 
    1917from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
     18from .calculator_widgets import OutputTextCtrl 
     19from .calculator_widgets import InputTextCtrl 
    2020 
    2121_BOX_WIDTH = 77 
  • src/sas/sasgui/perspectives/calculator/model_editor.py

    r9bf40e7 r5251ec6  
    578578        self.base = base 
    579579        self.path = path 
    580         self.font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT) 
     580        self.font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT) 
    581581        self.font.SetPointSize(10) 
    582582        self.reader = None 
     
    781781            if item.count("_") < 1: 
    782782                try: 
    783                     exec "float(math.%s)" % item 
     783                    exec("float(math.%s)" % item) 
    784784                    self.math_combo.Append(str(item)) 
    785785                except Exception: 
  • src/sas/sasgui/perspectives/calculator/resolcal_thread.py

    r20fa5fe r5251ec6  
    4646        executing computation 
    4747        """ 
    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] 
    5151        elapsed = time.time() - self.starttime 
    5252 
  • src/sas/sasgui/perspectives/calculator/resolution_calculator_panel.py

    r1cf490b6 r5251ec6  
    148148        # Custom sorting 
    149149        source_list = [] 
    150         for key, _ in self.source_mass.iteritems(): 
     150        for key, _ in self.source_mass.items(): 
    151151            name_source = str(key) 
    152152            source_list.append(name_source) 
     
    667667        Execute the computation of resolution 
    668668        """ 
     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() 
    669675        wx.CallAfter(self.on_compute_call, event) 
    670676 
     
    753759            wx.MessageBox(msg, 'Warning') 
    754760            return 
    755             #raise ValueError, "Invalid Q Input..." 
     761            #raise ValueError("Invalid Q Input...") 
    756762 
    757763        # Validate the q inputs 
     
    934940    def _sigma_strings(self): 
    935941        """ 
    936         Recode sigmas as strins 
     942        Recode sigmas as strings 
    937943        """ 
    938944        sigma_r = self.format_number(self.resolution.sigma_1) 
     
    10821088                msg = "The numbers must be one or two (separated by ',')..." 
    10831089                self._status_info(msg, 'stop') 
    1084                 raise RuntimeError, msg 
     1090                raise RuntimeError(msg) 
    10851091 
    10861092        return new_string 
     
    10991105                value = float(string_split[ind]) 
    11001106                new_string.append(value) 
    1101             except: 
    1102                 logger.error(sys.exc_value) 
     1107            except Exception as exc: 
     1108                logger.error(exc) 
    11031109 
    11041110        return new_string 
     
    11411147                        out = self._string2inputlist(string) 
    11421148                        return out 
    1143                 except: 
    1144                     logger.error(sys.exc_value) 
     1149                except Exception as exc: 
     1150                    logger.error(exc) 
    11451151 
    11461152    def _on_xy_coordinate(self, event=None): 
     
    12691275            try: 
    12701276                basename = os.path.basename(path) 
    1271                 if basename not in self.spectrum_dic.keys(): 
     1277                if basename not in self.spectrum_dic: 
    12721278                    self.spectrum_cb.Append(basename) 
    12731279                self.spectrum_dic[basename] = self._read_file(path) 
     
    12861292        dlg = wx.FileDialog(self, 
    12871293                            "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) 
    12891295        path = None 
    12901296        if dlg.ShowModal() == wx.ID_OK: 
     
    13181324                    wavelength.append(wave) 
    13191325                    intensity.append(intens) 
    1320                 except: 
     1326                except Exception as exc: 
    13211327                    # Skip non-data lines 
    1322                     logger.error(sys.exc_value) 
     1328                    logger.error(exc) 
    13231329 
    13241330            return [wavelength, intensity] 
  • src/sas/sasgui/perspectives/calculator/sld_panel.py

    r2d220dd r5251ec6  
    363363 
    364364        """ 
     365        # TODO: use periodictable.elements object 
     366        #    energy = xray_energy(periodictable.elements[element].K_alpha) 
     367        # TODO: code is very similar to sld helper 
    365368        myformula = formula(str(element)) 
    366369        if len(myformula.atoms) != 1: 
    367370            return 
    368         element = myformula.atoms.keys()[0] 
     371        element = list(myformula.atoms.keys())[0] 
    369372        energy = xray_energy(element.K_alpha) 
    370373 
     
    413416                    msg += "Error for wavelength value :expect float" 
    414417            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                #         ... 
    415421                try: 
    416422                    import periodictable 
     
    447453 
    448454        """ 
     455        # TODO: use periodictable.elements object 
     456        #    energy = xray_energy(periodictable.elements[element].K_alpha) 
    449457        element_formula = formula(str(element)) 
    450458        if len(element_formula.atoms) != 1: 
    451459            return 
    452         element = element_formula.atoms.keys()[0] 
     460        element = list(element_formula.atoms.keys())[0] 
    453461        energy = xray_energy(element.K_alpha) 
     462 
    454463        atom = molecule_formula.atoms 
    455464        return xray_sld_from_atoms(atom, density=density, energy=energy) 
     
    505514            #self.wavelength_ctl.SetValue(str(self.wavelength)) 
    506515            #self.wavelength_ctl.SetValue(str(self.wavelength)) 
    507         except: 
     516        except Exception as exc: 
    508517            if self.base is not None: 
    509                 msg = "SLD Calculator: %s" % (sys.exc_value) 
     518                msg = "SLD Calculator: %s" % exc 
    510519                wx.PostEvent(self.base, StatusEvent(status=msg)) 
    511520        if event is not None: 
  • src/sas/sasgui/perspectives/calculator/slit_length_calculator_panel.py

    rd788619 r5251ec6  
    1717from sas.sasgui.guiframe.events import StatusEvent 
    1818from sas.sascalc.calculator.slit_length_calculator import SlitlengthCalculator 
    19 from calculator_widgets import OutputTextCtrl 
    20 from calculator_widgets import InterActiveOutputTextCtrl 
    2119from sas.sasgui.perspectives.calculator import calculator_widgets as widget 
    2220from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
     21from .calculator_widgets import OutputTextCtrl 
     22from .calculator_widgets import InterActiveOutputTextCtrl 
    2323 
    2424_BOX_WIDTH = 76 
     
    163163 
    164164        dlg = wx.FileDialog(self, "Choose a file", location, 
    165                             "", wildcard, wx.OPEN) 
     165                            "", wildcard, wx.FD_OPEN) 
    166166        if dlg.ShowModal() == wx.ID_OK: 
    167167            path = dlg.GetPath() 
     
    223223            self.reader.queue() 
    224224            self.load_update() 
    225         except: 
     225        except Exception as exc: 
    226226            if self.parent.parent is None: 
    227227                return 
    228             msg = "Slit Length Calculator: %s" % (sys.exc_value) 
     228            msg = "Slit Length Calculator: %s" % exc 
    229229            wx.PostEvent(self.parent.parent, 
    230230                          StatusEvent(status=msg, type='stop')) 
     
    264264            if x == [] or  x is None or y == [] or y is None: 
    265265                msg = "The current data is empty please check x and y" 
    266                 raise ValueError, msg 
     266                raise ValueError(msg) 
    267267            slit_length_calculator = SlitlengthCalculator() 
    268268            slit_length_calculator.set_data(x=x, y=y) 
    269269            slit_length = slit_length_calculator.calculate_slit_length() 
    270         except: 
     270        except Exception as exc: 
    271271            if self.parent.parent is None: 
    272272                return 
    273             msg = "Slit Size Calculator: %s" % (sys.exc_value) 
     273            msg = "Slit Size Calculator: %s" % exc 
    274274            wx.PostEvent(self.parent.parent, 
    275275                          StatusEvent(status=msg, type='stop')) 
Note: See TracChangeset for help on using the changeset viewer.