Python gtk3 filechooser限制文件夹 [英] Python gtk3 filechooser restrict folder

查看:241
本文介绍了Python gtk3 filechooser限制文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以将gtk filechooser设置为文件夹限制吗?

正常的文件选择器将显示从/(root)开始的所有文件夹文件树,我需要的是允许filechooser仅显示来自 / media 文件夹。因此,顶层可见文件夹仅为/ media,并非其他所有内容如 / home / usr 等。



感谢您的协助。

限制目录变更在 FileChooser 中不是直接可用的,但有以下几种方式:


  • 您可以定义文件过滤器( Gtk.FileFilter ),但基本上会过滤文件扩展名(或mime类型)。


  • 更有趣的是,当更改文件夹时,会发出一个名为'current_folder_changed'的信号。所以,你可以将一个函数绑定到该信号并采取行动。注意:如果由于这个信号而以编程方式更改文件夹,则可能会再次调用该信号,因此您必须在执行该操作时暂时阻止该信号。


>

Can gtk filechooser set to be folder-restricted?

A normal filechooser will display all folder files tree starting from / (root), what I need is, to allow filechooser displaying only from /media folder only. So, the top visible folder is only /media, not everything else like /home, /usr, etc.

Thank you for all your kindly help.

解决方案

Limiting directory changes isn't directly available in FileChooser, but there are a few ways:

  • You can define file filters (Gtk.FileFilter) but those basically filter on the file extension (or mime type).

  • More interesting is that, when changing the folder, a signal is emitted called 'current_folder_changed'. So, you could bind a function to that signal and take action. Mind: if you programmatically change the folder as a result of this signal, the signal will probably be called again, so you have to temporarily block the signal while doing that.

这篇关于Python gtk3 filechooser限制文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