source: trunk/G2importphase_GPX.py @ 580

Last change on this file since 580 was 580, checked in by toby, 12 years ago

finish import structure factor; refactor import classes

File size: 2.1 KB
Line 
1########### SVN repository information ###################
2# $Date: 2012-02-13 11:33:35 -0600 (Mon, 13 Feb 2012) $
3# $Author: vondreele & toby $
4# $Revision: 482 $
5# $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/G2importphase_GPX.py $
6# $Id: G2importphase_GPX.py 482 2012-02-13 17:33:35Z vondreele $
7########### SVN repository information ###################
8# Routines to import Phase information from GSAS-II .gpx files
9import cPickle
10import GSASIIIO as G2IO
11import GSASIIstruct as G2str
12
13class PhaseReaderClass(G2IO.ImportPhase):
14    def __init__(self):
15        super(self.__class__,self).__init__( # fancy way to say ImportPhase.__init__
16            extensionlist=('.gpx',),
17            strictExtension=True,
18            formatName = 'GSAS-II gpx',
19            longFormatName = 'GSAS-II project (.gpx file) import'
20            )
21    def ContentsValidator(self, filepointer):
22        # if the 1st section can't be read as a cPickle file, it can't be!
23        try: 
24            cPickle.load(filepointer)
25        except:
26            return False
27        return True
28    def Reader(self,filename,filepointer, ParentFrame=None):
29        try:
30            phasenames = G2str.GetPhaseNames(filename)
31            print phasenames
32        except:
33            return False
34        if not phasenames:
35            return False            # no blocks with coordinates
36        elif len(phasenames) == 1: # no choices
37            selblk = 0
38        else:                       # choose from options               
39            selblk = self.PhaseSelector(
40                phasenames,
41                ParentFrame=ParentFrame,
42                title= 'Select a phase from the list below',
43                )
44            if selblk is None: return False # User pressed cancel
45        try:
46            self.Phase = G2str.GetAllPhaseData(filename,phasenames[selblk])
47            return True
48        except Exception as detail:
49            print self.formatName+' error:',detail # for testing
50            print sys.exc_info()[0] # for testing
51            import traceback
52            print traceback.format_exc()
Note: See TracBrowser for help on using the repository browser.