Changeset 5251ec6 in sasview


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

improved support for py37 in sasgui

Location:
src/sas
Files:
98 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/guiframe/CategoryInstaller.py

    ra26f67f r5251ec6  
    121121        """ 
    122122        _model_dict = {model.name: model for model in model_list} 
    123         _model_list = _model_dict.keys() 
     123        _model_list = list(_model_dict.keys()) 
    124124 
    125125        serialized_file = None 
     
    146146                        by_model_dict.pop(model_name) 
    147147                        model_enabled_dict.pop(model_name) 
    148                     except Exception: 
    149                         logger.error("CategoryInstaller: %s", sys.exc_value) 
     148                    except Exception as exc: 
     149                        logger.error("CategoryInstaller: %s", exc) 
    150150                else: 
    151151                    add_list.remove(model_name) 
     
    171171                                                          model_enabled_dict) 
    172172 
    173             json.dump(master_category_dict, open(serialized_file, 'wb')) 
     173            json.dump(master_category_dict, open(serialized_file, 'w')) 
  • 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

    r8ac05a5 r5251ec6  
    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 
     
    286288        return client size tuple 
    287289        """ 
    288         width, height = self.GetClientSizeTuple() 
     290        width, height = self.GetClientSize() 
    289291        height -= 45 
    290292        # Adjust toolbar height 
     
    361363        try: 
    362364            self.read_batch_tofile(file_name=path) 
    363         except: 
     365        except Exception as exc: 
    364366            msg = "Error occurred when reading the file; %s\n" % path 
    365             msg += "%s\n" % sys.exc_value 
    366             wx.PostEvent(self, StatusEvent(status=msg, 
    367                                            info="error")) 
     367            msg += "%s\n" % exc 
     368            wx.PostEvent(self, StatusEvent(status=msg, info="error")) 
    368369 
    369370    def read_batch_tofile(self, file_name): 
     
    705706        try: 
    706707            self.load_from_cmd(self._input_file) 
    707         except: 
     708        except Exception as exc: 
    708709            msg = "%s Cannot load file %s\n" % (str(APPLICATION_NAME), 
    709710                                                str(self._input_file)) 
    710             msg += str(sys.exc_value) + '\n' 
     711            msg += str(exc) + '\n' 
    711712            logger.error(msg) 
    712713        if self._data_panel is not None and len(self.plugins) > 0: 
     
    797798                self._data_plugin = data_loader.Plugin() 
    798799                plugins.append(self._data_plugin) 
    799             except: 
     800            except Exception as exc: 
    800801                msg = "ViewerFrame._get_local_plugins:" 
    801                 msg += "cannot import dataloader plugin.\n %s" % sys.exc_value 
     802                msg += "cannot import dataloader plugin.\n %s" % exc 
    802803                logger.error(msg) 
    803804        if style2 == GUIFRAME.PLOTTING_ON: 
     
    807808                self._plotting_plugin = plotting.Plugin() 
    808809                plugins.append(self._plotting_plugin) 
    809             except: 
     810            except Exception as exc: 
    810811                msg = "ViewerFrame._get_local_plugins:" 
    811                 msg += "cannot import plotting plugin.\n %s" % sys.exc_value 
     812                msg += "cannot import plotting plugin.\n %s" % exc 
    812813                logger.error(msg) 
    813814 
     
    856857                                msg = "Found plug-in: %s" % module.PLUGIN_ID 
    857858                                logger.info(msg) 
    858                             except: 
     859                            except Exception as exc: 
    859860                                msg = "Error accessing PluginPanel" 
    860                                 msg += " in %s\n  %s" % (name, sys.exc_value) 
     861                                msg += " in %s\n  %s" % (name, exc) 
    861862                                config.printEVT(msg) 
    862                     except: 
    863                         msg = "ViewerFrame._find_plugins: %s" % sys.exc_value 
     863                    except Exception as exc: 
     864                        msg = "ViewerFrame._find_plugins: %s" % exc 
    864865                        logger.error(msg) 
    865866                    finally: 
    866867                        if file is not None: 
    867868                            file.close() 
    868         except: 
     869        except Exception as exc: 
    869870            # Should raise and catch at a higher level and 
    870871            # display error on status bar 
    871             logger.error(sys.exc_value) 
     872            logger.error(exc) 
    872873 
    873874        return plugins 
     
    15991600        """ 
    16001601        # This CallAfter fixes many crashes on MAC. 
    1601         wx.CallAfter(self.sb.set_status, evt) 
     1602        wx.CallAfter(self.sb.set_status, evt.Clone()) 
    16021603 
    16031604    def on_view(self, evt): 
     
    16431644        ID = str(uid) 
    16441645        config.printEVT("delete_panel: %s" % ID) 
    1645         if ID in self.panels.keys(): 
     1646        if ID in self.panels: 
    16461647            self.panel_on_focus = None 
    16471648            panel = self.panels[ID] 
     
    16551656 
    16561657            # delete uid number not str(uid) 
    1657             if ID in self.plot_panels.keys(): 
     1658            if ID in self.plot_panels: 
    16581659                del self.plot_panels[ID] 
    1659             if ID in self.panels.keys(): 
     1660            if ID in self.panels: 
    16601661                del self.panels[ID] 
    16611662        else: 
     
    16911692                    try: 
    16921693                        reader.read(path) 
    1693                     except: 
     1694                    except Exception as exc: 
    16941695                        msg = "DataLoader Error: Encounted Non-ASCII character" 
    1695                         msg += "\n(%s)" % sys.exc_value 
     1696                        msg += "\n(%s)" % exc 
    16961697                        wx.PostEvent(self, StatusEvent(status=msg, 
    16971698                                                       info="error", 
     
    17741775 
    17751776            self.add_data(data_list=output) 
    1776         except: 
     1777        except Exception as exc: 
    17771778            error_message = "Error while loading" 
    17781779            error_message += " Data from cmd:\n %s\n" % str(path) 
    1779             error_message += str(sys.exc_value) + "\n" 
     1780            error_message += str(exc) + "\n" 
    17801781            logger.error(error_message) 
    17811782 
     
    17951796            else: 
    17961797                return 
    1797         except: 
     1798        except Exception as exc: 
    17981799            error_message = "Error while loading" 
    17991800            error_message += " Data folder from cmd:\n %s\n" % str(path) 
    1800             error_message += str(sys.exc_value) + "\n" 
     1801            error_message += str(exc) + "\n" 
    18011802            logger.error(error_message) 
    18021803 
     
    18651866            self._data_panel.selection_cbox.SetValue('Select all Data') 
    18661867            self._data_panel._on_selection_type(None) 
    1867             for _, theory_dict in self._data_panel.list_cb_theory.iteritems(): 
    1868                 for key, value in theory_dict.iteritems(): 
     1868            for _, theory_dict in self._data_panel.list_cb_theory.items(): 
     1869                for key, value in theory_dict.items(): 
    18691870                    item, _, _ = value 
    18701871                    item.Check(True) 
     
    19741975            # case of a panel with multi-pages 
    19751976            if hasattr(panel, "opened_pages"): 
    1976                 for _, page in panel.opened_pages.iteritems(): 
     1977                for _, page in panel.opened_pages.items(): 
    19771978                    data = page.get_data() 
    19781979                    # state must be cloned 
     
    20962097                msg += " Please try again later." 
    20972098                self.SetStatusText(msg) 
    2098             elif cmp(version, config.__version__) > 0: 
     2099            elif version > config.__version__: 
    20992100                msg = "Version %s is available! " % str(version) 
    21002101                if not standalone: 
     
    21122113                    msg += " of %s" % str(config.__appname__) 
    21132114                    self.SetStatusText(msg) 
    2114         except: 
     2115        except Exception as exc: 
    21152116            msg = "guiframe: could not get latest application" 
    2116             msg += " version number\n  %s" % sys.exc_value 
     2117            msg += " version number\n  %s" % exc 
    21172118            logger.error(msg) 
    21182119            if not standalone: 
     
    21542155        # S King, Sep 2018 
    21552156 
    2156         from documentation_window import DocumentationWindow 
     2157        from .documentation_window import DocumentationWindow 
    21572158        _TreeLocation = "user/release.html" 
    21582159        DocumentationWindow(self, -1, _TreeLocation, "", 
     
    21702171        # original 2.x tutorial. 
    21712172        # Code below, implemented from 4.2.0, redirects 
    2172         # action to the Tutorials page of the help  
     2173        # action to the Tutorials page of the help 
    21732174        # documentation to give access to all available 
    21742175        # tutorials 
    21752176        # S King, Sep 2018 
    21762177 
    2177         from documentation_window import DocumentationWindow 
     2178        from .documentation_window import DocumentationWindow 
    21782179        _TreeLocation = "user/tutorial.html" 
    21792180        DocumentationWindow(self, -1, _TreeLocation, "", 
     
    21902191        # Running SasView "in-place" using run.py means the docs will be in a 
    21912192        # different place than they would otherwise. 
    2192         from documentation_window import DocumentationWindow 
     2193        from .documentation_window import DocumentationWindow 
    21932194        _TreeLocation = "user/user.html" 
    21942195        DocumentationWindow(self, -1, _TreeLocation, "", 
     
    22382239                if (style == GUIFRAME.MANAGER_ON) \ 
    22392240                        and self.panels[item] == self._data_panel: 
    2240                     if 'data_panel' in self.panels.keys(): 
     2241                    if 'data_panel' in self.panels: 
    22412242                        frame = self.panels['data_panel'].get_frame() 
    22422243                        if frame is None: 
     
    22902291        # set data in the data panel 
    22912292        if self._data_panel is not None: 
    2292             data_state = self._data_manager.get_data_state(data_list.keys()) 
     2293            data_state = self._data_manager.get_data_state(list(data_list.keys())) 
    22932294            self._data_panel.load_data_list(data_state) 
    22942295        # if the data panel is shown wait for the user to press a button 
     
    23022303        else: 
    23032304            # automatically send that to the current perspective 
    2304             self.set_data(data_id=data_list.keys()) 
     2305            self.set_data(data_id=list(data_list.keys())) 
    23052306 
    23062307    def set_data(self, data_id, theory_id=None): 
     
    23102311        list_data, _ = self._data_manager.get_by_id(data_id) 
    23112312        if self._current_perspective is not None: 
    2312             self._current_perspective.set_data(list_data.values()) 
     2313            self._current_perspective.set_data(list(list_data.values())) 
    23132314 
    23142315        else: 
     
    23222323        if self._current_perspective is not None: 
    23232324            try: 
    2324                 self._current_perspective.set_theory(list_theory.values()) 
    2325             except: 
    2326                 msg = "Guiframe set_theory: \n" + str(sys.exc_value) 
     2325                self._current_perspective.set_theory(list(list_theory.values())) 
     2326            except Exception as exc: 
     2327                msg = "Guiframe set_theory: \n" + str(exc) 
    23272328                logger.info(msg) 
    23282329                wx.PostEvent(self, StatusEvent(status=msg, info="error")) 
     
    23382339        data_list, _ = self._data_manager.get_by_id(data_id) 
    23392340        _, temp_list_theory = self._data_manager.get_by_id(theory_id) 
    2340         total_plot_list = data_list.values() 
     2341        total_plot_list = list(data_list.values()) 
    23412342        for item in temp_list_theory.values(): 
    23422343            theory_data, theory_state = item 
     
    23872388        data_list, _ = self._data_manager.get_by_id(data_id) 
    23882389        _, temp_list_theory = self._data_manager.get_by_id(theory_id) 
    2389         total_plot_list = data_list.values() 
     2390        total_plot_list = list(data_list.values()) 
    23902391        for item in temp_list_theory.values(): 
    23912392            theory_data, theory_state = item 
     
    24102411                                            group_id=("res" + str(id)), 
    24112412                                            action='remove')) 
    2412         except: 
    2413             logger.error(sys.exc_value) 
     2413        except Exception as exc: 
     2414            logger.error(exc) 
    24142415 
    24152416    def save_data1d(self, data, fname): 
     
    25162517            wx.PostEvent(self, StatusEvent(status=msg, 
    25172518                                           info="error")) 
    2518             raise ValueError, msg 
     2519            raise ValueError(msg) 
    25192520        # text = str(data) 
    25202521        text = data.__str__() 
     
    25512552                                                  dy_val, 
    25522553                                                  dx_val) 
    2553         from pdfview import TextFrame 
     2554        from .pdfview import TextFrame 
    25542555        frame = TextFrame(None, -1, "Data Info: %s" % data.name, text) 
    25552556        # put icon 
     
    26352636                break 
    26362637 
    2637         from pdfview import TextFrame 
     2638        from .pdfview import TextFrame 
    26382639        frame = TextFrame(None, -1, "Data Info: %s" % data.name, text) 
    26392640        # put icon 
     
    27022703        check = "Theory1D" 
    27032704        is_theory = len(self.panel_on_focus.plots) <= 1 and \ 
    2704             self.panel_on_focus.plots.values()[0].__class__.__name__ == check 
     2705            list(self.panel_on_focus.plots.values())[0].__class__.__name__ == check 
    27052706 
    27062707        is_data2d = hasattr(new_plot, 'data') 
     
    32183219            else: 
    32193220                self.frame.Show() 
    3220         except: 
     3221        except Exception as exc: 
    32213222            if self.s_screen is not None: 
    32223223                self.s_screen.Close() 
    32233224            msg = "Cannot display splash screen\n" 
    3224             msg += str(sys.exc_value) 
     3225            msg += str(exc) 
    32253226            logger.error(msg) 
    32263227            self.frame.Show() 
     
    32773278                        if os.path.isfile(file_path): 
    32783279                            os.remove(file_path) 
    3279                 except: 
     3280                except Exception as exc: 
    32803281                    logger.error("gui_manager.clean_plugin_models:\n  %s" 
    3281                                   % sys.exc_value) 
     3282                                 % exc) 
    32823283 
    32833284    def set_manager(self, manager): 
     
    33723373                              path=SPLASH_SCREEN_PATH): 
    33733374        """Displays the splash screen.  It will exactly cover the main frame.""" 
     3375        try: 
     3376            from wx.adv import SplashScreen, SPLASH_TIMEOUT, SPLASH_CENTRE_ON_SCREEN 
     3377        except ImportError: 
     3378            # CRUFT: wx 4 moved SplashScreen from wx to wx.adv 
     3379            from wx import SplashScreen, SPLASH_TIMEOUT, SPLASH_CENTRE_ON_SCREEN 
    33743380 
    33753381        # Prepare the picture.  On a 2GHz intel cpu, this takes about a second. 
     
    33883394        # Note that on Linux, the timeout appears to occur immediately in which 
    33893395        # case the splash screen disappears upon entering the event loop. 
    3390         s_screen = wx.SplashScreen(bitmap=bm, 
    3391                                    splashStyle=(wx.SPLASH_TIMEOUT | 
    3392                                                 wx.SPLASH_CENTRE_ON_SCREEN), 
    3393                                    style=(wx.SIMPLE_BORDER | 
    3394                                           wx.FRAME_NO_TASKBAR | 
    3395                                           wx.FRAME_FLOAT_ON_PARENT), 
    3396                                    milliseconds=SS_MAX_DISPLAY_TIME, 
    3397                                    parent=parent, 
    3398                                    id=wx.ID_ANY) 
     3396        s_screen = SplashScreen(bitmap=bm, 
     3397                                splashStyle=(SPLASH_TIMEOUT | 
     3398                                             SPLASH_CENTRE_ON_SCREEN), 
     3399                                style=(wx.SIMPLE_BORDER | 
     3400                                       wx.FRAME_NO_TASKBAR | 
     3401                                       wx.FRAME_FLOAT_ON_PARENT), 
     3402                                milliseconds=SS_MAX_DISPLAY_TIME, 
     3403                                parent=parent, 
     3404                                id=wx.ID_ANY) 
    33993405        from sas.sasgui.guiframe.gui_statusbar import SPageStatusbar 
    34003406        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

    r9c7e2b8 r5251ec6  
    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

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

    r20fa5fe r5251ec6  
    4646        executing computation 
    4747        """ 
    48         self.image = map(self.func, self.qx, self.qy, 
    49                         self.qx_min, self.qx_max, 
    50                         self.qy_min, self.qy_max)[0] 
     48        self.image = list(map(self.func, self.qx, self.qy, 
     49                              self.qx_min, self.qx_max, 
     50                              self.qy_min, self.qy_max))[0] 
    5151        elapsed = time.time() - self.starttime 
    5252 
  • src/sas/sasgui/perspectives/calculator/resolution_calculator_panel.py

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

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

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

    r5652efc r5251ec6  
    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 r5251ec6  
    1212import logging 
    1313import traceback 
    14 from Queue import Queue 
     14try: 
     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/fitpage.py

    rba1c145 r5251ec6  
    766766                disp_box = wx.ComboBox(self, wx.ID_ANY, size=(65, -1), 
    767767                                       style=wx.CB_READONLY, name='%s' % name1) 
    768                 for key, value in POLYDISPERSITY_MODELS.iteritems(): 
     768                for key, value in POLYDISPERSITY_MODELS.items(): 
    769769                    name_disp = str(key) 
    770770                    disp_box.Append(name_disp, value) 
     
    930930                disp_box = wx.ComboBox(self, wx.ID_ANY, size=(65, -1), 
    931931                                style=wx.CB_READONLY, name='%s' % name1) 
    932                 for key, value in POLYDISPERSITY_MODELS.iteritems(): 
     932                for key, value in POLYDISPERSITY_MODELS.items(): 
    933933                    name_disp = str(key) 
    934934                    disp_box.Append(name_disp, value) 
     
    13721372                self._check_value_enter(self.fittable_param) 
    13731373                self._check_value_enter(self.parameters) 
    1374             except: 
     1374            except Exception as exc: 
    13751375                tcrtl.SetBackgroundColour("pink") 
    1376                 msg = "Model Error:wrong value entered : %s" % sys.exc_value 
     1376                msg = "Model Error:wrong value entered : %s" % exc 
    13771377                wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    13781378                return 
     
    14861486                else: 
    14871487                    tcrtl.SetBackgroundColour("pink") 
    1488                     msg = "Model Error:wrong value entered : %s" % sys.exc_value 
     1488                    _, exc, _ = sys.exc_info() 
     1489                    msg = "Model Error:wrong value entered : %s" % exc 
    14891490                    wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    14901491                    return 
    1491             except: 
     1492            except Exception as exc: 
    14921493                tcrtl.SetBackgroundColour("pink") 
    1493                 msg = "Model Error:wrong value entered : %s" % sys.exc_value 
     1494                msg = "Model Error:wrong value entered : %s" % exc 
    14941495                wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    14951496                return 
     
    18591860                    wx.PostEvent(self._manager.parent, StatusEvent(status=msg, 
    18601861                                               info="error")) 
    1861                     raise ValueError, msg 
     1862                    raise ValueError(msg) 
    18621863 
    18631864            else: 
     
    18711872                    wx.PostEvent(self._manager.parent, StatusEvent(status=msg, 
    18721873                                               info="error")) 
    1873                     raise ValueError, msg 
     1874                    raise ValueError(msg) 
    18741875                # Maximum value of data 
    18751876                qmax = math.sqrt(x * x + y * y) 
     
    21132114        self._on_fit_complete() 
    21142115        if out is None or not np.isfinite(chisqr): 
    2115             raise ValueError, "Fit error occured..." 
     2116            raise ValueError("Fit error occured...") 
    21162117 
    21172118        is_modified = False 
     
    21882189                i += 1 
    21892190            else: 
    2190                 raise ValueError, "onsetValues: Invalid parameters..." 
     2191                raise ValueError("onsetValues: Invalid parameters...") 
    21912192        # Show error title when any errors displayed 
    21922193        if has_error: 
     
    29472948        # type can be either Guassian or Array 
    29482949        if len(self.model.dispersion.values()) > 0: 
    2949             type = self.model.dispersion.values()[0]["type"] 
     2950            dist_type = list(self.model.dispersion.values())[0]["type"] 
    29502951        else: 
    2951             type = "Gaussian" 
     2952            dist_type = "Gaussian" 
    29522953 
    29532954        iy += 1 
     
    30083009 
    30093010        # For Gaussian only 
    3010         if type.lower() != "array": 
     3011        if dist_type.lower() != "array": 
    30113012            for item in self.model.orientation_params: 
    30123013                if not self.magnetic_on: 
  • 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

    raba4559 r5251ec6  
    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 
     
    780780        if fid is None: 
    781781            return 
    782         if uid in self.page_finder.keys(): 
     782        if uid in self.page_finder: 
    783783            self.page_finder[uid].set_weight(flag=flag, is2d=is2d) 
    784784 
     
    793793        :param qmax: maximum  value of the fit range 
    794794        """ 
    795         if uid in self.page_finder.keys(): 
     795        if uid in self.page_finder: 
    796796            self.page_finder[uid].set_range(qmin=qmin, qmax=qmax, fid=fid) 
    797797 
     
    804804        :param uid: the id related to a page containing fitting information 
    805805        """ 
    806         if uid in self.page_finder.keys(): 
     806        if uid in self.page_finder: 
    807807            self.page_finder[uid].schedule_tofit(value) 
    808808 
     
    823823        """ 
    824824        sim_page_id = self.sim_page.uid 
    825         for uid, value in self.page_finder.iteritems(): 
     825        for uid, value in self.page_finder.items(): 
    826826            if uid != sim_page_id and uid != self.batch_page.uid: 
    827827                model_list = value.get_model() 
     
    888888        Stop the fit 
    889889        """ 
    890         if uid in self.fit_thread_list.keys(): 
     890        if uid in self.fit_thread_list: 
    891891            calc_fit = self.fit_thread_list[uid] 
    892892            if calc_fit is not  None and calc_fit.isrunning(): 
     
    900900        batch_flag = self.batch_page is not None and uid == self.batch_page.uid 
    901901        if sim_flag or batch_flag: 
    902             for uid, value in self.page_finder.iteritems(): 
     902            for uid, value in self.page_finder.items(): 
    903903                if value.get_scheduled() == 1: 
    904                     if uid in self.fit_panel.opened_pages.keys(): 
     904                    if uid in self.fit_panel.opened_pages: 
    905905                        panel = self.fit_panel.opened_pages[uid] 
    906906                        panel._on_fit_complete() 
     
    919919        :param draw: Determine if the theory needs to be plot 
    920920        """ 
    921         if uid not in self.page_finder.keys(): 
     921        if uid not in self.page_finder: 
    922922            return 
    923923        self.page_finder[uid].enable_smearing(flag=enable_smearer) 
     
    930930                msg += "Got data = %s .\n" % str(data) 
    931931                return 
    932                 #raise ValueError, msg 
     932                #raise ValueError(msg) 
    933933            model = self.page_finder[uid].get_model(fid=fid) 
    934934            if model is None: 
     
    10321032        list_page_id = [] 
    10331033        fit_id = 0 
    1034         for page_id, page_info in self.page_finder.iteritems(): 
     1034        for page_id, page_info in self.page_finder.items(): 
    10351035            # For simulfit (uid give with None), do for-loop 
    10361036            # if uid is specified (singlefit), do it only on the page. 
     
    10591059 
    10601060                    pars = [str(element[1]) for element in page.param_toFit] 
    1061                     fitproblem_list = page_info.values() 
    1062                     for fitproblem in  fitproblem_list: 
     1061                    for fitproblem in page_info.values(): 
    10631062                        if sim_fitter is None: 
    10641063                            fitter = Fit() 
     
    10791078                wx.PostEvent(self.parent, evt) 
    10801079                return True 
    1081             except: 
     1080            except Exception as exc: 
    10821081                raise 
    1083                 msg = "Fitting error: %s" % str(sys.exc_value) 
     1082                msg = "Fitting error: %s" % exc 
    10841083                evt = StatusEvent(status=msg, info="error", type="stop") 
    10851084                wx.PostEvent(self.parent, evt) 
     
    11381137        :param fid: the id of the fitproblem(data, model, range,etc) 
    11391138        """ 
    1140         if uid not in self.page_finder.keys(): 
     1139        if uid not in self.page_finder: 
    11411140            return 
    11421141        fitproblemList = self.page_finder[uid].get_fit_problem(fid) 
     
    11831182                evt = StatusEvent(status=msg, info="warning") 
    11841183                wx.PostEvent(self.parent, evt) 
    1185         except Exception: 
    1186             msg = "Creating Fit page: %s" % sys.exc_value 
     1184        except Exception as exc: 
     1185            msg = "Creating Fit page: %s" % exc 
    11871186            wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 
    11881187 
     
    12641263        # case that uid is not specified 
    12651264        if uid is None: 
    1266             for page_id in self.page_finder.keys(): 
     1265            for page_id in self.page_finder: 
    12671266                self.page_finder[page_id].schedule_tofit(value) 
    12681267        # when uid is given 
    12691268        else: 
    1270             if uid in self.page_finder.keys(): 
     1269            if uid in self.page_finder: 
    12711270                self.page_finder[uid].schedule_tofit(value) 
    12721271 
     
    13021301        panel = self.plot_panel 
    13031302        if panel is None: 
    1304             raise ValueError, "Fitting:_onSelect: NonType panel" 
     1303            raise ValueError("Fitting:_onSelect: NonType panel") 
    13051304        Plugin.on_perspective(self, event=event) 
    13061305        self.select_data(panel) 
     
    13351334        """ 
    13361335        uid = page_id[0] 
    1337         if uid in self.fit_thread_list.keys(): 
     1336        if uid in self.fit_thread_list: 
    13381337            del self.fit_thread_list[uid] 
    13391338 
     
    13611360                #get all fittable parameters of the current model 
    13621361                for param in  model.getParamList(): 
    1363                     if param  not in batch_outputs.keys(): 
     1362                    if param  not in batch_outputs: 
    13641363                        batch_outputs[param] = [] 
    13651364                for param in model.getDispParamList(): 
    13661365                    if not model.is_fittable(param) and \ 
    1367                         param in batch_outputs.keys(): 
     1366                        param in batch_outputs: 
    13681367                        del batch_outputs[param] 
    13691368                # Add fitted parameters and their error 
    13701369                for param in res.param_list: 
    1371                     if param not in batch_outputs.keys(): 
     1370                    if param not in batch_outputs: 
    13721371                        batch_outputs[param] = [] 
    13731372                    err_param = "error on %s" % str(param) 
    1374                     if err_param not in batch_inputs.keys(): 
     1373                    if err_param not in batch_inputs: 
    13751374                        batch_inputs[err_param] = [] 
    13761375        msg = "" 
     
    15261525        model = fitproblem.get_model() 
    15271526        #fill batch result information 
    1528         if "Data" not in batch_outputs.keys(): 
     1527        if "Data" not in batch_outputs: 
    15291528            batch_outputs["Data"] = [] 
    15301529        cell = BatchCell() 
     
    15551554        cell.object = [data, theory_data] 
    15561555        batch_outputs["Data"].append(cell) 
    1557         for key, value in data.meta_data.iteritems(): 
    1558             if key not in batch_inputs.keys(): 
     1556        for key, value in data.meta_data.items(): 
     1557            if key not in batch_inputs: 
    15591558                batch_inputs[key] = [] 
    15601559            #if key.lower().strip() != "loader": 
     
    15621561        param = "temperature" 
    15631562        if hasattr(data.sample, param): 
    1564             if param not in  batch_inputs.keys(): 
     1563            if param not in  batch_inputs: 
    15651564                batch_inputs[param] = [] 
    15661565            batch_inputs[param].append(data.sample.temperature) 
     
    16331632                    wx.PostEvent(self.parent, evt) 
    16341633 
    1635         except Exception: 
    1636             msg = ("Fit completed but the following error occurred: %s" 
    1637                    % sys.exc_value) 
     1634        except Exception as exc: 
     1635            msg = "Fit completed but the following error occurred: %s" % exc 
    16381636            #msg = "\n".join((traceback.format_exc(), msg)) 
    16391637            evt = StatusEvent(status=msg, info="warning", type="stop") 
     
    17231721        if model is None: 
    17241722            return 
    1725         if uid not in self.page_finder.keys(): 
     1723        if uid not in self.page_finder: 
    17261724            return 
    17271725        # save the name containing the data name with the appropriate model 
     
    20802078                                  source=source) 
    20812079            self.calc_1D.queue() 
    2082         except: 
     2080        except Exception as exc: 
    20832081            msg = " Error occurred when drawing %s Model 1D: " % model.name 
    2084             msg += " %s" % sys.exc_value 
     2082            msg += " %s" % exc 
    20852083            wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    20862084 
  • 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) 
  • src/sas/sasgui/perspectives/pr/__init__.py

    r959eb01 r5251ec6  
    11PLUGIN_ID = "P(r) plug-in 1.0" 
    2 from pr import * 
     2from .pr import * 
  • src/sas/sasgui/perspectives/pr/explore_dialog.py

    r20fa5fe r5251ec6  
    3535from sas.sasgui.plottools.plottables import Graph 
    3636 
    37 from pr_widgets import PrTextCtrl 
     37from .pr_widgets import PrTextCtrl 
    3838 
    3939# Default number of points on the output plot 
     
    416416                results.pos_err.append(pos_err) 
    417417                results.osc.append(osc) 
    418             except: 
     418            except Exception as exc: 
    419419                # This inversion failed, skip this D_max value 
    420420                msg = "ExploreDialog: inversion failed " 
    421                 msg += "for D_max=%s\n%s" % (str(d), sys.exc_value) 
     421                msg += "for D_max=%s\n%s" % (str(d), exc) 
    422422                logger.error(msg) 
    423423 
  • src/sas/sasgui/perspectives/pr/inversion_panel.py

    rcb62bd5 r5251ec6  
    55__revision__ = "$Revision: 1193 $" 
    66 
    7 import wx 
    87import os 
    98import sys 
    109import logging 
     10 
     11import wx 
    1112from wx.lib.scrolledpanel import ScrolledPanel 
     13 
    1214from sas.sasgui.guiframe.events import StatusEvent 
    1315from sas.sasgui.guiframe.panel_base import PanelBase 
    14 from inversion_state import InversionState 
    15 from pr_widgets import PrTextCtrl 
    16 from pr_widgets import DataFileTextCtrl 
    17 from pr_widgets import OutputTextCtrl 
    1816from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
     17 
     18from .inversion_state import InversionState 
     19from .pr_widgets import PrTextCtrl 
     20from .pr_widgets import DataFileTextCtrl 
     21from .pr_widgets import OutputTextCtrl 
    1922 
    2023logger = logging.getLogger(__name__) 
     
    752755        except ValueError: 
    753756            logger.error("InversionControl._on_accept_alpha got a value that was not a number: %s" % alpha ) 
    754         except: 
     757        except Exception as exc: 
    755758            # No estimate or bad estimate, either do nothing 
    756             logger.error("InversionControl._on_accept_alpha: %s" % sys.exc_value) 
     759            logger.error("InversionControl._on_accept_alpha: %s" % exc) 
    757760 
    758761    def _on_accept_nterms(self, evt): 
     
    768771        except ValueError: 
    769772            logger.error("InversionControl._on_accept_nterms got a value that was not a number: %s" % nterms ) 
    770         except: 
     773        except Exception as exc: 
    771774            # No estimate or bad estimate, either do nothing 
    772             logger.error("InversionControl._on_accept_nterms: %s" % sys.exc_value) 
     775            logger.error("InversionControl._on_accept_nterms: %s" % exc) 
    773776 
    774777    def clear_panel(self): 
     
    901904                message += "than the number of points" 
    902905                wx.PostEvent(self._manager.parent, StatusEvent(status=message)) 
    903                 raise ValueError, message 
     906                raise ValueError(message) 
    904907            self.nfunc_ctl.SetBackgroundColour(wx.WHITE) 
    905908            self.nfunc_ctl.Refresh() 
     
    957960        Invoke the d_max exploration dialog 
    958961        """ 
    959         from explore_dialog import ExploreDialog 
     962        from .explore_dialog import ExploreDialog 
    960963        if self._manager._last_pr is not None: 
    961964            pr = self._manager._create_plot_pr() 
     
    10081011                self._on_invert(None) 
    10091012                self._set_analysis(True) 
    1010             except: 
    1011                 msg = "InversionControl._change_file: %s" % sys.exc_value 
     1013            except Exception as exc: 
     1014                msg = "InversionControl._change_file: %s" % exc 
    10121015                logger.error(msg) 
    10131016 
  • src/sas/sasgui/perspectives/pr/inversion_state.py

    r2469df7 r5251ec6  
    1818import logging 
    1919from lxml import etree 
     20 
    2021from sas.sasgui.guiframe.dataFitting import Data1D 
    2122from sas.sascalc.dataloader.readers.cansas_reader import Reader as CansasReader 
     
    238239            msg = "InversionState no longer supports non-CanSAS" 
    239240            msg += " format for P(r) files" 
    240             raise RuntimeError, msg 
     241            raise RuntimeError(msg) 
    241242 
    242243        if node.get('version') and node.get('version') == '1.0': 
     
    252253                try: 
    253254                    self.timestamp = float(entry.get('epoch')) 
    254                 except: 
     255                except Exception as exc: 
    255256                    msg = "InversionState.fromXML: Could not read " 
    256                     msg += "timestamp\n %s" % sys.exc_value 
     257                    msg += "timestamp\n %s" % exc 
    257258                    logger.error(msg) 
    258259 
     
    432433                state = InversionState() 
    433434                state.fromXML(node=nodes[0]) 
    434         except: 
     435        except Exception as exc: 
    435436            msg = "XML document does not contain P(r) " 
    436             msg += "information.\n %s" % sys.exc_value 
     437            msg += "information.\n %s" % exc 
    437438            logger.info(msg) 
    438439 
     
    481482                        output.append(sas_entry) 
    482483        else: 
    483             raise RuntimeError, "%s is not a file" % path 
     484            raise RuntimeError("%s is not a file" % path) 
    484485 
    485486        # Return output consistent with the loader's api 
     
    525526            msg = "The cansas writer expects a Data1D " 
    526527            msg += "instance: %s" % str(datainfo.__class__.__name__) 
    527             raise RuntimeError, msg 
     528            raise RuntimeError(msg) 
    528529 
    529530        # Create basic XML document 
  • src/sas/sasgui/perspectives/pr/pr.py

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

    rac07a3a r5251ec6  
    4141            # Thread was interrupted, just proceed 
    4242            pass 
    43         except: 
     43        except Exception as exc: 
    4444            if self.error_func is not None: 
    45                 self.error_func("CalcPr.compute: %s" % sys.exc_value) 
     45                self.error_func("CalcPr.compute: %s" % exc) 
    4646 
    4747class EstimatePr(CalcThread): 
     
    6969            # Thread was interrupted, just proceed 
    7070            pass 
    71         except: 
     71        except Exception as exc: 
    7272            if self.error_func is not None: 
    73                 self.error_func("EstimatePr.compute: %s" % sys.exc_value) 
     73                self.error_func("EstimatePr.compute: %s" % exc) 
    7474 
    7575class EstimateNT(CalcThread): 
     
    109109            # Thread was interrupted, just proceed 
    110110            pass 
    111         except: 
     111        except Exception as exc: 
    112112            if self.error_func is not None: 
    113                 self.error_func("EstimatePr2.compute: %s" % sys.exc_value) 
     113                self.error_func("EstimatePr2.compute: %s" % exc) 
  • src/sas/sasgui/perspectives/simulation/ShapeAdapter.py

    r959eb01 r5251ec6  
    8787            self.sim_canvas._model_changed() 
    8888        else: 
    89             raise ValueError, "SimShapeVisitor: Wrong class for visited object" 
     89            raise ValueError("SimShapeVisitor: Wrong class for visited object") 
    9090         
    9191         
     
    115115            self.sim_canvas._model_changed() 
    116116        else: 
    117             raise ValueError, "SimShapeVisitor: Wrong class for visited object" 
     117            raise ValueError("SimShapeVisitor: Wrong class for visited object") 
    118118         
    119119     
     
    130130            shape.accept_update(self) 
    131131        else: 
    132             raise ValueError, "ShapeAdapter: Shape [%s] not in list" % shape.name 
     132            raise ValueError("ShapeAdapter: Shape [%s] not in list" % shape.name) 
    133133 
  • src/sas/sasgui/perspectives/simulation/ShapeParameters.py

    ra1b8fee r5251ec6  
    1010from __future__ import print_function 
    1111 
     12import sys 
     13from copy import deepcopy 
     14 
    1215import wx 
    13 import sys 
    1416import wx.lib.newevent 
    15 from copy import deepcopy 
    16 import SimCanvas 
     17 
     18from . import SimCanvas 
    1719 
    1820(CreateShapeEvent, EVT_ADD_SHAPE) = wx.lib.newevent.NewEvent() 
     
    201203            n = 1 
    202204            self.parameters = [] 
    203             keys = shape.params.keys() 
    204             keys.sort() 
    205              
    206             for item in keys: 
     205             
     206            for item in sorted(shape.params.keys()): 
    207207                if item in ['contrast', 'order']: 
    208208                    continue 
     
    393393                if not tmp==None: 
    394394                    self.current_shape.params[item[0]] = tmp  
    395         except: 
     395        except Exception as exc: 
    396396            print("Could not create") 
    397             print(sys.exc_value) 
     397            print(exc) 
    398398                 
    399399    def _onCreate(self, evt): 
     
    489489            print("NOT YET IMPLMENTED") 
    490490            print("renaming", self.shape_listbox.GetString(indices[0])) 
    491                  
  • src/sas/sasgui/perspectives/simulation/__init__.py

    r959eb01 r5251ec6  
    11PLUGIN_ID = "Simulation plug-in 1.0" 
    2 from simulation import * 
     2from .simulation import * 
  • src/sas/sasgui/perspectives/simulation/simulation.py

    r7432acb r5251ec6  
    1515 
    1616# Application imports 
    17 import SimCanvas 
    18 import ShapeParameters 
    19 import ShapeAdapter 
     17from sas.sascalc.realspace import VolumeCanvas 
     18from sas.sascalc.data_util.calcthread import CalcThread 
    2019from sas.sasgui.guiframe.dataFitting import Data1D 
    21 # Real-space simulation import 
    22 import sas.sascalc.realspace.VolumeCanvas as VolumeCanvas 
    23  
    24 from sas.sascalc.data_util.calcthread import CalcThread 
    2520from sas.guicomm.events import NewPlotEvent, StatusEvent     
     21 
     22from . import SimCanvas 
     23from . import ShapeParameters 
     24from . import ShapeAdapter 
    2625 
    2726logger = logging.getLogger(__name__) 
  • src/sas/sasgui/plottools/LineModel.py

    ra26f67f r5251ec6  
    8383        elif x.__class__.__name__ == 'tuple': 
    8484            msg = "Tuples are not allowed as input to BaseComponent models" 
    85             raise ValueError, msg 
     85            raise ValueError(msg) 
    8686        else: 
    8787            return self._line(x) 
     
    105105        elif x.__class__.__name__ == 'tuple': 
    106106            msg = "Tuples are not allowed as input to BaseComponent models" 
    107             raise ValueError, msg 
     107            raise ValueError(msg) 
    108108        else: 
    109109            return self._line(x) 
  • src/sas/sasgui/plottools/PlotPanel.py

    r2469df7 r5251ec6  
    66import logging 
    77import traceback 
     8import math 
     9import os 
     10import operator 
     11import copy 
     12 
    813import wx 
     14import numpy as np 
     15 
    916# Try a normal import first 
    1017# If it fails, try specifying a version 
     
    1522from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg 
    1623from matplotlib.figure import Figure 
    17 import os 
    18 import transform 
    19 #TODO: make the plottables interactive 
    20 from binder import BindArtist 
    2124from matplotlib.font_manager import FontProperties 
    22 DEBUG = False 
    23  
    24 from plottables import Graph 
    25 from TextDialog import TextDialog 
    26 from LabelDialog import LabelDialog 
    27 import operator 
    28  
    29 import math 
    3025import pylab 
    3126DEFAULT_CMAP = pylab.cm.jet 
    32 import copy 
    33 import numpy as np 
    3427 
    3528from sas.sasgui.guiframe.events import StatusEvent 
     29 
     30#TODO: make the plottables interactive 
     31from . import transform 
     32from .TextDialog import TextDialog 
     33from .LabelDialog import LabelDialog 
     34from .binder import BindArtist 
     35from .convert_units import convert_unit 
     36from .plottables import Graph 
    3637from .toolbar import NavigationToolBar, PlotPrintout, bind 
    3738 
     39DEBUG = False 
    3840logger = logging.getLogger(__name__) 
    3941 
     
    4446        for a in obj.get_children(): show_tree(a, d + 1) 
    4547 
    46 from convert_units import convert_unit 
    4748 
    4849 
     
    116117        self.figure = Figure(None, dpi, linewidth=2.0) 
    117118        self.color = '#b3b3b3' 
    118         from canvas import FigureCanvas 
     119        from .canvas import FigureCanvas 
    119120        self.canvas = FigureCanvas(self, -1, self.figure) 
    120121        self.SetColor(color) 
     
    657658        else: 
    658659            plot_dict = plotlist 
    659         from fitDialog import LinearFit 
     660        from .fitDialog import LinearFit 
    660661 
    661662        if len(plot_dict.keys()) > 0: 
    662             first_item = plot_dict.keys()[0] 
     663            first_item = list(plot_dict.keys())[0] 
    663664            dlg = LinearFit(parent=None, plottable=first_item, 
    664665                            push_data=self.onFitDisplay, 
     
    703704 
    704705        """ 
    705         from fitDialog import LinearFit 
     706        from .fitDialog import LinearFit 
    706707        if self._fit_dialog is not None: 
    707708            return 
     
    736737            first_item = plot_list.keys()[0] 
    737738            if first_item.x != []: 
    738                 from PropertyDialog import Properties 
     739                from .PropertyDialog import Properties 
    739740                dial = Properties(self, -1, 'Properties') 
    740741                dial.setValues(self.prevXtrans, self.prevYtrans, self.viewModel) 
     
    10011002        Remove legend for ax or the current axes. 
    10021003        """ 
    1003         from pylab import gca 
    10041004        if ax is None: 
    1005             ax = gca() 
     1005            ax = pylab.gca() 
    10061006        ax.legend_ = None 
    10071007 
     
    13271327        if id is None: 
    13281328            id = name 
    1329         from plottable_interactor import PointInteractor 
     1329        from .plottable_interactor import PointInteractor 
    13301330        p = PointInteractor(self, self.subplot, zorder=zorder, id=id) 
    13311331        if p.markersize is not None: 
     
    13441344        if id is None: 
    13451345            id = name 
    1346         from plottable_interactor import PointInteractor 
     1346        from .plottable_interactor import PointInteractor 
    13471347        p = PointInteractor(self, self.subplot, zorder=zorder, id=id) 
    13481348        p.curve(x, y, dy=dy, color=color, symbol=symbol, zorder=zorder, 
     
    17541754            self.graph.delete(self.fit_result) 
    17551755            if hasattr(self, 'plots'): 
    1756                 if 'fit' in self.plots.keys(): 
     1756                if 'fit' in self.plots: 
    17571757                    del self.plots['fit'] 
    17581758        self.ly = None 
  • src/sas/sasgui/plottools/__init__.py

    refe730d r5251ec6  
    1 from PlotPanel import PlotPanel 
    2 from plottables import Data1D, Theory1D 
     1from .PlotPanel import PlotPanel 
     2from .plottables import Data1D, Theory1D 
  • src/sas/sasgui/plottools/binder.py

    r20fa5fe r5251ec6  
    2828        return self.artist is not other.artist 
    2929 
    30     def __nonzero__(self): 
     30    def __bool__(self): 
    3131        return self.artist is not None 
     32 
     33    __nonzero__ = __bool__ 
    3234 
    3335 
    3436class BindArtist(object): 
    3537    """ 
     38    Track keyboard modifiers for events. 
    3639    """ 
    37     # Track keyboard modifiers for events. 
    3840    # TODO: Move keyboard modifier support into the backend.  We cannot 
    3941    # TODO: properly support it from outside the windowing system since there 
     
    6567            ] 
    6668        except: 
    67             print("bypassing scroll_event: wrong matplotlib version") 
     69            logger.warn("bypassing scroll_event: wrong matplotlib version") 
    6870            self._connections = [ 
    6971                canvas.mpl_connect('motion_notify_event', self._onMotion), 
     
    7476            ] 
    7577 
     78        # Turn off picker if it hasn't already been done 
     79        try: 
     80            canvas.mpl_disconnect(canvas.button_pick_id) 
     81            canvas.mpl_disconnect(canvas.scroll_pick_id) 
     82        except Exception as exc: 
     83            logger.error(exc) 
     84 
    7685        self._current = None 
    7786        self._actions = {} 
     
    8796        Use clearall() to reset all connections. 
    8897        """ 
    89  
    9098        for h in artists: 
    9199            for a in self.events: 
     
    123131        """ 
    124132        try: 
    125             for cid in self._connections: self.canvas.mpl_disconnect(cid) 
    126         except: 
    127             logger.error("Error disconnection canvas: %s" % sys.exc_value) 
     133            for cid in self._connections: 
     134                self.canvas.mpl_disconnect(cid) 
     135        except Exception as exc: 
     136            logger.error("Error disconnection canvas: %s" % exc) 
    128137        self._connections = [] 
    129138 
     
    172181        sure it applies.  E.g., the callback for 'press' might be: 
    173182            if event.button == 1 and event.shift: process Shift-click 
    174  
    175         TODO: Only receive events with the correct modifiers (e.g., S-click, 
    176         TODO:   or *-click for any modifiers). 
    177         TODO: Only receive button events for the correct button (e.g., click1 
    178         TODO:   release3, or dclick* for any button) 
    179         TODO: Support virtual artist, so that and artist can be flagged as 
    180         TODO:   having a tag list and receive the correct events 
    181         TODO: Support virtual events for binding to button-3 vs shift button-1 
    182         TODO:   without changing callback code 
    183         TODO: Attach multiple callbacks to the same event? 
    184         TODO: Clean up interaction with toolbar modes 
    185         TODO: push/pushclear/pop context so that binding changes for 
    186              the duration 
    187         TODO:   e.g., to support ? context sensitive help 
    188         """ 
     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 
    189197        # Check that the trigger is valid 
    190198        if trigger not in self._actions: 
    191             raise ValueError, "%s invalid --- valid triggers are %s"\ 
    192                  % (trigger, ", ".join(self.events)) 
     199            raise ValueError("%s invalid --- valid triggers are %s" 
     200                % (trigger, ", ".join(self.events))) 
    193201 
    194202        # Register the trigger callback 
     
    205213        """ 
    206214        if action not in self.events: 
    207             raise ValueError, "Trigger expects " + ", ".join(self.events) 
     215            raise ValueError("Trigger expects " + ", ".join(self.events)) 
    208216 
    209217        # Tag the event with modifiers 
     
    214222        setattr(ev, 'prop', {}) 
    215223 
    216         # Fallback scheme.  If the event does not return false, pass to parent. 
     224        # Fallback scheme. If the event does not return false, pass to parent. 
    217225        processed = False 
    218226        artist, prop = actor.artist, actor.prop 
     
    237245        """ 
    238246        # TODO: sort by zorder of axes then by zorder within axes 
    239         self._artists.sort(cmp=lambda x, y: cmp(y.zorder, x.zorder)) 
     247        self._artists.sort(key=lambda x: x.zorder, reverse=True) 
    240248        found = Selection() 
    241249        for artist in self._artists: 
     
    276284 
    277285            transform = self._hasclick.artist.get_transform() 
    278             # x,y = event.xdata,event.ydata 
     286            #x,y = event.xdata,event.ydata 
    279287            x, y = event.x, event.y 
    280288            try: 
     
    286294                    # #transform ="CompositeGenericTransform" crash 
    287295                    pass 
    288             except: 
    289                 # # CRUFT matplotlib-0.91 support 
     296            except: # CRUFT: matplotlib-0.91 support 
    290297                # # exception for transform ="CompositeGenericTransform" 
    291298                # # crashes also here 
    292299                x, y = transform.inverse_xy_tup((x, y)) 
    293300 
    294             # event.xdata, event.ydata = x, y 
     301            #TODO: why compute (x,y) if it isn't being used? 
     302            #event.xdata, event.ydata = x, y 
    295303            self.trigger(self._hasclick, 'drag', event) 
    296304        else: 
  • src/sas/sasgui/plottools/canvas.py

    r7432acb r5251ec6  
    9797        try: 
    9898            dc.DrawBitmap(self.canvas.bitmap, (0, 0)) 
    99         except: 
    100             logger.error(sys.exc_value) 
     99        except Exception as exc: 
     100            logger.error(exc) 
    101101 
    102102    # restore original figure  resolution 
     
    208208            try: 
    209209                fig.draw(self) 
    210             except ValueError: 
    211                 logger.error(sys.exc_value) 
     210            except ValueError as exc: 
     211                logger.error(exc) 
    212212        else: 
    213213            self._isRendered = False 
  • src/sas/sasgui/plottools/convert_units.py

    ra1b8fee r5251ec6  
    1313    """ 
    1414    if power != 0: 
    15         if string.find(unit, "^") != -1:  # if the unit contains a powerer ^ 
    16             toks = re.split("\^", unit) 
    17             if string.find(toks[0], "/") != -1 or \ 
    18                 string.find(toks[0], "-") != -1: 
     15        if unit.find("^") != -1:  # if the unit contains a powerer ^ 
     16            toks = re.split(r"\^", unit) 
     17            if toks[0].find("/") != -1 or \ 
     18                toks[0].find("-") != -1: 
    1919                if power == 1: 
    2020                    unit = unit 
     
    2222                    unit = "(" + unit + ")" + "^{" + str(power) + "}" 
    2323            else: 
    24                 if string.find(toks[1], "{") != -1:  # if found a { 
     24                if toks[1].find("{") != -1:  # if found a { 
    2525                    find_power_toks = re.split("{", toks[1]) 
    26                     if string.find(find_power_toks[1], "}") != -1:  # found } 
     26                    if find_power_toks[1].find("}") != -1:  # found } 
    2727                        unit_toks = re.split("}", find_power_toks[1]) 
    28                         if string.find(unit_toks[0], ".") != -1: 
     28                        if unit_toks[0].find(".") != -1: 
    2929                            powerer = float(unit_toks[0]) * power 
    30                         elif string.find(unit_toks[0], "/") != -1: 
     30                        elif unit_toks[0].find("/") != -1: 
    3131                            power_toks = re.split("/", unit_toks[0]) 
    3232                            powerer = power * int(power_toks[0])\ 
     
    4444                            unit = toks[0] + "^{" + str(powerer) + "}" 
    4545                else: 
    46                     raise ValueError, "missing } in unit expression" 
     46                    raise ValueError("missing } in unit expression") 
    4747        else:  # no powerer 
    4848            if  power != 1: 
    4949                unit = "(" + unit + ")" + "^{" + str(power) + "}" 
    5050    else: 
    51         raise ValueError, "empty unit ,enter a powerer different from zero" 
     51        raise ValueError("empty unit, enter a power different from zero") 
    5252    return unit 
    5353 
  • src/sas/sasgui/plottools/fitDialog.py

    r2469df7 r5251ec6  
     1import sys 
     2import math 
     3 
    14import wx 
    2 from plottables import Theory1D 
    3 import math 
    45import numpy as np 
    5 import fittings 
    6 import transform 
    7 import sys 
     6 
     7from . import fittings 
     8from . import transform 
     9from .plottables import Theory1D 
    810 
    911# Linear fit panel size 
     
    8688        self.layout() 
    8789        # Receives the type of model for the fitting 
    88         from LineModel import LineModel 
     90        from .LineModel import LineModel 
    8991        self.model = LineModel() 
    9092        # Display the fittings values 
     
    671673                return x 
    672674            else: 
    673                 raise ValueError, "cannot compute log of a negative number" 
     675                raise ValueError("cannot compute log of a negative number") 
    674676 
    675677    def floatInvTransform(self, x): 
     
    734736        except: 
    735737            msg = "LinearFit.set_fit_region: fit range must be floats" 
    736             raise ValueError, msg 
     738            raise ValueError(msg) 
    737739        self.xminFit.SetValue(format_number(xmin)) 
    738740        self.xmaxFit.SetValue(format_number(xmax)) 
  • src/sas/sasgui/plottools/fittings.py

    ra1b8fee r5251ec6  
    101101    # Testing implementation 
    102102    # Fit a Line model 
    103     from LineModel import LineModel 
     103    from .LineModel import LineModel 
    104104    line = LineModel() 
    105105    cstA = Parameter(line, 'A', event.cstA) 
  • src/sas/sasgui/plottools/plottable_interactor.py

    r2469df7 r5251ec6  
    44from __future__ import print_function 
    55 
    6 from BaseInteractor import _BaseInteractor 
     6from .BaseInteractor import _BaseInteractor 
    77 
    88 
  • src/sas/sasgui/plottools/plottables.py

    r2469df7 r5251ec6  
    389389 
    390390        """ 
    391         raise NotImplemented, "Not a valid transform" 
     391        raise NotImplemented("Not a valid transform") 
    392392 
    393393    # Related issues 
     
    689689                msg = "Plottable.View: Given x and dx are not" 
    690690                msg += " of the same length" 
    691                 raise ValueError, msg 
     691                raise ValueError(msg) 
    692692            # Check length of y array 
    693693            if not len(y) == len(x): 
    694694                msg = "Plottable.View: Given y " 
    695695                msg += "and x are not of the same length" 
    696                 raise ValueError, msg 
     696                raise ValueError(msg) 
    697697 
    698698            if dy is not None and not len(dy) == 0 and not len(y) == len(dy): 
    699699                msg = "Plottable.View: Given y and dy are not of the same " 
    700700                msg += "length: len(y)=%s, len(dy)=%s" % (len(y), len(dy)) 
    701                 raise ValueError, msg 
     701                raise ValueError(msg) 
    702702            self.x = [] 
    703703            self.y = [] 
     
    734734                msg = "Plottable.View: transformed x " 
    735735                msg += "and y are not of the same length" 
    736                 raise ValueError, msg 
     736                raise ValueError(msg) 
    737737            if has_err_x and not (len(self.x) == len(self.dx)): 
    738738                msg = "Plottable.View: transformed x and dx" 
    739739                msg += " are not of the same length" 
    740                 raise ValueError, msg 
     740                raise ValueError(msg) 
    741741            if has_err_y and not (len(self.y) == len(self.dy)): 
    742742                msg = "Plottable.View: transformed y" 
    743743                msg += " and dy are not of the same length" 
    744                 raise ValueError, msg 
     744                raise ValueError(msg) 
    745745            # Check that negative values are not plot on x and y axis for 
    746746            # log10 transformation 
     
    812812                        tempy.append(self.y[i]) 
    813813                        tempdy.append(self.dy[i]) 
    814                 except: 
     814                except Exception as exc: 
    815815                    logger.error("check_data_logX: skipping point x %g", self.x[i]) 
    816                     logger.error(sys.exc_value) 
     816                    logger.error(exc) 
    817817            self.x = tempx 
    818818            self.y = tempy 
     
    842842                        tempy.append(self.y[i]) 
    843843                        tempdy.append(self.dy[i]) 
    844                 except: 
     844                except Exception as exc: 
    845845                    logger.error("check_data_logY: skipping point %g", self.y[i]) 
    846                     logger.error(sys.exc_value) 
     846                    logger.error(exc) 
    847847 
    848848            self.x = tempx 
     
    996996            self.zmax = zmax 
    997997        else: 
    998             raise "zmin is greater or equal to zmax " 
     998            raise("zmin is greater or equal to zmax ") 
    999999 
    10001000    def render(self, plot, **kw): 
     
    11081108        Plottable.__init__(self) 
    11091109        msg = "Theory1D is no longer supported, please use Data1D and change symbol.\n" 
    1110         raise DeprecationWarning, msg 
     1110        raise DeprecationWarning(msg) 
    11111111 
    11121112class Fit1D(Plottable): 
  • src/sas/sasgui/plottools/toolbar.py

    r20fa5fe r5251ec6  
    6565                           'Forward', 'Forward navigation view') 
    6666        # todo: get new bitmap 
    67         self.AddCheckTool(self._NTB2_PAN, _load_bitmap('move.png'), 
    68                           shortHelp='Pan', 
    69                           longHelp='Pan with left, zoom with right') 
    70         self.AddCheckTool(self._NTB2_ZOOM, _load_bitmap('zoom_to_rect.png'), 
    71                           shortHelp='Zoom', longHelp='Zoom to rectangle') 
     67        # todo: update with code from matplotlib/backends/backend_wx.py 
     68        is_phoenix = 'phoenix' in wx.PlatformInfo 
     69        if is_phoenix: # wx phoenix >= 4.0.0b2 
     70            self.AddCheckTool(self._NTB2_PAN, "Pan", _load_bitmap('move.png'), 
     71                              shortHelp='Pan', 
     72                              longHelp='Pan with left, zoom with right') 
     73            self.AddCheckTool(self._NTB2_ZOOM, "Zoom", _load_bitmap('zoom_to_rect.png'), 
     74                              shortHelp='Zoom', longHelp='Zoom to rectangle') 
     75        else: 
     76            self.AddCheckTool(self._NTB2_PAN, _load_bitmap('move.png'), 
     77                              shortHelp='Pan', 
     78                              longHelp='Pan with left, zoom with right') 
     79            self.AddCheckTool(self._NTB2_ZOOM, _load_bitmap('zoom_to_rect.png'), 
     80                              shortHelp='Zoom', longHelp='Zoom to rectangle') 
    7281 
    7382        self.AddSeparator() 
  • src/sas/sasgui/plottools/transform.py

    r7432acb r5251ec6  
    2424    """ 
    2525    if not x > 0: 
    26         raise ValueError, "Transformation only accepts positive values." 
     26        raise ValueError("Transformation only accepts positive values.") 
    2727    else: 
    2828        return x 
     
    5050    """ 
    5151    if not x >= 0: 
    52         raise ValueError, "square root of a negative value " 
     52        raise ValueError("square root of a negative value ") 
    5353    else: 
    5454        return math.sqrt(x) 
     
    7676    """ 
    7777    if not x >= 0: 
    78         raise ValueError, "double square root of a negative value " 
     78        raise ValueError("double square root of a negative value ") 
    7979    else: 
    8080        return math.sqrt(math.sqrt(x)) 
     
    9090    """ 
    9191    if not x > 0: 
    92         raise ValueError, "Log(x)of a negative value " 
     92        raise ValueError("Log(x)of a negative value ") 
    9393    else: 
    9494        return math.log(x) 
     
    100100        return 1 / x 
    101101    else: 
    102         raise ValueError, "cannot divide by zero" 
     102        raise ValueError("cannot divide by zero") 
    103103 
    104104 
     
    109109        return 1 / math.sqrt(y) 
    110110    else: 
    111         raise ValueError, "transform.toOneOverSqrtX: cannot be computed" 
     111        raise ValueError("transform.toOneOverSqrtX: cannot be computed") 
    112112 
    113113 
     
    118118        return math.log(y * (x ** 2)) 
    119119    else: 
    120         raise ValueError, "transform.toLogYX2: cannot be computed" 
     120        raise ValueError("transform.toLogYX2: cannot be computed") 
    121121 
    122122 
     
    127127        return math.log(math.pow(x, 4) * y) 
    128128    else: 
    129         raise ValueError, "transform.toLogYX4: input error" 
     129        raise ValueError("transform.toLogYX4: input error") 
    130130 
    131131 
     
    149149    """ 
    150150    if not (x * y) > 0: 
    151         raise ValueError, "Log(X*Y)of a negative value " 
     151        raise ValueError("Log(X*Y)of a negative value ") 
    152152    else: 
    153153        return math.log(x * y) 
     
    211211    else: 
    212212        msg = "transform.errFromX2: can't compute error of negative x" 
    213         raise ValueError, msg 
     213        raise ValueError(msg) 
    214214 
    215215 
     
    245245    else: 
    246246        msg = "transform.errFromX4: can't compute error of negative x" 
    247         raise ValueError, msg 
     247        raise ValueError(msg) 
    248248 
    249249 
     
    264264        msg = "Transformation does not accept" 
    265265        msg += " point that are consistent with zero." 
    266         raise ValueError, msg 
     266        raise ValueError(msg) 
    267267    if x != 0: 
    268268        dx = dx / (x * math.log(10)) 
    269269    else: 
    270         raise ValueError, "errToLogX: divide by zero" 
     270        raise ValueError("errToLogX: divide by zero") 
    271271    return dx 
    272272 
     
    287287        dx = dx / x 
    288288    else: 
    289         raise ValueError, "errToLogX: divide by zero" 
     289        raise ValueError("errToLogX: divide by zero") 
    290290    return dx 
    291291 
     
    312312        msg = "Transformation does not accept point " 
    313313        msg += " that are consistent with zero." 
    314         raise ValueError, msg 
     314        raise ValueError(msg) 
    315315    if x != 0 and y != 0: 
    316316        if dx is None: 
     
    320320        err = (dx / x) ** 2 + (dy / y) ** 2 
    321321    else: 
    322         raise ValueError, "cannot compute this error" 
     322        raise ValueError("cannot compute this error") 
    323323 
    324324    return math.sqrt(math.fabs(err)) 
     
    335335        msg = "Transformation does not accept point" 
    336336        msg += " that are consistent with zero." 
    337         raise ValueError, msg 
     337        raise ValueError(msg) 
    338338    if x > 0 and y > 0: 
    339339        if dx is None: 
     
    343343        err = (2.0 * dx / x) ** 2 + (dy / y) ** 2 
    344344    else: 
    345         raise ValueError, "cannot compute this error" 
     345        raise ValueError("cannot compute this error") 
    346346    return math.sqrt(math.fabs(err)) 
    347347 
     
    357357        err = dx / x ** 2 
    358358    else: 
    359         raise ValueError, "Cannot compute this error" 
     359        raise ValueError("Cannot compute this error") 
    360360    return math.fabs(err) 
    361361 
     
    371371        err = -1 / 2 * math.pow(x, -3.0 / 2.0) * dx 
    372372    else: 
    373         raise ValueError, "Cannot compute this error" 
     373        raise ValueError("Cannot compute this error") 
    374374    return math.fabs(err) 
    375375 
     
    387387        msg = "Transformation does not accept point " 
    388388        msg += " that are consistent with zero." 
    389         raise ValueError, msg 
     389        raise ValueError(msg) 
    390390    if dx is None: 
    391391        dx = 0 
  • src/sas/sasview/sasview.py

    r1270e3c r5251ec6  
    4242 
    4343        from sas.sasgui.guiframe.gui_manager import SasViewApp 
     44        from sas.sasgui.guiframe.gui_style import GUIFRAME_ICON 
    4445        self.gui = SasViewApp(0) 
     46        GUIFRAME_ICON.load_icons() 
    4547        if sys.platform == "darwin": 
    4648            self.check_sasmodels_compiler() 
     
    228230        logger.error("Wx version: error reading version") 
    229231 
    230     from . import wxcruft 
    231     wxcruft.call_later_fix() 
     232    # TODO: Do we need the call later fix for wx 3? Or is it wx < 3 only? 
     233    if "phoenix" in wx.PlatformInfo: 
     234        #wx.NewId = wx.Window.NewControlId 
     235        pass 
     236    else: 
     237        from . import wxcruft 
     238        wxcruft.call_later_fix() 
    232239    #wxcruft.trace_new_id() 
    233240    #Always use private .matplotlib setup to avoid conflicts with other 
  • src/sas/sasview/welcome_panel.py

    rb963b20 r5251ec6  
    22    Welcome page 
    33""" 
    4 import wx 
    5 import wx.aui 
    6 import wx.lib.hyperlink 
    74import os.path 
    85import os, sys 
    96 
     7import wx 
     8import wx.aui 
     9try: 
     10    # CRUFT: wx 4 moved hyperlink to wx.lib.agw 
     11    from wx.lib import hyperlink 
     12except ImportError: 
     13    from wx.lib.agw import hyperlink 
    1014from wx.lib.scrolledpanel import ScrolledPanel 
    1115 
     
    115119        send_ticket += "help@sasview.org" 
    116120        self.hyperlink_paper = \ 
    117             wx.lib.hyperlink.HyperLinkCtrl(self, -1, 
     121            hyperlink.HyperLinkCtrl(self, -1, 
    118122                                           send_ticket, URL=config._license) 
    119123 
  • src/sas/sasview/wxcruft.py

    r914ba0a r5251ec6  
    44import wx 
    55from wx import Timer 
    6 import wx._misc 
    76 
    87def call_later_fix(): 
     
    1615 
    1716def NewId(): 
     17    import wx._misc 
    1818    id = wx._misc.NewId() 
    1919    path, line, function = _get_caller() 
Note: See TracChangeset for help on using the changeset viewer.