Reputation: 11
I just wrote a little code that is supposed to put some TextCtrl in ScrolledPanel...The code Works if you keep the variable words in range under 1440, if you put more the layout is like the panels will stack on each other...Then if they stack and you press the add widget button, everything will get back to normal...I don't understand this behaviour, could someone light my candle please ? :p
<code># -*- coding: cp1252 -*-
import wx
import wx.lib.scrolledpanel as scrolled #Sinon ça ne marche pas...
class MyForm(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial", size=(200,500))
# Add a panel so it looks the correct on all platforms
self.panel = wx.Panel(self, wx.ID_ANY)
#Controls
self.scrolled_panel = scrolled.ScrolledPanel(self.panel, -1,
style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="panel1")
self.scrolled_panel.SetupScrolling()
#Layout
#-- Scrolled Window
self.spSizer = wx.BoxSizer(wx.VERTICAL)
words=range(0,2000)# Works nice untill around 1430 then layout is incorrect...
for word in words:
text = wx.TextCtrl(self.scrolled_panel, value=str(word))
self.spSizer.Add(text)
self.scrolled_panel.SetSizer(self.spSizer)
self.spSizer.Fit(self.scrolled_panel)
#bouton
btn = wx.Button(self.panel, label="Add Widget")
btn.Bind(wx.EVT_BUTTON, self.onAdd)
#Panel
panelSizer = wx.BoxSizer(wx.VERTICAL)
panelSizer.AddSpacer(50)
panelSizer.Add(self.scrolled_panel, 1, wx.EXPAND)
panelSizer.Add(btn)
self.panel.SetSizer(panelSizer)
panelSizer.Fit(self.panel)
panelSizer.Layout()
# --------------------
# Scrolled panel stuff
self.scrolled_panel.SetAutoLayout(1)
#----------------------------------------------------------------------
def onAdd(self, event):
""""""
print "in onAdd"
new_text = wx.TextCtrl(self.scrolled_panel, value="New Text")
self.spSizer.Add(new_text)
self.scrolled_panel.Layout()
self.scrolled_panel.SetupScrolling()
event.Skip()
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm().Show()
app.MainLoop()
Upvotes: 0
Views: 177
Reputation: 22678
It's really not a good idea to create thousands of text controls, you're almost certainly running into some Windows (I'll go out on a limb and assume that this is what you use even if you don't say it) limitation. The most likely one seems to be ~32000 limit on windows coordinates, but even if you could avoid this one, you would still run out of GDI resources if you created 10000 of them.
So the answer is basically: don't do this. You should use something like wxListCtrl
, wxDataViewCtrl
or wxGrid
to display data and allow editing it on demand, i.e. by only creating a single wxTextCtrl
when it's needed.
Upvotes: 1