Changeset 2479 for trunk/GSASII.py


Ignore:
Timestamp:
Sep 28, 2016 11:55:35 AM (5 years ago)
Author:
toby
Message:

Rework plotting to refresh after refinements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r2457 r2479  
    246246        item.Enable(state)
    247247        self.SeqRefine.append(item) # save menu obj for use in self.EnableSeqRefineMenu
    248         self.Bind(wx.EVT_MENU, self.OnSeqRefine, id=item.GetId())
    249        
     248        if GSASIIpath.GetConfigValue('debug'): # allow exceptions for debugging
     249            self.Bind(wx.EVT_MENU, self.OnSeqRefine, id=item.GetId())
     250            item = parent.Append(help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL,
     251                text='Debug graphics refresh')
     252            self.Bind(wx.EVT_MENU, self.TestResetPlot, id=item.GetId())
     253
    250254    def _init_Imports(self):
    251255        '''import all the G2phase*.py & G2sfact*.py & G2pwd*.py files that
     
    37093713        '''Perform a refinement.
    37103714        Called from the Calculate/Refine menu.
    3711         '''       
     3715        '''
    37123716        Id = G2gd.GetPatternTreeItemId(self,self.root,'Sequential results')
    37133717        if Id:
     
    37433747        dlg.CenterOnParent()
    37443748        Rw = 100.00
    3745         oldId =  self.PatternTree.GetSelection()        #retain current selection
    3746         oldPath = self.GetTreeItemsList(oldId)
    3747         parentName = ''
    3748         oldName = self.PatternTree.GetItemText(oldId)
    3749         parentId = self.PatternTree.GetItemParent(oldId)
    3750         if parentId:
    3751             parentName = self.PatternTree.GetItemText(parentId)     #find the current data tree name
    3752             if 'Phases' in parentName:
    3753                 tabId = self.dataDisplay.GetSelection()
     3749        self.SaveTreeSetting()
    37543750        try:
    37553751            OK,Msg = G2stMn.Refine(self.GSASprojectfile,dlg)    #Msg is Rvals dict if Ok=True
     
    37693765            try:
    37703766                if dlg2.ShowModal() == wx.ID_OK:
    3771                     Id = 0
    37723767                    self.PatternTree.DeleteChildren(self.root)
    37733768                    self.HKL = []
    37743769                    G2IO.ProjFileOpen(self,False)
    3775                     Id =  self.root
    3776                     txt = None
    3777                     for txt in oldPath:
    3778                         Id = G2gd.GetPatternTreeItemId(self, Id, txt)
    3779                     self.PickIdText = None  #force reload of page
    3780                     if Id:
    3781                         self.PickId = Id
    3782                         self.PatternTree.SelectItem(Id)
    3783                         G2gd.MovePatternTreeToGrid(self,Id) # reload current tree item, should update current plot
     3770                    self.ResetPlots()
    37843771            finally:
    37853772                dlg2.Destroy()
    37863773        else:
    37873774            self.ErrorDialog('Refinement error',Msg)
    3788 
     3775       
     3776    def SaveTreeSetting(self):
     3777        'Save the last tree setting'
     3778        oldId =  self.PatternTree.GetSelection()        #retain current selection
     3779        oldPath = self.GetTreeItemsList(oldId)
     3780        self.lastTreeSetting = oldPath
     3781        # note that for reasons unclear, it does not seem necessary to reload the Atoms tab
     3782        #parentName = ''
     3783        #tabId = None
     3784        # parentId = self.PatternTree.GetItemParent(oldId)
     3785        # if parentId:
     3786        #     parentName = self.PatternTree.GetItemText(parentId)     #find the current data tree name
     3787        #     if 'Phases' in parentName:
     3788        #         tabId = self.dataDisplay.GetSelection()
     3789        #self.lastTreeSetting = oldPath,tabId
     3790        #GSASIIpath.IPyBreak()
     3791       
     3792    def ReloadTreeSetting(self):
     3793        'Reload the last tree setting, triggering the routine to redraw the data window and possibly a plot'
     3794        #oldPath,tabId = self.lastTreeSetting
     3795        oldPath = self.lastTreeSetting
     3796        Id = self.root
     3797        for txt in oldPath:
     3798            Id = G2gd.GetPatternTreeItemId(self, Id, txt)
     3799        self.PickIdText = None  #force reload of page
     3800        if Id:
     3801            self.PickId = Id
     3802            self.PatternTree.SelectItem(Id)
     3803            G2gd.MovePatternTreeToGrid(self,Id) # reload current tree item
     3804           
     3805    def TestResetPlot(self,event):
     3806        '''Debug code to test cleaning up plots after a refinement'''
     3807        #for i in range(self.G2plotNB.nb.GetPageCount()):
     3808        #    [self.G2plotNB.nb.GetPageText(i)
     3809        # save current tree item and (if needed) atoms tab
     3810        self.SaveTreeSetting()
     3811        self.ResetPlots()
     3812       
     3813    def ResetPlots(self):
     3814        '''This reloads the current tree item, often drawing a plot. It refreshes any plots
     3815        that have registered a refresh routine (see G2plotNB.RegisterRedrawRoutine)
     3816        and deletes all plots that have not been refreshed and
     3817        require one (see G2plotNB.SetNoDelete).
     3818        '''
     3819        lastRaisedPlotTab = self.G2plotNB.lastRaisedPlotTab # save the last page saved
     3820        #print 'lastRaisedPlotTab=',lastRaisedPlotTab
     3821        self.G2plotNB.lastRaisedPlotTab = None
     3822        # mark displayed plots as invalid
     3823        for lbl,frame in zip(self.G2plotNB.plotList,self.G2plotNB.panelList):
     3824            frame.plotInvalid = True
     3825        # reload current tree item
     3826        self.ReloadTreeSetting()
     3827        treeItemPlot = self.G2plotNB.lastRaisedPlotTab
     3828        # update other self-updating plots
     3829        for lbl,frame in zip(self.G2plotNB.plotList,self.G2plotNB.panelList):
     3830            if frame.plotInvalid and frame.replotFunction:
     3831                frame.replotFunction(*frame.replotArgs,**frame.replotKWargs)
     3832        # delete any remaining plots that are still invalid and need a refresh
     3833        for lbl,frame in zip(self.G2plotNB.plotList,self.G2plotNB.panelList):
     3834            if frame.plotInvalid and frame.plotRequiresRedraw:
     3835                self.G2plotNB.Delete(lbl)
     3836            #     print('deleting '+lbl) # debug code
     3837            # elif not frame.plotInvalid: # debug code
     3838            #     print(lbl+ ' was redrawn') # debug code
     3839        # put the previously last-raised tab on top, if present. If not, use the one corresponding to
     3840        # the last tree item to be selected
     3841        wx.CallAfter(self.G2plotNB.RaiseLastPage,lastRaisedPlotTab,treeItemPlot)
     3842       
    37893843    def OnSeqRefine(self,event):
    37903844        '''Perform a sequential refinement.
     
    38273881            try:
    38283882                if dlg.ShowModal() == wx.ID_OK:
    3829                     Id = 0
    3830 #                    self.G2plotNB.setReplotFlags() # mark all plots as old - doesn't exist!
    38313883                    self.PickIdText = None  #force reload of PickId contents
    38323884                    self.PatternTree.DeleteChildren(self.root)
     
    38353887                        self.G2plotNB.clear()
    38363888                    G2IO.ProjFileOpen(self,False)
     3889                    self.ResetPlots()
    38373890                    Id = G2gd.GetPatternTreeItemId(self,self.root,'Sequential results')
    38383891                    self.PatternTree.SelectItem(Id)
    38393892                    G2gd.MovePatternTreeToGrid(self,Id) # reload current tree item, should update current plot
    3840 #                    self.G2plotNB.replotAll() # refresh any plots not yet updated - doesn't exist!
    38413893            finally:
    38423894                dlg.Destroy()
Note: See TracChangeset for help on using the changeset viewer.