4

I am working with some code that uses Traits UI to show a dialog from which the user is able to select two files:

class Files(HasTraits):
    filename_1 = File(exists=True)
    filename_2 = File(exists=True)

    traits_ui = View(
        'filename_1', 'filename_2',
        title   = 'Select Geometry Files',
        buttons = ['OK', 'Cancel']
    )

files = Files()
ui = files.edit_traits(kind='modal')

When editing the filename_1 or filename_2 values, a file chooser dialog is displayed with the title ‘Save As’. I’ve been asked to change the title to ‘Open’ or even ‘Select File’. Unfortunately, I can’t seem to find out how I can change this. Can anyone help?

  • Running this now, I see the file browser dialog titled "Select a File". Can you confirm that this issue still exists? – Peter Wang Jan 08 '10 at 15:25
  • yes, since posting this message I noticed that the "Save As.." title only appears when the above code is run as part of a larger set of code. On its own, you're correct, it says "Select a File". I never did get to the bottom of why this is the case but, as I don't usually use TraitsUI, I just wrote some plain Qt code. Thanks. –  Jan 09 '10 at 17:25
  • Is the answer acceptable? Then please accept it. Thx. – K.-Michael Aye Mar 26 '12 at 16:06

1 Answers1

3

At some point after Traits 3.2, a new trait was added to the FileEditor ToolkitEditorFactory that enables you set whether editing the trait is an 'open' or 'save' dialog. Try this:

from enthought.traits.ui.api import FileEditor    

save_file_editor = FileEditor(dialog_style='save')

class Files(HasTraits):
    filename_1 = File(exists=True)
    filename_2 = File(exists=True)

    traits_ui = View(
        Item('filename_1', editor=save_file_editor),
        Item('filename_2', editor=save_file_editor),
        title   = 'Select Geometry Files',
        buttons = ['OK', 'Cancel']
    )

files = Files()
ui = files.edit_traits(kind='modal')
Jon
  • 398
  • 1
  • 11