3232 * 'txt' : str
3333 * 'init' : float
3434 * 'rowlbl' : (array, key)
35+ * 'setintfunc' : function
3536
3637One of 'val', 'ref' or 'str' elements will be present.
3738
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
@@ -269,6 +273,7 @@ def OnCopySel(event):
269273 if not hasattr (G2frame ,'GroupInfo' ):
270274 G2frame .GroupInfo = {}
271275 G2frame .GroupInfo ['displayMode' ] = G2frame .GroupInfo .get ('displayMode' ,'Sample' )
276+ #G2frame.GroupInfo['displayMode'] = G2frame.GroupInfo.get('displayMode','Background')
272277 G2frame .GroupInfo ['groupName' ] = G2frame .GPXtree .GetItemText (item )
273278 G2gd .SetDataMenuBar (G2frame ,G2frame .dataWindow .GroupMenu )
274279 G2frame .Bind (wx .EVT_MENU , OnCopyAll , id = G2G .wxID_GRPALL )
@@ -374,30 +379,35 @@ def onSetAll(event):
374379 all edit widgets
375380 '''
376381 but = event .GetEventObject ()
377- dataSource = but .valDict ['dataSource' ]
378- valList = but .valDict ['arrays' ]
379- histList = but .valDict ['hists' ]
380- valEditList = but .valDict ['valEditList' ]
381- firstVal = indexArrayVal (dataSource ,histList [0 ],valList [0 ])
382- for c in valEditList :
383- c .ChangeValue (firstVal )
382+ firstVal = indexArrayVal (but .valDict ['dataSource' ],
383+ but .valDict ['hists' ][0 ],but .valDict ['arrays' ][0 ])
384+ for f in but .valDict ['valSetFxnList' ]:
385+ f (firstVal )
384386
385387def displayDataArray (rowLabels ,DataArray ,Sizer ,Panel ,lblRow = False ,deltaMode = False ,
386388 lblSizer = None ,lblPanel = None ,CopyCtrl = True ):
387389 '''Displays the data table in `DataArray` in Scrolledpanel `Panel`
388390 with wx.FlexGridSizer `Sizer`.
389391 '''
392+ def OnSpin (evt ):
393+ '''respond when a SpinButton entry is changed (currently used for
394+ background terms only)
395+ '''
396+ spin = (evt .GetEventObject ())
397+ spin .arr [spin .indx ] = evt .GetEventObject ().GetValue ()
398+ spin .txt .SetLabel (str (spin .arr [spin .indx ]))
399+ spin .setTermsFnx ()
390400 firstentry = None
391401 #lblRow = True
392402 if lblSizer is None : lblSizer = Sizer
393403 if lblPanel is None : lblPanel = Panel
394404 checkButList = {}
395- valEditList = {}
405+ valSetFxnList = {}
396406 lblDict = {}
397407 dataSource = DataArray ['_dataSource' ]
398408 for row in rowLabels :
399409 checkButList [row ] = []
400- valEditList [row ] = []
410+ valSetFxnList [row ] = []
401411 # show the row labels, when not in a separate sizer
402412 if lblRow :
403413 # is a copy across and/or a refine all button needed?
@@ -409,7 +419,6 @@ def displayDataArray(rowLabels,DataArray,Sizer,Panel,lblRow=False,deltaMode=Fals
409419 valList .append (DataArray [hist ][row ]['val' ])
410420 if 'ref' in DataArray [hist ][row ]:
411421 refList .append (DataArray [hist ][row ]['ref' ])
412-
413422 arr = None
414423 histList = []
415424 for hist in DataArray :
@@ -425,7 +434,7 @@ def displayDataArray(rowLabels,DataArray,Sizer,Panel,lblRow=False,deltaMode=Fals
425434 lblSizer .Add (w ,0 ,wx .ALIGN_CENTER_VERTICAL | wx .ALIGN_RIGHT )
426435 lblDict [row ] = w
427436
428- if len (refList ) > 2 :
437+ if len (refList ) > 2 : # >two refinement flags in this row. Include ste/clear all button
429438 lbl = SetAllLbl
430439 if all ([indexArrayVal (dataSource ,hist ,i ) for i in refList ]): lbl = ClearAllLbl
431440 refAll = wx .Button (lblPanel ,label = lbl ,style = wx .BU_EXACTFIT )
@@ -445,10 +454,11 @@ def displayDataArray(rowLabels,DataArray,Sizer,Panel,lblRow=False,deltaMode=Fals
445454 if hist == '_dataSource' : continue
446455 i += 1
447456 if i == 1 and len (valList ) > 2 and not deltaMode and CopyCtrl :
457+ # copy button; place after 0th column
448458 but = wx .Button (Panel ,wx .ID_ANY ,'\u2192 ' ,style = wx .BU_EXACTFIT )
449459 but .valDict = {'arrays' : valList , 'hists' : histList ,
450460 'dataSource' :dataSource ,
451- 'valEditList ' :valEditList [row ]}
461+ 'valSetFxnList ' :valSetFxnList [row ]}
452462 Sizer .Add (but ,0 ,wx .ALIGN_CENTER_VERTICAL )
453463 but .Bind (wx .EVT_BUTTON ,onSetAll )
454464 elif i == 1 and CopyCtrl :
@@ -481,7 +491,7 @@ def displayDataArray(rowLabels,DataArray,Sizer,Panel,lblRow=False,deltaMode=Fals
481491 Sizer .Add (valrefsiz ,0 ,
482492 wx .EXPAND | wx .ALIGN_RIGHT )
483493 elif 'init' in DataArray [hist ][row ] and deltaMode :
484- # does this ever happen?
494+ # I don't think this ever happens
485495 arr ,indx = indexArrayRef (dataSource ,hist ,DataArray [hist ][row ]['val' ])
486496 delta = arr [indx ]
487497 arr ,indx = DataArray [hist ][row ]['init' ]
@@ -492,13 +502,35 @@ def displayDataArray(rowLabels,DataArray,Sizer,Panel,lblRow=False,deltaMode=Fals
492502 deltaS = f"\u0394 { delta :.4g} "
493503 Sizer .Add (wx .StaticText (Panel ,label = deltaS ),0 ,
494504 wx .ALIGN_CENTER_VERTICAL | wx .ALIGN_RIGHT )
505+ elif 'setintfunc' in DataArray [hist ][row ]:
506+ spinsiz = wx .BoxSizer (wx .HORIZONTAL )
507+ spin = wx .SpinButton (Panel , wx .ID_ANY )
508+ spin .Bind (wx .EVT_SPIN , OnSpin )
509+ spin .txt = wx .StaticText (Panel ,label = '?' )
510+ spinsiz .Add (spin .txt ,0 ,wx .ALIGN_CENTER_VERTICAL )
511+ spinsiz .Add ((5 ,- 1 ))
512+ spinsiz .Add (spin ,0 ,wx .ALIGN_CENTER_VERTICAL )
513+ Sizer .Add (spinsiz ,0 ,wx .ALIGN_CENTER_VERTICAL | wx .ALIGN_CENTER )
514+
515+ spin .SetRange (1 ,36 )
516+ spin .arr ,spin .indx = indexArrayRef (dataSource ,hist ,DataArray [hist ][row ]['val' ])
517+ spin .setTermsFnx = DataArray [hist ][row ]['setintfunc' ]
518+ spin .SetValue (spin .arr [spin .indx ])
519+ spin .txt .SetLabel (str (spin .arr [spin .indx ]))
520+ def SetVal (newval ,spin = spin ):
521+ 'Used to set a value for the current spinbutton & associated StaticText'
522+ spin .arr [spin .indx ] = newval
523+ spin .SetValue (spin .arr [spin .indx ])
524+ spin .txt .SetLabel (str (newval ))
525+ spin .setTermsFnx ()
526+ valSetFxnList [row ].append (SetVal )
495527 elif 'val' in DataArray [hist ][row ] and 'ref' in DataArray [hist ][row ]:
496528 valrefsiz = wx .BoxSizer (wx .HORIZONTAL )
497529 arr ,indx = indexArrayRef (dataSource ,hist ,DataArray [hist ][row ]['val' ])
498530 w = G2G .ValidatedTxtCtrl (Panel ,arr ,indx ,size = (80 ,- 1 ),
499531 nDig = [9 ,7 ,'g' ],
500532 xmin = minval ,xmax = maxval )
501- valEditList [row ].append (w )
533+ valSetFxnList [row ].append (w . ChangeValue )
502534 valrefsiz .Add (w ,0 ,WACV )
503535 if firstentry is None : firstentry = w
504536 arr ,indx = indexArrayRef (dataSource ,hist ,DataArray [hist ][row ]['ref' ])
@@ -514,7 +546,7 @@ def displayDataArray(rowLabels,DataArray,Sizer,Panel,lblRow=False,deltaMode=Fals
514546 w = G2G .ValidatedTxtCtrl (Panel ,arr ,indx ,size = (80 ,- 1 ),
515547 nDig = nDig ,
516548 xmin = minval ,xmax = maxval ,notBlank = False )
517- valEditList [row ].append (w )
549+ valSetFxnList [row ].append (w . ChangeValue )
518550 Sizer .Add (w ,0 ,wx .ALIGN_CENTER_VERTICAL | wx .ALIGN_LEFT )
519551 if firstentry is None : firstentry = w
520552
@@ -552,7 +584,7 @@ def HistFrame(G2frame,Histograms):
552584 prmArray = getLimitVals (G2frame ,Histograms )
553585 elif G2frame .GroupInfo ['displayMode' ].startswith ('Background' ):
554586 prmArray = getBkgVals (G2frame ,Histograms )
555- CopyCtrl = False
587+ CopyCtrl = True
556588 else :
557589 prmArray = None
558590 print ('Unexpected' , G2frame .GroupInfo ['displayMode' ])
@@ -818,12 +850,19 @@ def getBkgVals(G2frame,Histograms):
818850 indexDict [hist ] = {}
819851 for lbl ,indx ,typ in [('Function' ,0 ,'str' ),
820852 ('ref flag' ,1 ,'ref' ),
821- ('# Bkg terms' ,2 ,'str ' )]:
853+ ('# Bkg terms' ,2 ,'val ' )]:
822854 indexDict [hist ][lbl ] = {
823855 typ : ('Background' ,0 ,indx )
824856 }
825857 if indx == 2 :
826858 indexDict [hist ][lbl ]['fmt' ] = '.0f'
859+ def OnChangeBkgTerms (Histograms = Histograms ,hist = hist ):
860+ 'set the number of terms to match the new number'
861+ nterms = Histograms [hist ]['Background' ][0 ][2 ]
862+ Histograms [hist ]['Background' ][0 ][3 :] = (
863+ Histograms [hist ]['Background' ][0 ][3 :] +
864+ 36 * [0.0 ])[:nterms ]
865+ indexDict [hist ][lbl ]['setintfunc' ] = OnChangeBkgTerms
827866 indexDict [hist ]['# Debye terms' ] = {
828867 'str' : ('Background' ,1 ,'nDebye' ),
829868 'fmt' : '.0f' }
0 commit comments