Changeset 2610


Ignore:
Timestamp:
Jan 4, 2017 1:31:26 PM (5 years ago)
Author:
toby
Message:

fix bug on change in PDF files; save location when images are moved

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r2563 r2610  
    141141    return Comments,Peaks,limits,wave
    142142
    143 def CheckImageFile(G2frame,imagefile):
     143def GetCheckImageFile(G2frame,treeId):
    144144    '''Try to locate an image file if the project and image have been moved
    145145    together. If the image file cannot be found, request the location from
     
    147147
    148148    :param wx.Frame G2frame: main GSAS-II Frame and data object
    149     :param str imagefile: name of image file
    150     :returns: imagefile, if it exists, or the name of a file
    151       that does exist or False if the user presses Cancel
     149    :param wx.Id treeId: Id for the main tree item for the image
     150    :returns: Npix,imagefile,imagetag with (Npix) number of pixels,
     151       imagefile, if it exists, or the name of a file that does exist or False if the user presses Cancel
     152       and (imagetag) an optional image number
    152153
    153154    '''
     155    Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(G2frame.Image)
    154156    if not os.path.exists(imagefile):
    155157        print 'Image file '+imagefile+' not found'
     
    162164            if os.path.exists(os.path.join(G2frame.dirname,fil)):
    163165                print 'found image file '+os.path.join(G2frame.dirname,fil)
    164                 return os.path.join(G2frame.dirname,fil)
     166                imagefile = os.path.join(G2frame.dirname,fil)
     167                G2frame.PatternTree.UpdateImageLoc(G2frame.Image,imagefile)
     168                return Npix,imagefile,imagetag
    165169            pth,enddir = os.path.split(pth)
    166170            fil = os.path.join(enddir,fil)
     
    184188            if os.path.exists(os.path.join(pth,fil)):
    185189                print 'found image file '+os.path.join(pth,fil)
    186                 return os.path.join(pth,fil)
     190                imagefile = os.path.join(pth,fil)
     191                G2frame.PatternTree.UpdateImageLoc(G2frame.Image,imagefile)
     192                return Npix,imagefile,imagetag
    187193            pth,enddir = os.path.split(pth)
    188194        #GSASIIpath.IPyBreak()
     
    198204            if dlg.ShowModal() == wx.ID_OK:
    199205                imagefile = dlg.GetPath()
     206                G2frame.PatternTree.UpdateImageLoc(G2frame.Image,imagefile)
    200207            else:
    201208                imagefile = False
    202209        finally:
    203210            dlg.Destroy()
    204     return imagefile
     211    return Npix,imagefile,imagetag
    205212
    206213def EditImageParms(parent,Data,Comments,Image,filename):
  • trunk/GSASIIctrls.py

    r2608 r2610  
    222222            return size,imagefile,None
    223223
     224    def UpdateImageLoc(self,TreeId,imagefile):
     225        '''Saves a new imagefile name in the Tree. Handles cases where the
     226        image name is specified, as well as where the image file name is
     227        a tuple containing the image file and an image number
     228        '''
     229       
     230        idata = self.GetItemPyData(TreeId)
     231        if type(idata[1]) is tuple or type(idata[1]) is list:
     232            idata[1][0] = [imagefile,idata[1][1]]
     233        else:
     234            idata[1]  = imagefile
     235       
    224236    def SaveExposedItems(self):
    225237        '''Traverse the top level tree items and save names of exposed (expanded) tree items.
  • trunk/GSASIIimgGUI.py

    r2604 r2610  
    5656    '''
    5757   
    58     Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(G2frame.Image)
    59     imagefile = G2IO.CheckImageFile(G2frame,imagefile)
     58    Npix,imagefile,imagetag = G2IO.GetCheckImageFile(G2frame,G2frame.Image)
    6059    formatName = data.get('formatName','')
    6160    sumImg = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag,FormatName=formatName)
     
    7069            Ddata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Did,'Image Controls'))
    7170            dformatName = Ddata.get('formatName','')
    72             Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(Did)
    73             imagefile = G2IO.CheckImageFile(G2frame,imagefile)
     71            Npix,imagefile,imagetag = G2IO.GetCheckImageFile(G2frame,Did)
    7472            darkImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag,FormatName=dformatName)
    7573            if darkImg is not None:               
     
    8179        Bid = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, backImg)
    8280        if Bid:
    83             Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(Bid)
    84             imagefile = G2IO.CheckImageFile(G2frame,imagefile)
     81            Npix,imagefile,imagetag = G2IO.GetCheckImageFile(G2frame,Bid)
    8582            Bdata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Bid,'Image Controls'))
    8683            bformatName = Bdata.get('formatName','')
     
    9188                    Ddata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Did,'Image Controls'))
    9289                    dformatName = Ddata.get('formatName','')
    93                     Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(Did)
    94                     imagefile = G2IO.CheckImageFile(G2frame,imagefile)
     90                    Npix,imagefile,imagetag = G2IO.GetCheckImageFile(G2frame,Did)
    9591                    darkImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag,FormatName=dformatName)
    9692                    if darkImage is not None:
  • trunk/GSASIIpwdGUI.py

    r2596 r2610  
    45694569#####  PDF controls
    45704570################################################################################           
    4571        
    45724571def UpdatePDFGrid(G2frame,data):
    45734572    '''respond to selection of PWDR PDF data tree item.
    4574     '''
    4575     global inst
    4576     tth2q = lambda t,w:4.0*math.pi*sind(t/2.0)/w
    4577     tof2q = lambda t,C:2.0*math.pi*C/t
    4578     dataFile = G2frame.PatternTree.GetItemText(G2frame.PatternId)
    4579     powName = 'PWDR'+dataFile[4:]
    4580     powId = G2gd.GetPatternTreeItemId(G2frame,G2frame.root, powName)
    4581     fullLimits,limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,powId, 'Limits'))[:2]
    4582     inst = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,powId, 'Instrument Parameters'))[0]
    4583     if 'C' in inst['Type'][0]:
    4584         wave = G2mth.getWave(inst)
    4585         keV = 12.397639/wave
    4586         qLimits = [tth2q(fullLimits[0],wave),tth2q(fullLimits[1],wave)]
    4587         polariz = inst['Polariz.'][1]
    4588     else:   #'T'of
    4589         qLimits = [tof2q(fullLimits[1],inst['difC'][1]),tof2q(fullLimits[0],inst['difC'][1])]
    4590         polariz = 1.0
    4591     data['QScaleLim'][1] = min(qLimits[1],data['QScaleLim'][1])
    4592     if data['QScaleLim'][0]:
    4593         data['QScaleLim'][0] = max(qLimits[0],data['QScaleLim'][0])
    4594     else:                                #initial setting at 90% of max Q
    4595         data['QScaleLim'][0] = 0.90*data['QScaleLim'][1]
    4596     itemDict = {}
    4597     #patch
    4598     if 'BackRatio' not in data:
    4599         data['BackRatio'] = 0.
    4600     if 'noRing' not in data:
    4601         data['noRing'] = False
    4602     if 'Rmax' not in data:
    4603         data['Rmax'] = 100.
    4604     if 'Flat Bkg' not in data:
    4605         data['Flat Bkg'] = 0.
    4606     if 'IofQmin' not in data:
    4607         data['IofQmin'] = 1.0
    4608    
     4573    '''   
    46094574    def FillFileSizer(fileSizer,key):
    46104575        #fileSizer is a FlexGridSizer(3,6)
     
    46174582            Obj.SetValue(fmt%(value))
    46184583            data[fileKey][itemKey] = value
    4619             wx.CallAfter(UpdatePDFGrid,G2frame,data)
     4584            wx.CallLater(100,UpdatePDFGrid,G2frame,data)
     4585            wx.CallAfter(OnComputePDF,None)
    46204586           
    46214587        def OnMoveMult(event):
     
    48964862            G2plt.PlotISFG(G2frame,newPlot=True,plotType='G(R)')
    48974863            print ' Done calculating PDFs:'
    4898        
     4864
     4865    # Routine UpdatePDFGrid starts here
     4866    global inst
     4867    tth2q = lambda t,w:4.0*math.pi*sind(t/2.0)/w
     4868    tof2q = lambda t,C:2.0*math.pi*C/t
     4869    dataFile = G2frame.PatternTree.GetItemText(G2frame.PatternId)
     4870    powName = 'PWDR'+dataFile[4:]
     4871    powId = G2gd.GetPatternTreeItemId(G2frame,G2frame.root, powName)
     4872    fullLimits,limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,powId, 'Limits'))[:2]
     4873    inst = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,powId, 'Instrument Parameters'))[0]
     4874    if 'C' in inst['Type'][0]:
     4875        wave = G2mth.getWave(inst)
     4876        keV = 12.397639/wave
     4877        qLimits = [tth2q(fullLimits[0],wave),tth2q(fullLimits[1],wave)]
     4878        polariz = inst['Polariz.'][1]
     4879    else:   #'T'of
     4880        qLimits = [tof2q(fullLimits[1],inst['difC'][1]),tof2q(fullLimits[0],inst['difC'][1])]
     4881        polariz = 1.0
     4882    data['QScaleLim'][1] = min(qLimits[1],data['QScaleLim'][1])
     4883    if data['QScaleLim'][0]:
     4884        data['QScaleLim'][0] = max(qLimits[0],data['QScaleLim'][0])
     4885    else:                                #initial setting at 90% of max Q
     4886        data['QScaleLim'][0] = 0.90*data['QScaleLim'][1]
     4887    itemDict = {}
     4888    #patch
     4889    if 'BackRatio' not in data:
     4890        data['BackRatio'] = 0.
     4891    if 'noRing' not in data:
     4892        data['noRing'] = False
     4893    if 'Rmax' not in data:
     4894        data['Rmax'] = 100.
     4895    if 'Flat Bkg' not in data:
     4896        data['Flat Bkg'] = 0.
     4897    if 'IofQmin' not in data:
     4898        data['IofQmin'] = 1.0       
    48994899    if G2frame.dataDisplay:
    49004900        G2frame.dataFrame.Clear()
Note: See TracChangeset for help on using the changeset viewer.