简体   繁体   English

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

[英]pyface FileDialog with different default filename when wildcard changes

I would like to provide a user with different default file names based on the wildcard that they select.我想根据通配符 select 为用户提供不同的默认文件名。

It seems that pyface.FileDialog inherits from HasTraits so I should be above to observe it's wildcard_index trait to notice the change and update the default_filename trait.似乎pyface.FileDialog继承自HasTraits所以我应该在上面观察它的wildcard_index特征以注意到变化并更新default_filename特征。

Here are my versions,这是我的版本,

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

EDM python environment电火花 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)]'

Using the WX backend使用 WX 后端

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

Here is the simplest possible demo.这是最简单的演示。 of the problem,的问题,


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

I suggest that you post this question to the ets-users google group (For viewers not familiar with it, this is at: https://groups.google.com/forum/#!forum/ets-users ).我建议您将此问题发布到 ets-users google 组(对于不熟悉它的观众,此问题位于: https://groups.google.com/forum/#!forum/ets-users )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Mac中的wxPython FileDialog崩溃 - wxPython FileDialog crash in mac Python Web服务器-拆分文件名时出现IndexError - Python web server - IndexError when splitting filename WindowsError:[错误123]用“:”替换文件名“%3”时 - WindowsError:[Error 123] When Replace in filename “%3” by “:” 使用 Python CGI 时,有没有办法 output bash 命令导致与默认格式不同的格式 - Is there a way to output bash command results in a different format from default when using Python CGI 如何获得不同目录中的所有文件名? - How can I get all filename in different directories? 当我在Python中使用open(filename)或在C中使用fopen(filename)时,保存文件的编码是什么? - What's the encoding in which the file is saved when I use open(filename) in Python or fopen(filename) in C? 使用python目录太长时无法显示文件名 - Can not print out the filename when the directory is too long by using python 如何在python中执行linux命令以更改默认提示 - how to execute linux command in python which changes default prompt 在python 2.7中使用openpyxl时,模式或文件名无效 - Invalid mode or filename when using openpyxl in python 2.7 部署到Google Appengine时,“文件名中的无效字符:__static__” - “Invalid character in filename: __static__” when deploying to Google Appengine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM