scrolledpanel stop adding children widgets

in the code below I have simple test application to generate dynamic lines of panels to main scrolledpanel when the button ‘generate lines is clicked’;each panel has RichTextCtrl shows text referring to the panel(line) number.after 5 or 6 lines addition and when the scrollbar come into view
, the application will showing only blank panels without RichTextCtrl inside …and I have no idea about reason(s):

import wx.lib.scrolledpanel as SP
import wx.richtext as rtc
import wx
class P(SP.ScrolledPanel):
  def __init__(self,parent,SIZE, *args, **kwds):
    SP.ScrolledPanel.__init__(self,parent,size=SIZE, *args, **kwds)
    self.rtcSTORE={}
    self.lines={}
    self.LINES_counter=1
    self.sizer = wx.BoxSizer(wx.VERTICAL)
    self.AlwaysShowScrollbars(horz=False)
  def add_line(self):
    self.SetupScrolling(scroll_y=True,scroll_x= False,rate_x=0,rate_y=1,scrollToTop=False)
    line=wx.Panel(self,size=(self.GetSize()[0]-5,75))
    self.lines[self.LINES_counter]=line
    self.sizer.Add(line,0,wx.ALIGN_CENTRE,2)
    self.SetSizer(self.sizer)
    self.Layout()
    self.construct_line()
    self.ScrollChildIntoView(self.lines[self.LINES_counter])
    self.LINES_counter+=1
    self.ClearBackground()
    self.Refresh()


  def construct_line(self):
      
        self.inner_line_sizer=wx.BoxSizer(wx.VERTICAL)
        self.msg_=wx.Panel(self.lines[self.LINES_counter],size=(self.lines[self.LINES_counter].GetSize()[0],50))
        self.msg_.SetBackgroundColour('blue')
        self.inner_line_sizer.Add(self.msg_,0,wx.EXPAND)
        self.lines[self.LINES_counter].SetSizer(self.inner_line_sizer)
        self.lines[self.LINES_counter].Layout()
        self.lines[self.LINES_counter].Refresh()
···
        ##################

        ########################################
        self.rtcSTORE[self.LINES_counter]=rtc.RichTextCtrl(self.msg_, size=self.msg_.GetSize(),style=rtc.RE_MULTILINE|wx.EXPAND)
        self.rtcSTORE[self.LINES_counter].ApplyAlignmentToSelection(wx.TEXT_ALIGNMENT_CENTER)
        self.rtcSTORE[self.LINES_counter].SetBackgroundColour('yellow')
        self.rtcSTORE[self.LINES_counter].WriteText('this is line number '+str(self.LINES_counter))
        self.rtcSTORE[self.LINES_counter].SetFocus()
        self.msg_.Layout()
        self.msg_.Refresh()   


class application(wx.Frame):
  def __init__(self, *args, **kwds):
    wx.Frame.__init__(self, *args, **kwds)
    sizer = wx.BoxSizer(wx.VERTICAL)
    self.p =P(self,(460,400))

    self.box2=wx.Panel(self,size=(300,100))
    self.box2.SetBackgroundColour("gray")
    sizer.Add(self.p)
    sizer.Add(self.box2,wx.EXPAND)
    self.b=wx.Button(self.box2,label='generate lines',size=(120,60),pos=(50,50))

    self.SetSizer(sizer)
    self.Layout()
    self.Refresh()
    self.SetSize((600, 600))
    self.Bind(wx.EVT_BUTTON,self.add_line,self.b)
   
  def add_line(self,e):
      e.Skip()   
      self.p.add_line()

if __name__ == '__main__':
  app = wx.App()
  dialog = application(None, -1)

  dialog.Show()
  app.MainLoop()

ahmed abbas wrote:

in the code below I have simple test application to generate dynamic
lines of panels to main scrolledpanel when the button 'generate lines
is clicked';each panel has RichTextCtrl shows text referring to the
panel(line) number.after 5 or 6 lines addition and when the scrollbar
come into view
, the application will showing only blank panels without RichTextCtrl
inside ..and I have no idea about reason(s):

The reason seems to be related to the inner sizer. I can only make wild
speculations as to the reason; it may be that the inner sizer is
confused because it's being asked to adjust itself outside of the
containing window.

If you comment out the three lines that refer to "inner_line_sizer",
your application works as expected. See attached.

x.py (1.96 KB)

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

have a look on the screen shot just taken for the edited code by you…the line number 6 i missing .
I tested that many times and found that line 6 to be added the same time scrollbar appeared …may be the inner sizer is part of the problem but not the unique reason,I hope to fix it soon

Capture.PNG

well…I commented the inner sizer lines on the original code mine .and yes it is now working…thank you for help