Skip to content

Commit 00ebc2c

Browse files
committed
Merge branch 'TOFgroup' of github.com:AdvancedPhotonSource/GSAS-II into TOFgroup
merge two different sets of changes
2 parents 249020c + 85b53a0 commit 00ebc2c

File tree

2 files changed

+60
-18
lines changed

2 files changed

+60
-18
lines changed

GSASII/GSASIIgroupGUI.py

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* 'txt' : str
3333
* 'init' : float
3434
* 'rowlbl' : (array, key)
35+
* 'setintfunc' : function
3536
3637
One of 'val', 'ref' or 'str' elements will be present.
3738
@@ -76,6 +77,9 @@
7677
should not be enforced. The 'range' values will be used as limits
7778
for the entry widget.
7879
80+
* The 'setintfunc' value defines a function that is executed when the
81+
'ref' tuple is changed. When this is supplied, a spin box is used
82+
to set the value rather than a TextCtrl.
7983
'''
8084

8185
# import math
@@ -273,6 +277,7 @@ def OnCopySel(event):
273277
G2frame.GroupInfo = {}
274278
# start with Sample but reuse the last displayed item
275279
G2frame.GroupInfo['displayMode'] = G2frame.GroupInfo.get('displayMode','Sample')
280+
#G2frame.GroupInfo['displayMode'] = G2frame.GroupInfo.get('displayMode','Background')
276281
G2frame.GroupInfo['groupName'] = G2frame.GPXtree.GetItemText(item)
277282
G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.GroupMenu)
278283
G2frame.Bind(wx.EVT_MENU, OnCopyAll, id=G2G.wxID_GRPALL)
@@ -378,13 +383,10 @@ def onSetAll(event):
378383
all edit widgets
379384
'''
380385
but = event.GetEventObject()
381-
dataSource = but.valDict['dataSource']
382-
valList = but.valDict['arrays']
383-
histList = but.valDict['hists']
384-
valEditList = but.valDict['valEditList']
385-
firstVal = indexArrayVal(dataSource,histList[0],valList[0])
386-
for c in valEditList:
387-
c.ChangeValue(firstVal)
386+
firstVal = indexArrayVal(but.valDict['dataSource'],
387+
but.valDict['hists'][0],but.valDict['arrays'][0])
388+
for f in but.valDict['valSetFxnList']:
389+
f(firstVal)
388390

