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

improved support for py37 in sasgui

File:
1 edited

Legend:

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