Daniel Farrell
Daniel Farrell

Reputation: 9740

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.

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.

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

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

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

Upvotes: 1

Views: 73

Answers (1)

Jonathan March
Jonathan March

Reputation: 5810

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

Upvotes: 0

Related Questions