Skip to content

Commit df1849d

Browse files
committed
finish copy/ref button implementation
1 parent 47b4858 commit df1849d

File tree

1 file changed

+68
-25
lines changed

1 file changed

+68
-25
lines changed

GSASII/GSASIIgroupGUI.py

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,17 @@ def histLabels(G2frame):
171171
return commonltrs,histlbls
172172

173173
def onRefineAll(event):
174+
'''Respond to the Refine All button. On the first press, all
175+
refine check buttons are set as "on" and the button is relabeled
176+
as 'C' (for clear). On the second press, all refine check
177+
buttons are set as "off" and the button is relabeled as 'S' (for
178+
set).
179+
'''
174180
but = event.GetEventObject()
175181
refList = but.refList
176182
checkButList = but.checkButList
177183

178-
print('before',[item[0][item[1]] for item in refList])
184+
#print('before',[item[0][item[1]] for item in refList])
179185
if but.GetLabelText() == 'S':
180186
setting = True
181187
but.SetLabelText('C')
@@ -186,17 +192,36 @@ def onRefineAll(event):
186192
c.SetValue(setting)
187193
for item in refList:
188194
item[0][item[1]] = setting
189-
print('after ',[item[0][item[1]] for item in refList])
195+
#print('after ',[item[0][item[1]] for item in refList])
196+
197+
def onSetAll(event):
198+
'''Respond to the copy right button. Copies the first value to
199+
all edit widgets
200+
'''
201+
but = event.GetEventObject()
202+
valList = but.valList
203+
valEditList = but.valEditList
204+
#print('before',[item[0][item[1]] for item in valList])
205+
firstVal = valList[0][0][valList[0][1]]
206+
for c in valEditList:
207+
c.ChangeValue(firstVal)
208+
#print('after',[item[0][item[1]] for item in valList])
190209

