2

它应该很简单,但我无法弄清楚如何在 enaml 中进行简单的确定/取消确认对话框。有人可以启发我吗?我正在使用带有 pyside api、python 2.7 和 enaml 0.6.8 的 Qt4 的 ETS 工具包。

我的应用程序由一个 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()

提前致谢

4

1 回答 1

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()
于 2013-07-14T17:12:51.247 回答