pyface FileDialog,通配符更改时具有不同的默认文件名

问题描述 投票:1回答:1

我想根据用户选择的通配符为用户提供不同的默认文件名。

[似乎pyface.FileDialog是从HasTraits继承的,所以我应该在上面观察它的wildcard_index特性,以注意到更改并更新了default_filename特性。

这是我的版本,

import pyface, traits, traitsui
pyface.__version__, traits.__version__, traitsui.__version__
('6.1.2', '5.1.2', '6.1.3')

EDM python环境

import sys
sys.version
'2.7.15 |Enthought, Inc. (x86_64)| (default, Jun 21 2018, 22:10:16) [MSC v.1500 64 bit (AMD64)]'

使用WX后端

import wx
wx.version()
'3.0.2.0 msw (classic)'

这里是最简单的演示。问题,


from pyface.api import FileDialog
from traits.api import on_trait_change

class MyFileDialog(FileDialog):
    """ Subclass that allows the suggested file name to change based on the wildcard type.
    """

    @on_trait_change('wildcard_index')
    def on_wildcard_changed(self, idx):
        # This is never called
        self.default_filename = [
            'filename_john',
            'filename_paul',
            'filename_george',
            'filename_ringo'][idx]

if __name__ == '__main__':
    types = ["*.a", "*.b", "*.c", "*.d"]
    dialog = MyFileDialog(
        action="save as",
        wildcard="|".join(["%s|%s" % (t, t) for t in types]),
    )
    dialog.open()
python-2.7 wxpython enthought traitsui pyface
1个回答
0
投票

我建议您将此问题发布到ets-users谷歌论坛(对于不熟悉此问题的查看者,请访问https://groups.google.com/forum/#!forum/ets-users)。

© www.soinside.com 2019 - 2024. All rights reserved.