source: trunk/G2importphase_GPX.py @ 469

Last change on this file since 469 was 469, checked in by toby, 10 years ago

rework phase import

File size: 1.5 KB
Line 
1# Routines to import Phase information from GSAS-II .gpx files
2import cPickle
3import GSASIIIO as G2IO
4
5class PhaseReaderClass(G2IO.ImportPhase):
6    def __init__(self):
7        super(self.__class__,self).__init__( # fancy way to say ImportPhase.__init__
8            extensionlist=('.gpx',),
9            strictExtension=True,
10            formatName = 'GSAS-II gpx',
11            longFormatName = 'GSAS-II project (.gpx file) import'
12            )
13    def ContentsValidator(self, filepointer):
14        filepointer.seek(0) # rewind the file pointer
15        # if the 1st section can't be read as a cPickle file, it can't be!
16        try: 
17            cPickle.load(filepointer)
18        except:
19            return False
20        return True
21    def Reader(self,filename,filepointer, ParentFrame=None):
22        try:
23            phasenames = G2IO.GetPhaseNames(filename)
24            print phasenames
25        except:
26            return False
27        if not phasenames:
28            return False            # no blocks with coordinates
29        elif len(phasenames) == 1: # no choices
30            selblk = 0
31        else:                       # choose from options               
32            selblk = self.PhaseSelector(
33                phasenames,
34                ParentFrame=ParentFrame,
35                title= 'Select a phase from the list below',
36                )
37            if selblk is None: return False # User pressed cancel
38        try:
39            self.Phase = G2IO.GetAllPhaseData(filename,phasenames[selblk])
40            return True
41        except:
42            return False
43
Note: See TracBrowser for help on using the repository browser.