Wx.TextCtrl.LoadFile()
Solution 1:
Are people really going to read (or need) all 10MB in a text control? Probably not.
Suggest that, you load on demand by paging in portions of the data.
Or better still, provide some user search functionality that narrows down the results to the information of interest.
Solution 2:
You can load all the data at once with AppendText, why you need to do it line by line, but still it will take seconds as 10MB is huge. If you use wx.RichTextCtrl it is bit faster in my test it loaded 10 MB in 6 secs instead of 9 sec for TextCtrl.
I do not see the reason why you need to set all the data at once? and who is going to read 10MB?
So depending on the purpose there can be better ways.
If you need to display all data in super fast way, write a custom control which keeps a list of lines and only renders the lines visible in the view.
here is a test app where you can try various things
import wx
import wx.richtext
import string
import time
# create a big text
line = string.ascii_letters+"\n"
bigText = line*200000
app = wx.PySimpleApp()
myframe = wx.Frame(None)
#tc = wx.TextCtrl(myframe, style=wx.TE_MULTILINE)
tc = wx.richtext.RichTextCtrl(myframe)
def loadData():
s = time.time()
tc.SetMaxLength(len(bigText))
tc.AppendText(bigText)
print time.time()-s
# load big text after 5 secs
wx.CallLater(5000, loadData)
app.SetTopWindow(myframe)
myframe.Show()
app.MainLoop()
If you do not want to paint everything youself in a custom control, you can just use a textctrl with separate scrollbar and update text of textcntrl on scrolling, so at a time you will be loading few lines only.
Edit: as you said in your comment that data may be 1-2 MB, 1MB data with AppendText takes only .5 sec I think that is ok
Post a Comment for "Wx.TextCtrl.LoadFile()"