Changeset 2873


Ignore:
Timestamp:
Jun 23, 2017 2:33:41 PM (6 years ago)
Author:
toby
Message:

more fixes & cleanup for phase/data window

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIddataGUI.py

    r2841 r2873  
    5050
    5151    '''
    52     G2frame.dataFrame.SetStatusText('')
    53     keyList = G2frame.GetHistogramNames(['PWDR','HKLF'])
    54     UseList = data['Histograms']
    55     if UseList:
    56         G2frame.dataFrame.DataMenu.Enable(G2gd.wxID_DATADELETE,True)
    57         for item in G2frame.Refine: item.Enable(True)
    58     else:
    59         G2frame.dataFrame.DataMenu.Enable(G2gd.wxID_DATADELETE,False)
    60         for item in G2frame.Refine: item.Enable(False)
    61     generalData = data['General']
    62     PhaseName = generalData['Name']       
    63     SGData = generalData['SGData']
    64     if len(UseList) == 0: # no associated, don't display anything
    65         G2frame.hist = ''
    66     elif hist: # something was input as a selection
    67         G2frame.hist = hist
    68     elif not G2frame.hist or G2frame.hist not in UseList: # no or bad selection but have data, take the first
    69         for key in keyList:
    70             if key in UseList:
    71                     G2frame.hist = key
    72                     break
    73     PWDR = any(['PWDR' in item for item in keyList])
    74     Indx = {}
    75    
    7652    def PlotSizer():
    7753
     
    794770       
    795771    def OnSelect(event):
    796         G2frame.hist = keyList[select.GetSelection()]
     772        G2frame.hist = G2frame.dataFrame.HistsInPhase[select.GetSelection()]
    797773        oldFocus = wx.Window.FindFocus()
    798774        G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
     
    812788       
    813789    def ShowHistogramInfo():
     790        '''This creates a sizer with all the information pulled out from the Phase/data dict
     791        '''
    814792       
    815793        def OnUseData(event):
     
    979957            bottomSizer.Add(twinSizer(),0,WACV|wx.BOTTOM,5)
    980958        return bottomSizer
    981                
     959
     960    ######################################################################
     961    # Beginning of UpdateDData execution here
     962    ######################################################################
     963    G2frame.dataFrame.SetStatusText('')
     964    keyList = G2frame.GetHistogramNames(['PWDR','HKLF'])
     965    UseList = data['Histograms']
     966    if UseList:
     967        G2frame.dataFrame.DataMenu.Enable(G2gd.wxID_DATADELETE,True)
     968        for item in G2frame.Refine: item.Enable(True)
     969    else:
     970        G2frame.dataFrame.DataMenu.Enable(G2gd.wxID_DATADELETE,False)
     971        for item in G2frame.Refine: item.Enable(False)
     972    # make a list of histograms (any type) used in this phase, ordered as in tree
     973    G2frame.dataFrame.HistsInPhase = [name for name in keyList if name in UseList]
     974    generalData = data['General']
     975    PhaseName = generalData['Name']       
     976    SGData = generalData['SGData']
     977    if len(G2frame.dataFrame.HistsInPhase) == 0: # no associated histograms, nothing to display here
     978        G2frame.hist = ''
     979    elif hist and hist in G2frame.dataFrame.HistsInPhase: # something was input as a selection as an argument
     980        G2frame.hist = hist
     981    elif (not G2frame.hist) or (G2frame.hist not in G2frame.dataFrame.HistsInPhase): # no or bad selection but have data, take the first
     982        G2frame.hist = G2frame.dataFrame.HistsInPhase[0]
     983    Indx = {}
     984   
    982985    if DData.GetSizer():
    983986        DData.GetSizer().Clear(True)
    984     useList = []
    985     for name in keyList:
    986         if name in UseList:
    987             useList.append(name)
    988987    if not G2frame.dataFrame.GetStatusBar():
    989988        G2frame.dataFrame.CreateStatusBar()
    990989    mainSizer = wx.BoxSizer(wx.VERTICAL)
    991990    mainSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Histogram data for '+PhaseName+':'),0,WACV|wx.LEFT,5)
    992     if G2frame.hist != '':
     991    if G2frame.hist:
    993992        topSizer = wx.FlexGridSizer(1,2,5,5)
    994         select = wx.ListBox(DData,choices=useList,style=wx.LB_SINGLE,size=(-1,120))
    995         select.SetSelection(useList.index(G2frame.hist))
    996         select.SetFirstItem(useList.index(G2frame.hist))
     993        select = wx.ListBox(DData,choices=G2frame.dataFrame.HistsInPhase,
     994                            style=wx.LB_SINGLE,size=(-1,120))
     995        select.SetSelection(G2frame.dataFrame.HistsInPhase.index(G2frame.hist))
     996        select.SetFirstItem(G2frame.dataFrame.HistsInPhase.index(G2frame.hist))
    997997        select.Bind(wx.EVT_LISTBOX,OnSelect)
    998998        topSizer.Add(select,0,WACV|wx.LEFT,5)
    999         if PWDR:
     999        if any(['PWDR' in item for item in keyList]):
    10001000            topSizer.Add(PlotSizer())
    10011001        mainSizer.Add(topSizer)       
     
    10051005        mainSizer.Add(wx.StaticText(DData,wx.ID_ANY,'  (This project has no data; use Import to read it)'),
    10061006                      0,WACV|wx.TOP,10)
    1007     elif not UseList:
     1007    elif not UseListG2frame.dataFrame.HistsInPhase:
    10081008        mainSizer.Add(wx.StaticText(DData,wx.ID_ANY,'  (This phase has no associated data; use appropriate Edit/Add... menu item)'),
    10091009                      0,WACV|wx.TOP,10)
  • trunk/GSASIIphsGUI.py

    r2872 r2873  
    506506                NShkl = len(G2spc.MustrainNames(SGData))
    507507                NDij = len(G2spc.HStrainNames(SGData))
    508                 UseList = data['Histograms']
    509                 for hist in UseList:
    510                     UseList[hist]['Mustrain'][4:6] = [NShkl*[0.01,],NShkl*[False,]]
    511                     UseList[hist]['HStrain'] = [NDij*[0.0,],NDij*[False,]]
     508                for hist in data['Histograms']:
     509                    data['Histograms'][hist]['Mustrain'][4:6] = [NShkl*[0.01,],NShkl*[False,]]
     510                    data['Histograms'][hist]['HStrain'] = [NDij*[0.0,],NDij*[False,]]
    512511                wx.CallAfter(UpdateGeneral)
    513512               
     
    55565555       
    55575556    def OnHklfAdd(event):
    5558         UseList = data['Histograms']
    5559         keyList = UseList.keys()
     5557        keyList = data['Histograms'].keys()
    55605558        TextList = []
    55615559        if not G2frame.PatternTree.GetCount():
     
    56055603            Id = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,histoName)
    56065604            refDict,reflData = G2frame.PatternTree.GetItemPyData(Id)
    5607             UseList[histoName] = {'Histogram':histoName,'Show':False,'Scale':[1.0,True],
     5605            data['Histograms'][histoName] = {'Histogram':histoName,'Show':False,'Scale':[1.0,True],
    56085606                'Babinet':{'BabA':[0.0,False],'BabU':[0.0,False]},
    56095607                'Extinction':['Lorentzian','None',
     
    56115609                'Flack':[0.0,False],'Twins':[[np.array([[1,0,0],[0,1,0],[0,0,1]]),[1.0,False,0]],]}                       
    56125610            if 'TwMax' in reflData:     #nonmerohedral twins present
    5613                 UseList[histoName]['Twins'] = []
     5611                data['Histograms'][histoName]['Twins'] = []
    56145612                for iT in range(reflData['TwMax'][0]+1):
    56155613                    if iT in reflData['TwMax'][1]:
    5616                         UseList[histoName]['Twins'].append([False,0.0])
     5614                        data['Histograms'][histoName]['Twins'].append([False,0.0])
    56175615                    else:
    5618                         UseList[histoName]['Twins'].append([np.array([[1,0,0],[0,1,0],[0,0,1]]),[1.0,False,reflData['TwMax'][0]]])
     5616                        data['Histograms'][histoName]['Twins'].append([np.array([[1,0,0],[0,1,0],[0,0,1]]),[1.0,False,reflData['TwMax'][0]]])
    56195617            else:   #no nonmerohedral twins
    5620                 UseList[histoName]['Twins'] = [[np.array([[1,0,0],[0,1,0],[0,0,1]]),[1.0,False,0]],]
     5618                data['Histograms'][histoName]['Twins'] = [[np.array([[1,0,0],[0,1,0],[0,0,1]]),[1.0,False,0]],]
    56215619            UpdateHKLFdata(histoName)
    5622             data['Histograms'] = UseList
    56235620        wx.CallAfter(G2ddG.UpdateDData,G2frame,DData,data)
    56245621        wx.EndBusyCursor()
    56255622       
    56265623    def OnDataUse(event):
    5627         UseList = data['Histograms']
    56285624        hist = G2frame.hist
    5629         keyList = sorted(UseList.keys())
    5630         if UseList:
     5625        if data['Histograms']:
    56315626            dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame, 'Use histograms',
    5632                 'Use which histograms?',keyList)
     5627                'Use which histograms?',G2frame.dataFrame.HistsInPhase)
    56335628            try:
    56345629                if dlg.ShowModal() == wx.ID_OK:
    56355630                    sel = dlg.GetSelections()
    5636                     for id,item in enumerate(keyList):
     5631                    for id,item in enumerate(G2frame.dataFrame.HistsInPhase):
    56375632                        if id in sel:
    5638                             UseList[item]['Use'] = True
     5633                            data['Histograms'][item]['Use'] = True
    56395634                        else:
    5640                             UseList[item]['Use'] = False                       
     5635                            data['Histograms'][item]['Use'] = False                       
    56415636            finally:
    56425637                dlg.Destroy()
    56435638        wx.CallAfter(G2ddG.UpdateDData,G2frame,DData,data)
     5639
     5640    # Note: function replaced by one with identical name, below
     5641    # def UpdateHKLFdata(histoName):
     5642    #     generalData = data['General']
     5643    #     Id = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,histoName)
     5644    #     refDict,reflData = G2frame.PatternTree.GetItemPyData(Id)
     5645    #     SGData = generalData['SGData']
     5646    #     Cell = generalData['Cell'][1:7]
     5647    #     G,g = G2lat.cell2Gmat(Cell))
     5648    #         try:
     5649    #             if dlg.ShowModal() == wx.ID_OK:
     5650    #                 sel = dlg.GetSelections()
     5651    #                 for id,item in enumerate(keyList):  # <<<<< something is likely wrong here
     5652    #                     if id in sel:
     5653    #                         data['Histograms'][item]['Use'] = True
     5654    #                     else:
     5655    #                         data['Histograms'][item]['Use'] = False                       
     5656    #         finally:
     5657    #             dlg.Destroy()
     5658    #     wx.CallAfter(G2ddG.UpdateDData,G2frame,DData,data)
    56445659               
    56455660    def UpdateHKLFdata(histoName):
     
    56565671       
    56575672    def OnDataCopy(event):
    5658         UseList = data['Histograms']
    56595673        hist = G2frame.hist
    5660         keyList = sorted(UseList.keys())
     5674        keyList = G2frame.dataFrame.HistsInPhase[:]
    56615675        if hist in keyList: keyList.remove(hist)
    5662         sourceDict = UseList[hist]
     5676        if not keyList:
     5677            G2G.G2MessageBox(G2frame.dataFrame,'No histograms to copy to')
     5678            return
     5679        sourceDict = data['Histograms'][hist]
    56635680        if 'HKLF' in sourceDict['Histogram']:
    56645681            copyNames = ['Scale','Extinction','Babinet','Flack','Twins']
     
    56685685        for name in copyNames:
    56695686            copyDict[name] = copy.deepcopy(sourceDict[name])        #force copy
    5670         if UseList:
    5671             dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame,
    5672                     u'Copy phase/histogram parameters\nfrom '+hist[5:][:35],
    5673                     'Copy phase/hist parameters', keyList)
    5674             try:
    5675                 if dlg.ShowModal() == wx.ID_OK:
    5676                     for sel in dlg.GetSelections():
    5677                         UseList[keyList[sel]].update(copy.deepcopy(copyDict))
    5678             finally:
    5679                 dlg.Destroy()
     5687        dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame,
     5688                u'Copy phase/histogram parameters\nfrom '+hist[5:][:35],
     5689                'Copy phase/hist parameters', keyList)
     5690        try:
     5691            if dlg.ShowModal() == wx.ID_OK:
     5692                for sel in dlg.GetSelections():
     5693                    data['Histograms'][keyList[sel]].update(copy.deepcopy(copyDict))
     5694        finally:
     5695            dlg.Destroy()
    56805696       
    56815697    def OnDataCopyFlags(event):
    5682         UseList = data['Histograms']
    56835698        hist = G2frame.hist
    5684         sourceDict = UseList[hist]
     5699        sourceDict = data['Histograms'][hist]
    56855700        copyDict = {}
    56865701        if 'HKLF' in sourceDict['Histogram']:
     
    57135728                for bab in babNames:
    57145729                    copyDict[name][bab] = sourceDict[name][bab][1]                       
    5715         keyList = sorted(UseList.keys())
     5730        keyList = G2frame.dataFrame.HistsInPhase[:]
    57165731        if hist in keyList: keyList.remove(hist)
    5717         if UseList:
    5718             dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame,
    5719                     u'Copy phase/histogram flags\nfrom '+hist[5:][:35],
    5720                     'Copy phase/hist flags', keyList)
    5721             try:
    5722                 if dlg.ShowModal() == wx.ID_OK:
    5723                     for sel in dlg.GetSelections():
    5724                         item = keyList[sel]
    5725                         UseList[item]
    5726                         for name in copyNames:
    5727                             if name in ['Scale','Extinction','HStrain','Flack','Twins']:
    5728                                 if name == 'Extinction' and 'HKLF' in sourceDict['Histogram']:
    5729                                     UseList[item][name][:2] = copy.deepcopy(sourceDict[name][:2])
    5730                                     for itm in ['Eg','Es','Ep']:
    5731                                         UseList[item][name][2][itm][1] = copy.deepcopy(copyDict[name][itm])
    5732                                 elif name == 'Twins':
    5733                                     UseList[item]['Twins'][0][1][1] = copyDict['Twins']
    5734                                 else:
    5735                                     try:
    5736                                         UseList[item][name][1] = copy.deepcopy(copyDict[name])
    5737                                     except KeyError:
    5738                                         continue
    5739                             elif name in ['Size','Mustrain']:
    5740                                 UseList[item][name][0] = copy.deepcopy(copyDict[name][0])
    5741                                 UseList[item][name][2] = copy.deepcopy(copyDict[name][1])
    5742                                 UseList[item][name][4] = copy.deepcopy(copyDict[name][2])
    5743                             elif name == 'Pref.Ori.':
    5744                                 UseList[item][name][0] = copy.deepcopy(copyDict[name][0])
    5745                                 UseList[item][name][2] = copy.deepcopy(copyDict[name][1])
    5746                                 if sourceDict[name][0] == 'SH':
    5747                                    SHflags = copy.deepcopy(copyDict[name][2])
    5748                                    SHterms = copy.deepcopy(sourceDict[name][5])
    5749                                    UseList[item][name][6] = copy.deepcopy(sourceDict[name][6])
    5750                                    UseList[item][name][7] = copy.deepcopy(sourceDict[name][7])
    5751                             elif name == 'Babinet':
    5752                                 for bab in babNames:
    5753                                     UseList[item][name][bab][1] = copy.deepcopy(copyDict[name][bab])                                             
    5754             finally:
    5755                 dlg.Destroy()
     5732        if not keyList:
     5733            G2G.G2MessageBox(G2frame.dataFrame,'No histograms to copy to')
     5734            return
     5735        dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame,
     5736                u'Copy phase/histogram flags\nfrom '+hist[5:][:35],
     5737                'Copy phase/hist flags', keyList)
     5738        try:
     5739            if dlg.ShowModal() == wx.ID_OK:
     5740                for sel in dlg.GetSelections():
     5741                    item = keyList[sel]
     5742                    for name in copyNames:
     5743                        if name in ['Scale','Extinction','HStrain','Flack','Twins']:
     5744                            if name == 'Extinction' and 'HKLF' in sourceDict['Histogram']:
     5745                                data['Histograms'][item][name][:2] = copy.deepcopy(sourceDict[name][:2])
     5746                                for itm in ['Eg','Es','Ep']:
     5747                                    data['Histograms'][item][name][2][itm][1] = copy.deepcopy(copyDict[name][itm])
     5748                            elif name == 'Twins':
     5749                                data['Histograms'][item]['Twins'][0][1][1] = copyDict['Twins']
     5750                            else:
     5751                                try:
     5752                                    data['Histograms'][item][name][1] = copy.deepcopy(copyDict[name])
     5753                                except KeyError:
     5754                                    continue
     5755                        elif name in ['Size','Mustrain']:
     5756                            data['Histograms'][item][name][0] = copy.deepcopy(copyDict[name][0])
     5757                            data['Histograms'][item][name][2] = copy.deepcopy(copyDict[name][1])
     5758                            data['Histograms'][item][name][4] = copy.deepcopy(copyDict[name][2])
     5759                        elif name == 'Pref.Ori.':
     5760                            data['Histograms'][item][name][0] = copy.deepcopy(copyDict[name][0])
     5761                            data['Histograms'][item][name][2] = copy.deepcopy(copyDict[name][1])
     5762                            if sourceDict[name][0] == 'SH':
     5763                               SHflags = copy.deepcopy(copyDict[name][2])
     5764                               SHterms = copy.deepcopy(sourceDict[name][5])
     5765                               data['Histograms'][item][name][6] = copy.deepcopy(sourceDict[name][6])
     5766                               data['Histograms'][item][name][7] = copy.deepcopy(sourceDict[name][7])
     5767                        elif name == 'Babinet':
     5768                            for bab in babNames:
     5769                                data['Histograms'][item][name][bab][1] = copy.deepcopy(copyDict[name][bab])                                             
     5770        finally:
     5771            dlg.Destroy()
    57565772       
    57575773    def OnSelDataCopy(event):
    5758         UseList = data['Histograms']
    57595774        hist = G2frame.hist
    5760         keyList = sorted(UseList.keys())
     5775        sourceDict = data['Histograms'][hist]
     5776        keyList = G2frame.dataFrame.HistsInPhase[:]
    57615777        if hist in keyList: keyList.remove(hist)
    5762         sourceDict = UseList[hist]
     5778        if not keyList:
     5779            G2G.G2MessageBox(G2frame.dataFrame,'No histograms to copy to')
     5780            return
    57635781        copyDict = {}
    57645782        if 'HKLF' in sourceDict['Histogram']:
     
    57785796        for parm in selectedItems:
    57795797            copyDict[parm] = copy.deepcopy(sourceDict[parm])
    5780         if UseList:
    5781             dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame,
    5782                     u'Copy selected phase/histogram parameters\nfrom '+hist[5:][:35],
    5783                     'Copy selected phase/hist parameters', keyList)
    5784             try:
    5785                 if dlg.ShowModal() == wx.ID_OK:
    5786                     for sel in dlg.GetSelections():
    5787                         UseList[keyList[sel]].update(copy.deepcopy(copyDict))
    5788             finally:
    5789                 dlg.Destroy()           
     5798        dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame,
     5799                        u'Copy selected phase/histogram parameters\nfrom '+hist[5:][:35],
     5800                        'Copy selected phase/hist parameters', keyList)
     5801        try:
     5802            if dlg.ShowModal() == wx.ID_OK:
     5803                for sel in dlg.GetSelections():
     5804                    data['Histograms'][keyList[sel]].update(copy.deepcopy(copyDict))
     5805        finally:
     5806            dlg.Destroy()           
    57905807       
    57915808    def OnPwdrAdd(event):
    57925809        generalData = data['General']
    57935810        SGData = generalData['SGData']
    5794         UseList = data['Histograms']
    57955811        newList = []
    57965812        NShkl = len(G2spc.MustrainNames(SGData))
    57975813        NDij = len(G2spc.HStrainNames(SGData))
    5798         keyList = UseList.keys()
     5814        keyList = data['Histograms'].keys()
    57995815        TextList = []
    58005816        if G2frame.PatternTree.GetCount():
     
    58185834                    for histoName in newList:
    58195835                        Id = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,histoName)
    5820                         UseList[histoName] = {'Histogram':histoName,'Show':False,'LeBail':False,'newLeBail':True,
     5836                        data['Histograms'][histoName] = {'Histogram':histoName,'Show':False,'LeBail':False,'newLeBail':True,
    58215837                            'Scale':[1.0,False],'Pref.Ori.':['MD',1.0,False,[0,0,1],0,{},['',],0.1],
    58225838                            'Size':['isotropic',[1.,1.,1.],[False,False,False],[0,0,1],
     
    58285844                        refList = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Reflection Lists'))
    58295845                        refList[generalData['Name']] = {}                       
    5830                     data['Histograms'] = UseList
    58315846                    wx.CallAfter(G2ddG.UpdateDData,G2frame,DData,data)
    58325847            finally:
     
    58345849               
    58355850    def OnDataDelete(event):
    5836         UseList = data['Histograms']
    5837         keyList = sorted(UseList.keys())
    5838         keyList.sort()
    5839         if UseList:
     5851        if G2frame.dataFrame.HistsInPhase:
    58405852            DelList = []
    58415853            dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame, 'Delete histogram',
    5842                 'Which histogram to delete from this phase?',keyList)
     5854                'Which histogram to delete from this phase?',G2frame.dataFrame.HistsInPhase)
    58435855            try:
    58445856                if dlg.ShowModal() == wx.ID_OK:
    5845                     result = dlg.GetSelections()
    5846                     for i in result:
    5847                         DelList.append(keyList[i])
     5857                    DelList = [G2frame.dataFrame.HistsInPhase[i] for i in dlg.GetSelections()]
    58485858                    for i in DelList:
    5849                         del UseList[i]
    5850                     data['Histograms'] = UseList
     5859                        del data['Histograms'][i]
    58515860            finally:
    58525861                dlg.Destroy()
Note: See TracChangeset for help on using the changeset viewer.