enthought / enthought/traitsui

File(exists=True) not working as expected?

Open
#1,658 5 comments 1 reaction 0 assignees View on GitHub
type: bug
Dominant language
Python
Stars
306
Forks
99
PR merge metrics
No merged PRs in 30d

Description

In the following example, I would expect the OK button to be enable after selecting a file.

```python
import traits.api as t
import traitsui.api as tu
from traitsui.menu import OKButton, CancelButton

class Load(t.HasTraits):
filename = t.File(exists=True)
lazy = t.Bool(False)

view = tu.View(
tu.Group('filename', "lazy"),
kind='livemodal',
buttons=[OKButton, CancelButton],
title='Load file')

load_ui = Load()
load_ui.configure_traits()

```

Disable the OK button:
![image](https://user-images.githubusercontent.com/11851990/117568538-b447af80-b0b8-11eb-8b83-ccc860526931.png)

Not setting `exists=True` in the definition of `filename` and specifying the editor instead works:

```python
import traits.api as t
import traitsui.api as tu
from traitsui.file_dialog import FileEditor
from traitsui.menu import OKButton, CancelButton

class Load(t.HasTraits):
filename = t.File()
lazy = t.Bool(False)

view = tu.View(
tu.Group(tu.Item('filename', editor=FileEditor(dialog_style='open')),
"lazy"),
kind='livemodal',
buttons=[OKButton, CancelButton],
title='Load file')

load_ui = Load()
load_ui.configure_traits()
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.