enthought / enthought/traitsui

Default view creates an error dialog due to readonly Property

Open
#1,401 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
306
Forks
99
PR merge metrics
No merged PRs in 30d

Description

Consider this example:

```
from traits.api import *
from traitsui.api import *

class Person(HasTraits):

age = Int(20)
is_adult = Property(Bool())

def _get_is_adult(self):
return self.age >= 18

if __name__ == "__main__":
Person().configure_traits()

```

If you run this, the first thing that appears is an error dialog that says 'is_adult' trait of a Person instance is 'read only':
![Screenshot 2020-11-16 at 17 23 41](https://user-images.githubusercontent.com/3673984/99286239-7e73ed80-2830-11eb-842a-201648bcb53b.png)

If you press "Enter", then the view for the `Person` appears as expected:
![Screenshot 2020-11-16 at 17 24 12](https://user-images.githubusercontent.com/3673984/99286293-90ee2700-2830-11eb-98d6-b4fcf8b5b96c.png)

There is a traceback on the console too:
```
Traceback (most recent call last):
File "/Users/kchoi/Work/ETS/py39-venv/pyface-env/lib/python3.9/site-packages/traitsui/qt4/boolean_editor.py", line 49, in update_object
self.value = bool(state)
File "/Users/kchoi/Work/ETS/py39-venv/pyface-env/lib/python3.9/site-packages/traitsui/editor.py", line 755, in _set_value
self.ui.do_undoable(self.__set_value, value)
File "/Users/kchoi/Work/ETS/py39-venv/pyface-env/lib/python3.9/site-packages/traitsui/ui.py", line 658, in do_undoable
action(*args, **kw)
File "/Users/kchoi/Work/ETS/py39-venv/pyface-env/lib/python3.9/site-packages/traitsui/editor.py", line 689, in __set_value
method(self.ui.info, self.object, name, value)
File "/Users/kchoi/Work/ETS/py39-venv/pyface-env/lib/python3.9/site-packages/traitsui/handler.py", line 289, in setattr
setattr(object, name, value)
File "/Users/kchoi/Work/ETS/py39-venv/pyface-env/lib/python3.9/site-packages/traits/trait_type.py", line 65, in _read_only
raise TraitError(
traits.trait_errors.TraitError: The 'is_adult' trait of a Person instance is 'read only'.
```

While this specific example can be workaround by specifying a custom view, ideally the default view should not show that first error dialog.

(Note that the checkbox is editable. The user can click the checkbox and be greeted with the same dialog.)

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.