《wxPython in Action》chap 9 笔记

1. Modal Dialog(模式对话框)

A modal dialog blocks other widgets from receiving user events until it is closed;

in other words, it places the user in dialog mode for the duration of its existence.

模式对话框阻塞了别的窗口部件接收用户事件,直到该模式对话框被关闭。

严格来说,dialog 与 frame 在外观上没有区别,只是处理事件(event)的方式不一样。

通常,dialog 在外观上要稍微简单一点,所以很少使用 wx.Panel。

wx.Dialog 具备 wx.Panel 的性质,widgets 一般直接添加到 wx.Dialog 中即可。

2. 展示与关闭 Dialog

Modal Dialog 与 普通的 Frame 用法略有差别。

最简单的示例代码如下:

import wx

class SubclassDialog(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self, None, -1, 'Dialog Subclass', size=(300, 100))
okButton = wx.Button(self, wx.ID_OK, "OK", pos=(15, 15))
okButton.SetDefault()
cancelButton = wx.Button(self, wx.ID_CANCEL, "Cancel", pos=(115, 15)) if __name__ == '__main__':
app = wx.PySimpleApp()
dialog = SubclassDialog()
result = dialog.ShowModal()
if result == wx.ID_OK:
print "OK"
else:
print "Cancel"
dialog.Destroy()

2.1 展示 Dialog

展示 Dialog 使用 ShowModal(),程序会等待 ShowModal() 执行结束并获取其返回值。

此时,Dialog 是 wxPython 应用接受用户事件的唯一组件。其他应用不受影响。

2.2 结束 Dialog Mode

调用 EndModal(retCode) 方法可以关闭(close)Dialog Mode,retCode 是 int 值,被 ShowModal() 返回。

此时,只是结束了 Dialog Mode,并未摧毁 Dialog。可以在其他地方继续展示该 Dialog。

通常在 event 的 handler 中调用 EndModal()。

2.3 摧毁 Dialog

调用 Destroy() 方法

2.4 典型用法

dialog = SubclassDialog()
result = dialog.ShowModal() # 展示对话框,并等待结果
if result == wx.ID_OK: # 判断结果,并执行相应处理
print "OK"
else:
print "Cancel"
dialog.Destroy() # 摧毁 Dialog

2.5 自定义 event 的 handler,一般需要调用 EndModal()

例如,用于连接数据库的 handler 实现如下:

def OnConnect(self, event=None):
host = self.input_host.GetValue()
port = int(self.input_port.GetValue())
if db.connect(host, port): # connected
self.EndModal(wx.ID_OK)
else:
msg_error = 'Error connecting to host(%s)' % host
wx.MessageBox(msg_error, 'Error', wx.OK | wx.ICON_ERROR)

wxPython Modal Dialog 模式对话框的更多相关文章

  1. VUE实现Studio管理后台(完结):标签式输入、名值对输入、对话框(modal dialog)

    一周的时间,几乎每天都要工作十几个小时,敲代码+写作文,界面原型算是完成了,下一步是写内核的HTML处理引擎,纯JS实现.本次实战展示告一段落,等RXEditor下一个版本完成,再继续分享吧.剩下的功 ...

  2. Bootstrap技术: 模式对话框的使用

    一.概述 说到模式对话框,大家肯定都会想到windows下GUI程序,在gui程序中,有大量的对话框. 在web程序中,随着页面交互式功能的增多,有很多场景下也会用到对话框.在html原生的支持下,有 ...

  3. 【转】VC 模式对话框和非模式对话框的创建,销毁和区别

    原文网址:http://blog.csdn.net/mycaibo/article/details/6002151 VC 模式对话框和非模式对话框的创建,销毁和区别   在WIN32中,模式对话框的创 ...

  4. JAVA的模式对话框和非模式对话框

    周末的时候,一位网友让我帮他把他的无模式对话框改成有模式对话框. 界面是由swing制作的,都是JFrame,我从来没有接触过swing编程.大致的代码还是看的懂,很多都和C#很相似. 然后就去查资料 ...

  5. MFC模式对话框与非模式对话框 消息处理顺序

    对话框有两种创建方式:DoModal和Creat. 其中DoModal创建的是模态的对话框,而Creat创建的是非模态的对话框下面总结下他们的不同. 对于模态的对话框,在该对话框被关闭前,用户将不能在 ...

  6. Create Custom Modal Dialog Windows For User Input In Oracle Forms

    An example is given below to how to create a modal dialog window in Oracle Forms for asking user inp ...

  7. iframe中的jquery ui modal dialog 覆盖父窗口

    在iframe中 使用jquery ui dialog,弹出后可以覆盖父窗体 ///iframe中的jquery ui modal dialog 覆盖父窗口 function openDialog() ...

  8. Qt之模式、非模式、半模式对话框

    简述 关于"模式"和"非模式"对话框,相信大家都比较熟悉,但其中有一个可能很多人都比较陌生,介于两者之间的状态,我们称之为"半模式". 简述 ...

  9. 模式对话框里的CheckedChanged事件

    问题:   模式对话框里的CheckedChanged事件不被触发: 解决方法: 一.先不直接showModalDialog出要的页面,而是要放一个中单页面 window.showModalDialo ...

随机推荐

  1. sed程序

    程序1: 实现简单的shell sed替换功能 程序2:修改haproxy配置文件  1.查 输入:www.oldboy.org 获取当前backend下的所有记录 2.新建 输入: arg = { ...

  2. ASP.NET弹出模态对话框【转】

    主页面 PageBase.aspx.cs 中的代码 protected void Page_Load(object sender, EventArgs e) {    if (!this.IsPost ...

  3. maven管理多模块系统

    1.创建mydemo项目cd d:\myworkmvn archetype:create -DgroupId=com.example.mydemo -DartifactId=mydemo 生成myde ...

  4. 终于又可以用WLW了.

    前面有一段时间没有写博客,然后过完年想继续用WLW的时候,出现问题了. An unexpected error occurred while attempting to detect weblog s ...

  5. Linux学习之路:变量值的删除、替代和替换

    一.删除 var为变量名, ${var#v*r}:从左到右匹配将:头部是“v”,尾部是“r”的最短的部分删除 ${var##v*r}:从左到右匹配将:头部是“v”,尾部是“r”的最长的部分删除 ${v ...

  6. ORM之PetaPoco错误--VS中NUGet程序包管理安装PetaPoco

    一般在Vs中使用PetaPoco的时候都是使用NuGet程序包管理来安装PetaPoco的,如果你在安装PetaPoco前设置了ConnectionString,那么PetaPoco中的T4模板会自动 ...

  7. (转)嵌入式学习准备---linux c 文件锁

    (1)fcntl函数说明 前面的这5个基本函数实现了文件的打开.读写等基本操作,这一节将讨论的是,在文 件已经共享的情况下如何操作,也就是当多个用户共同使用.操作一个文件的情况,这时,Linux 通常 ...

  8. jquery jsonp实现跨域

    html代码: $("#testJsonp").click(function(){ $.ajax({ url: "http://www.test.cc/1.php&quo ...

  9. CXF(2.7.10) - A simple JAX-WS service

    1. 下载 apache-cxf-x.x.x.zip,在工程导入依赖的 jar 包.也可以基于 Maven 构建工程. 2. 定义服务接口. package com.huey.demo.ws; imp ...

  10. Jersey(1.19.1) - Root Resource Classes

    Root resource classes are POJOs (Plain Old Java Objects) that are annotated with @Path have at least ...