191-
def displayDataTable(rowLabels,Table,Sizer,Panel,lblRow=False,deltaMode=False):
210+
211+
def displayDataTable(rowLabels,Table,Sizer,Panel,lblRow=False,deltaMode=False,lblSizer=None,lblPanel=None):
192212
'''Displays the data table in `Table` in Scrolledpanel `Panel`
193213
with wx.FlexGridSizer `Sizer`.
194214
'''
195215
firstentry = None
196-
216+
#lblRow = True
217+
if lblSizer is None: lblSizer = Sizer
218+
if lblPanel is None: lblPanel = Panel
197219
checkButList = {}
220+
valEditList = {}
221+
lblDict = {}
198222
for row in rowLabels:
199223
checkButList[row] = []
224+
valEditList[row] = []
200225
# show the row labels, when not in a separate sizer
201226
if lblRow:
202227
# is a copy across and/or a refine all button needed?
@@ -216,27 +241,28 @@ def displayDataTable(rowLabels,Table,Sizer,Panel,lblRow=False,deltaMode=False):
216241
arr,key = Table[hist][row]['rowlbl']
217242
break
218243
if arr is None:
219-
Sizer.Add(wx.StaticText(Panel,label=row),0,
220-
wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
244+
w = wx.StaticText(lblPanel,label=row)
221245
else:
222-
Sizer.Add(
223-
G2G.ValidatedTxtCtrl(Panel,arr,key,size=(125,-1)),
224-
0,wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
246+
w = G2G.ValidatedTxtCtrl(lblPanel,arr,key,size=(125,-1))
247+
lblSizer.Add(w,0,wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
248+
lblDict[row] = w
225249

226250
if len(refList) > 2:
227-
refAll = wx.Button(Panel,label='S',style=wx.BU_EXACTFIT)
251+
refAll = wx.Button(lblPanel,label='S',style=wx.BU_EXACTFIT)
228252
refAll.refList = refList
229-
refAll.Bind(wx.EVT_BUTTON,onRefineAll)
230253
refAll.checkButList = checkButList[row]
231-
Sizer.Add(refAll,0,wx.ALIGN_CENTER_VERTICAL)
254+
lblSizer.Add(refAll,0,wx.ALIGN_CENTER_VERTICAL)
255+
refAll.Bind(wx.EVT_BUTTON,onRefineAll)
232256
else:
233-
Sizer.Add((-1,-1))
257+
lblSizer.Add((-1,-1))
234258
if len(valList) > 2:
235-
but = wx.Button(Panel,wx.ID_ANY,'\u2192',style=wx.BU_EXACTFIT)
259+
but = wx.Button(lblPanel,wx.ID_ANY,'\u2192',style=wx.BU_EXACTFIT)
236260
but.valList = valList
237-
Sizer.Add(but,0,wx.ALIGN_CENTER_VERTICAL)
261+
but.valEditList = valEditList[row]
262+
lblSizer.Add(but,0,wx.ALIGN_CENTER_VERTICAL)
263+
but.Bind(wx.EVT_BUTTON,onSetAll)
238264
else:
239-
Sizer.Add((-1,-1))
265+
lblSizer.Add((-1,-1))
240266

241267
for hist in Table:
242268
minval = None
@@ -285,6 +311,7 @@ def displayDataTable(rowLabels,Table,Sizer,Panel,lblRow=False,deltaMode=False):
285311
arr,indx = Table[hist][row]['val']
286312
w = G2G.ValidatedTxtCtrl(Panel,arr,indx,size=(80,-1),
287313
xmin=minval,xmax=maxval)
314+
valEditList[row].append(w)
288315
valrefsiz.Add(w,0,WACV)
289316
if firstentry is None: firstentry = w
290317
arr,indx = Table[hist][row]['ref']
@@ -297,6 +324,7 @@ def displayDataTable(rowLabels,Table,Sizer,Panel,lblRow=False,deltaMode=False):
297324
arr,indx = Table[hist][row]['val']
298325
w = G2G.ValidatedTxtCtrl(Panel,arr,indx,size=(80,-1),
299326
xmin=minval,xmax=maxval,notBlank=False)
327+
valEditList[row].append(w)
300328
Sizer.Add(w,0,wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT)
301329
if firstentry is None: firstentry = w
302330

@@ -310,7 +338,8 @@ def displayDataTable(rowLabels,Table,Sizer,Panel,lblRow=False,deltaMode=False):
310338
wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER)
311339
else:
312340
print('Should not happen',Table[hist][row],hist,row)
313-
return firstentry
341+
return firstentry,lblDict
342+
314343

315344
def HistFrame(G2frame):
316345
'''Give up on side-by-side scrolled panels. Put everything
@@ -363,8 +392,9 @@ def HistFrame(G2frame):
363392
label=f"\u25A1 = {hist}"),
364393
0,wx.ALIGN_CENTER)
365394
deltaMode = "\u0394" in G2frame.GroupInfo['displayMode']
366-
firstentry = displayDataTable(rowLabels,prmTable,valSizer,midPanel,
367-
True,deltaMode)
395+
firstentry,lblDict = displayDataTable(rowLabels,prmTable,valSizer,midPanel,
396+
lblRow=True,
397+
deltaMode=deltaMode)
368398
#G2frame.dataWindow.SetDataSize()
369399
if firstentry is not None: # prevent scroll to show last entry
370400
wx.Window.SetFocus(firstentry)
@@ -645,7 +675,7 @@ def OnScroll(event):
645675
lblScroll = wx.lib.scrolledpanel.ScrolledPanel(panel,
646676
style=wx.VSCROLL|wx.HSCROLL|wx.ALWAYS_SHOW_SB)
647677
hpad = 3 # space between rows
648-
lblSizer = wx.FlexGridSizer(0,1,hpad,10)
678+
lblSizer = wx.FlexGridSizer(0,3,hpad,2)
649679
lblScroll.SetSizer(lblSizer)
650680
bigSizer.Add(lblScroll,0,wx.EXPAND)
651681

@@ -663,18 +693,31 @@ def OnScroll(event):
663693
for hist in histLabels(G2frame)[1]:
664694
HAPSizer.Add(wx.StaticText(HAPScroll,label=f"\u25A1 = {hist}"),
665695
0,wx.ALIGN_CENTER)
666-
firstentry = displayDataTable(rowLabels,HAPtable,HAPSizer,HAPScroll)
696+
w0 = wx.StaticText(lblScroll,label=' ')
697+
lblSizer.Add(w0)
698+
lblSizer.Add(wx.StaticText(lblScroll,label=' Ref '))
699+
lblSizer.Add(wx.StaticText(lblScroll,label=' Copy '))
700+
firstentry,lblDict = displayDataTable(rowLabels,HAPtable,HAPSizer,HAPScroll,
701+
lblRow=True,lblSizer=lblSizer,lblPanel=lblScroll)
667702
# get row sizes in data table
668703
HAPSizer.Layout()
669704
rowHeights = HAPSizer.GetRowHeights()
670-
# match rose sizes in Labels
705+
# set row sizes in Labels
671706
# (must be done after HAPSizer row heights are defined)
672707
s = wx.Size(-1,rowHeights[0])
673-
lblSizer.Add(wx.StaticText(lblScroll,label=' ',size=s))
708+
w0.SetMinSize(s)
709+
# for i,row in enumerate(rowLabels):
710+
# s = wx.Size(-1,rowHeights[i+1])
711+
# w = wx.StaticText(lblScroll,label=row,size=s)
712+
# lblSizer.Add(w,0,wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
713+
# lblDict = {}
714+
# for i,row in enumerate(rowLabels):
715+
# w = wx.StaticText(lblScroll,label=row)
716+
# lblDict[row] = w
717+
# lblSizer.Add(w,0,wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
674718
for i,row in enumerate(rowLabels):
675719
s = wx.Size(-1,rowHeights[i+1])
676-
lblSizer.Add(wx.StaticText(lblScroll,label=row,size=s),0,
677-
wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
720+
lblDict[row].SetMinSize(s)
678721
# Fit the scrolled windows to their content
679722
lblSizer.Layout()
680723
xLbl,_ = lblSizer.GetMinSize()

0 commit comments

Comments
 (0)