Changeset 3136 for trunk/GSASIIlog.py


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/GSASIIlog.py

    r3023 r3136  
    1515such as menu item, tree item, button press, value change and so on.
    1616'''
     17from __future__ import division, print_function
    1718try:
    1819    import wx
     
    8990        self.indexRefs = indexRefs
    9091        self.value = value
    91         if debug: print 'Logging var change: w/treeRefs',treeRefs,'indexRefs',indexRefs,'new value=',value
     92        if debug: print ('Logging var change: w/treeRefs',treeRefs,'indexRefs',indexRefs,'new value=',value)
    9293    def __str__(self):
    9394        treeList = self.treeRefs[:]
     
    130131                if l: l += ' -> '
    131132                l += item
    132             print 'Logging menu command: '+l
     133            print ('Logging menu command: '+l)
    133134    def __str__(self):
    134135        return 'Menu press: From '+_l2s(self.menulabellist,'/')
     
    152153        self.wintitle = title
    153154        self.tablabel = tabname
    154         if debug: print 'Logging tab: "'+tabname+'" on window titled '+title
     155        if debug: print ('Logging tab: "'+tabname+'" on window titled '+title)
    155156    def __str__(self):
    156157        return 'Tab press: Tab='+_l2s([self.tablabel])+' on window labeled '+str(self.wintitle)
    157158    def Repaint(self):
    158159        'Used to redraw a window created in response to a Tab press'
    159         if debug: print 'Repaint'
     160        if debug: print ('Repaint')
    160161        saveval = LogInfo['LastPaintAction']
    161162        self.Replay()
     
    167168        LogInfo['LastPaintAction'] = self
    168169        if LogInfo['Tree'].G2frame.GetTitle() != wintitle:
    169             print LogInfo['Tree'].G2frame.GetTitle(),' != ',wintitle
     170            print (LogInfo['Tree'].G2frame.GetTitle()+' != '+wintitle)
    170171            raise Exception('tab in wrong window')
    171172        for PageNum in range(LogInfo['Tree'].G2frame.dataDisplay.GetPageCount()):
     
    174175                return
    175176        else:
    176             print tabname,'not in',[
     177            print (tabname+'not in'+[
    177178                LogInfo['Tree'].G2frame.dataDisplay.GetPageText(PageNum) for
    178                 PageNum in range(LogInfo['Tree'].G2frame.dataDisplay.GetPageCount())]
     179                PageNum in range(LogInfo['Tree'].G2frame.dataDisplay.GetPageCount())])
    179180            raise Exception('tab not found')
    180181def MakeTabLog(title,tabname):
     
    186187    def __init__(self,itemlist):
    187188        self.treeItemList = itemlist
    188         if debug: print 'Logging press on tree: ',itemlist
     189        if debug: print ('Logging press on tree: '+itemlist)
    189190    def __str__(self):
    190191        treeList = self.treeItemList[:]
     
    196197    def Repaint(self):
    197198        'Used to redraw a window created in response to a click on a data tree item'
    198         if debug: print 'Repaint'
     199        if debug: print ('Repaint')
    199200        saveval = LogInfo['LastPaintAction']
    200201        LogInfo['Tree'].SelectItem(LogInfo['Tree'].root) # need to select something else
     
    213214            item = G2gd.GetGPXtreeItemId(LogInfo['Tree'].G2frame,parent,txt)
    214215            if not item:
    215                 print 'Not found',txt
     216                print ('Not found',+txt)
    216217                return
    217218            else:
     
    228229        self.locationcode = locationcode
    229230        self.label = label
    230         if debug: print 'Logging '+label+' button press in '+locationcode
     231        if debug: print ('Logging '+label+' button press in '+locationcode)
    231232    def __str__(self):
    232233        return 'Press of '+self.label+' button in '+self.locationcode
     
    354355            if lastLog.treeRefs == treevars and lastLog.indexRefs == fullrefs:
    355356                lastLog.value = result[key]
    356                 if debug: print 'update last log to ',result[key]
     357                if debug: print ('update last log to '+result[key])
    357358                return
    358359        G2logList.append(VarLogEntry(treevars,fullrefs,result[key]))
    359360    else:
    360         print key,'Error: var change has no provenance info'
     361        print (key+' Error: var change has no provenance info')
    361362
    362363#===========================================================================
     
    410411        else:
    411412            # menu not found in menu, something is wrong
    412             print 'error tracing menuitem to parent menu',menuLabelList
     413            print ('error tracing menuitem to parent menu'+menuLabelList)
    413414            #raise Exception('debug1: error tracing menuitem')
    414415            return
     
    428429
    429430    # menu not found in menubar, something is wrong
    430     print 'error tracing menuitem to menubar',menuLabelList
     431    print ('error tracing menuitem to menubar'+menuLabelList)
    431432    #raise Exception('debug2: error tracing menuitem')
    432433    return
     
    461462        handler(event)
    462463    else:
    463         print 'Error no binding for menu command',menuLabelList,'id=',id
     464        print ('Error no binding for menu command'+menuLabelList+'id=%d'%id)
    464465        return
    465466
     
    468469def LogOn():
    469470    'Turn On logging of actions'
    470     if debug: print 'LogOn'
     471    if debug: print ('LogOn')
    471472    LogInfo['Logging'] = True
    472473
    473474def LogOff():
    474475    'Turn Off logging of actions'
    475     if debug: print 'LogOff'
     476    if debug: print ('LogOff')
    476477    LogInfo['Logging'] = False
    477478   
     
    496497    logstat = ShowLogStatus()
    497498    if logstat: LogOff()
    498     if debug: print 70*'='
     499    if debug: print (70*'=')
    499500    for i in sels:
    500501        i += 1
    501502        item = G2logList[i]
    502         if debug: print 'replaying',item
     503        if debug: print ('replaying'+item)
    503504        item.Replay()
    504505        wx.Yield()
     
    508509        clb.DeselectAll()
    509510        clb.SetSelection(i)
    510     if debug: print 70*'='
     511    if debug: print (70*'=')
    511512    # if the last command did not display a window, repaint it in
    512513    # case something on that window changed.
Note: See TracChangeset for help on using the changeset viewer.