Changeset 2092


Ignore:
Timestamp:
Dec 14, 2015 5:37:54 PM (6 years ago)
Author:
toby
Message:

reorg. integration GUI

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimgGUI.py

    r2086 r2092  
    177177       
    178178    def OnIntegrateAll(event):
    179         print 'integrate all'
    180179        TextList = [[False,'All IMG',0]]
    181180#        Names = []
     
    19871986      processing loop. (Default is 3.0 seconds.)
    19881987    '''
    1989     def OnTimerLoop(self,event):
    1990         '''A method that is called every :meth:`PollTime` seconds that is
    1991         used to check for new files and process them. This is called only
    1992         after the "Start" button is pressed (when its label reads "Pause").
    1993         '''
    1994         G2frame = self.G2frame
    1995         try:
    1996             self.currImageList = sorted(
    1997                 glob.glob(os.path.join(self.imagedir,self.params['filter'])))
    1998         except IndexError:
    1999             self.currImageList = []
    2000             return
    2001 
    2002         # Create a list of image files that have already been read
    2003         imageFileList = []
    2004         for img in G2gd.GetPatternTreeDataNames(G2frame,['IMG ']):
    2005             imgId = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,img)
    2006             size,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(imgId)
    2007             if imagefile not in imageFileList: imageFileList.append(imagefile)
    2008         # loop over image files matching glob, reading in new ones
    2009         for newImage in self.currImageList:
    2010             if newImage in imageFileList: continue # already read
    2011             for imgId in G2IO.ReadImages(G2frame,newImage):
    2012                 controlsDict = G2frame.PatternTree.GetItemPyData(
    2013                     G2gd.GetPatternTreeItemId(G2frame,imgId, 'Image Controls'))
    2014                 ImageMasks = G2frame.PatternTree.GetItemPyData(
    2015                     G2gd.GetPatternTreeItemId(G2frame,imgId, 'Masks'))
    2016                 if self.params['Mode'] == 'table':
    2017                     dist = controlsDict['distance']
    2018                     interpDict,imgctrl,immask = self.Evaluator(dist) # interpolated calibration values
    2019                     #if GSASIIpath.GetConfigValue('debug'):
    2020                     print 'interpolated: ',interpDict
    2021                     self.ImageControls = ReadControls(imgctrl)
    2022                     self.ImageControls.update(interpDict)
    2023                     self.ImageControls['showLines'] = True
    2024                     self.ImageControls['ring'] = []
    2025                     self.ImageControls['rings'] = []
    2026                     self.ImageControls['ellipses'] = []
    2027                     self.ImageControls['setDefault'] = False
    2028                     for i in 'range','size','GonioAngles':
    2029                         if i in self.ImageControls:
    2030                             del self.ImageControls[i]
    2031                     # load copy of Image Masks
    2032                     if immask:
    2033                         self.ImageMasks = ReadMask(immask)
    2034                         del self.Thresholds['Thresholds']
    2035                     else:
    2036                         self.ImageMasks = {'Points':[],'Rings':[],'Arcs':[],'Polygons':[],'Frames':[]}
    2037                 # update controls from master
    2038                 controlsDict.update(self.ImageControls)
    2039                 # update masks from master w/o Thresholds
    2040                 ImageMasks.update(self.ImageMasks)
    2041         # now integrate the images that have not already been processed before
    2042         for img in G2gd.GetPatternTreeDataNames(G2frame,['IMG ']):
    2043             if img in G2frame.IntegratedList: continue
    2044             G2frame.IntegratedList.append(img)
    2045             imgId = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,img)
    2046             G2frame.Image = imgId
    2047             G2frame.PickId = G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls')
    2048             #  integrate in this entry
    2049             size,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(imgId)
    2050             G2frame.ImageZ = G2IO.GetImageData(G2frame,imagefile,True,imagetag)
    2051             masks = G2frame.PatternTree.GetItemPyData(
    2052                 G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Masks'))
    2053             data = G2frame.PatternTree.GetItemPyData(G2frame.PickId)
    2054             self.oldImagefile = '' # mark image as changed; reread as needed
    2055             # simulate a Image Controls press, since that is where the
    2056             # integration is hidden
    2057             UpdateImageControls(G2frame,data,masks,IntegrateOnly=True)
    2058             # split name and control number
    2059             s = re.split(r'(\d+)\Z',os.path.split(os.path.splitext(imagefile)[0])[1])
    2060             namepre = s[0]
    2061             if len(s) > 1:
    2062                 namenum = s[1]
    2063             else:
    2064                 namenum = ''
    2065             # write out the images in the selected formats and save the names,
    2066             # reset will delete them
    2067             for Id in G2frame.IntgOutList:
    2068                 treename = G2frame.PatternTree.GetItemText(Id)
    2069                 G2frame.AutointPWDRnames.append(treename)
    2070                 Sdata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Sample Parameters'))
    2071                 # determine the name for the current file
    2072                 fileroot = namepre
    2073                 if len(G2frame.IntgOutList) > 1:
    2074                     fileroot += "_AZM"
    2075                     if 'Azimuth' in Sdata:
    2076                         fileroot += str(int(10*Sdata['Azimuth']))
    2077                     fileroot += "_"
    2078                 fileroot += namenum
    2079                 # loop over selected formats
    2080                 for dfmt in self.fmtlist:
    2081                     if not self.params[dfmt[1:]]: continue
    2082                     if self.params['SeparateDir']:
    2083                         subdir = dfmt[1:]
    2084                     else:
    2085                         subdir = ''
    2086                     fil = os.path.join(self.params['outdir'],subdir,fileroot)
    2087                     print('writing file '+fil+dfmt)
    2088                     G2IO.ExportPowder(G2frame,treename,fil,dfmt)
    2089        
    2090         if GSASIIpath.GetConfigValue('debug'):
    2091             import datetime
    2092             print ("Timer tick at {:%d %b %Y %H:%M:%S}\n".format(datetime.datetime.now()))
    2093 
    2094     def StartLoop(self):
    2095         '''Save current Image params for use in future integrations
    2096         also label the window so users understand whatis being used
    2097         '''
    2098         print '\nStarting new autointegration\n'
    2099         G2frame = self.G2frame
    2100         # show current IMG base
    2101         self.ControlBaseLbl.SetLabel(G2frame.PatternTree.GetItemText(G2frame.Image))
    2102         if self.params['Mode'] != 'table':
    2103             # load copy of Image Controls from current image and clean up
    2104             # items that should not be copied
    2105             self.ImageControls = copy.deepcopy(
    2106                 G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(
    2107                     G2frame,G2frame.Image, 'Image Controls')))
    2108             self.ImageControls['showLines'] = True
    2109             self.ImageControls['ring'] = []
    2110             self.ImageControls['rings'] = []
    2111             self.ImageControls['ellipses'] = []
    2112             self.ImageControls['setDefault'] = False
    2113             del self.ImageControls['range']
    2114             del self.ImageControls['size']
    2115             del self.ImageControls['GonioAngles']
    2116             # load copy of Image Masks, keep thresholds
    2117             self.ImageMasks = copy.deepcopy(
    2118                 G2frame.PatternTree.GetItemPyData(
    2119                     G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Masks')))
    2120             self.Thresholds = self.ImageMasks['Thresholds'][:]
    2121         # make sure all output directories exist
    2122         if self.params['SeparateDir']:
    2123             for dfmt in self.fmtlist:
    2124                 if not self.params[dfmt[1:]]: continue
    2125                 dir = os.path.join(self.params['outdir'],dfmt[1:])
    2126                 if not os.path.exists(dir): os.makedirs(dir)
    2127         else:
    2128             if not os.path.exists(self.params['outdir']):
    2129                 os.makedirs(self.params['outdir'])
    2130         if self.Reset: # special things to do after Reset has been pressed
    2131             # reset controls and masks for all IMG items in tree to master
    2132             for img in G2gd.GetPatternTreeDataNames(G2frame,['IMG ']):
    2133                 # update controls from master
    2134                 controlsDict = G2frame.PatternTree.GetItemPyData(
    2135                     G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls'))
    2136                 controlsDict.update(self.ImageControls)
    2137                 # update masks from master
    2138                 ImageMasks = G2frame.PatternTree.GetItemPyData(
    2139                     G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Masks'))
    2140                 ImageMasks.update(self.ImageMasks)
    2141             # delete all PWDR items created after last Start was pressed
    2142             idlist = []
    2143             item, cookie = G2frame.PatternTree.GetFirstChild(G2frame.root)
    2144             while item:
    2145                 itemName = G2frame.PatternTree.GetItemText(item)
    2146                 if itemName in G2frame.AutointPWDRnames:
    2147                     idlist.append(item)
    2148                 item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie)
    2149             for item in idlist:
    2150                 G2frame.PatternTree.Delete(item)
    2151             self.Reset = False
    2152         G2frame.AutointPWDRnames = [] # list of created PWDR tree item names
    21531988
    21541989    def __init__(self,G2frame,PollTime=60.0):
     
    21662001            #    G2G.G2MessageBox(self,err)
    21672002            #    return
     2003            self.Pause = False
    21682004            # change button label
    21692005            if btnstart.GetLabel() != 'Pause':
    21702006                btnstart.SetLabel('Pause')
    21712007                if self.timer.IsRunning(): self.timer.Stop()
     2008                self.PreventReEntryTimer = False
    21722009                self.StartLoop()
    21732010                self.OnTimerLoop(None) # run once immediately and again after delay
     
    21792016                print('\nPausing autointegration\n')
    21802017                self.Status.SetStatusText('Press Resume to continue integration or Reset to prepare to reintegrate all images')
     2018                self.Pause = True
    21812019
    21822020        def OnReset(event):
     
    21892027            if self.timer.IsRunning(): self.timer.Stop()
    21902028            self.Reset = True
    2191             self.G2frame.IntegratedList = []
     2029            self.Pause = True
    21922030           
    21932031        def OnQuit(event):
     
    22222060            self.Evaluator = None
    22232061            if r2.GetValue():
    2224                 self.params['Mode'] = 'table'
    22252062                try:
    22262063                    dlg = IntegParmTable(self.G2frame) # create the dialog
    22272064                    if dlg.ShowModal() == wx.ID_OK:
    22282065                        self.Evaluator = DefineEvaluator(dlg)
     2066                        self.params['Mode'] = 'table'
    22292067                    else:
    2230                         r1.SetValue(True)
     2068                        self.useActive.SetValue(True)
    22312069                finally:
    22322070                    dlg.Destroy()
    2233             else:
     2071            if self.useActive.GetValue():
    22342072                self.params['Mode'] = 'active'
     2073                self.imageBase = G2frame.Image
     2074                self.useActive.SetLabel("Active Image: "+
     2075                        G2frame.PatternTree.GetItemText(self.imageBase))
     2076
    22352077        ##################################################
    22362078        # beginning of __init__ processing
     
    22402082        self.params = {}
    22412083        self.Reset = False
     2084        self.Pause = False
     2085        self.PreventReEntryShowMatch = False
     2086        self.PreventReEntryTimer = False
    22422087        self.params['IMGfile'] = ''
    22432088        self.params['MaskFile'] = ''
     
    22462091        self.timer = wx.Timer()
    22472092        self.timer.Bind(wx.EVT_TIMER,self.OnTimerLoop)
     2093        self.imageBase = G2frame.Image
    22482094
    22492095        controlsId = G2frame.PatternTree.GetSelection()
    2250         size,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(G2frame.Image)       
     2096        size,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(self.imageBase)       
    22512097        self.imagedir,fileroot = os.path.split(imagefile)
    22522098        self.params['filter'] = '*'+os.path.splitext(fileroot)[1]
     
    22572103        mnpnl = wx.Panel(self)
    22582104        mnsizer = wx.BoxSizer(wx.VERTICAL)
    2259         sizer = wx.BoxSizer(wx.HORIZONTAL)
    2260         sizer.Add(wx.StaticText(mnpnl, wx.ID_ANY,'Integration based on: '))
    2261         self.ControlBaseLbl = wx.StaticText(mnpnl, wx.ID_ANY,'?')
    2262         self.ControlBaseLbl.SetLabel(G2frame.PatternTree.GetItemText(G2frame.Image))
    2263         sizer.Add(self.ControlBaseLbl)
    2264         mnsizer.Add(sizer,0,wx.ALIGN_LEFT,1)
     2105        # box for integration controls & masks input
     2106        lbl = wx.StaticBox(mnpnl, wx.ID_ANY, "Integration Control")
     2107        lblsizr = wx.StaticBoxSizer(lbl, wx.VERTICAL)
     2108        lblsizr.Add(wx.StaticText(mnpnl, wx.ID_ANY,'Use integration parameters from:'))
     2109        self.useActive = wx.RadioButton(mnpnl, wx.ID_ANY,
     2110                            style = wx.RB_GROUP)
     2111        self.useActive.Bind(wx.EVT_RADIOBUTTON, OnRadioSelect)
     2112        self.useActive.SetLabel("Active Image: "+
     2113                                G2frame.PatternTree.GetItemText(self.imageBase))
     2114        lblsizr.Add(self.useActive,1,wx.EXPAND,1)
     2115        self.useActive.SetValue(True)
     2116        r2 = wx.RadioButton(mnpnl, wx.ID_ANY, "From look-up table")
     2117        lblsizr.Add(r2,1,wx.EXPAND,1)
     2118        r2.Bind(wx.EVT_RADIOBUTTON, OnRadioSelect)
     2119        mnsizer.Add(lblsizr,1,wx.EXPAND,1)
     2120
    22652121        # file filter stuff
    22662122        sizer = wx.BoxSizer(wx.HORIZONTAL)
    22672123        sizer.Add(wx.StaticText(mnpnl, wx.ID_ANY,'Image filter'))
    2268         flterInp = G2G.ValidatedTxtCtrl(mnpnl,self.params,'filter')
     2124        flterInp = G2G.ValidatedTxtCtrl(mnpnl,self.params,'filter',
     2125                                        OnLeave=self.ShowMatchingFiles)
    22692126        sizer.Add(flterInp)
    22702127        mnsizer.Add(sizer,0,wx.ALIGN_RIGHT,1)
    2271         # box for integration controls & masks input
    2272         lbl = wx.StaticBox(mnpnl, wx.ID_ANY, "Integration Controls/Masks source")
    2273         lblsizr = wx.StaticBoxSizer(lbl, wx.VERTICAL)
    2274         r1 = wx.RadioButton(mnpnl, wx.ID_ANY, "Use Active Image",
    2275                             style = wx.RB_GROUP)
    2276         r1.Bind(wx.EVT_RADIOBUTTON, OnRadioSelect)
    2277         lblsizr.Add(r1)
    2278         r1.SetValue(True)
    2279         r2 = wx.RadioButton(mnpnl, wx.ID_ANY, "Use from table")
    2280         lblsizr.Add(r2)
    2281         r2.Bind(wx.EVT_RADIOBUTTON, OnRadioSelect)
    2282         mnsizer.Add(lblsizr)
    2283 
     2128        self.ListBox = wx.ListBox(mnpnl,size=(-1,100))
     2129        mnsizer.Add(self.ListBox,0,wx.EXPAND,1)
     2130        self.ShowMatchingFiles(self.params['filter'])
    22842131        # box for output selections
    22852132        lbl = wx.StaticBox(mnpnl, wx.ID_ANY, "Output settings")
     
    23332180        self.CenterOnParent()
    23342181        self.Show()
     2182
     2183    def ShowMatchingFiles(self,value,invalid=False,**kwargs):
     2184        G2frame = self.G2frame
     2185        if invalid: return
     2186        if self.PreventReEntryShowMatch: return
     2187        self.PreventReEntryShowMatch = True
     2188        imageFileList = []
     2189        for img in G2gd.GetPatternTreeDataNames(G2frame,['IMG ']):
     2190            imgId = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,img)
     2191            size,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(imgId)
     2192            if imagefile not in imageFileList: imageFileList.append(imagefile)
     2193        try:
     2194            imageList = sorted(
     2195                glob.glob(os.path.join(self.imagedir,value)))
     2196            if not imageList:
     2197                #title = 'Warning'
     2198                msg = 'Warning: No files match search string '+os.path.join(self.imagedir,value)
     2199            else:
     2200                #title='Matched files'
     2201                msg = ''
     2202                for fil in imageList:
     2203                    if fil not in imageFileList: msg += '\n  '+fil
     2204                if msg:
     2205                    msg = 'Files to process from '+os.path.join(self.imagedir,value)+msg
     2206                else:
     2207                    msg = 'All files processed'
     2208        except IndexError:
     2209            #title = 'Error'
     2210            msg = 'Error searching for files named '+os.path.join(self.imagedir,value)
     2211            #print(msg)
     2212        self.ListBox.Clear()
     2213        self.ListBox.AppendItems(msg.split('\n'))
     2214        self.PreventReEntryShowMatch = False
     2215        return
     2216       
     2217    def IntegrateImage(self,img):
     2218        '''Integrates a single image'''
     2219        G2frame = self.G2frame
     2220        imgId = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,img)
     2221        G2frame.Image = imgId
     2222        G2frame.PickId = G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls')
     2223        # do integration
     2224        size,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(imgId)
     2225        G2frame.ImageZ = G2IO.GetImageData(G2frame,imagefile,True,imagetag)
     2226        masks = G2frame.PatternTree.GetItemPyData(
     2227                G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Masks'))
     2228        data = G2frame.PatternTree.GetItemPyData(G2frame.PickId)
     2229        # simulate a Image Controls press, since that is where the
     2230        # integration is hidden
     2231        UpdateImageControls(G2frame,data,masks,IntegrateOnly=True)
     2232        G2frame.IntegratedList.append(img) # note this as integrated
     2233        # split name and control number
     2234        s = re.split(r'(\d+)\Z',os.path.split(os.path.splitext(imagefile)[0])[1])
     2235        namepre = s[0]
     2236        if len(s) > 1:
     2237            namenum = s[1]
     2238        else:
     2239            namenum = ''
     2240        for Id in G2frame.IntgOutList: # loop over newly created PDWR entry(ies)
     2241            # save the created PWDR tree names so that a reset can delete them
     2242            treename = G2frame.PatternTree.GetItemText(Id)
     2243            G2frame.AutointPWDRnames.append(treename)
     2244            # write out the images in the selected formats
     2245            Sdata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Sample Parameters'))
     2246            # determine the name for the current file
     2247            fileroot = namepre
     2248            if len(G2frame.IntgOutList) > 1:
     2249                fileroot += "_AZM"
     2250                if 'Azimuth' in Sdata:
     2251                    fileroot += str(int(10*Sdata['Azimuth']))
     2252                fileroot += "_"
     2253            fileroot += namenum
     2254            # loop over selected formats
     2255            for dfmt in self.fmtlist:
     2256                if not self.params[dfmt[1:]]: continue
     2257                if self.params['SeparateDir']:
     2258                    subdir = dfmt[1:]
     2259                else:
     2260                    subdir = ''
     2261                fil = os.path.join(self.params['outdir'],subdir,fileroot)
     2262                print('writing file '+fil+dfmt)
     2263                G2IO.ExportPowder(G2frame,treename,fil,dfmt)
     2264               
     2265    def ResetFromTable(self):
     2266        '''Sets integration parameters based on values from
     2267        the lookup table
     2268        '''
     2269        dist = controlsDict['distance']
     2270        interpDict,imgctrl,immask = self.Evaluator(dist) # interpolated calibration values
     2271        #if GSASIIpath.GetConfigValue('debug'):
     2272        if GSASIIpath.GetConfigValue('debug'):
     2273            print 'interpolated values: ',interpDict
     2274        self.ImageControls = ReadControls(imgctrl)
     2275        self.ImageControls.update(interpDict)
     2276        self.ImageControls['showLines'] = True
     2277        self.ImageControls['ring'] = []
     2278        self.ImageControls['rings'] = []
     2279        self.ImageControls['ellipses'] = []
     2280        self.ImageControls['setDefault'] = False
     2281        for i in 'range','size','GonioAngles':
     2282            if i in self.ImageControls:
     2283                del self.ImageControls[i]
     2284        # load copy of Image Masks
     2285        if immask:
     2286            self.ImageMasks = ReadMask(immask)
     2287            del self.Thresholds['Thresholds']
     2288        else:
     2289            self.ImageMasks = {'Points':[],'Rings':[],'Arcs':[],'Polygons':[],'Frames':[]}
     2290       
     2291    def StartLoop(self):
     2292        '''Save current Image params for use in future integrations
     2293        also label the window so users understand what is being used
     2294        '''
     2295        print '\nStarting new autointegration\n'
     2296        G2frame = self.G2frame
     2297        # show current IMG base
     2298        if self.params['Mode'] != 'table':
     2299            self.useActive.SetLabel("Active Image: "+
     2300                                    G2frame.PatternTree.GetItemText(self.imageBase))
     2301            # load copy of Image Controls from current image and clean up
     2302            # items that should not be copied
     2303            self.ImageControls = copy.deepcopy(
     2304                G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(
     2305                    G2frame,self.imageBase, 'Image Controls')))
     2306            self.ImageControls['showLines'] = True
     2307            self.ImageControls['ring'] = []
     2308            self.ImageControls['rings'] = []
     2309            self.ImageControls['ellipses'] = []
     2310            self.ImageControls['setDefault'] = False
     2311            del self.ImageControls['range']
     2312            del self.ImageControls['size']
     2313            del self.ImageControls['GonioAngles']
     2314            # load copy of Image Masks, keep thresholds
     2315            self.ImageMasks = copy.deepcopy(
     2316                G2frame.PatternTree.GetItemPyData(
     2317                    G2gd.GetPatternTreeItemId(G2frame,self.imageBase, 'Masks')))
     2318            self.Thresholds = self.ImageMasks['Thresholds'][:]
     2319        # make sure all output directories exist
     2320        if self.params['SeparateDir']:
     2321            for dfmt in self.fmtlist:
     2322                if not self.params[dfmt[1:]]: continue
     2323                dir = os.path.join(self.params['outdir'],dfmt[1:])
     2324                if not os.path.exists(dir): os.makedirs(dir)
     2325        else:
     2326            if not os.path.exists(self.params['outdir']):
     2327                os.makedirs(self.params['outdir'])
     2328        if self.Reset: # special things to do after Reset has been pressed
     2329            self.G2frame.IntegratedList = []
     2330           
     2331            if self.params['Mode'] != 'table': # reset controls and masks for all IMG items in tree to master
     2332                for img in G2gd.GetPatternTreeDataNames(G2frame,['IMG ']):
     2333                    # update controls from master
     2334                    controlsDict = G2frame.PatternTree.GetItemPyData(
     2335                        G2gd.GetPatternTreeItemId(G2frame,self.imageBase, 'Image Controls'))
     2336                    controlsDict.update(self.ImageControls)
     2337                    # update masks from master
     2338                    ImageMasks = G2frame.PatternTree.GetItemPyData(
     2339                        G2gd.GetPatternTreeItemId(G2frame,self.imageBase, 'Masks'))
     2340                    ImageMasks.update(self.ImageMasks)
     2341            # delete all PWDR items created after last Start was pressed
     2342            idlist = []
     2343            item, cookie = G2frame.PatternTree.GetFirstChild(G2frame.root)
     2344            while item:
     2345                itemName = G2frame.PatternTree.GetItemText(item)
     2346                if itemName in G2frame.AutointPWDRnames:
     2347                    idlist.append(item)
     2348                item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie)
     2349            for item in idlist:
     2350                G2frame.PatternTree.Delete(item)
     2351            wx.Yield()
     2352            self.Reset = False
     2353        G2frame.AutointPWDRnames = [] # list of created PWDR tree item names
     2354
     2355    def OnTimerLoop(self,event):
     2356        '''A method that is called every :meth:`PollTime` seconds that is
     2357        used to check for new files and process them. This is called only
     2358        after the "Start" button is pressed (when its label reads "Pause").
     2359        '''
     2360        G2frame = self.G2frame
     2361        try:
     2362            self.currImageList = sorted(
     2363                glob.glob(os.path.join(self.imagedir,self.params['filter'])))
     2364            self.ShowMatchingFiles(self.params['filter'])
     2365        except IndexError:
     2366            self.currImageList = []
     2367            return
     2368
     2369        if self.PreventReEntryTimer: return
     2370        self.PreventReEntryTimer = True
     2371        imageFileList = []
     2372        # integrate the images that have already been read in, but
     2373        # have not yet been processed
     2374        for img in G2gd.GetPatternTreeDataNames(G2frame,['IMG ']):
     2375            imgId = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,img)
     2376            size,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(imgId)
     2377            # Create a list of image files that have been read in
     2378            if imagefile not in imageFileList: imageFileList.append(imagefile)
     2379            # skip if already integrated
     2380            if img in G2frame.IntegratedList: continue
     2381            if self.params['Mode'] == 'table': # look up parameter values from table
     2382                controlsDict = G2frame.PatternTree.GetItemPyData(
     2383                    G2gd.GetPatternTreeItemId(G2frame,imgId, 'Image Controls'))
     2384                ImageMasks = G2frame.PatternTree.GetItemPyData(
     2385                    G2gd.GetPatternTreeItemId(G2frame,imgId, 'Masks'))
     2386                self.ResetFromTable()
     2387                # update controls from master
     2388                controlsDict.update(self.ImageControls)
     2389                # update masks from master w/o Thresholds
     2390                ImageMasks.update(self.ImageMasks)
     2391            self.IntegrateImage(img)
     2392            self.G2frame.oldImagefile = '' # mark image as changed; reread as needed
     2393            wx.Yield()
     2394            self.ShowMatchingFiles(self.params['filter'])
     2395            wx.Yield()
     2396            if self.Pause: return
     2397
     2398        # loop over image files matching glob, reading in any new ones
     2399        for newImage in self.currImageList:
     2400            if newImage in imageFileList: continue # already read?
     2401            for imgId in G2IO.ReadImages(G2frame,newImage):
     2402                controlsDict = G2frame.PatternTree.GetItemPyData(
     2403                    G2gd.GetPatternTreeItemId(G2frame,imgId, 'Image Controls'))
     2404                ImageMasks = G2frame.PatternTree.GetItemPyData(
     2405                    G2gd.GetPatternTreeItemId(G2frame,imgId, 'Masks'))
     2406                if self.params['Mode'] == 'table': # look up parameter values from table
     2407                    self.ResetFromTable()
     2408                # update controls from master
     2409                controlsDict.update(self.ImageControls)
     2410                # update masks from master w/o Thresholds
     2411                ImageMasks.update(self.ImageMasks)
     2412                # now integrate the image
     2413                img = G2frame.PatternTree.GetItemText(imgId)
     2414                self.IntegrateImage(img)
     2415                self.G2frame.oldImagefile = '' # mark image as changed; reread as needed
     2416                wx.Yield()
     2417                self.ShowMatchingFiles(self.params['filter'])
     2418                wx.Yield()
     2419            if self.Pause: return
     2420       
     2421        if GSASIIpath.GetConfigValue('debug'):
     2422            import datetime
     2423            print ("Timer tick at {:%d %b %Y %H:%M:%S}\n".format(datetime.datetime.now()))
     2424        self.PreventReEntryTimer = False
    23352425
    23362426def DefineEvaluator(dlg):
Note: See TracChangeset for help on using the changeset viewer.