enthought / enthought/traitsui

OKButton cannot be renamed

Open
#1,148 1 comment 0 reactions 0 assignees View on GitHub
component: core type: enhancement
Dominant language
Python
Stars
306
Forks
99
PR merge metrics
No merged PRs in 30d

Description

The [OKButton](https://docs.enthought.com/traitsui/api/traitsui.menu.html?highlight=okbutton#traitsui.menu.OKButton) has special behaviour that is not replicable by defining another [Action](https://docs.enthought.com/traitsui/traitsui_user_manual/handler.html#actions) - when it is clicked, the `close` method is fired with `is_ok=True`. It would be useful to make it possible to rename this button (for example, to localise to another language) but keep the special window closing behaviour. This also applies to other built in Actions.

Example:
```
from traits.api import HasTraits, Str, Instance
from traitsui.api import View, Item, ModelView
from traitsui.menu import OKButton, CancelButton

class Demo(HasTraits):
name = Str()

class DemoView(ModelView):
model = Instance(Demo)
def close(self, info, is_ok):
if is_ok:
print('Closed using OKButton') # some behaviour
else:
print('Closed some other way') # some other behaviour
return True
def default_traits_view(self):
return View(Item('model.name'), buttons = [OKButton, CancelButton])

demoview = DemoView(model=Demo())
demoview.configure_traits()
```

gives

traitsui

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.