【问题标题】:Performance impact when hiding text with elide使用 elide 隐藏文本时的性能影响
【发布时间】:2017-04-14 17:29:08
【问题描述】:

我已经设置了一个带有标签的 Text 小部件,该小部件将使用 elide 隐藏部分信息。它适用于普通条目,但如果我用省略号隐藏大部分文本,我会看到性能下降。我注意到的文本文件约为 53,000 行,较小的文件影响较小。该程序运行良好,我能够在窗口中滚动和移动,直到我隐藏我的文本部分。

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 个)并使用上面的代码将它们全部转储到 Text 小部件中。然后双击带有“============================================的行===" 以最小化该文件中的所有文本。如果您最小化已打印的最后一个文件,则一切正常。如果您将第一个最小化,您将开始看到在突出显示文本、单击窗口中的任意位置等方面反应缓慢。

当 'elide' 设置为 true 时会发生什么导致这种情况?

在使用 pyinstaller 创建 exe 后,我在 pycharm 和另一台机器上对此进行了测试。

【问题讨论】:

  • elide 的性能问题将在 Tcl/Tk 版本 8.7 中修复
  • @BradLanam 在 8.7 发布 GA 时,哪里是观看它的最佳地点?另外,您是否应该将此作为答案以便对其进行标记?

标签: python python-3.x text tkinter tk


【解决方案1】:

文本小部件目前正在进行彻底的重写和广泛的测试。 Tcl/Tk 8.7 版应该可以使用具有更好的 elide 性能的新版本。

新版本的公告通常在comp.lang.tcl 新闻组中发布。新版本也将在主网站上公布 http://www.tcl.tk/.

很遗憾,由于人员和时间限制,无法估计发布的时间。我的期望(猜测)是会有一个 8.6.7 的错误修复版本,之后可能是 8.7。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-24
    • 1970-01-01
    • 2011-10-24
    • 1970-01-01
    • 2010-09-30
    相关资源
    最近更新 更多