Ignore:
Timestamp:
Oct 23, 2017 11:39:16 AM (6 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/GSASIIconstrGUI.py

    r3079 r3136  
    1515
    1616'''
     17from __future__ import division, print_function
    1718import sys
    1819import wx
     
    158159                    j += 1
    159160        if j:
    160             print str(key) + ': '+str(j)+' variable(s) as strings converted to objects'
     161            print (str(key) + ': '+str(j)+' variable(s) as strings converted to objects')
    161162    ##################################################################################
    162163    rigidbodyDict = G2frame.GPXtree.GetItemPyData(
     
    165166    rbVary,rbDict = G2stIO.GetRigidBodyModels(rigidbodyDict,Print=False)
    166167    badPhaseParms = ['Ax','Ay','Az','Amul','AI/A','Atype','SHorder','mV0','mV1','mV2','waveType','Vol','isMag',]
    167     globalList = rbDict.keys()
     168    globalList = list(rbDict.keys())
    168169    globalList.sort()
    169170    try:
     
    385386            pass
    386387        else:
    387             raise Exception, 'Unknown constraint page '+ page[1]                   
     388            raise Exception('Unknown constraint page '+ page[1])                   
    388389        if len(choices):
    389390            l1 = l2 = 1
     
    487488                return [constr+[1.0,None,'c']]
    488489            else:
    489                 raise Exception,'Unknown constraint type: '+str(constType)
     490                raise Exception('Unknown constraint type: '+str(constType))
    490491        else:
    491492            dlg = wx.MessageDialog(
     
    537538            errmsg,warnmsg = CheckConstraints(allcons1)
    538539            if errmsg:
    539                 print errmsg
    540                 print G2mv.VarRemapShow([],True)
     540                print (errmsg)
     541                print (G2mv.VarRemapShow([],True))
    541542            return False
    542543        elif warnmsg:
    543             print 'Unexpected contraint warning:\n',warnmsg
     544            print ('Unexpected contraint warning:\n'+warnmsg)
    544545        return True
    545546
     
    566567            errmsg,warnmsg = CheckConstraints(allcons1)
    567568            if errmsg:
    568                 print errmsg
    569                 print G2mv.VarRemapShow([],True)
     569                print (errmsg)
     570                print (G2mv.VarRemapShow([],True))
    570571            return False
    571572        elif warnmsg:
    572             print 'Unexpected contraint warning:\n',warnmsg
     573            print ('Unexpected contraint warning:\n'+warnmsg)
    573574        return True
    574575             
     
    594595            return None,None,None
    595596        else:
    596             raise Exception,'Should not happen!'
     597            raise Exception('Should not happen!')
    597598        return vartype,varList,constrDictEnt
    598599
     
    771772            if atName in Atoms:
    772773                Atoms[atName].append(item)
    773         AtNames = Atoms.keys()
     774        AtNames = list(Atoms.keys())
    774775        AtNames.sort()
    775776        dlg = G2G.G2SingleChoiceDialog(G2frame,'Select 1st atom:',
     
    788789        dlg.Destroy()
    789790        if FrstAtom == '':
    790             print 'no atom selected'
     791            print ('no atom selected')
    791792            return
    792793        dlg = G2G.G2MultiChoiceDialog(
     
    797798            Selections = dlg.GetSelections()[:]
    798799        else:
    799             print 'no target atom selected'
     800            print ('no target atom selected')
    800801            dlg.Destroy()
    801802            return
     
    949950                    typeString = 'EQUIV'
    950951                else:
    951                     print 'Unexpected constraint',item
     952                    print ('Unexpected constraint'+item)
    952953               
    953954            else:
    954                 print 'Removing old-style constraints'
     955                print ('Removing old-style constraints')
    955956                data[name] = []
    956957                return constSizer
     
    10461047        except:
    10471048            import traceback
    1048             print traceback.format_exc()
     1049            print (traceback.format_exc())
    10491050        finally:
    10501051            dlg.Destroy()
     
    10921093            if 'DELETED' in str(PhaseConstr):   #seems to be no other way to do this (wx bug)
    10931094                if GSASIIpath.GetConfigValue('debug'):
    1094                     print 'wx error: PhaseConstr not cleanly deleted after Refine'
     1095                    print ('wx error: PhaseConstr not cleanly deleted after Refine')
    10951096                return
    10961097            UpdateConstraintPanel(PhaseConstr,'Phase')
     
    11671168                            'Error in constraints:\n'+errmsg+'\nCheck console output for more information',
    11681169                            parent=G2frame)
    1169         print errmsg
    1170         print G2mv.VarRemapShow([],True)
     1170        print (errmsg)
     1171        print (G2mv.VarRemapShow([],True))
    11711172    elif warnmsg:
    1172         print 'Unexpected contraint warning:\n',warnmsg
     1173        print ('Unexpected contraint warning:\n'+warnmsg)
    11731174
    11741175################################################################################
     
    13521353        dlg = wx.FileDialog(G2frame,message='Choose '+macName+' rigid body macro file',
    13531354            defaultDir=defDir,defaultFile="",wildcard="GSAS-II macro file (*.mac)|*.mac",
    1354             style=wx.OPEN | wx.CHANGE_DIR)
     1355            style=wx.FD_OPEN | wx.CHANGE_DIR)
    13551356        try:
    13561357            if dlg.ShowModal() == wx.ID_OK:
     
    13591360                head = macro.readline()
    13601361                if macName not in head:
    1361                     print head
    1362                     print '**** ERROR - wrong restraint macro file selected, try again ****'
     1362                    print (head)
     1363                    print ('**** ERROR - wrong restraint macro file selected, try again ****')
    13631364                    macro = []
    13641365            else: # cancel was pressed
     
    13721373            "GSAS-II text file (*.txt)|*.txt|XYZ file (*.xyz)|*.xyz|"
    13731374            "Sybyl mol2 file (*.mol2)|*.mol2|PDB file (*.pdb;*.ent)|*.pdb;*.ent",
    1374             wx.OPEN | wx.CHANGE_DIR)
     1375            wx.FD_OPEN | wx.CHANGE_DIR)
    13751376        try:
    13761377            if dlg.ShowModal() == wx.ID_OK:
     
    13991400        if dlg.ShowModal() == wx.ID_OK:
    14001401            nAtoms,nTrans = dlg.GetValues()
    1401             rbId = ran.randint(0,sys.maxint)
     1402            rbId = ran.randint(0,sys.maxsize)
    14021403            vecMag = [1.0 for i in range(nTrans)]
    14031404            vecRef = [False for i in range(nTrans)]
     
    14211422            items = macStr.split()
    14221423            if 'I' == items[0]:
    1423                 rbId = ran.randint(0,sys.maxint)
     1424                rbId = ran.randint(0,sys.maxsize)
    14241425                rbName = items[1]
    14251426                rbTypes = []
     
    14541455                    'SelSeq':[0,0],'useCount':0}
    14551456                data['RBIds']['Residue'].append(rbId)
    1456                 print 'Rigid body '+rbName+' added'
     1457                print ('Rigid body '+rbName+' added')
    14571458            macStr = macro.readline()
    14581459        macro.close()
     
    14641465        if not text:
    14651466            return
    1466         rbId = ran.randint(0,sys.maxint)
     1467        rbId = ran.randint(0,sys.maxsize)
    14671468        rbTypes = []
    14681469        rbXYZ = []
     
    15231524                'atNames':atNames,'rbRef':[0,1,2,False],'rbSeq':[],'SelSeq':[0,0],'useCount':0}
    15241525            data['RBIds']['Residue'].append(rbId)
    1525             print 'Rigid body UNKRB added'
     1526            print ('Rigid body UNKRB added')
    15261527        text.close()
    15271528        UpdateResidueRB()
     
    15651566                       
    15661567    def OnDefineTorsSeq(event):
    1567         rbKeys = data['Residue'].keys()
     1568        rbKeys = list(data['Residue'].keys())
    15681569        rbKeys.remove('AtInfo')
    15691570        rbNames = [data['Residue'][k]['RBname'] for k in rbKeys]
     
    15721573        rbId = 0
    15731574        if len(rbNames) == 0:
    1574             print 'There are no rigid bodies defined'
     1575            print ('There are no rigid bodies defined')
    15751576            G2frame.ErrorDialog('No rigid bodies','There are no rigid bodies defined',
    15761577                                parent=G2frame)
     
    16171618        if 'DELETED' in str(G2frame.GetStatusBar()):   #seems to be no other way to do this (wx bug)
    16181619            if GSASIIpath.GetConfigValue('debug'):
    1619                 print 'wx error: Rigid Body/Status not cleanly deleted after Refine'
     1620                print ('wx error: Rigid Body/Status not cleanly deleted after Refine')
    16201621            return
    16211622        SetStatusLine(' You may use e.g. "c60" or "s60" for a vector entry')
     
    17701771            vecGrid = G2G.GSGrid(VectorRBDisplay)
    17711772            vecGrid.SetTable(vecTable, True)
    1772             vecGrid.Bind(wg.EVT_GRID_CELL_CHANGE, ChangeCell)
     1773            if 'phoenix' in wx.version():
     1774                vecGrid.Bind(wg.EVT_GRID_CELL_CHANGED, ChangeCell)
     1775            else:
     1776                vecGrid.Bind(wg.EVT_GRID_CELL_CHANGE, ChangeCell)
    17731777            if not imag:
    17741778                vecGrid.Bind(wg.EVT_GRID_CELL_LEFT_DCLICK, TypeSelect)
     
    19681972            resList.append(vecGrid)
    19691973            vecGrid.SetTable(vecTable, True)
    1970             vecGrid.Bind(wg.EVT_GRID_CELL_CHANGE, ChangeCell)
     1974            if 'phoenix' in wx.version():
     1975                vecGrid.Bind(wg.EVT_GRID_CELL_CHANGED, ChangeCell)
     1976            else:
     1977                vecGrid.Bind(wg.EVT_GRID_CELL_CHANGE, ChangeCell)
    19711978            vecGrid.Bind(wg.EVT_GRID_CELL_LEFT_DCLICK, TypeSelect)
    19721979            vecGrid.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK, RowSelect)
Note: See TracChangeset for help on using the changeset viewer.