问题描述
目前,我正在与FileChooser
进行大量合作,但在文档.该小工具很棒,但是如果有人要刷新显示的文件,则必须从当前目录进行移动才能刷新文件.
Currently I'm working with FileChooser
a lot and I didn't find any mention of refreshing the widget in the docs. The widget is awesome, but if someone wants to refresh shown files, a movement from current directory is necessary to refresh files.
问题是当您将单个目录作为rootpath
并且内部只有文件时,因此无法进行此类移动.
The problem is when you have a single directory as a rootpath
and inside are only files, therefore no such movement is possible.
我的问题是,如果我想避免浪费性地删除/添加FileChooser
并尽可能将其嵌套在kv
文件中的FileChooser
尽可能短的话,该如何刷新窗口小部件.
My question was how to refresh the widget if I want to avoid any wasteful removing/adding of FileChooser
and do it as short as possible for a FileChooser
that is very nested in a kv
file.
推荐答案
在搜索filechooser.py
之后,我发现了代码,它会在目录之间的每次移动中触发.鉴于FileChooserIconView
和FileChooserListView
从FileChooserController
继承的事实,对该函数的访问很简单,并且不需要其他导入.
After I searched filechooser.py
I found the code which is triggered on each movement between directories. Giving the fact the FileChooserIconView
and FileChooserListView
inherit from FileChooserController
, the access to the function is simple and no additional imports are required.
比方说我们有filechooser = FileChooserIconView()
:
Let's say we have filechooser = FileChooserIconView()
:
filechooser._update_files()
效果很好,当FileChooser
嵌套在某处时,通过id
filechooser._update_files()
works well and when is FileChooser
nested somewhere, it's easy to access it with id
要进行更多调整,Clock.schedule_interval(filechooser._update_files, t)
可能会有所帮助,您可以在合理的时间内更新目录内容.
For more tweaks Clock.schedule_interval(filechooser._update_files, t)
may be helpful where you can update your directory content within a reasonable time.
(我在这里添加它,因为我没有提到它,但是它可能对某人有用.)
(I add it here, because I found no mention of it, however it may be useful to someone.)
这篇关于刷新/重新加载FileChooser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!