Changeset 2667


Ignore:
Timestamp:
Jan 27, 2017 5:11:33 PM (5 years ago)
Author:
toby
Message:

prevent Unicode in data tree names; move PDF setup to standalone routine

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r2660 r2667  
    873873                    HistName = dlg.GetValue()
    874874                dlg.Destroy()
    875             HistName = 'HKLF '+HistName
     875            HistName = 'HKLF '+G2obj.StripUnicode(HistName,'_')
    876876            # make new histogram names unique
    877877            if len(rd.Banks):
     
    15491549                        Iparm1[key] = rd.instdict[key]
    15501550            lastdatafile = rd.powderentry[0]
    1551             HistName = rd.idstring
    1552             HistName = 'PWDR '+HistName
     1551            HistName = 'PWDR '+G2obj.StripUnicode(rd.idstring,'_')
    15531552            # make new histogram names unique
    15541553            if HistName in PWDRlist:
     
    35953594                if dlg.ShowModal() == wx.ID_OK:
    35963595                    for i in dlg.GetSelections():
    3597                         item = TextList[i]
    3598                         ElList = ElLists[i]
    3599                         PWDRname = item[4:]
    3600                         Id = self.PatternTree.AppendItem(parent=self.root,text='PDF '+PWDRname)
    3601                         Data = {
    3602                             'Sample':{'Name':item,'Mult':1.0},
    3603                             'Sample Bkg.':{'Name':'','Mult':-1.0},
    3604                             'Container':{'Name':'','Mult':-1.0},
    3605                             'Container Bkg.':{'Name':'','Mult':-1.0,'Add':0.0},'ElList':ElList,
    3606                             'Geometry':'Cylinder','Diam':1.0,'Pack':0.50,'Form Vol':10.0,
    3607                             'DetType':'Image plate','ObliqCoeff':0.2,'Ruland':0.025,'QScaleLim':Qlimits[i],
    3608                             'Lorch':False,'BackRatio':0.0,'Rmax':100.,'noRing':False,'IofQmin':1.0,
    3609                             'I(Q)':[],'S(Q)':[],'F(Q)':[],'G(R)':[]}
    3610                         self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='PDF Controls'),Data)
    3611                         self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='PDF Peaks'),
    3612                             {'Limits':[1.,5.],'Background':[2,[0.,-0.2*np.pi],False],'Peaks':[]})       
     3596                        G2obj.CreatePDFitems(self,TextList[i],ElLists[i],Qlimits[i])
    36133597                for item in self.ExportPDF: item.Enable(True)
    36143598            finally:
  • trunk/GSASIIobj.py

    r2546 r2667  
    883883data tree item.
    884884'''
     885def StripUnicode(string,subs='.'):
     886    '''Strip non-ASCII characters from strings
     887   
     888    :param str string: string to strip Unicode characters from
     889    :param str subs: character(s) to place into string in place of each
     890      Unicode character. Defaults to '.'
     891
     892    :returns: a new string with only ASCII characters
     893    '''
     894    s = ''
     895    for c in string:
     896        if ord(c) < 128:
     897            s += c
     898        else:
     899            s += subs
     900    return s.encode('ascii','replace')
    885901
    886902def MakeUniqueLabel(lbl,labellist):
     
    893909      ``_10-99``, etc.) appended at the end
    894910    '''
    895     lbl = lbl.strip()
     911    lbl = StripUnicode(lbl.strip(),'_')
    896912    if not lbl: # deal with a blank label
    897913        lbl = '_1'
     
    20682084        return repr(self.msg)
    20692085
     2086def CreatePDFitems(G2frame,PWDRtree,ElList,Qlimits):
     2087    '''Create and initialize a new set of PDF tree entries
     2088
     2089    :param Frame G2frame: main GSAS-II tree frame object
     2090    :param str PWDRtree: name of PWDR to be used to create PDF item
     2091    :param dict ElList: data structure with composition
     2092    :param list Qlimits: Q limits to be used for computing the PDF
     2093    :returns: the Id of the newly created PDF entry
     2094    '''
     2095    PWDRname = PWDRtree[4:]
     2096    Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text='PDF '+PWDRname)
     2097    Data = {
     2098        'Sample':{'Name':PWDRtree,'Mult':1.0},
     2099        'Sample Bkg.':{'Name':'','Mult':-1.0},
     2100        'Container':{'Name':'','Mult':-1.0},
     2101        'Container Bkg.':{'Name':'','Mult':-1.0,'Add':0.0},'ElList':ElList,
     2102        'Geometry':'Cylinder','Diam':1.0,'Pack':0.50,'Form Vol':10.0,
     2103        'DetType':'Image plate','ObliqCoeff':0.2,'Ruland':0.025,'QScaleLim':Qlimits,
     2104        'Lorch':False,'BackRatio':0.0,'Rmax':100.,'noRing':False,'IofQmin':1.0,
     2105        'I(Q)':[],'S(Q)':[],'F(Q)':[],'G(R)':[]}
     2106    G2frame.PatternTree.SetItemPyData(G2frame.PatternTree.AppendItem(Id,text='PDF Controls'),Data)
     2107    G2frame.PatternTree.SetItemPyData(G2frame.PatternTree.AppendItem(Id,text='PDF Peaks'),
     2108        {'Limits':[1.,5.],'Background':[2,[0.,-0.2*np.pi],False],'Peaks':[]})
     2109    return Id       
     2110
    20702111
    20712112if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.