Refresh / Reload FileChooser

ぐ巨炮叔叔 提交于 2021-02-08 07:30:54

问题


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.

The problem is when you have a single directory as a rootpath and inside are only files, therefore no such movement is possible.

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.


回答1:


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.


Let's say we have filechooser = FileChooserIconView():

filechooser._update_files() works well and when is FileChooser nested somewhere, it's easy to access it with id

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.)



来源:https://stackoverflow.com/questions/36264301/refresh-reload-filechooser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!