2

It should be so simple, but I have not been able to figure out how to do a simple OK/cancel confirmation dialog in enaml. Could someone please enlighten me? I am using an ETS toolkit of Qt4 with pyside api, python 2.7, and enaml 0.6.8.

My application consists of a MainWindow and is launched like the following:


from enaml.stdlib.sessions import simple_session
from enaml.qt.qt_application import QtApplication

...

session = simple_session('myApp',...)

app = QtApplication([session])
app.start_session('myApp')
app.start()

Thanks in advance

icedwater
  • 4,701
  • 3
  • 35
  • 50
benpro
  • 4,325
  • 4
  • 19
  • 17

1 Answers1

3

Does seem like there should be a built-in widget. Nevertheless, based on the FileDialog example that ships with enaml, here's something that works and the pattern is readily extensible.

from enaml.layout.api import vbox, align
from enaml.widgets.api import Window, Container, Label, PushButton


enamldef Main(Window): main_win:

    title = 'Main'
    attr dlg_result : str = 'waiting'

    Container:
        constraints = [
            vbox(pb, lbl),
            align('h_center', lbl, pb),
        ]

        Label: lbl:
            align = 'center'
            text << main_win.dlg_result

        PushButton: pb:
            text = 'Dialog'
            clicked ::
                session.add_window( TheDialog(listener=main_win,result='dlg_result') )

enamldef TheDialog(Window): dlg_win:
    title = 'Dialog'
    modality = 'application_modal' # one of ['non_modal', 'window_modal', 'application_modal']
    attr listener
    attr result

    Container:
        constraints = []

        PushButton: ok_btn:
            text = 'Okay'
            clicked ::
                setattr(listener, result, 'Okay')
                dlg_win.close()

        PushButton: cancel_btn:
            text = 'Cancel'
            clicked ::
                setattr(listener, result, 'Cancel')
                dlg_win.close()
JefferyRPrice
  • 895
  • 5
  • 17