@@ -79,6 +79,16 @@ def histLabels(G2frame):
7979def HAPframe (G2frame ):
8080 def OnPageChanged (event ):
8181 'respond to a notebook tab'
82+ def OnScroll (event ):
83+ 'Synchronize vertical scrolling between the two scrolled windows'
84+ obj = event .GetEventObject ()
85+ pos = obj .GetViewStart ()[1 ]
86+ if obj == lblScroll :
87+ HAPScroll .Scroll (- 1 , pos )
88+ else :
89+ lblScroll .Scroll (- 1 , pos )
90+ event .Skip ()
91+
8292 if event :
8393 page = event .GetSelection ()
8494 print ('page selected' ,page ,phaseList [page ])
@@ -93,7 +103,35 @@ def OnPageChanged(event):
93103 if panel .GetSizer ():
94104 panel .GetSizer ().Destroy ()
95105 panel = HAPtabs [page ]
96- HAPSizer = wx .FlexGridSizer (0 ,len (HAPtable )+ 1 ,2 ,10 )
106+ bigSizer = wx .BoxSizer (wx .HORIZONTAL )
107+ panel .SetSizer (bigSizer )
108+
109+ # Create scrolled window for labels
110+ #lblScroll = wx.ScrolledWindow(panel, style=wx.VSCROLL)
111+ lblScroll = wx .ScrolledWindow (panel , style = wx .VSCROLL | wx .HSCROLL
112+ | wx .ALWAYS_SHOW_SB
113+ )
114+ lblScroll .SetScrollRate (0 , 10 )
115+ hpad = 10
116+ lblSizer = wx .FlexGridSizer (0 ,1 ,hpad ,10 )
117+ lblScroll .SetSizer (lblSizer )
118+ bigSizer .Add (lblScroll ,0 ,wx .EXPAND ,0 )
119+ # bigSizer.Add(lblScroll)
120+
121+ # Create scrolled window for data
122+ HAPScroll = wx .ScrolledWindow (panel , style = wx .VSCROLL | wx .HSCROLL
123+ | wx .ALWAYS_SHOW_SB
124+ )
125+ #HAPScroll.ShowScrollbars(wx.SHOW_SB_ALWAYS, wx.SHOW_SB_ALWAYS)
126+ HAPScroll .SetScrollRate (10 , 10 )
127+ HAPSizer = wx .FlexGridSizer (0 ,len (HAPtable ),hpad ,10 )
128+ HAPScroll .SetSizer (HAPSizer )
129+ bigSizer .Add (HAPScroll ,1 ,wx .EXPAND ,1 )
130+ # bigSizer.Add(HAPScroll)
131+
132+ # Bind scroll events to synchronize scrolling
133+ lblScroll .Bind (wx .EVT_SCROLLWIN , OnScroll )
134+ HAPScroll .Bind (wx .EVT_SCROLLWIN , OnScroll )
97135 # construct a list of row labels, attempting to keep the
98136 # order they appear in the original array
99137 rowsLbls = []
@@ -110,45 +148,80 @@ def OnPageChanged(event):
110148 prevkey = key
111149 # label columns with histograms
112150 common ,hLbl = histLabels (G2frame )
113- HAPSizer .Add ((- 1 ,- 1 ))
151+ # HAPSizer.Add((-1,-1))
114152 for hist in hLbl :
115- HAPSizer .Add (wx .StaticText (panel ,label = f"\u25A1 = { hist } " ),0 ,
153+ HAPSizer .Add (wx .StaticText (HAPScroll ,label = f"\u25A1 = { hist } " ),0 ,
116154 wx .ALIGN_CENTER )
155+ #for i in range(len(rowsLbls)+1):
156+ # HAPSizer.AddGrowableRow(i)
117157 for row in rowsLbls :
118- HAPSizer .Add (wx .StaticText (panel ,label = row ),0 ,WACV )
158+ # HAPSizer.Add(wx.StaticText(panel,label=row),0,WACV)
119159 for hist in HAPtable :
120160 if row not in HAPtable [hist ]:
121161 HAPSizer .Add ((- 1 ,- 1 ))
122162 elif 'val' in HAPtable [hist ][row ] and 'ref' in HAPtable [hist ][row ]:
123163 valrefsiz = wx .BoxSizer (wx .HORIZONTAL )
124164 arr ,indx = HAPtable [hist ][row ]['ref' ]
125- valrefsiz .Add (G2G .G2CheckBox (panel ,'' ,arr ,indx ),0 ,WACV )
165+ valrefsiz .Add (G2G .G2CheckBox (HAPScroll ,'' ,arr ,indx ),0 ,WACV )
126166 arr ,indx = HAPtable [hist ][row ]['val' ]
127- valrefsiz .Add (G2G .ValidatedTxtCtrl (panel ,
167+ valrefsiz .Add (G2G .ValidatedTxtCtrl (HAPScroll ,
128168 arr ,indx ,size = (75 ,- 1 )),0 ,WACV )
129169 HAPSizer .Add (valrefsiz ,0 ,
130170 wx .ALIGN_CENTER_VERTICAL | wx .ALIGN_RIGHT )
131171 elif 'val' in HAPtable [hist ][row ]:
132172 arr ,indx = HAPtable [hist ][row ]['val' ]
133- HAPSizer .Add (G2G .ValidatedTxtCtrl (panel ,
173+ HAPSizer .Add (G2G .ValidatedTxtCtrl (HAPScroll ,
134174 arr ,indx ,size = (75 ,- 1 )),0 ,
135175 wx .ALIGN_CENTER_VERTICAL | wx .ALIGN_RIGHT )
136176
137177 elif 'ref' in HAPtable [hist ][row ]:
138178 arr ,indx = HAPtable [hist ][row ]['ref' ]
139- HAPSizer .Add (G2G .G2CheckBox (panel ,'' ,arr ,indx ),0 ,
179+ HAPSizer .Add (G2G .G2CheckBox (HAPScroll ,'' ,arr ,indx ),0 ,
140180 wx .ALIGN_CENTER_VERTICAL | wx .ALIGN_RIGHT )
141181 elif 'str' in HAPtable [hist ][row ]:
142- HAPSizer .Add (wx .StaticText (panel ,
182+ HAPSizer .Add (wx .StaticText (HAPScroll ,
143183 label = HAPtable [hist ][row ]['str' ]),0 ,
144184 wx .ALIGN_CENTER_VERTICAL | wx .ALIGN_CENTER )
145185# wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
146186 else :
147187 print ('Should not happen' ,HAPtable [hist ][row ],hist ,row )
148- panel .SetSizer (HAPSizer )
149- HAPSizer .Fit (panel )
150- panel .SetScrollbars (1 , 1 , HAPSizer .GetMinSize ().width ,
151- HAPSizer .GetMinSize ().height )
188+ HAPSizer .Layout ()
189+ rowHeights = HAPSizer .GetRowHeights ()
190+ # label rows (must be done after HAPSizer row heights are defined)
191+ s = wx .Size (- 1 ,rowHeights [0 ])
192+ lblSizer .Add (wx .StaticText (lblScroll ,label = ' ' ,size = s ))
193+ #lblSizer.AddGrowableRow(0)
194+ for i ,row in enumerate (rowsLbls ):
195+ s = wx .Size (- 1 ,rowHeights [i + 1 ])
196+ lblSizer .Add (wx .StaticText (lblScroll ,label = row ,size = s ),0 ,WACV | wx .ALIGN_RIGHT )
197+ # lblSizer.AddGrowableRow(i+1)
198+ #lblSizer.Add(wx.StaticText(lblScroll,label=' ',size=(-1,10))) # pad for scrollbar
199+
200+ # Fit the scrolled windows to their content
201+ xWin ,yWin = panel .GetSize ()
202+ xLbl ,_ = lblSizer .GetMinSize ()
203+ xTab ,yTab = HAPSizer .GetMinSize ()
204+ #lblScroll.SetSize((xLbl,-1))
205+ #lblScroll.SetMinSize((xLbl,-1))
206+ #HAPScroll.SetSize((min(xTab,xWin-xLbl),yTab))
207+ #lblSizer.Fit(lblScroll)
208+ #HAPSizer.Fit(HAPScroll)
209+ #lblScroll.SetVirtualSize(lblSizer.GetMinSize()[0],yTab)
210+ lblScroll .SetVirtualSize (lblSizer .GetMinSize ())
211+ HAPScroll .SetVirtualSize (HAPSizer .GetMinSize ())
212+ print ('panel' ,xWin ,yWin )
213+ print ('lblScroll.SetSize' ,xLbl ,yTab )
214+ print ('HAPScroll.SetSize' ,min (xTab ,xWin - xLbl ),yTab )
215+ print ('lblScroll.SetVirtualSize' ,lblSizer .GetMinSize ())
216+ print ('HAPScroll.SetVirtualSize' ,HAPSizer .GetMinSize ())
217+ #lblScroll.ShowScrollbars(wx.SHOW_SB_DEFAULT, wx.SHOW_SB_NEVER)
218+ G2frame .SendSizeEvent ()
219+ pass
220+
221+ # panel.SetSizer(HAPSizer)
222+ # HAPSizer.Fit(panel)
223+ # panel.SetScrollbars(1, 1, HAPSizer.GetMinSize().width,
224+ # HAPSizer.GetMinSize().height)
152225
153226 #breakpoint()
154227
@@ -181,7 +254,8 @@ def OnPageChanged(event):
181254 phaseList = []
182255 for phaseName in Phases :
183256 phaseList .append (phaseName )
184- HAPtabs .append (wx .ScrolledWindow (HAPBook ))
257+ #HAPtabs.append(wx.ScrolledWindow(HAPBook))
258+ HAPtabs .append (wx .Panel (HAPBook ))
185259 HAPBook .AddPage (HAPtabs [- 1 ],phaseName )
186260 HAPBook .Bind (wx .aui .EVT_AUINOTEBOOK_PAGE_CHANGED , OnPageChanged )
187261 #G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.DataMenu)
@@ -198,12 +272,12 @@ def OnPageChanged(event):
198272 # menu.Append(Id,page,'')
199273 # TabSelectionIdDict[Id] = page
200274 # G2frame.Bind(wx.EVT_MENU, OnSelectPage, id=Id)
275+ G2frame .dataWindow .SetDataSize ()
201276 page = 0
202277 HAPBook .SetSelection (page )
203278 OnPageChanged (None )
204279 #wx.CallAfter(FillDDataWindow,page)
205280 # done
206- G2frame .dataWindow .SetDataSize ()
207281
208282def getHAPvals (G2frame ,phase = None ):
209283 sub = G2gd .GetGPXtreeItemId (G2frame ,G2frame .root ,'Phases' )
0 commit comments