Changeset d4cde37 in sasview


Ignore:
Timestamp:
Mar 30, 2019 6:15:51 PM (5 years ago)
Author:
GitHub <noreply@…>
Branches:
release-4.2.2
Children:
f5f8553, cc2cd5a
Parents:
09d7021 (diff), 31c1bae (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Paul Kienzle <pkienzle@…> (03/30/19 18:15:51)
git-committer:
GitHub <noreply@…> (03/30/19 18:15:51)
Message:

Merge pull request #209 from SasView?/ticket-1242-2d-resolution

Use dQ/|Q| for 2-D resolution

Location:
src/sas
Files:
98 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/fitpage.py

    r82d88d5 rd4cde37  
    23652365                percent = self.dx_percent/100 
    23662366                if self._is_2D(): 
    2367                     data.dqx_data[data.dqx_data == 0] = percent * data.qx_data 
    2368                     data.dqy_data[data.dqy_data == 0] = percent * data.qy_data 
     2367                    q = np.sqrt(data.qx_data**2 + data.qy_data**2) 
     2368                    data.dqx_data = data.dqy_data = percent*q 
    23692369                else: 
    23702370                    data.dx = percent * data.x 
  • src/sas/sasgui/guiframe/CategoryInstaller.py

    ra26f67f rcb64d86  
    2020 
    2121logger = logging.getLogger(__name__) 
     22 
     23if sys.version_info[0] > 2: 
     24    def json_dump(obj, filename): 
     25        with open(filename, 'w', newline='\n') as fd: 
     26            json.dump(obj, fd) 
     27else: # CRUFT: python 2.7 support 
     28    def json_dump(obj, filename): 
     29        with open(filename, 'wb') as fd: 
     30            json.dump(obj, fd) 
    2231 
    2332class CategoryInstaller(object): 
     
    121130        """ 
    122131        _model_dict = {model.name: model for model in model_list} 
    123         _model_list = _model_dict.keys() 
     132        _model_list = list(_model_dict.keys()) 
    124133 
    125134        serialized_file = None 
     
    146155                        by_model_dict.pop(model_name) 
    147156                        model_enabled_dict.pop(model_name) 
    148                     except Exception: 
    149                         logger.error("CategoryInstaller: %s", sys.exc_value) 
     157                    except Exception as exc: 
     158                        logger.error("CategoryInstaller: %s", exc) 
    150159                else: 
    151160                    add_list.remove(model_name) 
     
    171180                                                          model_enabled_dict) 
    172181 
    173             json.dump(master_category_dict, open(serialized_file, 'wb')) 
     182            json_dump(master_category_dict, serialized_file) 
  • src/sas/sasgui/guiframe/CategoryManager.py

    r463e7ffc r5251ec6  
    230230 
    231231        for model in model_name_list: 
    232             index = self.cat_list.InsertStringItem(sys.maxint, model) 
     232            index = self.cat_list.InsertStringItem(sys.maxsize, model) 
    233233            self.cat_list.SetStringItem(index, 1, \ 
    234234                                            str(self.by_model_dict[model]).\ 
     
    384384        """ 
    385385        cat_list = list() 
    386         for category in self.master_category_dict.iterkeys(): 
     386        for category in self.master_category_dict.keys(): 
    387387            if not category == 'Uncategorized': 
    388388                cat_list.append(category) 
  • src/sas/sasgui/guiframe/custom_pstats.py

    r959eb01 r5251ec6  
    3636        width = self.max_name_len 
    3737        if self.fcn_list: 
    38             list = self.fcn_list[:] 
     38            stats = self.fcn_list[:] 
    3939            temp_msg = "   Ordered by: " + self.sort_type + '\n' 
    4040        else: 
    41             list = self.stats.keys() 
     41            stats = list(self.stats.keys()) 
    4242            temp_msg = "   Random listing order was used\n" 
    4343 
    4444        for selection in amount: 
    45             list, temp_msg = self.eval_print_amount(selection, list, temp_msg) 
     45            stats, temp_msg = self.eval_print_amount(selection, stats, temp_msg) 
    4646 
    47         count = len(list) 
     47        count = len(stats) 
    4848 
    49         if not list: 
    50             width, list = 0, list 
     49        if not stats: 
     50            width = 0 
    5151        else: 
    52             msg +=   str(temp_msg) + '\n' 
     52            msg += str(temp_msg) + '\n' 
    5353            if count < len(self.stats): 
    5454                width = 0 
    55                 for func in list: 
     55                for func in stats: 
    5656                    if  len(func_std_string(func)) > width: 
    5757                        width = len(func_std_string(func)) 
    5858        
    59             width, list = width+2, list 
    60         if list: 
     59            width = width+2 
     60        if stats: 
    6161            msg += '   ncalls  tottime  percall  cumtime  percall' 
    6262            msg +=  ' filename:lineno(function)' + "\n" 
    63             for func in list: 
     63            for func in stats: 
    6464                cc, nc, tt, ct, callers = self.stats[func] 
    6565                c = str(nc) 
  • src/sas/sasgui/guiframe/data_manager.py

    r959eb01 r5251ec6  
    5151        _str += "No of states  is %s \n" % str(len(self.stored_data)) 
    5252        n_count = 0 
    53         for  value in self.stored_data.values(): 
     53        for value in self.stored_data.values(): 
    5454            n_count += 1  
    5555            _str += "State No %s \n"  % str(n_count) 
     
    134134        receive a list of  
    135135        """ 
    136         for id, data in data_list.iteritems(): 
     136        for id, data in data_list.items(): 
    137137            if id  in self.stored_data: 
    138138                msg = "Data manager already stores %s" % str(data.name) 
     
    150150        """ 
    151151        """ 
    152         if prev_data.id not in self.stored_data.keys(): 
     152        if prev_data.id not in self.stored_data: 
    153153            return None, {} 
    154154        data_state = self.stored_data[prev_data.id]  
    155155        self.stored_data[new_data.id]  = data_state.clone() 
    156156        self.stored_data[new_data.id].data = new_data 
    157         if prev_data.id in self.stored_data.keys(): 
     157        if prev_data.id in self.stored_data: 
    158158            del self.stored_data[prev_data.id]  
    159159        return prev_data.id, {new_data.id: self.stored_data[new_data.id]} 
     
    165165        if data_id is None and theory is not None: 
    166166            uid = theory.id 
    167         if uid in self.stored_data.keys(): 
     167        if uid in self.stored_data: 
    168168             data_state = self.stored_data[uid]  
    169169        else: 
     
    195195                if search_id == d_id: 
    196196                    _selected_data[search_id] = data 
    197                 if search_id in theory_list.keys(): 
     197                if search_id in theory_list: 
    198198                     _selected_theory_list[search_id] = theory_list[search_id] 
    199199                    
     
    204204        """ 
    205205        """ 
    206         return self.freeze_theory(self.stored_data.keys(), theory_id) 
     206        return self.freeze_theory(list(self.stored_data.keys()), theory_id) 
    207207         
    208208    def freeze_theory(self, data_id, theory_id): 
     
    215215                theory_list = data_state.get_theory() 
    216216                for t_id in theory_id: 
    217                     if t_id in theory_list.keys(): 
     217                    if t_id in theory_list: 
    218218                        theory_data, theory_state = theory_list[t_id] 
    219219                        new_theory = copy.deepcopy(theory_data) 
     
    235235        """ 
    236236        for d_id in data_id: 
    237             if d_id in self.stored_data.keys(): 
     237            if d_id in self.stored_data: 
    238238                data_state = self.stored_data[d_id] 
    239239                if data_state.data.name in self.data_name_dict: 
     
    253253                data_state = self.stored_data[d_id] 
    254254                theory_list = data_state.get_theory() 
    255                 if theory_id in theory_list.keys(): 
     255                if theory_id in theory_list: 
    256256                    del theory_list[theory_id] 
    257257        #del pure theory 
     
    273273        _selected_data = {} 
    274274        for selected_name in name_list: 
    275             for id, data_state in self.stored_data.iteritems(): 
     275            for id, data_state in self.stored_data.items(): 
    276276                if data_state.data.name == selected_name: 
    277277                    _selected_data[id] = data_state.data 
     
    283283        """ 
    284284        for selected_name in name_list: 
    285             for id, data_state in self.stored_data.iteritems(): 
     285            for id, data_state in self.stored_data.items(): 
    286286                if data_state.data.name == selected_name: 
    287287                    del self.stored_data[id] 
     
    293293        _selected_data_state = {} 
    294294        for id in data_id: 
    295             if id in self.stored_data.keys(): 
     295            if id in self.stored_data: 
    296296                _selected_data_state[id] = self.stored_data[id] 
    297297        return _selected_data_state 
     
    303303        return self.stored_data 
    304304     
    305  
    306          
  • src/sas/sasgui/guiframe/data_panel.py

    rb963b20 r5251ec6  
    1313from __future__ import print_function 
    1414 
     15import sys 
     16 
    1517import wx 
    16 from wx.build import build_options 
    17  
    18 import sys 
    1918from wx.lib.scrolledpanel import ScrolledPanel 
    2019import wx.lib.agw.customtreectrl as CT 
     20#from wx.build import build_options 
     21 
    2122from sas.sasgui.guiframe.dataFitting import Data1D 
    2223from sas.sasgui.guiframe.dataFitting import Data2D 
     
    444445            self.parent.get_data_manager().get_by_id(id_list=[id]) 
    445446        if data_list: 
    446             data = data_list.values()[0] 
     447            data = list(data_list.values())[0] 
    447448        if data is None: 
    448             data = theory_list.values()[0][0] 
     449            data = list(theory_list.values())[0][0] 
    449450        return data 
    450451 
     
    667668        """ 
    668669        if list: 
    669             for state_id, dstate in list.iteritems(): 
     670            for state_id, dstate in list.items(): 
    670671                data = dstate.get_data() 
    671672                theory_list = dstate.get_theory() 
     
    764765        if not theory_list: 
    765766            return 
    766         if state_id not in self.list_cb_data.keys(): 
     767        if state_id not in self.list_cb_data: 
    767768            root = self.tree_ctrl_theory.root 
    768769            tree = self.tree_ctrl_theory 
     
    783784        Append theory helper 
    784785        """ 
    785         if state_id in self.list_cb_theory.keys(): 
     786        if state_id in self.list_cb_theory: 
    786787            # update current list of theory for this data 
    787788            theory_list_ctrl = self.list_cb_theory[state_id] 
    788789 
    789             for theory_id, item in theory_list.iteritems(): 
     790            for theory_id, item in theory_list.items(): 
    790791                theory_data, _ = item 
    791792                if theory_data is None: 
     
    828829            # data didn't have a theory associated it before 
    829830            theory_list_ctrl = {} 
    830             for theory_id, item in theory_list.iteritems(): 
     831            for theory_id, item in theory_list.items(): 
    831832                theory_data, _ = item 
    832833                if theory_data is not None: 
     
    868869 
    869870        for theory_dict in self.list_cb_theory.values(): 
    870             for _, value in theory_dict.iteritems(): 
     871            for _, value in theory_dict.items(): 
    871872                item, _, _ = value 
    872873                if item.IsChecked(): 
     
    924925        theory_key = [] 
    925926        # remove  data from treectrl 
    926         for d_key, item in self.list_cb_data.iteritems(): 
     927        for d_key, item in self.list_cb_data.items(): 
    927928            data_c, _, _, _,  _, _, _, _ = item 
    928929            if data_c.IsChecked(): 
    929930                self.tree_ctrl.Delete(data_c) 
    930931                data_key.append(d_key) 
    931                 if d_key in self.list_cb_theory.keys(): 
     932                if d_key in self.list_cb_theory: 
    932933                    theory_list_ctrl = self.list_cb_theory[d_key] 
    933                     theory_to_remove += theory_list_ctrl.keys() 
     934                    theory_to_remove += list(theory_list_ctrl.keys()) 
    934935        # Remove theory from treectrl 
    935         for _, theory_dict in self.list_cb_theory.iteritems(): 
    936             for key, value in theory_dict.iteritems(): 
     936        for _, theory_dict in self.list_cb_theory.items(): 
     937            for key, value in theory_dict.items(): 
    937938                item, _, _ = value 
    938939                if item.IsChecked(): 
     
    950951        # remove theory  references independently of data 
    951952        for key in theory_key: 
    952             for _, theory_dict in self.list_cb_theory.iteritems(): 
     953            for _, theory_dict in self.list_cb_theory.items(): 
    953954                if key in theory_dict: 
    954                     for key, value in theory_dict.iteritems(): 
     955                    for key, value in theory_dict.items(): 
    955956                        item, _, _ = value 
    956957                        if item.IsChecked(): 
     
    10471048        if self.cb_plotpanel and self.cb_plotpanel.IsBeingDeleted(): 
    10481049            return 
    1049         for _, value in self.parent.plot_panels.iteritems(): 
     1050        for _, value in self.parent.plot_panels.items(): 
    10501051            name_plot_panel = str(value.window_caption) 
    10511052            if name_plot_panel not in self.cb_plotpanel.GetItems(): 
     
    11291130        #import documentation window here to avoid circular imports 
    11301131        #if put at top of file with rest of imports. 
    1131         from documentation_window import DocumentationWindow 
     1132        from .documentation_window import DocumentationWindow 
    11321133 
    11331134        _TreeLocation = "user/sasgui/guiframe/data_explorer_help.html" 
     
    14991500        window.Show(True) 
    15001501        window.load_data_list(list=temp_data_list) 
    1501     except: 
     1502    except Exception as exc: 
    15021503        # raise 
    1503         print("error", sys.exc_value) 
     1504        print("error", exc) 
    15041505 
    15051506    app.MainLoop() 
  • src/sas/sasgui/guiframe/data_processor.py

    r20fa5fe r5251ec6  
    234234        # overriden in this subclassn - actually we have currently 
    235235        # disabled the on_context_menu that would override the OnRightClick 
    236         self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnCellChange) 
     236        try: 
     237            EVT_GRID_CELL_CHANGED = wx.grid.EVT_GRID_CELL_CHANGED 
     238        except AttributeError: 
     239            # CRUFT: wx 3.x uses CHANGE rather than CHANGING/CHANGED 
     240            EVT_GRID_CELL_CHANGED = wx.grid.EVT_GRID_CELL_CHANGE 
     241        self.Bind(EVT_GRID_CELL_CHANGED, self.OnCellChange) 
    237242        self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnLeftClick) 
    238243        self.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnRightClick) 
     
    561566                value = self.GetCellValue(row, col) 
    562567                self.data[col_name].append(value) 
    563                 for k, value_list in self.data.iteritems(): 
     568                for k, value_list in self.data.items(): 
    564569                    if k != col_name: 
    565570                        length = len(value_list) 
     
    621626        if col_name.strip() != "Empty": 
    622627            self.SetCellValue(row, col, str(col_name.strip())) 
    623         if col_name in self.data.keys(): 
     628        if col_name in self.data: 
    624629            value_list = self.data[col_name] 
    625630            cell_row = 1 
     
    674679            self._cols = self.GetNumberCols() 
    675680            self._rows = self.GetNumberRows() 
    676             self.col_names = self.data_outputs.keys() 
     681            self.col_names = list(self.data_outputs.keys()) 
    677682            self.col_names.sort() 
    678683            nbr_user_cols = len(self.col_names) 
     
    682687                self.AppendCols(new_col_nbr, True) 
    683688            #Add more rows to the grid if necessary 
    684             nbr_user_row = len(self.data_outputs.values()[0]) 
     689            nbr_user_row = len(list(self.data_outputs.values())[0]) 
    685690            if nbr_user_row > self._rows + 1: 
    686691                new_row_nbr = nbr_user_row - self._rows + 1 
     
    909914                    msg = "Edit axis doesn't understand this selection.\n" 
    910915                    msg += "Please select only one column" 
    911                     raise ValueError, msg 
     916                    raise ValueError(msg) 
    912917            for (_, cell_col) in grid.selected_cells: 
    913918                if cell_col != col: 
     
    915920                    msg += "this operation.\n" 
    916921                    msg += "Please select elements of the same col.\n" 
    917                     raise ValueError, msg 
     922                    raise ValueError(msg) 
    918923 
    919924            # Finally check the highlighted cell if any cells missing 
     
    922927            msg = "No item selected.\n" 
    923928            msg += "Please select only one column or one cell" 
    924             raise ValueError, msg 
     929            raise ValueError(msg) 
    925930        return grid.selected_cells 
    926931 
     
    13261331            if sentence.strip() == "": 
    13271332                msg = "Select column values for x axis" 
    1328                 raise ValueError, msg 
     1333                raise ValueError(msg) 
    13291334        except: 
    13301335            msg = "X axis value error." 
     
    13451350            if sentence.strip() == "": 
    13461351                msg = "select value for y axis" 
    1347                 raise ValueError, msg 
     1352                raise ValueError(msg) 
    13481353        except: 
    13491354            msg = "Y axis value error." 
     
    14401445        """ 
    14411446 
    1442         for tok, (col_name, list) in dict.iteritems(): 
     1447        for tok, (col_name, list) in dict.items(): 
    14431448            col = column_names[col_name] 
    14441449            axis = self.get_plot_axis(col, list) 
     
    14461451                return None 
    14471452            sentence = sentence.replace(tok, "numpy.array(%s)" % str(axis)) 
    1448         for key, value in FUNC_DICT.iteritems(): 
     1453        for key, value in FUNC_DICT.items(): 
    14491454            sentence = sentence.replace(key.lower(), value) 
    14501455        return sentence 
     
    15461551            cell_list = self.notebook.on_edit_axis() 
    15471552            label, title = self.create_axis_label(cell_list) 
    1548         except: 
    1549             msg = str(sys.exc_value) 
     1553        except Exception as exc: 
     1554            msg = str(exc) 
    15501555            wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 
    15511556            return 
     
    20362041        frame = GridFrame(data_outputs=data, data_inputs=data_input) 
    20372042        frame.Show(True) 
    2038     except: 
    2039         print(sys.exc_value) 
     2043    except Exception as exc: 
     2044        print(exc) 
    20402045 
    20412046    app.MainLoop() 
  • src/sas/sasgui/guiframe/data_state.py

    r959eb01 r5251ec6  
    3737        _str += "Theories available: %s \n" % len(self.theory_list) 
    3838        if self.theory_list: 
    39             for id, item in self.theory_list.iteritems(): 
     39            for id, item in self.theory_list.items(): 
    4040                theory_data, theory_state = item 
    4141                _str += "Theory name : %s \n" % str(theory_data.name) 
     
    5353        obj.message = self.message 
    5454        obj.id = self.id 
    55         for id, item in self.theory_list.iteritems(): 
     55        for id, item in self.theory_list.items(): 
    5656            theory_data, theory_state = item 
    5757            state = None 
     
    9595        """ 
    9696        self.theory_list[theory_data.id] = [theory_data, theory_state] 
    97         data, state = self.theory_list.values()[0] 
     97        data, state = list(self.theory_list.values())[0] 
    9898        
    9999    def get_theory(self): 
     
    106106        return self.message 
    107107     
    108    
  • src/sas/sasgui/guiframe/gui_manager.py

    rdcd6efd r82d88d5  
    1313 
    1414 
    15 import wx 
    16 import wx.aui 
    1715import os 
    1816import sys 
     
    2523import urllib 
    2624import json 
     25import copy 
     26 
     27import wx 
     28import wx.aui 
    2729 
    2830from matplotlib import _pylab_helpers 
     
    275277        return client size tuple 
    276278        """ 
    277         width, height = self.GetClientSizeTuple() 
     279        width, height = self.GetClientSize() 
    278280        height -= 45 
    279281        # Adjust toolbar height 
     
    350352        try: 
    351353            self.read_batch_tofile(file_name=path) 
    352         except: 
     354        except Exception as exc: 
    353355            msg = "Error occurred when reading the file; %s\n" % path 
    354             msg += "%s\n" % sys.exc_value 
    355             wx.PostEvent(self, StatusEvent(status=msg, 
    356                                            info="error")) 
     356            msg += "%s\n" % exc 
     357            wx.PostEvent(self, StatusEvent(status=msg, info="error")) 
    357358 
    358359    def read_batch_tofile(self, file_name): 
     
    694695        try: 
    695696            self.load_from_cmd(self._input_file) 
    696         except: 
     697        except Exception as exc: 
    697698            msg = "%s Cannot load file %s\n" % (str(APPLICATION_NAME), 
    698699                                                str(self._input_file)) 
    699             msg += str(sys.exc_value) + '\n' 
     700            msg += str(exc) + '\n' 
    700701            logger.error(msg) 
    701702        if self._data_panel is not None and len(self.plugins) > 0: 
     
    786787                self._data_plugin = data_loader.Plugin() 
    787788                plugins.append(self._data_plugin) 
    788             except: 
     789            except Exception as exc: 
    789790                msg = "ViewerFrame._get_local_plugins:" 
    790                 msg += "cannot import dataloader plugin.\n %s" % sys.exc_value 
     791                msg += "cannot import dataloader plugin.\n %s" % exc 
    791792                logger.error(msg) 
    792793        if style2 == GUIFRAME.PLOTTING_ON: 
     
    796797                self._plotting_plugin = plotting.Plugin() 
    797798                plugins.append(self._plotting_plugin) 
    798             except: 
     799            except Exception as exc: 
    799800                msg = "ViewerFrame._get_local_plugins:" 
    800                 msg += "cannot import plotting plugin.\n %s" % sys.exc_value 
     801                msg += "cannot import plotting plugin.\n %s" % exc 
    801802                logger.error(msg) 
    802803 
     
    845846                                msg = "Found plug-in: %s" % module.PLUGIN_ID 
    846847                                logger.info(msg) 
    847                             except: 
     848                            except Exception as exc: 
    848849                                msg = "Error accessing PluginPanel" 
    849                                 msg += " in %s\n  %s" % (name, sys.exc_value) 
     850                                msg += " in %s\n  %s" % (name, exc) 
    850851                                config.printEVT(msg) 
    851                     except: 
    852                         msg = "ViewerFrame._find_plugins: %s" % sys.exc_value 
     852                    except Exception as exc: 
     853                        msg = "ViewerFrame._find_plugins: %s" % exc 
    853854                        logger.error(msg) 
    854855                    finally: 
    855856                        if file is not None: 
    856857                            file.close() 
    857         except: 
     858        except Exception as exc: 
    858859            # Should raise and catch at a higher level and 
    859860            # display error on status bar 
    860             logger.error(sys.exc_value) 
     861            logger.error(exc) 
    861862 
    862863        return plugins 
     
    15881589        """ 
    15891590        # This CallAfter fixes many crashes on MAC. 
    1590         wx.CallAfter(self.sb.set_status, evt) 
     1591        wx.CallAfter(self.sb.set_status, evt.Clone()) 
    15911592 
    15921593    def on_view(self, evt): 
     
    16321633        ID = str(uid) 
    16331634        config.printEVT("delete_panel: %s" % ID) 
    1634         if ID in self.panels.keys(): 
     1635        if ID in self.panels: 
    16351636            self.panel_on_focus = None 
    16361637            panel = self.panels[ID] 
     
    16441645 
    16451646            # delete uid number not str(uid) 
    1646             if ID in self.plot_panels.keys(): 
     1647            if ID in self.plot_panels: 
    16471648                del self.plot_panels[ID] 
    1648             if ID in self.panels.keys(): 
     1649            if ID in self.panels: 
    16491650                del self.panels[ID] 
    16501651        else: 
     
    16801681                    try: 
    16811682                        reader.read(path) 
    1682                     except: 
     1683                    except Exception as exc: 
    16831684                        msg = "DataLoader Error: Encounted Non-ASCII character" 
    1684                         msg += "\n(%s)" % sys.exc_value 
     1685                        msg += "\n(%s)" % exc 
    16851686                        wx.PostEvent(self, StatusEvent(status=msg, 
    16861687                                                       info="error", 
     
    17631764 
    17641765            self.add_data(data_list=output) 
    1765         except: 
     1766        except Exception as exc: 
    17661767            error_message = "Error while loading" 
    17671768            error_message += " Data from cmd:\n %s\n" % str(path) 
    1768             error_message += str(sys.exc_value) + "\n" 
     1769            error_message += str(exc) + "\n" 
    17691770            logger.error(error_message) 
    17701771 
     
    17841785            else: 
    17851786                return 
    1786         except: 
     1787        except Exception as exc: 
    17871788            error_message = "Error while loading" 
    17881789            error_message += " Data folder from cmd:\n %s\n" % str(path) 
    1789             error_message += str(sys.exc_value) + "\n" 
     1790            error_message += str(exc) + "\n" 
    17901791            logger.error(error_message) 
    17911792 
     
    18541855            self._data_panel.selection_cbox.SetValue('Select all Data') 
    18551856            self._data_panel._on_selection_type(None) 
    1856             for _, theory_dict in self._data_panel.list_cb_theory.iteritems(): 
    1857                 for key, value in theory_dict.iteritems(): 
     1857            for _, theory_dict in self._data_panel.list_cb_theory.items(): 
     1858                for key, value in theory_dict.items(): 
    18581859                    item, _, _ = value 
    18591860                    item.Check(True) 
     
    19631964            # case of a panel with multi-pages 
    19641965            if hasattr(panel, "opened_pages"): 
    1965                 for _, page in panel.opened_pages.iteritems(): 
     1966                for _, page in panel.opened_pages.items(): 
    19661967                    data = page.get_data() 
    19671968                    # state must be cloned 
     
    20852086                msg += " Please try again later." 
    20862087                self.SetStatusText(msg) 
    2087             elif cmp(version, config.__version__) > 0: 
     2088            elif version > config.__version__: 
    20882089                msg = "Version %s is available! " % str(version) 
    20892090                if not standalone: 
     
    21012102                    msg += " of %s" % str(config.__appname__) 
    21022103                    self.SetStatusText(msg) 
    2103         except: 
     2104        except Exception as exc: 
    21042105            msg = "guiframe: could not get latest application" 
    2105             msg += " version number\n  %s" % sys.exc_value 
     2106            msg += " version number\n  %s" % exc 
    21062107            logger.error(msg) 
    21072108            if not standalone: 
     
    21432144        # S King, Sep 2018 
    21442145 
    2145         from documentation_window import DocumentationWindow 
     2146        from .documentation_window import DocumentationWindow 
    21462147        _TreeLocation = "user/release.html" 
    21472148        DocumentationWindow(self, -1, _TreeLocation, "", 
     
    21642165        # S King, Sep 2018 
    21652166 
    2166         from documentation_window import DocumentationWindow 
     2167        from .documentation_window import DocumentationWindow 
    21672168        _TreeLocation = "user/tutorial.html" 
    21682169        DocumentationWindow(self, -1, _TreeLocation, "", 
     
    21792180        # Running SasView "in-place" using run.py means the docs will be in a 
    21802181        # different place than they would otherwise. 
    2181         from documentation_window import DocumentationWindow 
     2182        from .documentation_window import DocumentationWindow 
    21822183        _TreeLocation = "user/user.html" 
    21832184        DocumentationWindow(self, -1, _TreeLocation, "", 
     
    22272228                if (style == GUIFRAME.MANAGER_ON) \ 
    22282229                        and self.panels[item] == self._data_panel: 
    2229                     if 'data_panel' in self.panels.keys(): 
     2230                    if 'data_panel' in self.panels: 
    22302231                        frame = self.panels['data_panel'].get_frame() 
    22312232                        if frame is None: 
     
    22792280        # set data in the data panel 
    22802281        if self._data_panel is not None: 
    2281             data_state = self._data_manager.get_data_state(data_list.keys()) 
     2282            data_state = self._data_manager.get_data_state(list(data_list.keys())) 
    22822283            self._data_panel.load_data_list(data_state) 
    22832284        # if the data panel is shown wait for the user to press a button 
     
    22912292        else: 
    22922293            # automatically send that to the current perspective 
    2293             self.set_data(data_id=data_list.keys()) 
     2294            self.set_data(data_id=list(data_list.keys())) 
    22942295 
    22952296    def set_data(self, data_id, theory_id=None): 
     
    22992300        list_data, _ = self._data_manager.get_by_id(data_id) 
    23002301        if self._current_perspective is not None: 
    2301             self._current_perspective.set_data(list_data.values()) 
     2302            self._current_perspective.set_data(list(list_data.values())) 
    23022303 
    23032304        else: 
     
    23112312        if self._current_perspective is not None: 
    23122313            try: 
    2313                 self._current_perspective.set_theory(list_theory.values()) 
    2314             except: 
    2315                 msg = "Guiframe set_theory: \n" + str(sys.exc_value) 
     2314                self._current_perspective.set_theory(list(list_theory.values())) 
     2315            except Exception as exc: 
     2316                msg = "Guiframe set_theory: \n" + str(exc) 
    23162317                logger.info(msg) 
    23172318                wx.PostEvent(self, StatusEvent(status=msg, info="error")) 
     
    23272328        data_list, _ = self._data_manager.get_by_id(data_id) 
    23282329        _, temp_list_theory = self._data_manager.get_by_id(theory_id) 
    2329         total_plot_list = data_list.values() 
     2330        total_plot_list = list(data_list.values()) 
    23302331        for item in temp_list_theory.values(): 
    23312332            theory_data, theory_state = item 
     
    23762377        data_list, _ = self._data_manager.get_by_id(data_id) 
    23772378        _, temp_list_theory = self._data_manager.get_by_id(theory_id) 
    2378         total_plot_list = data_list.values() 
     2379        total_plot_list = list(data_list.values()) 
    23792380        for item in temp_list_theory.values(): 
    23802381            theory_data, theory_state = item 
     
    23992400                                            group_id=("res" + str(id)), 
    24002401                                            action='remove')) 
    2401         except: 
    2402             logger.error(sys.exc_value) 
     2402        except Exception as exc: 
     2403            logger.error(exc) 
    24032404 
    24042405    def save_data1d(self, data, fname): 
     
    25042505            wx.PostEvent(self, StatusEvent(status=msg, 
    25052506                                           info="error")) 
    2506             raise ValueError, msg 
     2507            raise ValueError(msg) 
    25072508        # text = str(data) 
    25082509        text = data.__str__() 
     
    25352536                                                  dy_val, 
    25362537                                                  dx_val) 
    2537         from pdfview import TextFrame 
     2538        from .pdfview import TextFrame 
    25382539        frame = TextFrame(None, -1, "Data Info: %s" % data.name, text) 
    25392540        # put icon 
     
    26272628                break 
    26282629 
    2629         from pdfview import TextFrame 
     2630        from .pdfview import TextFrame 
    26302631        frame = TextFrame(None, -1, "Data Info: %s" % data.name, text) 
    26312632        # put icon 
     
    26942695        check = "Theory1D" 
    26952696        is_theory = len(self.panel_on_focus.plots) <= 1 and \ 
    2696             self.panel_on_focus.plots.values()[0].__class__.__name__ == check 
     2697            list(self.panel_on_focus.plots.values())[0].__class__.__name__ == check 
    26972698 
    26982699        is_data2d = hasattr(new_plot, 'data') 
     
    32103211            else: 
    32113212                self.frame.Show() 
    3212         except: 
     3213        except Exception as exc: 
    32133214            if self.s_screen is not None: 
    32143215                self.s_screen.Close() 
    32153216            msg = "Cannot display splash screen\n" 
    3216             msg += str(sys.exc_value) 
     3217            msg += str(exc) 
    32173218            logger.error(msg) 
    32183219            self.frame.Show() 
     
    32693270                        if os.path.isfile(file_path): 
    32703271                            os.remove(file_path) 
    3271                 except: 
     3272                except Exception as exc: 
    32723273                    logger.error("gui_manager.clean_plugin_models:\n  %s" 
    3273                                   % sys.exc_value) 
     3274                                 % exc) 
    32743275 
    32753276    def set_manager(self, manager): 
     
    33643365                              path=SPLASH_SCREEN_PATH): 
    33653366        """Displays the splash screen.  It will exactly cover the main frame.""" 
     3367        try: 
     3368            from wx.adv import SplashScreen, SPLASH_TIMEOUT, SPLASH_CENTRE_ON_SCREEN 
     3369        except ImportError: 
     3370            # CRUFT: wx 4 moved SplashScreen from wx to wx.adv 
     3371            from wx import SplashScreen, SPLASH_TIMEOUT, SPLASH_CENTRE_ON_SCREEN 
    33663372 
    33673373        # Prepare the picture.  On a 2GHz intel cpu, this takes about a second. 
     
    33803386        # Note that on Linux, the timeout appears to occur immediately in which 
    33813387        # case the splash screen disappears upon entering the event loop. 
    3382         s_screen = wx.SplashScreen(bitmap=bm, 
    3383                                    splashStyle=(wx.SPLASH_TIMEOUT | 
    3384                                                 wx.SPLASH_CENTRE_ON_SCREEN), 
    3385                                    style=(wx.SIMPLE_BORDER | 
    3386                                           wx.FRAME_NO_TASKBAR | 
    3387                                           wx.FRAME_FLOAT_ON_PARENT), 
    3388                                    milliseconds=SS_MAX_DISPLAY_TIME, 
    3389                                    parent=parent, 
    3390                                    id=wx.ID_ANY) 
     3388        s_screen = SplashScreen(bitmap=bm, 
     3389                                splashStyle=(SPLASH_TIMEOUT | 
     3390                                             SPLASH_CENTRE_ON_SCREEN), 
     3391                                style=(wx.SIMPLE_BORDER | 
     3392                                       wx.FRAME_NO_TASKBAR | 
     3393                                       wx.FRAME_FLOAT_ON_PARENT), 
     3394                                milliseconds=SS_MAX_DISPLAY_TIME, 
     3395                                parent=parent, 
     3396                                id=wx.ID_ANY) 
    33913397        from sas.sasgui.guiframe.gui_statusbar import SPageStatusbar 
    33923398        statusBar = SPageStatusbar(s_screen) 
  • src/sas/sasgui/guiframe/gui_statusbar.py

    r463e7ffc r5251ec6  
    8686                                                    wx.ART_TOOLBAR) 
    8787        self.msg_txt.Newline() 
    88         self.msg_txt.WriteBitmap(icon_bmp) 
     88        # wx 3 has WriteImage and WriteBitmap; not sure if there 
     89        # is any difference between them.  wx 4 has only WriteImage. 
     90        self.msg_txt.WriteImage(icon_bmp) 
    8991        self.msg_txt.BeginTextColour(color) 
    9092        self.msg_txt.WriteText("\t") 
  • src/sas/sasgui/guiframe/gui_style.py

    ra1b8fee r5251ec6  
    5858    DRAG_ID_PATH = os.path.join(PATH, 'drag_hand.png') 
    5959    RESET_ID_PATH = os.path.join(PATH, 'reset.png') 
    60     PREVIEW_ID_PATH = os.path.join(PATH, 'report.png') 
     60    REPORT_ID_PATH = os.path.join(PATH, 'report.png') 
     61    PREVIEW_ID_PATH = os.path.join(PATH, 'preview.png') 
    6162    PRINT_ID_PATH = os.path.join(PATH, 'printer.png') 
    6263    HIDE_ID_PATH = os.path.join(PATH, 'hide.png') 
    6364     
    64    
    65     SAVE_ICON = wx.Image(os.path.join(PATH, 'save.png')) 
    66     UNDO_ICON = wx.Image(os.path.join(PATH, 'undo.png')) 
    67     REDO_ICON = wx.Image(os.path.join(PATH, 'redo.png')) 
    68     COPY_ICON = wx.Image(os.path.join(PATH, 'copy.png')) 
    69     PASTE_ICON = wx.Image(os.path.join(PATH, 'paste.png')) 
    70     BOOKMARK_ICON = wx.Image(os.path.join(PATH, 'bookmark.png')) 
    71     ZOOM_IN_ICON = wx.Image(os.path.join(PATH, 'zoom_in.png')) 
    72     ZOOM_OUT_ICON = wx.Image(os.path.join(PATH, 'zoom_out.png')) 
    73     ZOOM_ICON = wx.Image(os.path.join(PATH, 'search_pan.png')) 
    74     DRAG_ICON = wx.Image(os.path.join(PATH, 'drag_hand.png')) 
    75     RESET_ICON = wx.Image(os.path.join(PATH, 'reset.png')) 
    76     REPORT_ICON = wx.Image(os.path.join(PATH, 'report.png')) 
    77     PREVIEW_ICON = wx.Image(os.path.join(PATH, 'preview.png')) 
    78     PRINT_ICON = wx.Image(os.path.join(PATH, 'printer.png')) 
    79     HIDE_ICON = wx.Image(os.path.join(PATH, 'hide.png')) 
     65    # Note: wx 4 requires that the app be defined before 
     66    # the images are loaded, so they can't be processed 
     67    # at module load time.  Instead, need to load icons 
     68    # when the app is created. 
     69    @classmethod 
     70    def load_icons(cls): 
     71        cls.SAVE_ICON = wx.Image(cls.SAVE_ICON_PATH) 
     72        cls.UNDO_ICON = wx.Image(cls.UNDO_ICON_PATH) 
     73        cls.REDO_ICON = wx.Image(cls.REDO_ICON_PATH) 
     74        cls.COPY_ICON = wx.Image(cls.COPY_ICON_PATH) 
     75        cls.PASTE_ICON = wx.Image(cls.PASTE_ICON_PATH) 
     76        cls.BOOKMARK_ICON = wx.Image(cls.BOOKMARK_ICON_PATH) 
     77        cls.ZOOM_IN_ICON = wx.Image(cls.ZOOM_IN_ID_PATH) 
     78        cls.ZOOM_OUT_ICON = wx.Image(cls.ZOOM_OUT_ID_PATH) 
     79        cls.ZOOM_ICON = wx.Image(cls.ZOOM_ID_PATH) 
     80        cls.DRAG_ICON = wx.Image(cls.DRAG_ID_PATH) 
     81        cls.RESET_ICON = wx.Image(cls.RESET_ID_PATH) 
     82        cls.REPORT_ICON = wx.Image(cls.REPORT_ID_PATH) 
     83        cls.PREVIEW_ICON = wx.Image(cls.PREVIEW_ID_PATH) 
     84        cls.PRINT_ICON = wx.Image(cls.PRINT_ID_PATH) 
     85        cls.HIDE_ICON = wx.Image(cls.HIDE_ID_PATH) 
    8086 
    8187if __name__ == "__main__": 
  • src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py

    r5218180 r82d88d5  
    7070                cards.remove(item) 
    7171        wlist = '|'.join(cards) 
    72         style = wx.OPEN | wx.FD_MULTIPLE 
     72        style = wx.FD_OPEN | wx.FD_MULTIPLE 
    7373        dlg = wx.FileDialog(self.parent, 
    7474                            "Choose a file", 
     
    196196                                                      error_message) 
    197197                    if data_error: 
    198                         if basename in file_errors.keys(): 
     198                        if basename in file_errors: 
    199199                            file_errors[basename] += [error_message] 
    200200                        else: 
     
    219219        if len(file_errors) > 0: 
    220220            error_message = "" 
    221             for filename, error_array in file_errors.iteritems(): 
     221            for filename, error_array in file_errors.items(): 
    222222                error_message += "The following issues were found whilst " 
    223223                error_message += "loading {}:\n".format(filename) 
  • src/sas/sasgui/guiframe/local_perspectives/data_loader/load_thread.py

    r959eb01 r5251ec6  
    7272                if self.updatefn is not None: 
    7373                    self.updatefn(output=output, message=message) 
    74             except: 
     74            except Exception as exc: 
    7575                error_message = "Error while loading: %s\n" % str(path) 
    76                 error_message += str(sys.exc_value) + "\n" 
     76                error_message += str(exc) + "\n" 
    7777                self.updatefn(output=output, message=error_message) 
    7878 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/AnnulusSlicer.py

    r7432acb r5251ec6  
    77 
    88import math 
     9# from copy import deepcopy 
     10 
    911import wx 
    10 # from copy import deepcopy 
    11 # Debug printout 
     12 
    1213from sas.sasgui.guiframe.events import NewPlotEvent 
    1314from sas.sasgui.guiframe.events import StatusEvent 
    1415from sas.sasgui.guiframe.events import SlicerParameterEvent 
    1516from sas.sasgui.guiframe.events import EVT_SLICER_PARS 
    16 from BaseInteractor import _BaseInteractor 
    1717from sas.sasgui.guiframe.dataFitting import Data1D 
     18 
     19from .BaseInteractor import _BaseInteractor 
    1820 
    1921class AnnulusInteractor(_BaseInteractor): 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/Arc.py

    r7432acb r5251ec6  
    44import math 
    55 
    6 from BaseInteractor import _BaseInteractor 
    76from sas.sasgui.guiframe.events import SlicerParameterEvent 
     7 
     8from .BaseInteractor import _BaseInteractor 
    89 
    910class ArcInteractor(_BaseInteractor): 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/AzimutSlicer.py

    rd85c194 r5251ec6  
    55# 
    66import math 
     7 
    78import wx 
    8 from BaseInteractor import _BaseInteractor 
     9 
    910from sas.sasgui.guiframe.events import NewPlotEvent 
    1011from sas.sasgui.guiframe.events import EVT_SLICER_PARS 
     12 
     13from .BaseInteractor import _BaseInteractor 
    1114 
    1215class SectorInteractor(_BaseInteractor): 
     
    2932 
    3033        # Inner circle 
    31         from Arc import ArcInteractor 
     34        from .Arc import ArcInteractor 
    3235        self.inner_circle = ArcInteractor(self, self.base.subplot, 
    3336                                          zorder=zorder, 
     
    4346        self.outer_circle.qmax = self.qmax * 1.2 
    4447        # self.outer_circle.set_cursor(self.base.qmax/1.8, 0) 
    45         from Edge import RadiusInteractor 
     48        from .Edge import RadiusInteractor 
    4649        self.right_edge = RadiusInteractor(self, self.base.subplot, 
    4750                                           zorder=zorder + 1, 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/Edge.py

    r7432acb r5251ec6  
    11import math 
    2 from BaseInteractor import _BaseInteractor 
     2 
     3from .BaseInteractor import _BaseInteractor 
    34 
    45 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/Plotter1D.py

    r2469df7 r5251ec6  
    1111 
    1212 
    13 import wx 
    1413import sys 
    1514import math 
     15import logging 
     16 
     17import wx 
    1618import numpy as np 
    17 import logging 
     19 
    1820from sas.sasgui.plottools.PlotPanel import PlotPanel 
    1921from sas.sasgui.guiframe.events import StatusEvent 
     
    2224from sas.sasgui.guiframe.panel_base import PanelBase 
    2325from sas.sasgui.guiframe.gui_style import GUIFRAME_ICON 
    24 from appearanceDialog import appearanceDialog 
    25 from graphAppearance import graphAppearance 
     26 
     27from .appearanceDialog import appearanceDialog 
     28from .graphAppearance import graphAppearance 
    2629 
    2730logger = logging.getLogger(__name__) 
     
    3639def find_key(dic, val): 
    3740    """return the key of dictionary dic given the value""" 
    38     return [k for k, v in dic.iteritems() if v == val][0] 
     41    return [k for k, v in dic.items() if v == val][0] 
    3942 
    4043class ModelPanel1D(PlotPanel, PanelBase): 
     
    220223        if hasattr(event, 'is_corfunc'): 
    221224            self.is_corfunc = event.is_corfunc 
    222         if event.id in self.plots.keys(): 
     225        if event.id in self.plots: 
    223226            ctrl = event.ctrl 
    224227            self.cursor_id = event.id 
     
    243246                if position is not None and not self.is_corfunc: 
    244247                    wx.PostEvent(self.parent, StatusEvent(status=position)) 
    245             except: 
    246                 logger.error(sys.exc_value) 
     248            except Exception as exc: 
     249                logger.error(exc) 
    247250            if not event.leftdown: 
    248251                # text event 
     
    256259                    if is_moved: 
    257260                        self.canvas.draw() 
    258                 except: 
    259                     logger.error(sys.exc_value) 
     261                except Exception as exc: 
     262                    logger.error(exc) 
    260263                event.Skip() 
    261264                return 
     
    410413            self.canvas.draw() 
    411414            self.q_ctrl[vl_ind].SetValue(str(pos_x)) 
    412         except: 
    413             logger.error(sys.exc_value) 
     415        except Exception as exc: 
     416            logger.error(exc) 
    414417 
    415418    def set_resizing(self, resizing=False): 
     
    431434            Remove data from plot 
    432435        """ 
    433         if id in self.plots.keys(): 
     436        if id in self.plots: 
    434437            data = self.plots[id] 
    435438            self.graph.delete(data) 
     
    437440            data_list, theory_list = data_manager.get_by_id(id_list=[id]) 
    438441 
    439             if id in data_list.keys(): 
     442            if id in data_list: 
    440443                data = data_list[id] 
    441             if id in theory_list.keys(): 
     444            if id in theory_list: 
    442445                data = theory_list[id] 
    443446 
     
    457460        if data.__class__.__name__ == 'Data2D': 
    458461            return 
    459         plot_keys = self.plots.keys() 
     462        plot_keys = list(self.plots.keys()) 
    460463        if data.id in plot_keys: 
    461464            # Recover panel prop.s 
     
    476479            try: 
    477480                self._onEVT_FUNC_PROPERTY() 
    478             except Exception, exc: 
     481            except Exception as exc: 
    479482                wx.PostEvent(self.parent, 
    480483                             StatusEvent(status="Plotting Error: %s" % str(exc), info="error")) 
     
    493496                    # MAC: forcing to plot 2D avg 
    494497                    self.canvas._onDrawIdle() 
    495             except Exception, exc: 
     498            except Exception as exc: 
    496499                wx.PostEvent(self.parent, StatusEvent(status=\ 
    497500                    "Plotting Error: %s" % str(exc), info="error")) 
     
    567570        self.set_selected_from_menu(menu, event_id) 
    568571        ## Check if there is a selected graph to remove 
    569         if self.graph.selected_plottable in self.plots.keys(): 
     572        if self.graph.selected_plottable in self.plots: 
    570573            graph_id = self.graph.selected_plottable 
    571574            self.remove_data_by_id(graph_id) 
     
    603606            plot_menu = wx.Menu() 
    604607            if self.graph.selected_plottable: 
    605                 if not self.graph.selected_plottable in self.plots.keys(): 
     608                if not self.graph.selected_plottable in self.plots: 
    606609                    continue 
    607610                if plot != self.plots[self.graph.selected_plottable]: 
     
    623626                        plot_menu.Append(wx_id, item[0], name) 
    624627                        wx.EVT_MENU(self, wx_id, item[2]) 
    625                     except: 
     628                    except Exception as exc: 
    626629                        msg = "ModelPanel1D.onContextMenu: " 
    627                         msg += "bad menu item  %s" % sys.exc_value 
     630                        msg += "bad menu item  %s" % exc 
    628631                        wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    629632                plot_menu.AppendSeparator() 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/Plotter2D.py

    r3e5648b r5251ec6  
    1111 
    1212 
    13 import wx 
    1413import sys 
    1514import math 
     15import logging 
     16 
     17import wx 
    1618import numpy as np 
    17 import logging 
     19from matplotlib.font_manager import FontProperties 
     20 
    1821from sas.sasgui.plottools.PlotPanel import PlotPanel 
    1922from sas.sasgui.plottools.plottables import Graph 
     
    2427from sas.sasgui.guiframe.events import SlicerEvent 
    2528from sas.sasgui.guiframe.utils import PanelMenu 
    26 from  sas.sasgui.guiframe.local_perspectives.plotting.binder import BindArtist 
    27 from Plotter1D import ModelPanel1D 
     29from sas.sasgui.guiframe.local_perspectives.plotting.binder import BindArtist 
    2830from sas.sasgui.plottools.toolbar import NavigationToolBar 
    29 from matplotlib.font_manager import FontProperties 
    30 from graphAppearance import graphAppearance 
     31 
     32from .Plotter1D import ModelPanel1D 
     33from .graphAppearance import graphAppearance 
     34 
    3135(InternalEvent, EVT_INTERNAL) = wx.lib.newevent.NewEvent() 
    3236 
     
    4145def find_key(dic, val): 
    4246    """return the key of dictionary dic given the value""" 
    43     return [k for k, v in dic.iteritems() if v == val][0] 
     47    return [k for k, v in dic.items() if v == val][0] 
    4448 
    4549 
     
    200204        ## Update self.data2d with the current plot 
    201205        self.data2D = data 
    202         if data.id in self.plots.keys(): 
     206        if data.id in self.plots: 
    203207            #replace 
    204208            xlo, xhi = self.subplot.get_xlim() 
     
    326330                        slicerpop.Append(wx_id, item[0], item[1]) 
    327331                        wx.EVT_MENU(self, wx_id, item[2]) 
    328                     except: 
     332                    except Exception as exc: 
    329333                        msg = "ModelPanel1D.onContextMenu: " 
    330                         msg += "bad menu item  %s" % sys.exc_value 
     334                        msg += "bad menu item  %s" % exc 
    331335                        wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    332336                slicerpop.AppendSeparator() 
     
    447451 
    448452        """ 
    449         import detector_dialog 
     453        from . import detector_dialog 
    450454        dialog = detector_dialog.DetectorDialog(self, -1, base=self.parent, 
    451455                                                reset_zmin_ctl=self.default_zmin_ctl, 
     
    630634        """ 
    631635        if self.slicer is not None: 
    632             from parameters_panel_slicer import SlicerParameterPanel 
     636            from .parameters_panel_slicer import SlicerParameterPanel 
    633637            dialog = SlicerParameterPanel(self, -1, "Slicer Parameters") 
    634638            dialog.set_slicer(self.slicer.__class__.__name__, 
     
    641645        Perform sector averaging on Q and draw sector slicer 
    642646        """ 
    643         from SectorSlicer import SectorInteractor 
     647        from .SectorSlicer import SectorInteractor 
    644648        self.onClearSlicer(event) 
    645649        wx.PostEvent(self, InternalEvent(slicer=SectorInteractor)) 
     
    649653        Perform sector averaging on Phi and draw annulus slicer 
    650654        """ 
    651         from AnnulusSlicer import AnnulusInteractor 
     655        from .AnnulusSlicer import AnnulusInteractor 
    652656        self.onClearSlicer(event) 
    653657        wx.PostEvent(self, InternalEvent(slicer=AnnulusInteractor)) 
     
    657661        """ 
    658662        from sas.sasgui.guiframe.gui_manager import MDIFrame 
    659         from boxSum import BoxSum 
     663        from .boxSum import BoxSum 
    660664        self.onClearSlicer(event) 
    661665        self.slicer_z += 1 
     
    668672        params = self.slicer.get_params() 
    669673        ## Create a new panel to display results of summation of Data2D 
    670         from parameters_panel_boxsum import SlicerPanel 
     674        from .parameters_panel_boxsum import SlicerPanel 
    671675        win = MDIFrame(self.parent, None, 'None', (100, 200)) 
    672676        new_panel = SlicerPanel(parent=win, id=-1, 
     
    699703        :param event: wx.menu event 
    700704        """ 
    701         from boxSlicer import BoxInteractorX 
     705        from .boxSlicer import BoxInteractorX 
    702706        self.onClearSlicer(event) 
    703707        wx.PostEvent(self, InternalEvent(slicer=BoxInteractorX)) 
     
    711715 
    712716        """ 
    713         from boxSlicer import BoxInteractorY 
     717        from .boxSlicer import BoxInteractorY 
    714718        self.onClearSlicer(event) 
    715719        wx.PostEvent(self, InternalEvent(slicer=BoxInteractorY)) 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/SectorSlicer.py

    r8de66b6 r5251ec6  
    33""" 
    44import math 
     5 
    56import wx 
    6 from BaseInteractor import _BaseInteractor 
     7 
    78from sas.sasgui.guiframe.events import NewPlotEvent 
    89from sas.sasgui.guiframe.events import StatusEvent 
     
    1011from sas.sasgui.guiframe.events import EVT_SLICER_PARS 
    1112from sas.sasgui.guiframe.dataFitting import Data1D 
     13 
     14from .BaseInteractor import _BaseInteractor 
    1215 
    1316 
     
    238241            msg = "Phi left and phi right are different" 
    239242            msg += " %f, %f" % (self.left_line.phi, self.right_line.phi) 
    240             raise ValueError, msg 
     243            raise ValueError(msg) 
    241244        params["Phi [deg]"] = self.main_line.theta * 180 / math.pi 
    242245        params["Delta_Phi [deg]"] = math.fabs(self.left_line.phi * 180 / math.pi) 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/appearanceDialog.py

    rd85c194 r5251ec6  
    153153        Populate Symbols 
    154154        """ 
    155         self.sorted_symbo_labels = sorted(self.symbo_labels.iteritems(), 
     155        self.sorted_symbo_labels = sorted(self.symbo_labels.items(), 
    156156                                          key=operator.itemgetter(1)) 
    157157        self.sorted_sym_dic = {} 
     
    166166        Populate Colors 
    167167        """ 
    168         sortedcolor_labels = sorted(self.color_labels.iteritems(), 
     168        sortedcolor_labels = sorted(self.color_labels.items(), 
    169169                                    key=operator.itemgetter(1)) 
    170170        for color in sortedcolor_labels: 
     
    197197        Find key 
    198198        """ 
    199         return [k for k, v in dic.iteritems() if v == val][0] 
     199        return [k for k, v in dic.items() if v == val][0] 
    200200 
    201201    def get_current_values(self): 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/binder.py

    r20fa5fe r5251ec6  
    22Extension to MPL to support the binding of artists to key/mouse events. 
    33""" 
     4from __future__ import print_function 
     5 
     6import sys 
    47import logging 
    5 import sys 
    68 
    79logger = logging.getLogger(__name__) 
     
    1618    artist = None 
    1719    prop = {} 
     20 
    1821    def __init__(self, artist=None, prop={}): 
    1922        self.artist, self.prop = artist, self.prop 
     
    2528        return self.artist is not other.artist 
    2629 
    27     def __nonzero__(self): 
     30    def __bool__(self): 
    2831        return self.artist is not None 
     32 
     33    __nonzero__ = __bool__ 
     34 
    2935 
    3036class BindArtist(object): 
    3137    """ 
    32         Track keyboard modifiers for events. 
    33         TODO: Move keyboard modifier support into the backend.  We cannot 
    34         TODO: properly support it from outside the windowing system since there 
    35         TODO: is no way to recognized whether shift is held down when the mouse 
    36         TODO: first clicks on the the application window. 
     38    Track keyboard modifiers for events. 
    3739    """ 
     40    # TODO: Move keyboard modifier support into the backend.  We cannot 
     41    # TODO: properly support it from outside the windowing system since there 
     42    # TODO: is no way to recognized whether shift is held down when the mouse 
     43    # TODO: first clicks on the the application window. 
    3844    control, shift, alt, meta = False, False, False, False 
    3945 
     
    4652              'scroll', 'key', 'keyup'] 
    4753    # TODO: Need our own event structure 
     54 
    4855    def __init__(self, figure): 
    4956        canvas = figure.canvas 
     57 
    5058        # Link to keyboard/mouse 
    5159        try: 
     
    5967            ] 
    6068        except: 
    61             # print "bypassing scroll_event: wrong matplotlib version" 
     69            logger.warn("bypassing scroll_event: wrong matplotlib version") 
    6270            self._connections = [ 
    6371                canvas.mpl_connect('motion_notify_event', self._onMotion), 
     
    6775                canvas.mpl_connect('key_release_event', self._onKeyRelease), 
    6876            ] 
     77 
    6978        # Turn off picker if it hasn't already been done 
    7079        try: 
    7180            canvas.mpl_disconnect(canvas.button_pick_id) 
    7281            canvas.mpl_disconnect(canvas.scroll_pick_id) 
    73         except: 
    74             logger.error(sys.exc_value) 
     82        except Exception as exc: 
     83            logger.error(exc) 
     84 
     85        self._current = None 
     86        self._actions = {} 
    7587        self.canvas = canvas 
    7688        self.figure = figure 
     
    8395 
    8496        Use clearall() to reset all connections. 
    85  
    8697        """ 
    8798        for h in artists: 
     
    108119        for action in self.events: 
    109120            self._actions[action] = {} 
     121 
    110122        # Need activity state 
    111123        self._artists = [] 
     
    121133            for cid in self._connections: 
    122134                self.canvas.mpl_disconnect(cid) 
    123         except: 
    124             pass 
     135        except Exception as exc: 
     136            logger.error("Error disconnection canvas: %s" % exc) 
    125137        self._connections = [] 
    126138 
     
    169181        sure it applies.  E.g., the callback for 'press' might be: 
    170182            if event.button == 1 and event.shift: process Shift-click 
    171  
    172         :TODO: Only receive events with the correct modifiers (e.g., S-click, 
    173         :TODO:   or *-click for any modifiers). 
    174         :TODO: Only receive button events for the correct button (e.g., click1 
    175         :TODO:   release3, or dclick* for any button) 
    176         :TODO: Support virtual artist, so that and artist can be flagged as 
    177         :TODO:   having a tag list and receive the correct events 
    178         :TODO: Support virtual events for binding to button-3 vs shift button-1 
    179         :TODO:   without changing callback code 
    180         :TODO: Attach multiple callbacks to the same event? 
    181         :TODO: Clean up interaction with toolbar modes 
    182         :TODO: push/pushclear/pop context so that binding changes 
    183             for the duration 
    184         :TODO:   e.g., to support ? context sensitive help 
    185  
    186         """ 
     183        """ 
     184        #TODO: Only receive events with the correct modifiers (e.g., S-click, 
     185        #TODO:   or *-click for any modifiers). 
     186        #TODO: Only receive button events for the correct button (e.g., click1 
     187        #TODO:   release3, or dclick* for any button) 
     188        #TODO: Support virtual artist, so that and artist can be flagged as 
     189        #TODO:   having a tag list and receive the correct events 
     190        #TODO: Support virtual events for binding to button-3 vs shift button-1 
     191        #TODO:   without changing callback code 
     192        #TODO: Attach multiple callbacks to the same event? 
     193        #TODO: Clean up interaction with toolbar modes 
     194        #TODO: push/pushclear/pop context so that binding changes for the duration 
     195        #TODO:   e.g., to support ? context sensitive help 
     196 
    187197        # Check that the trigger is valid 
    188198        if trigger not in self._actions: 
    189             raise ValueError, "%s invalid --- valid triggers are %s" \ 
    190                 % (trigger, ", ".join(self.events)) 
     199            raise ValueError("%s invalid --- valid triggers are %s" 
     200                % (trigger, ", ".join(self.events))) 
     201 
    191202        # Register the trigger callback 
    192203        self._actions[trigger][artist] = action 
    193         # print "==> added",artist,[artist],"to",trigger,":", 
    194         # self._actions[trigger].keys() 
     204 
    195205        # Maintain a list of all artists 
    196206        if artist not in self._artists: 
     
    203213        """ 
    204214        if action not in self.events: 
    205             raise ValueError, "Trigger expects " + ", ".join(self.events) 
     215            raise ValueError("Trigger expects " + ", ".join(self.events)) 
     216 
    206217        # Tag the event with modifiers 
    207218        for mod in ('alt', 'control', 'shift', 'meta'): 
     
    210221        setattr(ev, 'action', action) 
    211222        setattr(ev, 'prop', {}) 
     223 
    212224        # Fallback scheme. If the event does not return false, pass to parent. 
    213225        processed = False 
     
    233245        """ 
    234246        # TODO: sort by zorder of axes then by zorder within axes 
    235         self._artists.sort(cmp=lambda x, y: cmp(y.zorder, x.zorder)) 
    236         # print "search"," ".join([str(h) for h in self._artists]) 
     247        self._artists.sort(key=lambda x: x.zorder, reverse=True) 
    237248        found = Selection() 
    238         # print "searching in",self._artists 
    239249        for artist in self._artists: 
    240250            # TODO: should contains() return false if invisible? 
     
    250260                found.artist, found.prop = artist, prop 
    251261                break 
    252         # print "found",found.artist 
    253262 
    254263        # TODO: how to check if prop is equal? 
     
    257266            self.trigger(found, 'enter', event) 
    258267        self._current = found 
     268 
    259269        return found 
    260270 
     
    274284 
    275285            transform = self._hasclick.artist.get_transform() 
    276             # x,y = event.xdata,event.ydata 
     286            #x,y = event.xdata,event.ydata 
    277287            x, y = event.x, event.y 
    278288            try: 
    279289                x, y = transform.inverted().transform_point((x, y)) 
    280  
    281             except: 
     290            except: # CRUFT: matplotlib-0.91 support 
    282291                x, y = transform.inverse_xy_tup((x, y)) 
     292 
    283293            event.xdata, event.ydata = x, y 
    284294            self.trigger(self._hasclick, 'drag', event) 
    285295        else: 
    286296            found = self._find_current(event) 
    287             # print "found",found.artist 
    288297            self.trigger(found, 'motion', event) 
    289298 
     
    296305        # Check for double-click 
    297306        event_time = time.time() 
    298         # print event_time,self._last_time,self.dclick_threshhold 
    299         # print (event_time > self._last_time + self.dclick_threshhold) 
    300         # print event.button,self._last_button 
    301307        if (event.button != self._last_button) or \ 
    302308                (event_time > self._last_time + self.dclick_threshhold): 
     
    381387            setattr(self, event.key, False) 
    382388            return 
     389 
    383390        if self._haskey: 
    384391            self.trigger(self._haskey, 'keyup', event) 
     
    391398        found = self._find_current(event) 
    392399        self.trigger(found, 'scroll', event) 
    393  
  • src/sas/sasgui/guiframe/local_perspectives/plotting/boxMask.py

    r7432acb r5251ec6  
    11import math 
    2 from BaseInteractor import _BaseInteractor 
    3 from boxSum import PointInteractor 
    4 from boxSum import VerticalDoubleLine 
    5 from boxSum import HorizontalDoubleLine 
     2from .BaseInteractor import _BaseInteractor 
     3from .boxSum import PointInteractor 
     4from .boxSum import VerticalDoubleLine 
     5from .boxSum import HorizontalDoubleLine 
    66 
    77 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/boxSlicer.py

    r20fa5fe r5251ec6  
     1import math 
     2 
    13import wx 
    2 import math 
    34import numpy as np 
     5 
    46from sas.sasgui.guiframe.events import NewPlotEvent 
    57from sas.sasgui.guiframe.events import StatusEvent 
    68from sas.sasgui.guiframe.events import SlicerParameterEvent 
    79from sas.sasgui.guiframe.events import EVT_SLICER_PARS 
    8 from BaseInteractor import _BaseInteractor 
    910from sas.sasgui.guiframe.dataFitting import Data1D 
     11 
     12from .BaseInteractor import _BaseInteractor 
    1013 
    1114 
     
    152155            if new_slab is None: 
    153156                msg = "post data:cannot average , averager is empty" 
    154                 raise ValueError, msg 
     157                raise ValueError(msg) 
    155158            self.averager = new_slab 
    156159        if self.direction == "X": 
     
    168171        else: 
    169172            msg = "post data:no Box Average direction was supplied" 
    170             raise ValueError, msg 
     173            raise ValueError(msg) 
    171174        # # Average data2D given Qx or Qy 
    172175        box = self.averager(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max, 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/boxSum.py

    r7432acb r5251ec6  
    44""" 
    55import math 
     6 
    67import wx 
    7 from BaseInteractor import _BaseInteractor 
     8 
    89from sas.sasgui.guiframe.events import SlicerParamUpdateEvent 
    910from sas.sasgui.guiframe.events import EVT_SLICER_PARS 
    1011from sas.sasgui.guiframe.events import StatusEvent 
     12 
     13from .BaseInteractor import _BaseInteractor 
    1114 
    1215 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/detector_dialog.py

    r7432acb r5251ec6  
    9999            self.cmap_selector.SetStringSelection("jet") 
    100100            self._on_select_cmap(event=None) 
    101         except: 
    102             msg = "error occurs while resetting Detector: %s" % sys.exc_value 
     101        except Exception as exc: 
     102            msg = "error occurs while resetting Detector: %s" % exc 
    103103            wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    104104 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/masking.py

    r20fa5fe r5251ec6  
    1818 
    1919# #Todo: cleaning up, improving the maskplotpanel initialization, and testing. 
    20 import wx 
    2120import sys 
    2221import time 
    23 import matplotlib.cm as cm 
    2422import math 
    2523import copy 
     24from functools import partial 
     25 
     26import wx 
    2627import numpy as np 
     28import matplotlib.cm as cm 
     29 
    2730from sas.sasgui.plottools.PlotPanel import PlotPanel 
    2831from sas.sasgui.plottools.plottables import Graph 
    29 from binder import BindArtist 
    3032from sas.sasgui.guiframe.dataFitting import Data1D, Data2D 
    31 from boxMask import BoxMask 
    32 from sector_mask import SectorMask 
    33 from AnnulusSlicer import CircularMask 
    34  
    3533from sas.sasgui.guiframe.events import SlicerEvent 
    3634from sas.sasgui.guiframe.events import StatusEvent 
    37 from functools import partial 
     35 
     36from .binder import BindArtist 
     37from .boxMask import BoxMask 
     38from .sector_mask import SectorMask 
     39from .AnnulusSlicer import CircularMask 
     40 
    3841 
    3942(InternalEvent, EVT_INTERNAL) = wx.lib.newevent.NewEvent() 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/parameters_panel_boxsum.py

    r37d461c r5251ec6  
    11import wx 
    22import wx.lib.newevent 
    3 from parameters_panel_slicer import SlicerParameterPanel 
     3 
    44from sas.sasgui.guiframe.utils import format_number 
    55from sas.sasgui.guiframe.panel_base import PanelBase 
     
    77                                        EVT_SLICER) 
    88 
     9from .parameters_panel_slicer import SlicerParameterPanel 
    910 
    1011class SlicerPanel(wx.Panel, PanelBase): 
     
    6465            n = 1 
    6566            self.parameters = [] 
    66             keys = params.keys() 
    67             keys.sort() 
     67            keys = list(sorted(params.keys())) 
    6868            for item in keys: 
    6969                if not item.lower() in ["num_points", "avg", "avg_error", "sum", 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/parameters_panel_slicer.py

    ra20a255 r5251ec6  
    22 
    33import os 
     4 
    45import wx 
    56import wx.lib.newevent 
     7 
    68from sas.sascalc.dataloader.readers.cansas_reader import Reader 
    79from sas.sasgui.guiframe.utils import format_number 
    810from sas.sasgui.guiframe.events import EVT_SLICER_PARS, EVT_SLICER 
    911from sas.sasgui.guiframe.events import SlicerParameterEvent, StatusEvent 
    10 from Plotter2D import ModelPanel2D 
     12 
     13from .Plotter2D import ModelPanel2D 
     14 
    1115apply_params, EVT_APPLY_PARAMS = wx.lib.newevent.NewEvent() 
    1216save_files, EVT_AUTO_SAVE = wx.lib.newevent.NewEvent() 
     
    100104            iy = 1 
    101105            self.parameters = [] 
    102             keys = params.keys() 
    103             keys.sort() 
     106            keys = list(sorted(params.keys())) 
    104107            for item in keys: 
    105108                ix = 0 
     
    127130                    self.bck.Add(text, (iy, ix), (1, 1), 
    128131                                 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    129                     options = BINNING_OPTIONS.keys() 
     132                    options = list(BINNING_OPTIONS.keys()) 
    130133                    self.bin_ctl = wx.ComboBox(parent=self, choices=options) 
    131134                    hint_msg = "Modify the value of %s to change" % item 
     
    325328 
    326329        # Find desired 2D data panels 
    327         for key, mgr in spp.plot_panels.iteritems(): 
     330        for key, mgr in spp.plot_panels.items(): 
    328331            if mgr.graph.prop['title'] in self.data_list.CheckedStrings: 
    329332                apply_to_list.append(mgr) 
     
    377380        self.loaded_data = [] 
    378381        # Iterate over the loaded plots and find all 2D panels 
    379         for key, value in self.main_window.plot_panels.iteritems(): 
     382        for key, value in self.main_window.plot_panels.items(): 
    380383            if isinstance(value, ModelPanel2D): 
    381384                self.loaded_data.append(value.data2D.name) 
     
    453456 
    454457        # Find the correct plots to save 
    455         for key, plot in self.main_window.plot_panels.iteritems(): 
     458        for key, plot in self.main_window.plot_panels.items(): 
    456459            if not hasattr(plot, "data2D"): 
    457460                for item in plot.plots: 
     
    461464 
    462465        # Save files as Text 
    463         for item, data1d in data_dic.iteritems(): 
     466        for item, data1d in data_dic.items(): 
    464467            base = '.'.join(item.split('.')[:-1]) 
    465468            file_name = base + append + ".txt" 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/plotting.py

    r2d9526d r5251ec6  
    1212################################################################################ 
    1313 
    14 import wx 
    1514import sys 
    1615from copy import deepcopy 
     16 
     17import wx 
     18 
    1719from sas.sasgui.guiframe.events import EVT_NEW_PLOT 
    1820from sas.sasgui.guiframe.events import EVT_PLOT_QRANGE 
     
    2325from sas.sasgui.guiframe.dataFitting import Data2D 
    2426from sas.sasgui.guiframe.gui_manager import MDIFrame 
     27 
    2528DEFAULT_MENU_ITEM_LABEL = "No graph available" 
    2629DEFAULT_MENU_ITEM_ID = wx.NewId() 
     
    9194        if event is None: 
    9295            return 
    93         if event.id in self.plot_panels.keys(): 
     96        if event.id in self.plot_panels: 
    9497            panel = self.plot_panels[event.id] 
    95         elif event.group_id in self.plot_panels.keys(): 
     98        elif event.group_id in self.plot_panels: 
    9699            panel = self.plot_panels[event.group_id] 
    97100        else: 
     
    102105        if event is None: 
    103106            return 
    104         if event.id in self.plot_panels.keys(): 
     107        if event.id in self.plot_panels: 
    105108            panel = self.plot_panels[event.id] 
    106         elif event.group_id in self.plot_panels.keys(): 
     109        elif event.group_id in self.plot_panels: 
    107110            panel = self.plot_panels[event.group_id] 
    108111        else: 
     
    123126        """ 
    124127 
    125         if group_id in self.plot_panels.keys(): 
     128        if group_id in self.plot_panels: 
    126129            panel = self.plot_panels[group_id] 
    127130            panel.remove_data_by_id(id=id) 
     
    134137        Clear and Hide all plot panels, and remove them from menu 
    135138        """ 
    136         for group_id in self.plot_panels.keys(): 
     139        for group_id in self.plot_panels: 
    137140            self.clear_panel_by_id(group_id) 
    138141        self.plot_panels = {} 
     
    142145        clear the graph 
    143146        """ 
    144         if group_id in self.plot_panels.keys(): 
     147        if group_id in self.plot_panels: 
    145148            panel = self.plot_panels[group_id] 
    146149            for plottable in panel.graph.plottables.keys(): 
     
    184187        # Create a new plot panel if none was available 
    185188        if issubclass(data.__class__, Data1D): 
    186             from Plotter1D import ModelPanel1D 
     189            from .Plotter1D import ModelPanel1D 
    187190            ## get the data representation label of the data to plot 
    188191            ## when even the user select "change scale" 
     
    200203 
    201204        msg = "1D Panel of group ID %s could not be created" % str(group_id) 
    202         raise ValueError, msg 
     205        raise ValueError(msg) 
    203206 
    204207    def create_2d_panel(self, data, group_id): 
     
    207210        if issubclass(data.__class__, Data2D): 
    208211            ##Create a new plotpanel for 2D data 
    209             from Plotter2D import ModelPanel2D 
     212            from .Plotter2D import ModelPanel2D 
    210213            scale = data.scale 
    211214            win = MDIFrame(self.parent, None, 'None', (200, 150)) 
     
    218221            return new_panel 
    219222        msg = "2D Panel of group ID %s could not be created" % str(group_id) 
    220         raise ValueError, msg 
     223        raise ValueError(msg) 
    221224 
    222225    def update_panel(self, data, panel): 
     
    238241            msg += " to panel %s\n" % str(panel.window_caption) 
    239242            msg += "Please edit %s's units, labels" % str(data.name) 
    240             raise ValueError, msg 
     243            raise ValueError(msg) 
    241244        else: 
    242245            if panel.group_id not in data.list_group_id: 
     
    247250        """ 
    248251        """ 
    249         if group_id in self.plot_panels.keys(): 
     252        if group_id in self.plot_panels: 
    250253            panel = self.plot_panels[group_id] 
    251254            uid = panel.uid 
     
    254257                                              caption=panel.window_caption)) 
    255258            del self.plot_panels[group_id] 
    256             if uid in self.parent.plot_panels.keys(): 
     259            if uid in self.parent.plot_panels: 
    257260                del self.parent.plot_panels[uid] 
    258261                panel.frame.Destroy() 
     
    280283                    for data in event.plots: 
    281284                        for panel in self.plot_panels.values(): 
    282                             if data.id in panel.plots.keys(): 
     285                            if data.id in panel.plots: 
    283286                                plot_exists = True 
    284287                                # Pass each panel it's own copy of the data 
     
    310313        data = event.plot 
    311314        group_id = data.group_id 
    312         if group_id in self.plot_panels.keys(): 
     315        if group_id in self.plot_panels: 
    313316            if action_check: 
    314317                # Check if the plot already exist. if it does, do nothing. 
    315                 if data.id in self.plot_panels[group_id].plots.keys(): 
     318                if data.id in self.plot_panels[group_id].plots: 
    316319                    return 
    317320            #update a panel graph 
     
    327330                    for p_group_id in self.plot_panels.keys(): 
    328331                        p_plot = self.plot_panels[p_group_id] 
    329                         if data.id in p_plot.plots.keys(): 
     332                        if data.id in p_plot.plots: 
    330333                            p_plot.plots[data.id] = data 
    331334                            self.plot_panels[group_id] = p_plot 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/sector_mask.py

    r7432acb r5251ec6  
    33""" 
    44import math 
     5 
    56import wx 
    6 #from copy import deepcopy 
    7 from BaseInteractor import _BaseInteractor 
    8 from SectorSlicer import SideInteractor 
    9 from SectorSlicer import LineInteractor 
     7 
    108from sas.sasgui.guiframe.events import SlicerParameterEvent 
     9 
     10from .BaseInteractor import _BaseInteractor 
     11from .SectorSlicer import SideInteractor 
     12from .SectorSlicer import LineInteractor 
    1113 
    1214class SectorMask(_BaseInteractor): 
     
    175177            msg += "different %f, %f" % (self.left_line.phi, 
    176178                                         self.right_line.phi) 
    177             raise ValueError, msg 
     179            raise ValueError(msg) 
    178180        params["Phi"] = self.main_line.theta 
    179181        params["Delta_Phi"] = math.fabs(self.left_line.phi) 
  • src/sas/sasgui/guiframe/plugin_base.py

    r20fa5fe r5251ec6  
    112112        Load  data 
    113113        """ 
    114         raise NotImplementedError 
     114        raise NotImplementedError() 
    115115 
    116116    def load_folder(self, event): 
     
    118118        Load entire folder 
    119119        """ 
    120         raise NotImplementedError 
     120        raise NotImplementedError() 
    121121 
    122122    def set_is_active(self, active=False): 
     
    277277        """ 
    278278        msg = "%s plugin: does not support import theory" % str(self.sub_menu) 
    279         raise ValueError, msg 
     279        raise ValueError(msg) 
    280280 
    281281    def on_set_state_helper(self, event): 
  • src/sas/sasgui/guiframe/proxy.py

    r20fa5fe r5251ec6  
    33from __future__ import print_function 
    44 
    5 import urllib2 
    65import sys 
    76import json 
     
    98import re 
    109 
     10try: 
     11    # CRUFT: python 3 uses urllib.request instead of urllib2 
     12    import urllib2 
     13except ImportError: 
     14    from urllib import request as urllib2 
    1115 
    1216logger = logging.getLogger(__name__) 
     
    5054                this_name, this_val, this_type = winreg.EnumValue(net, i) 
    5155                subkeys[this_name] = this_val 
    52             if 'AutoConfigURL' in subkeys.keys() and len(subkeys['AutoConfigURL']) > 0: 
     56            if 'AutoConfigURL' in subkeys and len(subkeys['AutoConfigURL']) > 0: 
    5357                pac_files.append(subkeys['AutoConfigURL']) 
    5458        elif sys.platform == 'darwin': 
     
    6165                # the first part is a long identifier 
    6266                net_key, network = network 
    63                 if 'ProxyAutoConfigURLString' in network['Proxies'].keys(): 
     67                if 'ProxyAutoConfigURLString' in network['Proxies']: 
    6468                    pac_files.append( 
    6569                        network['Proxies']['ProxyAutoConfigURLString']) 
     
    127131            logger.debug("Trying Direct connection to %s..."%self.url) 
    128132            response = urllib2.urlopen(req, timeout=self.timeout) 
    129         except Exception, e: 
     133        except Exception as exc: 
    130134            logger.debug("Failed!") 
    131             logger.debug(e) 
     135            logger.debug(exc) 
    132136            try: 
    133137                logger.debug("Trying to use system proxy if it exists...") 
    134138                self._set_proxy() 
    135139                response = urllib2.urlopen(req, timeout=self.timeout) 
    136             except Exception, e: 
     140            except Exception as exc: 
    137141                logger.debug("Failed!") 
    138                 logger.debug(e) 
     142                logger.debug(exc) 
    139143                pac_urls = self._get_addresses_of_proxy_pac() 
    140144                proxy_urls = self._parse_proxy_pac(pac_urls) 
     
    144148                        self._set_proxy(proxy) 
    145149                        response = urllib2.urlopen(req, timeout=self.timeout) 
    146                     except Exception, e: 
     150                    except Exception as exc: 
    147151                        logger.debug("Failed!") 
    148                         logger.debug(e) 
     152                        logger.debug(exc) 
    149153        if response is not None: 
    150154            logger.debug("The connection to %s was successful."%self.url) 
  • src/sas/sasgui/guiframe/report_dialog.py

    rd0ce666f r5251ec6  
    147147            self.Update() 
    148148            return pisaStatus.err 
    149         except Exception: 
    150             logger.error("Error creating pdf: %s" % sys.exc_value) 
     149        except Exception as exc: 
     150            logger.error("Error creating pdf: %s" % exc) 
    151151        return False 
  • src/sas/sasgui/guiframe/startup_configuration.py

    rb963b20 r5251ec6  
    197197        with open(path, 'w') as out_f: 
    198198            out_f.write("#Application appearance custom configuration\n") 
    199             for key, item in self.return_string.iteritems(): 
     199            for key, item in self.return_string.items(): 
    200200                if (key == 'DEFAULT_PERSPECTIVE') or \ 
    201201                    (key == 'DEFAULT_OPEN_FOLDER' and item != None): 
  • src/sas/sasgui/guiframe/utils.py

    r7432acb r5251ec6  
    208208        self.id_list = id_list 
    209209        self.index = -1 
    210     def next(self): 
     210    def __next__(self): 
    211211        self.index += 1 
    212212        return self.id_list[self.index] 
    213  
     213    # CRUFT: python 2 uses next rather than __next__ for iterator 
     214    next = __next__ 
     215 
  • 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

    r1752f38 r82d88d5  
    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')) 
  • src/sas/sasgui/perspectives/corfunc/__init__.py

    rc23f303 r5251ec6  
    11PLUGIN_ID = "Corfunc Plug-In 0.1" 
    2 from corfunc import * 
     2from .corfunc import * 
  • src/sas/sasgui/perspectives/corfunc/corfunc.py

    r9b90bf8 r5251ec6  
    1818from sas.sascalc.dataloader.loader import Loader 
    1919import sas.sascalc.dataloader 
    20 from plot_labels import * 
     20from .plot_labels import * 
    2121 
    2222logger = logging.getLogger(__name__) 
     
    148148                    self.data_id = data.id 
    149149                    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) 
    152152                    wx.PostEvent(self.parent, StatusEvent(status=msg, 
    153153                        info='error')) 
  • src/sas/sasgui/perspectives/corfunc/corfunc_panel.py

    ref74a8b r82d88d5  
    1717from sas.sascalc.corfunc.corfunc_calculator import CorfuncCalculator 
    1818from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
    19 from plot_labels import * 
     19from .plot_labels import * 
    2020 
    2121OUTPUT_STRINGS = { 
     
    396396                output.SetValue('-') 
    397397            return 
    398         for key, value in params.iteritems(): 
     398        for key, value in params.items(): 
    399399            output = self._extrapolation_outputs[key] 
    400400            rounded = self._round_sig_figs(value, 6) 
     
    417417                # Not all parameters were calculated 
    418418                error = True 
    419             for key, value in params.iteritems(): 
     419            for key, value in params.items(): 
    420420                rounded = self._round_sig_figs(value, 6) 
    421421                self._output_boxes[key].SetValue(rounded) 
     
    549549            wx.CENTER | wx.ADJUST_MINSIZE, 15) 
    550550 
    551         file_sizer.AddSpacer((1, 25), pos=(0,2)) 
     551        #file_sizer.AddSpacer((1, 25), pos=(0,2)) 
    552552        databox_sizer.Add(file_sizer, wx.TOP, 15) 
    553553 
     
    713713        self._output_boxes = dict() 
    714714        i = 0 
    715         for key, value in OUTPUT_STRINGS.iteritems(): 
     715        for key, value in OUTPUT_STRINGS.items(): 
    716716            # Create a label and a text box for each poperty 
    717717            label = wx.StaticText(self, -1, value) 
  • src/sas/sasgui/perspectives/corfunc/corfunc_state.py

    r5652efc r5251ec6  
    7474        if self.outputs != {} and self.outputs is not None: 
    7575            state += "\nOutputs:\n" 
    76             for key, value in self.outputs.iteritems(): 
     76            for key, value in self.outputs.items(): 
    7777                name = output_list[key][1] 
    7878                state += "{}: {}\n".format(name, str(value)) 
     
    158158        state = new_doc.createElement("state") 
    159159        top_element.appendChild(state) 
    160         for name, value in self.saved_state.iteritems(): 
     160        for name, value in self.saved_state.items(): 
    161161            element = new_doc.createElement(name) 
    162162            element.appendChild(new_doc.createTextNode(str(value))) 
     
    181181            output = new_doc.createElement("output") 
    182182            top_element.appendChild(output) 
    183             for key, value in self.outputs.iteritems(): 
     183            for key, value in self.outputs.items(): 
    184184                element = new_doc.createElement(key) 
    185185                element.appendChild(new_doc.createTextNode(str(value))) 
     
    214214                try: 
    215215                    self.timestamp = (entry.get('epoch')) 
    216                 except: 
     216                except Exception as exc: 
    217217                    msg = ("CorfuncState.fromXML: Could not read timestamp", 
    218                         "\n{}").format(sys.exc_value) 
     218                        "\n{}").format(exc) 
    219219                    logger.error(msg) 
    220220 
     
    222222            entry = get_content('ns:state', node) 
    223223            if entry is not None: 
    224                 for item in DEFAULT_STATE.iterkeys(): 
     224                for item in DEFAULT_STATE.keys(): 
    225225                    input_field = get_content("ns:{}".format(item), entry) 
    226226                    if input_field is not None: 
     
    283283            root, ext = os.path.splitext(basename) 
    284284            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)) 
    286286            tree = etree.parse(path, parser=etree.ETCompatXMLParser()) 
    287287            root = tree.getroot() 
     
    299299            # File not found 
    300300            msg = "{} is not a valid file path or doesn't exist".format(path) 
    301             raise IOError, msg 
     301            raise IOError(msg) 
    302302 
    303303        if len(output) == 0: 
     
    323323            msg = ("The CanSAS writer expects a Data1D instance. {} was " 
    324324                "provided").format(datainfo.__class__.__name__) 
    325             raise RuntimeError, msg 
     325            raise RuntimeError(msg) 
    326326        if datainfo.title is None or datainfo.title == '': 
    327327            datainfo.title = datainfo.name 
     
    358358                state = CorfuncState() 
    359359                state.fromXML(nodes[0]) 
    360         except: 
     360        except Exception as exc: 
    361361            msg = "XML document does not contain CorfuncState information\n{}" 
    362             msg.format(sys.exc_value) 
     362            msg.format(exc) 
    363363            logger.info(msg) 
    364364        return state 
  • src/sas/sasgui/perspectives/file_converter/__init__.py

    r77d92cd r5251ec6  
    11PLUGIN_ID = "File-Converter Plug-In 1.0" 
    2 from file_converter import * 
     2from .file_converter import * 
  • src/sas/sasgui/perspectives/file_converter/converter_panel.py

    ra26f67f r5251ec6  
    112112            [group_path, group_name] = os.path.split(filepath) 
    113113            ext = "." + group_name.split('.')[-1] # File extension 
    114             for frame_number, frame_data in frame_data.iteritems(): 
     114            for frame_number, frame_data in frame_data.items(): 
    115115                # Append frame number to base filename 
    116116                filename = group_name.replace(ext, str(frame_number)+ext) 
     
    155155            # If lines end with comma or semi-colon, trim the last character 
    156156            if end_char == ',' or end_char == ';': 
    157                 data = map(lambda s: s[0:-1], data) 
     157                data = [s[0:-1] for s in data] 
    158158            else: 
    159159                msg = ("Error reading {}: Lines must end with a digit, comma " 
     
    275275            else: 
    276276                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)) 
    278278        return { 'frames': frames, 'inc': increment, 'file': single_file } 
    279279 
     
    335335        if single_file: 
    336336            # Only need to set metadata on first Data1D object 
    337             frame_data = frame_data.values() # Don't need to know frame numbers 
     337            frame_data = list(frame_data.values()) # Don't need to know frame numbers 
    338338            frame_data[0].filename = output_path.split('\\')[-1] 
    339             for key, value in metadata.iteritems(): 
     339            for key, value in metadata.items(): 
    340340                setattr(frame_data[0], key, value) 
    341341        else: 
     
    343343            for datainfo in frame_data.values(): 
    344344                datainfo.filename = output_path.split('\\')[-1] 
    345                 for key, value in metadata.iteritems(): 
     345                for key, value in metadata.items(): 
    346346                    setattr(datainfo, key, value) 
    347347 
     
    355355    def convert_2d_data(self, dataset): 
    356356        metadata = self.get_metadata() 
    357         for key, value in metadata.iteritems(): 
     357        for key, value in metadata.items(): 
    358358            setattr(dataset[0], key, value) 
    359359 
  • src/sas/sasgui/perspectives/file_converter/converter_widgets.py

    r0e11ec7 r5251ec6  
    5454        v = Vector() 
    5555        if not self.Validate(): return v 
    56         for direction, control in self._inputs.iteritems(): 
     56        for direction, control in self._inputs.items(): 
    5757            try: 
    5858                value = float(control.GetValue()) 
  • src/sas/sasgui/perspectives/fitting/__init__.py

    r12d3e0e r5251ec6  
    11PLUGIN_ID = "Fitting plug-in 1.0" 
    22import os 
    3 from fitting import * 
    43from distutils.filelist import findall 
     4from .fitting import * 
    55def get_data_path(media): 
    66    """ 
  • src/sas/sasgui/perspectives/fitting/basepage.py

    r5323490 rcb64d86  
    1212import logging 
    1313import traceback 
    14 from Queue import Queue 
     14try: # CRUFT: python 2.x 
     15    from Queue import Queue 
     16except ImportError: 
     17    from queue import Queue 
    1518from threading import Thread 
    1619from collections import defaultdict 
     
    6669    FONT_VARIANT = 1 
    6770    ON_MAC = True 
     71if sys.version_info[0] >= 3: 
     72    unicode = str 
    6873 
    6974CUSTOM_MODEL = 'Plugin Models' 
     
    115120        # Q range for data set 
    116121        self.qmin_data_set = np.inf 
    117         self.qmax_data_set = None 
     122        self.qmax_data_set = -np.inf 
    118123        self.npts_data_set = 0 
    119124        # Q range 
     
    624629        if self.model is not None: 
    625630            self.m_name = self.model.name 
    626         if name in self.saved_states.keys(): 
     631        if name in self.saved_states: 
    627632            previous_state = self.saved_states[name] 
    628633            # reset state of checkbox,textcrtl  and  regular parameters value 
     
    893898 
    894899        if len(self._disp_obj_dict) > 0: 
    895             for k, v in self._disp_obj_dict.iteritems(): 
     900            for k, v in self._disp_obj_dict.items(): 
    896901                self.state.disp_obj_dict[k] = v.type 
    897902 
     
    960965 
    961966            if len(self.disp_cb_dict) > 0: 
    962                 for k, v in self.disp_cb_dict.iteritems(): 
     967                for k, v in self.disp_cb_dict.items(): 
    963968                    if v is None: 
    964969                        self.state.disp_cb_dict[k] = v 
     
    969974                            self.state.disp_cb_dict[k] = None 
    970975            if len(self._disp_obj_dict) > 0: 
    971                 for k, v in self._disp_obj_dict.iteritems(): 
     976                for k, v in self._disp_obj_dict.items(): 
    972977                    self.state.disp_obj_dict[k] = v.type 
    973978 
     
    10971102 
    10981103            else: 
    1099                 keys = self.model.getParamList() 
    1100                 for item in keys: 
     1104                for item in self.model.getParamList(): 
    11011105                    if item in self.disp_list and \ 
    11021106                            item not in self.model.details: 
     
    11421146        :return: combo_box_position 
    11431147        """ 
    1144         for key, value in self.master_category_dict.iteritems(): 
     1148        for key, value in self.master_category_dict.items(): 
    11451149            formfactor = state.formfactorcombobox.split(":") 
    11461150            if isinstance(formfactor, list): 
     
    13181322        Help to rest page for dispersions 
    13191323        """ 
    1320         keys = self.model.getParamList() 
    1321         for item in keys: 
     1324        for item in self.model.getParamList(): 
    13221325            if item in self.disp_list and \ 
    13231326                            item not in self.model.details: 
    13241327                self.model.details[item] = ["", None, None] 
    1325         # for k,v in self.state.disp_cb_dict.iteritems(): 
     1328        # for k,v in self.state.disp_cb_dict.items(): 
    13261329        self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 
    13271330        self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 
     
    13291332        self.weights = copy.deepcopy(state.weights) 
    13301333 
    1331         for key, disp_type in state.disp_obj_dict.iteritems(): 
     1334        for key, disp_type in state.disp_obj_dict.items(): 
    13321335            # disp_model = disp 
    13331336            disp_model = POLYDISPERSITY_MODELS[disp_type]() 
     
    13781381        dlg = wx.FileDialog(self, "Choose a weight file", 
    13791382                            self._default_save_location, "", 
    1380                             "*.*", wx.OPEN) 
     1383                            "*.*", wx.FD_OPEN) 
    13811384        path = None 
    13821385        if dlg.ShowModal() == wx.ID_OK: 
     
    13901393        """ 
    13911394        ids = iter(self._id_pool)  # Reusing ids for context menu 
    1392         for name, _ in self.state.saved_states.iteritems(): 
     1395        for name, _ in self.state.saved_states.items(): 
    13931396            self.number_saved_state += 1 
    13941397            # Add item in the context menu 
     
    19191922                else: 
    19201923                    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 
    19231926                    wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    19241927                    return 
    1925             except Exception: 
     1928            except Exception as exc: 
    19261929                tcrtl.SetBackgroundColour("pink") 
    1927                 msg = "Model Error: wrong value entered: %s" % sys.exc_info()[1] 
     1930                msg = "Model Error: wrong value entered: %s" % exc 
    19281931                wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    19291932                return 
     
    19761979                else: 
    19771980                    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 
    19801983                    wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    19811984                    return 
    1982             except Exception: 
     1985            except Exception as exc: 
    19831986                tcrtl.SetBackgroundColour("pink") 
    1984                 msg = "Model Error: wrong value entered: %s" % sys.exc_info()[1] 
     1987                msg = "Model Error: wrong value entered: %s" % exc 
    19851988                wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    19861989                return 
     
    22912294                    value_ctrl.SetValue(format_number(value)) 
    22922295 
    2293                 if name not in self.model.details.keys(): 
     2296                if name not in self.model.details: 
    22942297                    self.model.details[name] = ["", None, None] 
    22952298                old_low, old_high = self.model.details[name][1:3] 
     
    27502753        gui_manager = self._manager.parent 
    27512754        # loops through the panels [dic] 
    2752         for _, item2 in gui_manager.plot_panels.iteritems(): 
     2755        for _, item2 in gui_manager.plot_panels.items(): 
    27532756            data_title = self.data.group_id 
    27542757            # try to get all plots belonging to this control panel 
     
    33243327            if self.data.__class__.__name__ == "Data2D": 
    33253328                name = item[1] 
    3326                 if name in content.keys(): 
     3329                if name in content: 
    33273330                    values = content[name] 
    33283331                    check = values[0] 
     
    33733376                if not item[1] in orient_param: 
    33743377                    name = item[1] 
    3375                     if name in content.keys(): 
     3378                    if name in content: 
    33763379                        check = content[name][0] 
    33773380                        # Avoid changing combox content 
     
    34803483                self.state.weights = self.weights 
    34813484 
    3482         except Exception: 
     3485        except Exception as exc: 
    34833486            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) 
    34863488 
    34873489    def _set_disp_cb(self, isarray, item): 
     
    35483550 
    35493551        self.categorybox.Clear() 
    3550         cat_list = sorted(self.master_category_dict.keys()) 
     3552        cat_list = list(sorted(self.master_category_dict.keys())) 
    35513553        if uncat_str not in cat_list: 
    35523554            cat_list.append(uncat_str) 
  • src/sas/sasgui/perspectives/fitting/fit_thread.py

    rba8d326 r5251ec6  
    1212 
    1313def map_apply(arguments): 
    14     return apply(arguments[0], arguments[1:]) 
     14    fn, args = arguments[0], arguments[1:] 
     15    return fn(*args) 
    1516 
    1617class FitThread(CalcThread): 
     
    5051        except KeyboardInterrupt: 
    5152            msg = "Fitting: terminated by the user." 
    52             raise KeyboardInterrupt, msg 
     53            raise KeyboardInterrupt(msg) 
    5354 
    5455    def compute(self): 
     
    7677                         list_q, list_q, list_handler, list_curr_thread, 
    7778                         list_reset_flag) 
    78             result = map(map_apply, inputs) 
     79            result = list(map(map_apply, inputs)) 
    7980 
    8081            self.complete(result=result, 
     
    8586                          elapsed=time.time() - self.starttime) 
    8687 
    87         except KeyboardInterrupt, msg: 
     88        except KeyboardInterrupt as msg: 
    8889            # Thread was interrupted, just proceed and re-raise. 
    8990            # Real code should not print, but this is an example... 
  • src/sas/sasgui/perspectives/fitting/fitpanel.py

    r69363c7 r5251ec6  
    9494            batch_state = self.sim_page.set_state() 
    9595 
    96         for uid, page in self.opened_pages.iteritems(): 
     96        for uid, page in self.opened_pages.items(): 
    9797            data = page.get_data() 
    9898            # state must be cloned 
     
    135135        if uid not in self.opened_pages: 
    136136            msg = "Fitpanel cannot find ID: %s in self.opened_pages" % str(uid) 
    137             raise ValueError, msg 
     137            raise ValueError(msg) 
    138138        else: 
    139139            return self.opened_pages[uid] 
     
    217217        page_is_opened = False 
    218218        if state is not None: 
    219             for uid, panel in self.opened_pages.iteritems(): 
     219            for uid, panel in self.opened_pages.items(): 
    220220                # Don't return any panel is the exact same page is created 
    221221                if uid == panel.uid and panel.data == state.data: 
     
    396396        """ 
    397397        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") 
    399399        else: 
    400400            for page in self.opened_pages.values(): 
     
    592592        if selected_page in page_finder: 
    593593            # Delete the name of the page into the list of open page 
    594             for uid, list in self.opened_pages.iteritems(): 
     594            for uid, list in self.opened_pages.items(): 
    595595                # Don't return any panel is the exact same page is created 
    596596                if flag and selected_page.uid == uid: 
     
    600600 
    601601        # Delete the name of the page into the list of open page 
    602         for uid, list in self.opened_pages.iteritems(): 
     602        for uid, list in self.opened_pages.items(): 
    603603            # Don't return any panel is the exact same page is created 
    604604            if selected_page.uid == uid: 
  • src/sas/sasgui/perspectives/fitting/fitproblem.py

    r20fa5fe r5251ec6  
    545545        return fitproblem contained in this dictionary 
    546546        """ 
    547         return self.values() 
     547        return list(self.values()) 
    548548 
    549549    def set_result(self, result, fid): 
  • src/sas/sasgui/perspectives/fitting/fitting.py

    ra5cffe5 r98b9f32  
    147147        Given an ID create a fitproblem container 
    148148        """ 
    149         if page_id in self.page_finder.iterkeys(): 
     149        if page_id in self.page_finder: 
    150150            del self.page_finder[page_id] 
    151151 
     
    356356            # categories, the updated plugin may be in either the form factor 
    357357            # or the structure factor combo boxes 
    358             for uid, page in self.fit_panel.opened_pages.iteritems(): 
     358            for uid, page in self.fit_panel.opened_pages.items(): 
    359359                pbox = getattr(page, "formfactorbox", None) 
    360360                sbox = getattr(page, "structurebox", None) 
     
    417417                self.fit_panel.SetSelection(current_page_index) 
    418418 
    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) 
    421421 
    422422    def set_edit_menu(self, owner): 
     
    642642                            data.list_group_id.append(group_id) 
    643643                        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) 
    646646                wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 
    647647 
     
    654654                _, theory_state = item 
    655655                self.fit_panel.set_model_state(theory_state) 
    656             except Exception: 
     656            except Exception as exc: 
    657657                msg = "Fitting: cannot deal with the theory received" 
    658658                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)) 
    660660                wx.PostEvent(self.parent, evt) 
    661661 
     
    778778        # Note: this is used to set the data weights for the fit based on 
    779779        # the weight selection in the GUI. 
    780         if uid in self.page_finder.keys(): 
     780        if uid in self.page_finder: 
    781781            self.page_finder[uid].set_weight(flag=flag, is2d=is2d) 
    782782 
     
    791791        :param qmax: maximum  value of the fit range 
    792792        """ 
    793         if uid in self.page_finder.keys(): 
     793        if uid in self.page_finder: 
    794794            self.page_finder[uid].set_range(qmin=qmin, qmax=qmax, fid=fid) 
    795795 
     
    802802        :param uid: the id related to a page containing fitting information 
    803803        """ 
    804         if uid in self.page_finder.keys(): 
     804        if uid in self.page_finder: 
    805805            self.page_finder[uid].schedule_tofit(value) 
    806806 
     
    821821        """ 
    822822        sim_page_id = self.sim_page.uid 
    823         for uid, value in self.page_finder.iteritems(): 
     823        for uid, value in self.page_finder.items(): 
    824824            if uid != sim_page_id and uid != self.batch_page.uid: 
    825825                model_list = value.get_model() 
     
    886886        Stop the fit 
    887887        """ 
    888         if uid in self.fit_thread_list.keys(): 
     888        if uid in self.fit_thread_list: 
    889889            calc_fit = self.fit_thread_list[uid] 
    890890            if calc_fit is not  None and calc_fit.isrunning(): 
     
    898898        batch_flag = self.batch_page is not None and uid == self.batch_page.uid 
    899899        if sim_flag or batch_flag: 
    900             for uid, value in self.page_finder.iteritems(): 
     900            for uid, value in self.page_finder.items(): 
    901901                if value.get_scheduled() == 1: 
    902                     if uid in self.fit_panel.opened_pages.keys(): 
     902                    if uid in self.fit_panel.opened_pages: 
    903903                        panel = self.fit_panel.opened_pages[uid] 
    904904                        panel._on_fit_complete() 
     
    917917        :param draw: Determine if the theory needs to be plot 
    918918        """ 
    919         if uid not in self.page_finder.keys(): 
     919        if uid not in self.page_finder: 
    920920            return 
    921921        self.page_finder[uid].enable_smearing(flag=enable_smearer) 
     
    928928                msg += "Got data = %s .\n" % str(data) 
    929929                return 
    930                 #raise ValueError, msg 
     930                #raise ValueError(msg) 
    931931            model = self.page_finder[uid].get_model(fid=fid) 
    932932            if model is None: 
     
    10301030        list_page_id = [] 
    10311031        fit_id = 0 
    1032         for page_id, page_info in self.page_finder.iteritems(): 
     1032        for page_id, page_info in self.page_finder.items(): 
    10331033            # For simulfit (uid give with None), do for-loop 
    10341034            # if uid is specified (singlefit), do it only on the page. 
     
    10571057 
    10581058                    pars = [str(element[1]) for element in page.param_toFit] 
    1059                     fitproblem_list = page_info.values() 
    1060                     for fitproblem in  fitproblem_list: 
     1059                    for fitproblem in page_info.values(): 
    10611060                        if sim_fitter is None: 
    10621061                            fitter = Fit() 
     
    10771076                wx.PostEvent(self.parent, evt) 
    10781077                return True 
    1079             except: 
     1078            except Exception as exc: 
    10801079                raise 
    1081                 msg = "Fitting error: %s" % str(sys.exc_value) 
     1080                msg = "Fitting error: %s" % exc 
    10821081                evt = StatusEvent(status=msg, info="error", type="stop") 
    10831082                wx.PostEvent(self.parent, evt) 
     
    11361135        :param fid: the id of the fitproblem(data, model, range,etc) 
    11371136        """ 
    1138         if uid not in self.page_finder.keys(): 
     1137        if uid not in self.page_finder: 
    11391138            return 
    11401139        fitproblemList = self.page_finder[uid].get_fit_problem(fid) 
     
    11811180                evt = StatusEvent(status=msg, info="warning") 
    11821181                wx.PostEvent(self.parent, evt) 
    1183         except Exception: 
    1184             msg = "Creating Fit page: %s" % sys.exc_value 
     1182        except Exception as exc: 
     1183            msg = "Creating Fit page: %s" % exc 
    11851184            wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 
    11861185 
     
    12621261        # case that uid is not specified 
    12631262        if uid is None: 
    1264             for page_id in self.page_finder.keys(): 
     1263            for page_id in self.page_finder: 
    12651264                self.page_finder[page_id].schedule_tofit(value) 
    12661265        # when uid is given 
    12671266        else: 
    1268             if uid in self.page_finder.keys(): 
     1267            if uid in self.page_finder: 
    12691268                self.page_finder[uid].schedule_tofit(value) 
    12701269 
     
    13001299        panel = self.plot_panel 
    13011300        if panel is None: 
    1302             raise ValueError, "Fitting:_onSelect: NonType panel" 
     1301            raise ValueError("Fitting:_onSelect: NonType panel") 
    13031302        Plugin.on_perspective(self, event=event) 
    13041303        self.select_data(panel) 
     
    13331332        """ 
    13341333        uid = page_id[0] 
    1335         if uid in self.fit_thread_list.keys(): 
     1334        if uid in self.fit_thread_list: 
    13361335            del self.fit_thread_list[uid] 
    13371336 
     
    13591358                #get all fittable parameters of the current model 
    13601359                for param in  model.getParamList(): 
    1361                     if param  not in batch_outputs.keys(): 
     1360                    if param  not in batch_outputs: 
    13621361                        batch_outputs[param] = [] 
    13631362                for param in model.getDispParamList(): 
    13641363                    if not model.is_fittable(param) and \ 
    1365                         param in batch_outputs.keys(): 
     1364                        param in batch_outputs: 
    13661365                        del batch_outputs[param] 
    13671366                # Add fitted parameters and their error 
    13681367                for param in res.param_list: 
    1369                     if param not in batch_outputs.keys(): 
     1368                    if param not in batch_outputs: 
    13701369                        batch_outputs[param] = [] 
    13711370                    err_param = "error on %s" % str(param) 
    1372                     if err_param not in batch_inputs.keys(): 
     1371                    if err_param not in batch_inputs: 
    13731372                        batch_inputs[err_param] = [] 
    13741373        msg = "" 
     
    15241523        model = fitproblem.get_model() 
    15251524        #fill batch result information 
    1526         if "Data" not in batch_outputs.keys(): 
     1525        if "Data" not in batch_outputs: 
    15271526            batch_outputs["Data"] = [] 
    15281527        cell = BatchCell() 
     
    15531552        cell.object = [data, theory_data] 
    15541553        batch_outputs["Data"].append(cell) 
    1555         for key, value in data.meta_data.iteritems(): 
    1556             if key not in batch_inputs.keys(): 
     1554        for key, value in data.meta_data.items(): 
     1555            if key not in batch_inputs: 
    15571556                batch_inputs[key] = [] 
    15581557            #if key.lower().strip() != "loader": 
     
    15601559        param = "temperature" 
    15611560        if hasattr(data.sample, param): 
    1562             if param not in  batch_inputs.keys(): 
     1561            if param not in  batch_inputs: 
    15631562                batch_inputs[param] = [] 
    15641563            batch_inputs[param].append(data.sample.temperature) 
     
    16311630                    wx.PostEvent(self.parent, evt) 
    16321631 
    1633         except Exception: 
    1634             msg = ("Fit completed but the following error occurred: %s" 
    1635                    % sys.exc_value) 
     1632        except Exception as exc: 
     1633            msg = "Fit completed but the following error occurred: %s" % exc 
    16361634            #msg = "\n".join((traceback.format_exc(), msg)) 
    16371635            evt = StatusEvent(status=msg, info="warning", type="stop") 
     
    17211719        if model is None: 
    17221720            return 
    1723         if uid not in self.page_finder.keys(): 
     1721        if uid not in self.page_finder: 
    17241722            return 
    17251723        # save the name containing the data name with the appropriate model 
     
    20782076                                  source=source) 
    20792077            self.calc_1D.queue() 
    2080         except: 
     2078        except Exception as exc: 
    20812079            msg = " Error occurred when drawing %s Model 1D: " % model.name 
    2082             msg += " %s" % sys.exc_value 
     2080            msg += " %s" % exc 
    20832081            wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    20842082 
  • src/sas/sasgui/perspectives/fitting/model_thread.py

    r69363c7 r5251ec6  
    6565        if self.data is None: 
    6666            msg = "Compute Calc2D receive data = %s.\n" % str(self.data) 
    67             raise ValueError, msg 
     67            raise ValueError(msg) 
    6868 
    6969        # Define matrix where data will be plotted 
  • src/sas/sasgui/perspectives/fitting/resultpanel.py

    r959eb01 r5251ec6  
    5959    def on_plot_results(self, event): 
    6060        self.frame.Show(True) 
    61         result = event.result[0][0] 
     61        result = list(event.result[0])[0] 
    6262        filename = result.data.sas_data.filename 
    6363        current_time = datetime.datetime.now().strftime("%I:%M%p, %B %d, %Y") 
  • src/sas/sasgui/perspectives/fitting/simfitpage.py

    r20fa5fe r5251ec6  
    168168        i = 0 
    169169        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]) 
    171171            for saved_model in sim_state.model_list: 
    172172                save_id = saved_model.pop('name') 
     
    328328        sizer.Add(tab_used, (iy, ix), (1, 1), 
    329329                  wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    330         for id, value in self.page_finder.iteritems(): 
     330        for id, value in self.page_finder.items(): 
    331331            if id not in self.parent.opened_pages: 
    332332                continue 
     
    757757        self.set_button.Disable() 
    758758 
    759         for id, model in self.constraint_dict.iteritems(): 
     759        for id, model in self.constraint_dict.items(): 
    760760            # check if all parameters have been selected for constraint 
    761761            # then do not allow add constraint on parameters 
    762762            self.model_cbox_left.Append(str(model.name), model) 
    763763        self.model_cbox_left.Select(0) 
    764         for id, model in self.constraint_dict.iteritems(): 
     764        for id, model in self.constraint_dict.items(): 
    765765            # check if all parameters have been selected for constraint 
    766766            # then do not allow add constraint on parameters 
     
    814814        model_right = self.model_cbox_right.GetValue() 
    815815        model_b = self.model_cbox_right.GetClientData(selection_b) 
    816         for id, dic_model in self.constraint_dict.iteritems(): 
     816        for id, dic_model in self.constraint_dict.items(): 
    817817            if model == dic_model: 
    818818                param_list = self.page_finder[id].get_param2fit() 
     
    857857        if len(self.constraints_list) != 0: 
    858858            nb_fit_param = 0 
    859             for id, model in self.constraint_dict.iteritems(): 
     859            for id, model in self.constraint_dict.items(): 
    860860                nb_fit_param += len(self.page_finder[id].get_param2fit()) 
    861861            # Don't add anymore 
     
    879879        model_cbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
    880880        model_cbox.Clear() 
    881         for id, model in self.constraint_dict.iteritems(): 
     881        for id, model in self.constraint_dict.items(): 
    882882            # check if all parameters have been selected for constraint 
    883883            # then do not allow add constraint on parameters 
     
    931931        hide buttons related constraint 
    932932        """ 
    933         for id in self.page_finder.iterkeys(): 
     933        for id in self.page_finder.keys(): 
    934934            self.page_finder[id].clear_model_param() 
    935935 
     
    969969        model = model_cbox.GetClientData(n) 
    970970        param_list = [] 
    971         for id, dic_model in self.constraint_dict.iteritems(): 
     971        for id, dic_model in self.constraint_dict.items(): 
    972972            if model == dic_model: 
    973973                param_list = self.page_finder[id].get_param2fit() 
     
    10561056                msg += " in combobox to set constraint! " 
    10571057                wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    1058             for id, value in self.constraint_dict.iteritems(): 
     1058            for id, value in self.constraint_dict.items(): 
    10591059                if model == value: 
    10601060                    if constraint == "": 
     
    10801080                        return False 
    10811081 
    1082                     for fid in self.page_finder[id].iterkeys(): 
     1082                    for fid in self.page_finder[id].keys(): 
    10831083                        # wrap in param/constraint in str() to remove unicode 
    10841084                        self.page_finder[id].set_model_param(str(param), 
  • src/sas/sasgui/perspectives/invariant/__init__.py

    r5a405bd r5251ec6  
    33 
    44from distutils.filelist import findall 
    5 from invariant import * 
     5from .invariant import * 
    66 
    77def get_data_path(media): 
  • src/sas/sasgui/perspectives/invariant/invariant.py

    r7432acb r5251ec6  
    133133            name = data.__class__.__name__ 
    134134            msg = "Invariant use only Data1D got: [%s] " % str(name) 
    135             raise ValueError, msg 
     135            raise ValueError(msg) 
    136136        self.compute_helper(data=data) 
    137137 
     
    144144        if data_list is None: 
    145145            data_list = [] 
     146        else: 
     147            data_list = list(data_list)  # force iterator to list 
    146148        if len(data_list) >= 1: 
    147149            if len(data_list) == 1: 
     
    190192                try: 
    191193                    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) 
    194196                    wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 
    195197        else: 
     
    240242            msg = "invariant.save_file: the data being saved is" 
    241243            msg += " not a sas.sascalc.dataloader.data_info.Data1D object" 
    242             raise RuntimeError, msg 
     244            raise RuntimeError(msg) 
    243245 
    244246    def set_state(self, state=None, datainfo=None): 
     
    258260                msg = "invariant.set_state: datainfo parameter cannot" 
    259261                msg += " be None in standalone mode" 
    260                 raise RuntimeError, msg 
     262                raise RuntimeError(msg) 
    261263            # Make sure the user sees the invariant panel after loading 
    262264            # self.parent.set_perspective(self.perspective) 
     
    281283            self.on_set_state_helper(None) 
    282284 
    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) 
    285287 
    286288    def on_set_state_helper(self, event=None): 
     
    320322        else: 
    321323            msg = "Scale can not be zero." 
    322             raise ValueError, msg 
     324            raise ValueError(msg) 
    323325        if len(new_plot.x) == 0: 
    324326            return 
  • src/sas/sasgui/perspectives/invariant/invariant_details.py

    r20fa5fe r5251ec6  
    22    Invariant panel 
    33""" 
     4import sys 
     5 
    46import wx 
    5 import sys 
    67 
    78from sas.sasgui.guiframe.utils import format_number 
    8 from invariant_widgets import OutputTextCtrl 
     9from .invariant_widgets import OutputTextCtrl 
     10 
    911# Dimensions related to chart 
    1012RECTANGLE_WIDTH = 400.0 
     
    3335 
    3436 
    35 class InvariantContainer(wx.Object): 
     37class InvariantContainer: 
    3638    """ 
    3739    This class stores some values resulting resulting from invariant 
  • src/sas/sasgui/perspectives/invariant/invariant_panel.py

    r44e8f48 r5251ec6  
    319319        background = self.background_tcl.GetValue().lstrip().rstrip() 
    320320        if background == "": 
    321             raise ValueError, "Need a background" 
     321            raise ValueError("Need a background") 
    322322        if check_float(self.background_tcl): 
    323323            return float(background) 
    324324        else: 
    325325            msg = "Receive invalid value for background : %s" % (background) 
    326             raise ValueError, msg 
     326            raise ValueError(msg) 
    327327 
    328328    def get_scale(self): 
     
    332332        scale = self.scale_tcl.GetValue().lstrip().rstrip() 
    333333        if scale == "": 
    334             raise ValueError, "Need a background" 
     334            raise ValueError("Need a background") 
    335335        if check_float(self.scale_tcl): 
    336336            if float(scale) <= 0.0: 
     
    338338                self.scale_tcl.Refresh() 
    339339                msg = "Receive invalid value for scale: %s" % (scale) 
    340                 raise ValueError, msg 
     340                raise ValueError(msg) 
    341341            return float(scale) 
    342342        else: 
    343             raise ValueError, "Receive invalid value for scale : %s" % (scale) 
     343            raise ValueError("Receive invalid value for scale : %s" % (scale)) 
    344344 
    345345    def get_contrast(self): 
     
    386386                self.volume_tcl.SetValue(format_number(v)) 
    387387                self.volume_err_tcl.SetValue(format_number(dv)) 
    388             except: 
     388            except Exception as exc: 
    389389                self.volume_tcl.SetValue(format_number(None)) 
    390390                self.volume_err_tcl.SetValue(format_number(None)) 
    391391                msg = "Error occurred computing volume " 
    392                 msg += " fraction: %s" % sys.exc_value 
     392                msg += " fraction: %s" % exc 
    393393                wx.PostEvent(self.parent, StatusEvent(status=msg, 
    394394                                                      info="error", 
     
    406406                self.surface_tcl.SetValue(format_number(s)) 
    407407                self.surface_err_tcl.SetValue(format_number(ds)) 
    408             except: 
     408            except Exception as exc: 
    409409                self.surface_tcl.SetValue(format_number(None)) 
    410410                self.surface_err_tcl.SetValue(format_number(None)) 
    411411                msg = "Error occurred computing " 
    412                 msg += "specific surface: %s" % sys.exc_value 
     412                msg += "specific surface: %s" % exc 
    413413                wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", 
    414414                                                      type="stop")) 
     
    426426            self.inv_container.qstar_total = qstar_total 
    427427            self.inv_container.qstar_total_err = qstar_total_err 
    428         except: 
     428        except Exception as exc: 
    429429            self.inv_container.qstar_total = "Error" 
    430430            self.inv_container.qstar_total_err = "Error" 
     
    432432            self.invariant_total_err_tcl.SetValue(format_number(None)) 
    433433            msg = "Error occurred computing invariant using" 
    434             msg += " extrapolation: %s" % sys.exc_value 
     434            msg += " extrapolation: %s" % exc 
    435435            wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 
    436436 
     
    450450                self._manager.plot_theory(data=extrapolated_data, 
    451451                                          name="Low-Q extrapolation") 
    452             except: 
     452            except Exception as exc: 
    453453                self.inv_container.qstar_low = "ERROR" 
    454454                self.inv_container.qstar_low_err = "ERROR" 
    455455                self._manager.plot_theory(name="Low-Q extrapolation") 
    456456                msg = "Error occurred computing low-Q " 
    457                 msg += "invariant: %s" % sys.exc_value 
     457                msg += "invariant: %s" % exc 
    458458                wx.PostEvent(self.parent, 
    459459                             StatusEvent(status=msg, type="stop")) 
     
    462462            try: 
    463463                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) 
    466466 
    467467    def get_high_qstar(self, inv, high_q=False): 
     
    483483                self._manager.plot_theory(data=high_out_data, 
    484484                                          name="High-Q extrapolation") 
    485             except: 
     485            except Exception as exc: 
    486486                #raise 
    487487                self.inv_container.qstar_high = "ERROR" 
     
    489489                self._manager.plot_theory(name="High-Q extrapolation") 
    490490                msg = "Error occurred computing high-Q " 
    491                 msg += "invariant: %s" % sys.exc_value 
     491                msg += "invariant: %s" % exc 
    492492                wx.PostEvent(self.parent, StatusEvent(status=msg, 
    493493                                                      type="stop")) 
     
    496496            try: 
    497497                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) 
    500500 
    501501    def get_qstar(self, inv): 
     
    625625            background = self.get_background() 
    626626            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 
    629629            wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 
    630630            return 
     
    641641            inv, npts_low = self.set_extrapolation_low(inv=inv, low_q=low_q) 
    642642            inv, npts_high = self.set_extrapolation_high(inv=inv, high_q=high_q) 
    643         except: 
    644             msg = "Error occurred computing invariant: %s" % sys.exc_value 
     643        except Exception as exc: 
     644            msg = "Error occurred computing invariant: %s" % exc 
    645645            wx.PostEvent(self.parent, StatusEvent(status=msg, 
    646646                                                  info="warning", type="stop")) 
     
    652652        try: 
    653653            self.get_qstar(inv=inv) 
    654         except: 
    655             msg = "Error occurred computing invariant: %s" % sys.exc_value 
     654        except Exception as exc: 
     655            msg = "Error occurred computing invariant: %s" % exc 
    656656            wx.PostEvent(self.parent, StatusEvent(status=msg, 
    657657                                                  info="warning", 
     
    674674            porod_const = self.get_porod_const() 
    675675            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 
    679678            wx.PostEvent(self.parent, StatusEvent(status=msg, 
    680679                                                  info="error", 
     
    685684                            extrapolation=extrapolation) 
    686685            #compute surface and set value to txtcrtl 
    687         except: 
    688             msg = "Error occurred computing invariant: %s" % sys.exc_value 
     686        except Exception as exc: 
     687            msg = "Error occurred computing invariant: %s" % exc 
    689688            wx.PostEvent(self.parent, StatusEvent(status=msg, 
    690689                                                  info="warning", 
     
    695694                             extrapolation=extrapolation) 
    696695 
    697         except: 
    698             msg = "Error occurred computing invariant: %s" % sys.exc_value 
     696        except Exception as exc: 
     697            msg = "Error occurred computing invariant: %s" % exc 
    699698            wx.PostEvent(self.parent, StatusEvent(status=msg, 
    700699                                                  info="warning", 
     
    845844            if attr.__class__.__name__ == "StaticText": 
    846845                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 
    849850            else: 
    850851                value = str(value) 
    851852            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) 
    854855 
    855856    def get_bookmark_by_num(self, num=None): 
     
    867868        try: 
    868869            _, _, 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") 
    872873 
    873874        # set the parameters 
     
    962963            self.state.state_list[str(self.state.state_num)] = \ 
    963964                    self.state.clone_state() 
    964         except: 
    965             logger.error(sys.exc_value) 
     965        except Exception as exc: 
     966            logger.error(exc) 
    966967 
    967968        self._set_undo_flag(True) 
     
    10061007            try: 
    10071008                del self.state.state_list[str(i)] 
    1008             except: 
    1009                 logger.error(sys.exc_value) 
     1009            except Exception as exc: 
     1010                logger.error(exc) 
    10101011        # Enable the undo button if it was not 
    10111012        self._set_undo_flag(True) 
     
    10711072            try: 
    10721073                del self.state.state_list[str(i)] 
    1073             except: 
    1074                 logger.error(sys.exc_value) 
     1074            except Exception as exc: 
     1075                logger.error(exc) 
    10751076 
    10761077        # try to add new state of the text changes in the state_list 
     
    10861087            self.state.state_num = self.state.saved_state['state_num'] 
    10871088            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) 
    10901091 
    10911092        self._set_undo_flag(True) 
     
    11081109            self.state.saved_state[name] = str(value) 
    11091110            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) 
    11121113 
    11131114    def _get_input_list(self): 
     
    11181119        compute_num = self.state.saved_state['compute_num'] 
    11191120        # find values and put into the input list 
    1120         for key1, value1 in self.state.state_list[str(compute_num)].iteritems(): 
    1121             for key, _ in self.state.input_list.iteritems(): 
     1121        for key1, value1 in self.state.state_list[str(compute_num)].items(): 
     1122            for key, _ in self.state.input_list.items(): 
    11221123                if key == key1: 
    11231124                    self.state.input_list[key] = value1 
  • src/sas/sasgui/perspectives/invariant/invariant_state.py

    re9920cd r5251ec6  
    22    State class for the invariant UI 
    33""" 
     4from __future__ import print_function 
    45 
    56# import time 
     
    140141 
    141142        # text ctl general inputs ( excluding extrapolation text ctl) 
    142         for key, value in self.input_list.iteritems(): 
     143        for key, value in self.input_list.items(): 
    143144            if value == '': 
    144145                continue 
     
    166167        low_off = False 
    167168        high_off = False 
    168         for key, value in self.input_list.iteritems(): 
     169        for key, value in self.input_list.items(): 
    169170            key_split = key.split('_') 
    170171            max_ind = len(key_split) - 1 
     
    216217                # other outputs than Q* 
    217218                name = item[0] + "_tcl" 
    218                 if name in self.saved_state.keys(): 
     219                if name in self.saved_state: 
    219220                    value = self.saved_state[name] 
    220221 
     
    301302        top_element.appendChild(state) 
    302303 
    303         for name, value in self.saved_state.iteritems(): 
     304        for name, value in self.saved_state.items(): 
    304305            element = newdoc.createElement(str(name)) 
    305306            element.appendChild(newdoc.createTextNode(str(value))) 
     
    310311        top_element.appendChild(history) 
    311312 
    312         for name, value in self.state_list.iteritems(): 
     313        for name, value in self.state_list.items(): 
    313314            history_element = newdoc.createElement('state_' + str(name)) 
    314             for state_name, state_value in value.iteritems(): 
     315            for state_name, state_value in value.items(): 
    315316                state_element = newdoc.createElement(str(state_name)) 
    316317                child = newdoc.createTextNode(str(state_value)) 
     
    325326        top_element.appendChild(bookmark) 
    326327        item_list = ['time', 'date', 'state', 'comp_state'] 
    327         for name, value_list in self.bookmark_list.iteritems(): 
     328        for name, value_list in self.bookmark_list.items(): 
    328329            element = newdoc.createElement('mark_' + str(name)) 
    329330            _, date, state, comp_state = value_list 
     
    334335            state_list_element = newdoc.createElement('state') 
    335336            comp_state_list_element = newdoc.createElement('comp_state') 
    336             for state_name, state_value in value_list[2].iteritems(): 
     337            for state_name, state_value in value_list[2].items(): 
    337338                state_element = newdoc.createElement(str(state_name)) 
    338339                child = newdoc.createTextNode(str(state_value)) 
    339340                state_element.appendChild(child) 
    340341                state_list_element.appendChild(state_element) 
    341             for comp_name, comp_value in value_list[3].iteritems(): 
     342            for comp_name, comp_value in value_list[3].items(): 
    342343                comp_element = newdoc.createElement(str(comp_name)) 
    343344                comp_element.appendChild(newdoc.createTextNode(str(comp_value))) 
     
    368369            msg = "InvariantSate no longer supports non-CanSAS" 
    369370            msg += " format for invariant files" 
    370             raise RuntimeError, msg 
     371            raise RuntimeError(msg) 
    371372 
    372373        if node.get('version')\ 
     
    383384                try: 
    384385                    timestamp = (entry.get('epoch')) 
    385                 except: 
     386                except Exception as exc: 
    386387                    msg = "InvariantSate.fromXML: Could not read" 
    387                     msg += " timestamp\n %s" % sys.exc_value 
     388                    msg += " timestamp\n %s" % exc 
    388389                    logger.error(msg) 
    389390 
     
    453454        Get the values (strings) from __str__ for report 
    454455        """ 
    455         strings = self.__str__() 
    456  
    457456        # 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)} 
    461458        # 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 
    467465            else: 
    468                 item = lines[line].split(':') 
     466                item = line.split(':') 
    469467                item[0] = item[0].strip() 
    470468                if item[0] == "scale": 
    471                     s_3 = item[1] 
     469                    s[3] = item[1] 
    472470                elif item[0] == "porod constant": 
    473                     s_4 = item[1] 
     471                    s[4] = item[1] 
    474472                elif item[0] == "background": 
    475                     s_5 = item[1] 
     473                    s[5] = item[1] 
    476474                elif item[0] == "contrast": 
    477                     s_6 = item[1] 
     475                    s[6] = item[1] 
    478476                elif item[0] == "Extrapolation": 
    479477                    extra = item[1].split(";") 
    480478                    bool_0 = extra[0].split("=") 
    481479                    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] 
    484482                elif item[0] == "npts low": 
    485                     s_9 = item[1] 
     483                    s[9] = item[1] 
    486484                elif item[0] == "npts high": 
    487                     s_10 = item[1] 
     485                    s[10] = item[1] 
    488486                elif item[0] == "volume fraction": 
    489487                    val = item[1].split("+-")[0].strip() 
    490488                    error = item[1].split("+-")[1].strip() 
    491                     s_17 = val + " &plusmn; " + error 
     489                    s[17] = val + " &plusmn; " + error 
    492490                elif item[0] == "specific surface": 
    493491                    val = item[1].split("+-")[0].strip() 
    494492                    error = item[1].split("+-")[1].strip() 
    495                     s_18 = val + " &plusmn; " + error 
     493                    s[18] = val + " &plusmn; " + error 
    496494                elif item[0].split("(")[0].strip() == "power low": 
    497                     s_11 = item[0] + " =" + item[1] 
     495                    s[11] = item[0] + " =" + item[1] 
    498496                elif item[0].split("(")[0].strip() == "power high": 
    499                     s_12 = item[0] + " =" + item[1] 
     497                    s[12] = item[0] + " =" + item[1] 
    500498                elif item[0].split("[")[0].strip() == "Q* from low Q extrapolation": 
    501499                    # looks messy but this way the symbols +_ and % work on html 
     
    504502                    err = error.split("%")[0].strip() 
    505503                    percent = error.split("%")[1].strip() 
    506                     s_13 = val + " &plusmn; " + err + "&#37" + percent 
     504                    s[13] = val + " &plusmn; " + err + "&#37" + percent 
    507505                elif item[0].split("[")[0].strip() == "Q* from data": 
    508506                    val = item[1].split("+-")[0].strip() 
     
    510508                    err = error.split("%")[0].strip() 
    511509                    percent = error.split("%")[1].strip() 
    512                     s_14 = val + " &plusmn; " + err + "&#37" + percent 
     510                    s[14] = val + " &plusmn; " + err + "&#37" + percent 
    513511                elif item[0].split("[")[0].strip() == "Q* from high Q extrapolation": 
    514512                    val = item[1].split("+-")[0].strip() 
     
    516514                    err = error.split("%")[0].strip() 
    517515                    percent = error.split("%")[1].strip() 
    518                     s_15 = val + " &plusmn; " + err + "&#37" + percent 
     516                    s[15] = val + " &plusmn; " + err + "&#37" + percent 
    519517                elif item[0].split("[")[0].strip() == "total Q*": 
    520518                    val = item[1].split("+-")[0].strip() 
    521519                    error = item[1].split("+-")[1].strip() 
    522                     s_16 = val + " &plusmn; " + error 
     520                    s[16] = val + " &plusmn; " + error 
    523521                else: 
    524522                    continue 
    525523 
    526         s_1 = self._check_html_format(s_1) 
     524        s[1] = self._check_html_format(s[1]) 
    527525        file_name = self._check_html_format(self.file) 
    528526 
     
    530528        self.set_plot_state(extra_high=bool_0[1], extra_low=bool_1[1]) 
    531529        # 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") 
    536533 
    537534    def _check_html_format(self, name): 
     
    692689                state = InvariantState() 
    693690                state.fromXML(node=nodes[0]) 
    694         except: 
     691        except Exception as exc: 
    695692            msg = "XML document does not contain invariant" 
    696             msg += " information.\n %s" % sys.exc_value 
     693            msg += " information.\n %s" % exc 
    697694            logger.info(msg) 
    698695        return state 
     
    736733                        output.append(sas_entry) 
    737734        else: 
    738             raise RuntimeError, "%s is not a file" % path 
     735            raise RuntimeError("%s is not a file" % path) 
    739736 
    740737        # Return output consistent with the loader's api 
     
    782779            msg = "The cansas writer expects a Data1D" 
    783780            msg += " instance: %s" % str(datainfo.__class__.__name__) 
    784             raise RuntimeError, msg 
     781            raise RuntimeError(msg) 
    785782        # make sure title and data run is filled up. 
    786783        if datainfo.title is None or datainfo.title == '': 
  • src/sas/sasgui/perspectives/invariant/report_dialog.py

    rd0ce666f r5251ec6  
    9292                        # Mac 
    9393                        os.system("open %s" % fName) 
    94                     except: 
     94                    except Exception as exc: 
    9595                        # DO not open 
    96                         logger.error("Could not open file: %s" % sys.exc_value) 
     96                        logger.error("Could not open file: %s" % exc) 
    9797            # delete image file 
    9898            os.remove(pic_fname)