0

I'm using EPD traits for a basic GUI interface. I'm able to pop up a settings window using code like this:

settings_w.configure_traits(kind="livemodal")

The window has 'OK' and 'Cancel' buttons and I want to do something different depending on which button was pressed to exit the window. Seems like it should be simple but I can't figure out how to set this up.

Theoretically I'd like to do something like this:

# Display the settings widget
settings_w.configure_traits(kind="livemodal")

if settings_w.CancelButtonPressed:
    pass
else:
    print "I got the input"

But let me know if there's a better or more correct way to do this.

Also FWIW: here's the view properties of my settings window with standard OK and Cancel buttons:

view = View( 
    settings_group, 
    title   = 'Settings Editor',
    width = 500,
    buttons = [OKButton, CancelButton, 'Help' ],
    kind = 'modal',
    handler = SaveRestore_Handler()
)
Nick
  • 3,172
  • 3
  • 37
  • 49
  • Please provide your entire code so that we can make suggestions that are close to what you would like to do. – jonathanrocher Apr 04 '13 at 01:29
  • Relevant code is here: https://gist.github.com/anonymous/5307865 – Nick Apr 04 '13 at 04:39
  • I basically just want the cancel button to work. Right now it's functionally identical to the okay button which is just silly. – Nick Apr 04 '13 at 04:40

1 Answers1

2

If I understand the question, checking the output of configure_traits should do what you want:

result = settings_w.configure_traits(kind="livemodal")

if result:
    print "The user pressed OK."
else:
    print "The user pressed Cancel or closed the window."
pberkes
  • 5,141
  • 1
  • 24
  • 22
  • Thanks, I knew the answer should be simple like this. Just didn't know quite how to get there. – Nick Apr 04 '13 at 19:29
  • This works great when the user presses cancel or okay, but result returns True in my code when the user closes the window. How do I make closing the window equivalent to the cancel action? – Nick Apr 04 '13 at 23:02
  • @nickv2002 on which platform? – pberkes Apr 07 '13 at 16:45
  • I'm testing on Windows 7. Does this behaves differently on other platforms? – Nick Apr 07 '13 at 23:56
  • 1
    Sorry, I meant: on which backend? The code works correctly for qt (PyQt and PySide), but not for wx. This is probably a bug in TraitsUI. If it's an option, I would recommend switching to qt (set the environment variable `ETS_TOOLKIT=qt4`). Otherwise, you'll need to define your own button... – pberkes Apr 09 '13 at 11:35