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

improved support for py37 in sasgui

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/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 
Note: See TracChangeset for help on using the changeset viewer.