Changeset 2340


Ignore:
Timestamp:
Jun 23, 2016 2:54:24 PM (5 years ago)
Author:
toby
Message:

write multiple control files

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r2329 r2340  
    9595[ wxID_IMCALIBRATE,wxID_IMRECALIBRATE,wxID_IMINTEGRATE, wxID_IMCLEARCALIB,wxID_IMRECALIBALL, 
    9696    wxID_IMCOPYCONTROLS, wxID_INTEGRATEALL, wxID_IMSAVECONTROLS, wxID_IMLOADCONTROLS, wxID_IMAUTOINTEG,
    97     wxID_IMCOPYSELECTED,
    98 ] = [wx.NewId() for item in range(11)]
     97    wxID_IMCOPYSELECTED, wxID_SAVESELECTEDCONTROLS,
     98] = [wx.NewId() for item in range(12)]
    9999
    100100[ wxID_MASKCOPY, wxID_MASKSAVE, wxID_MASKLOAD, wxID_NEWMASKSPOT,wxID_NEWMASKARC,wxID_NEWMASKRING,
     
    17641764        self.ImageEdit.Append(help='Save image controls to file',
    17651765            id=wxID_IMSAVECONTROLS, kind=wx.ITEM_NORMAL,text='Save Controls')
     1766        self.ImageEdit.Append(help='Save controls from selected images to file',
     1767            id=wxID_SAVESELECTEDCONTROLS, kind=wx.ITEM_NORMAL,text='Save Multiple Controls')
    17661768        self.ImageEdit.Append(help='Load image controls from file',
    17671769            id=wxID_IMLOADCONTROLS, kind=wx.ITEM_NORMAL,text='Load Controls')
  • trunk/GSASIIimgGUI.py

    r2339 r2340  
    371371                # make sure extension is .imctrl
    372372                filename = os.path.splitext(filename)[0]+'.imctrl'
    373                 File = open(filename,'w')
    374                 keys = ['type','wavelength','calibrant','distance','center',
    375                     'tilt','rotation','azmthOff','fullIntegrate','LRazimuth',
    376                     'IOtth','outChannels','outAzimuths','invert_x','invert_y','DetDepth',
    377                     'calibskip','pixLimit','cutoff','calibdmin','Flat Bkg','varyList',
    378                     'binType','SampleShape','PolaVal','SampleAbs','dark image','background image']
    379                 for key in keys:
    380                     if key not in data:     #uncalibrated!
    381                         continue
    382                     File.write(key+':'+str(data[key])+'\n')
    383                 File.close()
     373                WriteControls(filename,data)
    384374        finally:
    385375            dlg.Destroy()
    386        
     376
     377    def WriteControls(filename,data):
     378        File = open(filename,'w')
     379        keys = ['type','wavelength','calibrant','distance','center',
     380            'tilt','rotation','azmthOff','fullIntegrate','LRazimuth',
     381            'IOtth','outChannels','outAzimuths','invert_x','invert_y','DetDepth',
     382            'calibskip','pixLimit','cutoff','calibdmin','Flat Bkg','varyList',
     383            'binType','SampleShape','PolaVal','SampleAbs','dark image','background image']
     384        for key in keys:
     385            if key not in data:     #uncalibrated!
     386                continue
     387            File.write(key+':'+str(data[key])+'\n')
     388        File.close()
     389       
     390    def OnSaveMultiControls(event):
     391        '''Save controls from multiple images
     392        '''
     393        imglist = []
     394        item, cookie = G2frame.PatternTree.GetFirstChild(G2frame.root)
     395        while item:
     396            name = G2frame.PatternTree.GetItemText(item)
     397            if name.startswith('IMG '):
     398                imglist.append(name)               
     399            item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie)
     400        if not imglist:
     401            print('No images!')
     402            return
     403        dlg = G2G.G2MultiChoiceDialog(G2frame, 'Which images to select?',
     404                                      'Select images', imglist, wx.CHOICEDLG_STYLE)
     405        try:
     406            if dlg.ShowModal() == wx.ID_OK:
     407                treeEntries = [imglist[i] for i in dlg.GetSelections()]
     408        finally:
     409            dlg.Destroy()
     410        if not treeEntries:
     411            print('No images selected!')
     412            return
     413        pth = G2G.GetExportPath(G2frame)
     414        dlg = wx.DirDialog(
     415            G2frame, 'Select directory for output files',pth,wx.DD_DEFAULT_STYLE)
     416        dlg.CenterOnParent()
     417        outdir = None
     418        try:
     419            if dlg.ShowModal() == wx.ID_OK:
     420                outdir = dlg.GetPath()
     421        finally:
     422            dlg.Destroy()
     423        if not outdir:
     424            print('No directory')
     425            return
     426        for img in treeEntries:
     427            item = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,img)
     428            data = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(
     429                G2frame,item,'Image Controls'))
     430            Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(item)
     431            filename = os.path.join(outdir,
     432                                    os.path.splitext(os.path.split(imagefile)[1])[0]
     433                                    + '.imctrl')
     434            print('writing '+filename)
     435            WriteControls(filename,data)
     436           
    387437    def OnLoadControls(event):
    388438        cntlList = ['wavelength','distance','tilt','invert_x','invert_y','type',
     
    11841234    G2frame.dataFrame.Bind(wx.EVT_MENU, OnCopySelected, id=G2gd.wxID_IMCOPYSELECTED)
    11851235    G2frame.dataFrame.Bind(wx.EVT_MENU, OnSaveControls, id=G2gd.wxID_IMSAVECONTROLS)
     1236    G2frame.dataFrame.Bind(wx.EVT_MENU, OnSaveMultiControls, id=G2gd.wxID_SAVESELECTEDCONTROLS)
    11861237    G2frame.dataFrame.Bind(wx.EVT_MENU, OnLoadControls, id=G2gd.wxID_IMLOADCONTROLS)
    11871238    def OnDestroy(event):
Note: See TracChangeset for help on using the changeset viewer.