wxPython Modal Dialog 模式对话框
《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 模式对话框的更多相关文章
- VUE实现Studio管理后台(完结):标签式输入、名值对输入、对话框(modal dialog)
一周的时间,几乎每天都要工作十几个小时,敲代码+写作文,界面原型算是完成了,下一步是写内核的HTML处理引擎,纯JS实现.本次实战展示告一段落,等RXEditor下一个版本完成,再继续分享吧.剩下的功 ...
- Bootstrap技术: 模式对话框的使用
一.概述 说到模式对话框,大家肯定都会想到windows下GUI程序,在gui程序中,有大量的对话框. 在web程序中,随着页面交互式功能的增多,有很多场景下也会用到对话框.在html原生的支持下,有 ...
- 【转】VC 模式对话框和非模式对话框的创建,销毁和区别
原文网址:http://blog.csdn.net/mycaibo/article/details/6002151 VC 模式对话框和非模式对话框的创建,销毁和区别 在WIN32中,模式对话框的创 ...
- JAVA的模式对话框和非模式对话框
周末的时候,一位网友让我帮他把他的无模式对话框改成有模式对话框. 界面是由swing制作的,都是JFrame,我从来没有接触过swing编程.大致的代码还是看的懂,很多都和C#很相似. 然后就去查资料 ...
- MFC模式对话框与非模式对话框 消息处理顺序
对话框有两种创建方式:DoModal和Creat. 其中DoModal创建的是模态的对话框,而Creat创建的是非模态的对话框下面总结下他们的不同. 对于模态的对话框,在该对话框被关闭前,用户将不能在 ...
- 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 ...
- iframe中的jquery ui modal dialog 覆盖父窗口
在iframe中 使用jquery ui dialog,弹出后可以覆盖父窗体 ///iframe中的jquery ui modal dialog 覆盖父窗口 function openDialog() ...
- Qt之模式、非模式、半模式对话框
简述 关于"模式"和"非模式"对话框,相信大家都比较熟悉,但其中有一个可能很多人都比较陌生,介于两者之间的状态,我们称之为"半模式". 简述 ...
- 模式对话框里的CheckedChanged事件
问题: 模式对话框里的CheckedChanged事件不被触发: 解决方法: 一.先不直接showModalDialog出要的页面,而是要放一个中单页面 window.showModalDialo ...
随机推荐
- IOS应用程序多语言本地化解决方案
最近要对一款游戏进行多语言本地化,在网上找了一些方案,加上自己的一点点想法整理出一套方案和大家分享! 多语言在应用程序中一般有两种做法:一.程序中提供给用户自己选择的机会:二.根据当前用户当前移动设备 ...
- Matrix multiplication hdu4920
Problem Description Given two matrices A and B of size n×n, find the product of them. bobo hates big ...
- reset.css(详细说明)
@charset "utf-8";/************************************************************************ ...
- Xquartz远程访问linux
实验环境:mac 操作系统: OS X 10.9.4 Mavericksmac IP 192.168.1.106XQuartz: ...
- 用继承实现XYPoint和Circle两个类
#import <Foundation/Foundation.h> @protocol show @required -(void)printOn; @end @interface XYP ...
- LeetCode 260
Single Number III Given an array of numbers nums, in which exactly two elements appear only once and ...
- [改善Java代码]多种最值算法,适时选择
建议64:多种最值算法,适时选择. 对一批数据进行排序,然后找出其中的最大值或最小值,这是基本的数据结构知识.在Java中我们可以通过编写算法的方式,也可以通过数组先排序再取值的方式来实现.下面以求最 ...
- js中call和apply的用法和区别
它们的作用都是将函数绑定到另外一个对象上去运行,两者仅在定义参数方式有所区别: obj.call(thisObj, arg1, arg2, ...); obj.apply(thisObj, [arg1 ...
- linq检索带命名空间的xml
XElement el = XElement.Load(fil); XNamespace ns = "http://schemas.microsoft.com/ado/2009/11/edm ...
- Jersey(1.19.1) - Life-cycle of Root Resource Classes
By default the life-cycle of root resource classes is per-request, namely that a new instance of a r ...