389391
def onResetAll(event):
390392
'''Respond to the Reset button. Copies the initial setting (which
@@ -407,17 +409,25 @@ def displayDataArray(rowLabels,DataArray,Sizer,Panel,lblRow=False,deltaMode=Fals
407409
'''Displays the data table in `DataArray` in Scrolledpanel `Panel`
408410
with wx.FlexGridSizer `Sizer`.
409411
'''
412+
def OnSpin(evt):
413+
'''respond when a SpinButton entry is changed (currently used for
414+
background terms only)
415+
'''
416+
spin = (evt.GetEventObject())
417+
spin.arr[spin.indx] = evt.GetEventObject().GetValue()
418+
spin.txt.SetLabel(str(spin.arr[spin.indx]))
419+
spin.setTermsFnx()
410420
firstentry = None
411421
#lblRow = True
412422
if lblSizer is None: lblSizer = Sizer
413423
if lblPanel is None: lblPanel = Panel
414424
checkButList = {}
415-
valEditList = {}
425+
valSetFxnList = {}
416426
lblDict = {}
417427
dataSource = DataArray['_dataSource']
418428
for row in rowLabels:
419429
checkButList[row] = []
420-
valEditList[row] = []
430+
valSetFxnList[row] = []
421431
# show the row labels, when not in a separate sizer
422432
if lblRow:
423433
# is a copy across and/or a refine all button needed?
@@ -429,7 +439,6 @@ def displayDataArray(rowLabels,DataArray,Sizer,Panel,lblRow=False,deltaMode=Fals
429439
valList.append(DataArray[hist][row]['val'])
430440
if 'ref' in DataArray[hist][row]:
431441
refList.append(DataArray[hist][row]['ref'])
432-
433442
arr = None
434443
histList = []
435444
for hist in DataArray:
@@ -445,7 +454,7 @@ def displayDataArray(rowLabels,DataArray,Sizer,Panel,lblRow=False,deltaMode=Fals
445454
lblSizer.Add(w,0,wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
446455
lblDict[row] = w
447456

448-
if len(refList) > 2:
457+
if len(refList) > 2: # >two refinement flags in this row. Include ste/clear all button
449458
lbl = SetAllLbl
450459
if all([indexArrayVal(dataSource,hist,i) for i in refList]): lbl = ClearAllLbl
451460
refAll = wx.Button(lblPanel,label=lbl,style=wx.BU_EXACTFIT)
@@ -472,10 +481,11 @@ def displayDataArray(rowLabels,DataArray,Sizer,Panel,lblRow=False,deltaMode=Fals
472481
if hist == '_dataSource': continue
473482
i += 1
474483
if i == 1 and len(valList) > 2 and not deltaMode and CopyCtrl:
484+
# copy button; place after 0th column
475485
but = wx.Button(Panel,wx.ID_ANY,'\u2192',style=wx.BU_EXACTFIT)
476486
but.valDict = {'arrays': valList, 'hists': histList,
477487
'dataSource':dataSource,
478-
'valEditList' :valEditList[row]}
488+
'valSetFxnList' :valSetFxnList[row]}
479489
Sizer.Add(but,0,wx.ALIGN_CENTER_VERTICAL)
480490
but.Bind(wx.EVT_BUTTON,onSetAll)
481491
elif i == 1 and CopyCtrl:
@@ -508,7 +518,7 @@ def displayDataArray(rowLabels,DataArray,Sizer,Panel,lblRow=False,deltaMode=Fals
508518
Sizer.Add(valrefsiz,0,
509519
wx.EXPAND|wx.ALIGN_RIGHT)
510520
elif 'init' in DataArray[hist][row] and deltaMode:
511-
# does this ever happen?
521+
# I don't think this ever happens
512522
arr,indx = indexArrayRef(dataSource,hist,DataArray[hist][row]['val'])
513523
delta = arr[indx]
514524
arr,indx = DataArray[hist][row]['init']
@@ -519,13 +529,35 @@ def displayDataArray(rowLabels,DataArray,Sizer,Panel,lblRow=False,deltaMode=Fals
519529
deltaS = f"\u0394 {delta:.4g} "
520530
Sizer.Add(wx.StaticText(Panel,label=deltaS),0,
521531
wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
532+
elif 'setintfunc' in DataArray[hist][row]:
533+
spinsiz = wx.BoxSizer(wx.HORIZONTAL)
534+
spin = wx.SpinButton(Panel, wx.ID_ANY)
535+
spin.Bind(wx.EVT_SPIN, OnSpin)
536+
spin.txt = wx.StaticText(Panel,label='?')
537+
spinsiz.Add(spin.txt,0,wx.ALIGN_CENTER_VERTICAL)
538+
spinsiz.Add((5,-1))
539+
spinsiz.Add(spin,0,wx.ALIGN_CENTER_VERTICAL)
540+
Sizer.Add(spinsiz,0,wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER)
541+
542+
spin.SetRange(1,36)
543+
spin.arr,spin.indx = indexArrayRef(dataSource,hist,DataArray[hist][row]['val'])
544+
spin.setTermsFnx = DataArray[hist][row]['setintfunc']
545+
spin.SetValue(spin.arr[spin.indx])
546+
spin.txt.SetLabel(str(spin.arr[spin.indx]))
547+
def SetVal(newval,spin=spin):
548+
'Used to set a value for the current spinbutton & associated StaticText'
549+
spin.arr[spin.indx] = newval
550+
spin.SetValue(spin.arr[spin.indx])
551+
spin.txt.SetLabel(str(newval))
552+
spin.setTermsFnx()
553+
valSetFxnList[row].append(SetVal)
522554
elif 'val' in DataArray[hist][row] and 'ref' in DataArray[hist][row]:
523555
valrefsiz = wx.BoxSizer(wx.HORIZONTAL)
524556
arr,indx = indexArrayRef(dataSource,hist,DataArray[hist][row]['val'])
525557
w = G2G.ValidatedTxtCtrl(Panel,arr,indx,size=(80,-1),
526558
nDig=[9,7,'g'],
527559
xmin=minval,xmax=maxval)
528-
valEditList[row].append(w)
560+
valSetFxnList[row].append(w.ChangeValue)
529561
valrefsiz.Add(w,0,WACV)
530562
if firstentry is None: firstentry = w
531563
arr,indx = indexArrayRef(dataSource,hist,DataArray[hist][row]['ref'])
@@ -541,7 +573,7 @@ def displayDataArray(rowLabels,DataArray,Sizer,Panel,lblRow=False,deltaMode=Fals
541573
w = G2G.ValidatedTxtCtrl(Panel,arr,indx,size=(80,-1),
542574
nDig=nDig,
543575
xmin=minval,xmax=maxval,notBlank=False)
544-
valEditList[row].append(w)
576+
valSetFxnList[row].append(w.ChangeValue)
545577
Sizer.Add(w,0,wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT)
546578
if firstentry is None: firstentry = w
547579

@@ -579,7 +611,7 @@ def HistFrame(G2frame,Histograms,refresh=None):
579611
prmArray = getLimitVals(G2frame,Histograms)
580612
elif G2frame.GroupInfo['displayMode'].startswith('Background'):
581613
prmArray = getBkgVals(G2frame,Histograms)
582-
CopyCtrl = False
614+
CopyCtrl = True
583615
else:
584616
prmArray = None
585617
print('Unexpected', G2frame.GroupInfo['displayMode'])
@@ -849,12 +881,19 @@ def getBkgVals(G2frame,Histograms):
849881
indexDict[hist] = {}
850882
for lbl,indx,typ in [('Function',0,'str'),
851883
('ref flag',1,'ref'),
852-
('# Bkg terms',2,'str')]:
884+
('# Bkg terms',2,'val')]:
853885
indexDict[hist][lbl] = {
854886
typ : ('Background',0,indx)
855887
}
856888
if indx == 2:
857889
indexDict[hist][lbl]['fmt'] = '.0f'
890+
def OnChangeBkgTerms(Histograms=Histograms,hist=hist):
891+
'set the number of terms to match the new number'
892+
nterms = Histograms[hist]['Background'][0][2]
893+
Histograms[hist]['Background'][0][3:] = (
894+
Histograms[hist]['Background'][0][3:] +
895+
36*[0.0])[:nterms]
896+
indexDict[hist][lbl]['setintfunc'] = OnChangeBkgTerms
858897
indexDict[hist]['# Debye terms'] = {
859898
'str' : ('Background',1,'nDebye'),
860899
'fmt' : '.0f'}

GSASII/GSASIIplot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,10 @@ def FindPlotTab(self,label,Type,newImage=True,saveLimits=False):
471471
Page.helpKey = self.G2frame.dataWindow.helpKey
472472
except AttributeError:
473473
Page.helpKey = 'HelpIntro'
474-
Page.toolbar.enableArrows() # Disable Arrow keys if present
474+
try:
475+
Page.toolbar.enableArrows() # Disable Arrow keys if present
476+
except AttributeError:
477+
pass
475478
return new,plotNum,Page,Plot,limits
476479

477480
def savePlotLims(self,Page=None,debug=False,label=None):

0 commit comments

Comments
 (0)