wx.TextCtrl.LoadFile() [英] wx.TextCtrl.LoadFile()

查看:552
本文介绍了wx.TextCtrl.LoadFile()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图快速显示搜索结果数据。我的网络驱动器上的文件的所有绝对文件路径都在一个〜50MB的文本文件中。 python脚本在这个文件[保存在本地驱动器]中的每一行都会在一秒或更短时间内传递一次,这是可以接受的。这是收集结果的时间。



但是,结果在wx.TextCtrl小部件中给出。将它们逐行添加到一个wx TextCtrl将是荒谬的。我提出的最好的方法是将结果写入文本文件,并调用wx.TextCtrl的LoadFile native,根据结果的数量,将文本行加载到窗格中,时间为0.1到5秒,或者所以。但是,对于10MB的文本入站,必须有更快的方式。结果立即计算,并在与GUI相同的过程中可用...所以,请告诉我有什么办法管道/代理/黑客的数据直接进入TextCtrl?请问mmap如何帮助传输?

解决方案

您可以使用AppendText一次加载所有数据,为什么需要按照线,但仍然需要几秒钟,因为10MB是巨大的。如果你使用wx.RichTextCtrl它是更快的
在我的测试中,它在6秒内加载了10 MB而不是9秒的TextCtrl。

我没有看到您需要一次设置所有数据的原因?谁将读取10MB?

因此,根据目的可以有更好的方法。

如果你需要以超快速的方式显示所有的数据,编写一个自定义控件,它保持一个行列表,只显示在视图中可见的行。



这是一个测试应用程序,你可以尝试各种各样的东西

 导入wx 
导入wx.richtext
导入字符串
输入时间

#创建一个大文本
line = string.ascii_letters +\\\

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

#5秒后载入大文本
wx.CallLater(5000,loadData)

app.SetTopWindow(myframe)
myframe。 Show()
app.MainLoop()




$ b

如果你不想在自定义控件中绘制所有的东西,你可以单独使用一个textctrl滚动条和更新滚动文本textcntrl的文本,所以一次只能加载几行。



编辑:数据可能是1-2 MB,1MB的数据与AppendText只需要0.5秒我认为这是可以的


I am trying to display search result data quickly. I have all absolute file paths for files on my network drive(s) in a single, ~50MB text file. The python script makes a single pass over every line in this file [kept on the local drive] in a second or less, and that is acceptable. That is the time it takes to gather results.

However, the results are given in a wx.TextCtrl widget. Appending them line by line to a wx TextCtrl would be ridiculous. The best method I have come up with is to write the results to a text file, and call wx.TextCtrl's LoadFile native, which, depending on the number of results, loads the lines of text into the pane in between 0.1 to 5 seconds or so. However there must be a faster way for 10+MB of text inbound. The results are immediately calculated and available in the same process as the GUI... so please, tell me is there any way I can pipe/proxy/hack that data directly into the TextCtrl? Would mmap help this transfer?

解决方案

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

这篇关于wx.TextCtrl.LoadFile()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