source: trunk/imports/G2img_SumG2.py

Last change on this file was 3136, checked in by vondreele, 5 years ago

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

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 1.6 KB
Line 
1# -*- coding: utf-8 -*-
2########### SVN repository information ###################
3# $Date: 2017-10-23 16:39:16 +0000 (Mon, 23 Oct 2017) $
4# $Author: toby $
5# $Revision: 3136 $
6# $URL: trunk/imports/G2img_SumG2.py $
7# $Id: G2img_SumG2.py 3136 2017-10-23 16:39:16Z toby $
8########### SVN repository information ###################
9'''
10*Module G2img_SumG2: Python pickled image*
11------------------------------------------
12
13'''
14
15from __future__ import division, print_function
16import platform
17if '2' in platform.python_version_tuple()[0]:
18    import cPickle
19else:
20    import pickle as cPickle
21import GSASIIobj as G2obj
22import GSASIIpath
23GSASIIpath.SetVersionNumber("$Revision: 3136 $")
24class G2_ReaderClass(G2obj.ImportImage):
25    '''Routine to read an image that has been pickled in Python. Images
26    in this format are created by the "Sum image data" command. At least for
27    now, only one image is permitted per file.
28    '''
29    def __init__(self):
30        super(self.__class__,self).__init__( # fancy way to self-reference
31            extensionlist=('.G2img',),
32            strictExtension=True,
33            formatName = 'GSAS-II image',
34            longFormatName = 'cPickled image from GSAS-II'
35            )
36
37    def ContentsValidator(self, filename):
38        '''test by trying to unpickle (should be quick)
39        '''
40        try:
41            fp = open(filename,'rb')
42            cPickle.load(fp)
43            fp.close()
44        except:
45            return False
46        return True
47       
48    def Reader(self,filename, ParentFrame=None, **unused):
49        '''Read using cPickle
50        '''
51        Fp = open(filename,'rb')
52        self.Comments,self.Data,self.Npix,self.Image = cPickle.load(Fp)
53        Fp.close()
54        self.LoadImage(ParentFrame,filename)
55        return True
Note: See TracBrowser for help on using the repository browser.