Ignore:
Timestamp:
Oct 23, 2017 11:39:16 AM (4 years ago)
Author:
vondreele
Message:

make GSAS-II python 3.6 compliant & preserve python 2.7 use;changes:
do from future import division, print_function for all GSAS-II py sources
all menu items revised to be py 2.7/3.6 compliant
all wx.OPEN --> wx.FD_OPEN in file dialogs
all integer divides (typically for image pixel math) made explicit with ; ambiguous ones made floats as appropriate
all print "stuff" --> print (stuff)
all print >> pFile,'stuff' --> pFile.writeCIFtemplate('stuff')
all read file opens made explicit 'r' or 'rb'
all cPickle imports made for py2.7 or 3.6 as cPickle or _pickle; test for '2' platform.version_tuple[0] for py 2.7
define cPickleload to select load(fp) or load(fp,encoding='latin-1') for loading gpx files; provides cross compatibility between py 2.7/3.6 gpx files
make dict.keys() as explicit list(dict.keys()) as needed (NB: possible source of remaining py3.6 bugs)
make zip(a,b) as explicit list(zip(a,b)) as needed (NB: possible source of remaining py3.6 bugs)
select unichr/chr according test for '2' platform.version_tuple[0] for py 2.7 (G2pwdGUI * G2plot) for special characters
select wg.EVT_GRID_CELL_CHANGE (classic) or wg.EVT_GRID_CELL_CHANGED (phoenix) in grid Bind
maxint --> maxsize; used in random number stuff
raise Exception,"stuff" --> raise Exception("stuff")
wx 'classic' sizer.DeleteWindows?() or 'phoenix' sizer.Clear(True)
wx 'classic' SetToolTipString?(text) or 'phoenix' SetToolTip?(wx.ToolTip?(text)); define SetToolTipString?(self,text) to handle the choice in plots
status.SetFields? --> status.SetStatusText?
'classic' AddSimpleTool? or 'phoenix' self.AddTool? for plot toolbar; Bind different as well
define GetItemPydata? as it doesn't exist in wx 'phoenix'
allow python versions 2.7 & 3.6 to run GSAS-II
Bind override commented out - no logging capability (NB: remove all logging code?)
all import ContentsValidator? open filename & test if valid then close; filepointer removed from Reader
binary importers (mostly images) test for 'byte' type & convert as needed to satisfy py 3.6 str/byte rules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIscriptable.py

    r3130 r3136  
    459459        print(u'**** ERROR: '+reader+u' is not a scriptable reader')
    460460        return None
    461     fl = open(filename,'rb')
    462461    rdlist = []
    463     if rd.ContentsValidator(fl):
    464         fl.seek(0)
     462    if rd.ContentsValidator(filename):
    465463        repeat = True
    466464        rdbuffer = {} # create temporary storage for file reader
     
    470468            repeat = False
    471469            rd.objname = ospath.basename(filename)
    472             flag = rd.Reader(filename,fl,None,buffer=rdbuffer,blocknum=block,)
     470            flag = rd.Reader(filename,None,buffer=rdbuffer,blocknum=block,)
    473471            if flag:
    474472                rdlist.append(copy.deepcopy(rd)) # save the result before it is written over
     
    617615            if atom[ct] in generalData['Isotope']:
    618616                if generalData['Isotope'][atom[ct]] not in generalData['Isotopes'][atom[ct]]:
    619                     isotope = generalData['Isotopes'][atom[ct]].keys()[-1]
     617                    isotope = list(generalData['Isotopes'][atom[ct]].keys())[-1]
    620618                    generalData['Isotope'][atom[ct]] = isotope
    621619                generalData['AtomMass'].append(Info['Isotopes'][generalData['Isotope'][atom[ct]]]['Mass'])
     
    623621                generalData['Isotope'][atom[ct]] = 'Nat. Abund.'
    624622                if 'Nat. Abund.' not in generalData['Isotopes'][atom[ct]]:
    625                     isotope = generalData['Isotopes'][atom[ct]].keys()[-1]
     623                    isotope = list(generalData['Isotopes'][atom[ct]].keys())[-1]
    626624                    generalData['Isotope'][atom[ct]] = isotope
    627625                generalData['AtomMass'].append(Info['Mass'])
     
    725723            rd.ReInitialize()
    726724            # Rewind file
    727             fp.seek(0)
    728725            rd.errors = ""
    729             if not rd.ContentsValidator(fp):
     726            if not rd.ContentsValidator(filename):
    730727                # Report error
    731728                pass
     
    737734            block = 0
    738735            rdbuffer = {}
    739             fp.seek(0)
    740736            repeat = True
    741737            while repeat:
     
    744740                rd.objname = os.path.basename(filename)
    745741                try:
    746                     flag = rd.Reader(filename, fp, buffer=rdbuffer, blocknum=block)
     742                    flag = rd.Reader(filename,buffer=rdbuffer, blocknum=block)
    747743                except:
    748744                    flag = False
     
    823819    valuesdict = {'wtFactor': 1.0,
    824820                  'Dummy': False,
    825                   'ranId': ran.randint(0, sys.maxint),
     821                  'ranId': ran.randint(0, sys.maxsize),
    826822                  'Offset': [0.0, 0.0], 'delOffset': 0.02*Ymax,
    827823                  'refOffset': -0.1*Ymax, 'refDelt': 0.1*Ymax,
     
    897893    elif isinstance(from_, list) and isinstance(into, list):
    898894        if len(from_) == len(into):
    899             for i in xrange(len(from_)):
     895            for i in range(len(from_)):
    900896                both_dicts = (isinstance(from_[i], dict)
    901897                              and isinstance(into[i], dict))
Note: See TracChangeset for help on using the changeset viewer.