python - Python kivy 在 TreeView 中显示大量数据
问题描述
我在使用 Kivy TreeView 的 Python 中遇到了优化问题。我有大量数据,我想使用 TreeView 在 kivy 中显示近 16 万个项目。
树的结构是这样的:Root -> Groups -> Types -> Items
. 只有物品是大量的。组 + 类型少于 200。
当加载和显示所有160k
项目时它是不可用的,所以我做了这个,当你点击 TreeView 中的类型时,与该类型对应的项目被加载并显示。它减少了少于几百个项目的类型的时间。当我单击包含多达 8k 个项目的类型时,加载和显示它们的速度非常慢。
我正在寻找一种更好的方法,最好使用 TreeView 和 Kivy,但对替代方案持开放态度。我需要补充一点,我想使用一些 GUI 对这些项目进行操作。
我正在使用的自定义 TreeViewLabel 类:
class TreeViewFile(TreeViewLabel):
def __init__(self, big_path=None, name=None, files_info=None, root=None, **kwargs):
super(TreeViewFile, self).__init__(**kwargs)
self._big_path = big_path
self._files_info = files_info
self.text = name
self._root = root
# On clik, if leaf create TreeViewItem
def on_touch_down(self, touch):
if not self.is_leaf:
self._root.toggle_node(self)
elif self._files_info is not None:
for file in self._files_info.keys():
self._root.add_node(TreeViewItem(file_info=self._files_info[file]), self)
编辑
查看评论我更改了我的代码,所以现在它在 TreeView 中使用 RecycleView。加载速度变快了,但问题在于,RecycleView 可以在 TreeView 内滚动。它看起来很奇怪,但有效。
def on_touch_down(self, touch):
if not self.is_leaf:
self._root.toggle_node(self)
elif self._files_info is not None:
rv = RV() # RecycleView
data = []
for file in self._files_info.keys():
if isinstance(self._files_info[file][-1], str):
data.append(self._files_info[file][-1])
else:
data.append(self._files_info[file][0])
rv.data = [{'text': x} for x in data]
self._root.add_node(rv, self)
解决方案
推荐阅读
- android - 未能通过 # 作为拨号应用程序中的输入
- c# - Swagger UI 输出“不支持的媒体类型”
- xamarin - MVVM Xamarin Forms,最适合在等待来自服务调用的几分钟响应时将函数保留在内存中
- amazon-web-services - 在foreach循环中执行powershell命令
- java - Spring ExceptionalHandler 的 Java 测试
- typescript - 在默认导出和命名导出中导出一个值(循环)
- sql - 使用 sql 脚本将文本文件从一个文件夹移动到另一个文件夹
- python - 如何在 Django 管理模板中检查当前查看的模型的权限
- java - @user_script:1: WRONGTYPE 对持有错误值的键的操作
- azure - Azure API 管理 - 如何通过 PowerShell 命令启用 HTTP/2?