创建确定/取消对话框

时间:2013-05-29 14:13:43

标签: python enthought enaml

应该这么简单,但我还没弄清楚如何在enaml中做一个简单的确定/取消确认对话框。有人可以赐教吗?我正在使用Qt4的ETS工具包和pyside api,python 2.7和enaml 0.6.8。

我的应用程序由MainWindow组成,并按以下方式启动:


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()

提前致谢

1 个答案:

答案 0 :(得分:3)

看起来应该有一个内置的小部件。尽管如此,基于与enaml一起提供的FileDialog示例,这里有一些有用的东西,而且模式很容易扩展。

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()