Python User Interface (Enthought)

I am working with some code that uses the "Traits" user interface to show a dialog from which the user can 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 values ​​of filename_1 or filename_2, a file selection dialog box opens with the name "Save As". I was asked to change the name to “Open or even“ Select File. ”Unfortunately, I can’t understand how I can change this. Can someone help?

+3
source share
1 answer

- Traits 3.2 ​​ FileEditor ToolkitEditorFactory, , "" '' save '. :

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')
+2

Source: https://habr.com/ru/post/1725050/


All Articles