使用 elide 隐藏文本时的性能影响
Performance impact when hiding text with elide
我已经设置了一个带有标签的文本小部件,这些标签将使用省略号隐藏信息部分。它适用于正常条目,但如果我用 elide 隐藏大部分文本,我会看到性能下降。我注意到的文本文件大约有 53,000 行,较小文件的影响较小。该程序运行良好,我可以在 window 中滚动和移动而不会出现问题,直到我隐藏我的文本部分。
from tkinter import *
master = Tk()
file = 'file\path'
file1 = 'file\path'
file2 = 'file\path'
file3 = 'file\path'
file4 = 'file\path'
file5 = 'file\path'
file6 = 'file\path'
file7 = 'file\path'
list = [file, file1, file2, file3, file4, file5, file6, file7]
def _toggle_visibility(event, widg):
global txt
try:
block_start, block_end = _get_block("insert", widg)
except:
return
next_hidden = widg.tag_nextrange("hidden", block_start, block_end)
if next_hidden:
widg.tag_remove("hidden", block_start, block_end)
else:
widg.tag_add("hidden", block_start, block_end)
def _get_block(index, widg):
global txt
'''return indicies after header, to next header or EOF'''
start = widg.index("%s lineend+1c" % index)
next_header = widg.tag_nextrange("header", start)
if next_header:
end = next_header[0]
else:
end = widg.index("end-1c")
return (start, end)
txt = Text(master)
txt.grid()
txt.tag_configure("header", foreground="#9b3e96") # , spacing1=10, spacing3=10)
txt.tag_bind("header", "<Double-1>", lambda event: _toggle_visibility(event, txt))
txt.tag_configure("hidden", elide=True)
for item in list:
with open(item) as f:
h = f.readlines()
txt.insert('end', '==============================================\n ', 'header')
txt.insert('end', h)
master.mainloop()
要复制:
获取一些非常大的文本文件(不必是 7 个)并使用上面的代码将它们全部转储到文本小部件中。然后双击带有“===========================================”的行=== 最小化该文件中的所有文本。如果您最小化已打印的最后一个文件,一切正常。如果将第一个最小化,您将开始看到在突出显示文本、单击 window 中的任意位置等方面的响应缓慢。
当 'elide' 设置为 true 时会发生什么情况?
在使用 pyinstaller 创建 exe 后,我在 pycharm 和另一台机器上对此进行了测试。
文本小部件目前正在进行全面重写和广泛测试。 Tcl/Tk 8.7 版应该可以使用具有更好的省略号性能的新版本。
新版本的公告通常在 comp.lang.tcl 新闻组中发布。新版本也将在主网站上公布
http://www.tcl.tk/.
遗憾的是,由于人员和时间的限制,无法估计发布时间。我的期望(猜测)是 8.6.7 错误修复版本,之后可能是 8.7。
我已经设置了一个带有标签的文本小部件,这些标签将使用省略号隐藏信息部分。它适用于正常条目,但如果我用 elide 隐藏大部分文本,我会看到性能下降。我注意到的文本文件大约有 53,000 行,较小文件的影响较小。该程序运行良好,我可以在 window 中滚动和移动而不会出现问题,直到我隐藏我的文本部分。
from tkinter import *
master = Tk()
file = 'file\path'
file1 = 'file\path'
file2 = 'file\path'
file3 = 'file\path'
file4 = 'file\path'
file5 = 'file\path'
file6 = 'file\path'
file7 = 'file\path'
list = [file, file1, file2, file3, file4, file5, file6, file7]
def _toggle_visibility(event, widg):
global txt
try:
block_start, block_end = _get_block("insert", widg)
except:
return
next_hidden = widg.tag_nextrange("hidden", block_start, block_end)
if next_hidden:
widg.tag_remove("hidden", block_start, block_end)
else:
widg.tag_add("hidden", block_start, block_end)
def _get_block(index, widg):
global txt
'''return indicies after header, to next header or EOF'''
start = widg.index("%s lineend+1c" % index)
next_header = widg.tag_nextrange("header", start)
if next_header:
end = next_header[0]
else:
end = widg.index("end-1c")
return (start, end)
txt = Text(master)
txt.grid()
txt.tag_configure("header", foreground="#9b3e96") # , spacing1=10, spacing3=10)
txt.tag_bind("header", "<Double-1>", lambda event: _toggle_visibility(event, txt))
txt.tag_configure("hidden", elide=True)
for item in list:
with open(item) as f:
h = f.readlines()
txt.insert('end', '==============================================\n ', 'header')
txt.insert('end', h)
master.mainloop()
要复制:
获取一些非常大的文本文件(不必是 7 个)并使用上面的代码将它们全部转储到文本小部件中。然后双击带有“===========================================”的行=== 最小化该文件中的所有文本。如果您最小化已打印的最后一个文件,一切正常。如果将第一个最小化,您将开始看到在突出显示文本、单击 window 中的任意位置等方面的响应缓慢。
当 'elide' 设置为 true 时会发生什么情况?
在使用 pyinstaller 创建 exe 后,我在 pycharm 和另一台机器上对此进行了测试。
文本小部件目前正在进行全面重写和广泛测试。 Tcl/Tk 8.7 版应该可以使用具有更好的省略号性能的新版本。
新版本的公告通常在 comp.lang.tcl 新闻组中发布。新版本也将在主网站上公布 http://www.tcl.tk/.
遗憾的是,由于人员和时间的限制,无法估计发布时间。我的期望(猜测)是 8.6.7 错误修复版本,之后可能是 8.7。