如何获取wxPython数据库自定义函数Dialog的数据

创建自定义事件的步骤:
定义事件类,该事件类必须继承自wx.PyCommandEvent,并定义get和set方法来获取和设置事件参数。
创建一个事件类型和一个绑定器对象去绑定该事件到特定的对象。
创建自定义事件对象,设置事件参数,并且使用ProcessEvent()方法将这个实例引入事件处理系统。
绑定自定义事件的event handler。
在event handler中响应事件。
#!/usr/bin/env&python
#coding=utf-8
import&wx&
class&MyTestEvent(wx.PyCommandEvent):&&&#<span style="color: #&定义事件&&&&&&&&&&
&&&&def&__init__(self,&evtType,&id):&&&&&&&&&&&&&&&&&
&&&&&&&&wx.PyCommandEvent.__init__(self,&evtType,&id)
&&&&&&&&self.eventArgs&=&""
&&&&def&GetEventArgs(self):&
&&&&&&&&return&self.eventArgs&
&&&&def&SetEventArgs(self,&args):&
&&&&&&&&self.eventArgs&=&args&
myEVT_MY_TEST&=&wx.NewEventType()&#<span style="color: #&创建一个事件类型&&&
EVT_MY_TEST&=&wx.PyEventBinder(myEVT_MY_TEST,&<span style="color: #)&&#<span style="color: #&创建一个绑定器对象&
class&MyFrame(wx.Frame):&
&&&&def&__init__(self):&
&&&&&&&&wx.Frame.__init__(self,&None,&-<span style="color: #,&"My&Frame",&size=(<span style="color: #0,&<span style="color: #0),pos=(<span style="color: #0,<span style="color: #0))&
&&&&&&&&panel&=&wx.Panel(self,&-<span style="color: #)&
&&&&&&&&self.button1&=&wx.Button(panel,id=-<span style="color: #,pos=(<span style="color: #,&<span style="color: #),label="button1")
&&&&&&&&self.Bind(wx.EVT_BUTTON,&self.OnButton1Click,&self.button1)
&&&&&&&&self.Bind(EVT_MY_TEST,&self.OnHandle)#&4绑定事件处理函数
&&&&def&OnButton1Click(self,event):
&&&&&&&&self.OnDoTest()
&&&&def&OnHandle(self,event):#<span style="color: #&事件处理函数
&&&&&&&&dlg&=&wx.MessageDialog(self,&event.GetEventArgs(),'A&Message&Box',wx.OK&|&wx.ICON_INFORMATION)
&&&&&&&&dlg.ShowModal()
&&&&&&&&dlg.Destroy()
&&&&def&OnDoTest(self):
&&&&&&&&evt&=&MyTestEvent(myEVT_MY_TEST,&self.button1.GetId())&#<span style="color: #&创建自定义事件对象&&&
&&&&&&&&evt.SetEventArgs("test&event")&&&#&6添加数据到事件&
&&&&&&&&self.GetEventHandler().ProcessEvent(evt)&&#<span style="color: #&处理事件&
if&__name__&==&'__main__':&
&&&&app&=&wx.PySimpleApp()&
&&&&frame&=&MyFrame()&
&&&&frame.Show(True)&
&&&&app.MainLoop()&
#1.定义MyTestEvent 类为wx.PyCommandEvent的子类,wx.PyCommandEvent是wxPython特定的结构,可以用来创建新的事件类并且可以把C++类和你的Python代码连接起来。
#2. wx.NewEventType()类似于wx.NewId();它返回一个唯一的事件类型ID。
#3.创建一个绑定器对象,第二个参数的取值位于[0,2]之间,它代表wxId标识号,该标识号用于wx.EvtHandler.Bind()方法去确定哪个对象是事件的源。
#4.绑定事件的处理器。
#5. 创建自定义事件对象,并把触发事件的控件的ID作为参数传给MyTestEvent的构造函数。
#6.添加数据给事件。可以将一些您需要的信息通过这种方法传递进去。
#7. ProcessEvent()的调用将这个新事件引入到事件处理系统中,GetEventHandler()调用返回wx.EvtHandler的一个实例,也就是窗口对象本身,即:MyFrame。
#8.绑定事件处理函数,这里的事件处理方式是通过MessageDialog显示出传入的事件参数。
--参考《wxPython in action》
阅读(...) 评论()& 列表选择框就是让用户从提供的列表中选择目标项,原型如下:
&&wxSingleChoiceDialog(* parent, const & message, const & caption, int n, const * choices, void** clientData = NULL, long style = wxCHOICEDLG_STYLE, const & pos = wxDefaultPosition)
&支持的方法如下:
wxSingleChoiceDialog::GetSelection 返回选项的index
wxSingleChoiceDialog::GetSelectionClientData 返回与选项绑定的clientdata内容
wxSingleChoiceDialog::GetStringSelection 返回选择的字符串内容
wxSingleChoiceDialog::SetSelection 设置选项
wxSingleChoiceDialog::ShowModal
&看一下实例:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Function:常用对话框实例
Input:NONE
Output: NONE
author: socrates
blog:/dyx1024/
class MyFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, u'测试面板Panel', size = (600, 300))
panel = wx.Panel(self)
#在Panel上添加Button
button = wx.Button(panel, label = u'关闭', pos = (150, 60), size = (100, 60))
#绑定单击事件
self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
#消息对话框
def OnCloseMe(self, event):
dlg = wx.MessageDialog(None, u"消息对话框测试", u"标题信息", wx.YES_NO | wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_YES:
self.Close(True)
dlg.Destroy()
#文本输入对话框
def OnCloseMe(self, event):
dlg = wx.TextEntryDialog(None, u"请在下面文本框中输入内容:", u"文本输入框标题", u"默认内容")
if dlg.ShowModal() == wx.ID_OK:
message = dlg.GetValue() #获取文本框中输入的值
dlg_tip = wx.MessageDialog(None, message, u"标题信息", wx.OK | wx.ICON_INFORMATION)
if dlg_tip.ShowModal() == wx.ID_OK:
self.Close(True)
dlg_tip.Destroy()
dlg.Destroy()
#列表选择对话框
def OnCloseMe(self, event):
dlg = wx.SingleChoiceDialog(None, u"请选择你喜欢的水果:", u"列表选择框标题",
[u"苹果", u"西瓜", u"草莓"])
if dlg.ShowModal() == wx.ID_OK:
message = dlg.GetStringSelection() #获取选择的内容
dlg_tip = wx.MessageDialog(None, message, u"标题信息", wx.OK | wx.ICON_INFORMATION)
if dlg_tip.ShowModal() == wx.ID_OK:
self.Close(True)
dlg_tip.Destroy()
dlg.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyFrame(parent = None, id = -1)
frame.Show()
app.MainLoop()
测试一下:
阅读(...) 评论()Android获取dialog自定义布局中的控件
public class PopUpDialog extends Dialog {
private View customV
public PopUpDialog(Context context) {
super(context);
public class PopUpDialog extends Dialog {
private View customV
public PopUpDialog(Context context) {
super(context);
this.context =
// TODO Auto-generated constructor stub
public PopUpDialog(Context context, int theme){
super(context, theme);
this.context =
LayoutInflater inflater= LayoutInflater.from(context);
customView = inflater.inflate(R.layout.mydialog, null);
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(customView);
public View findViewById(int id) {
// TODO Auto-generated method stub
return super.findViewById(id);
public View getCustomView() {
return customV
customView = inflater.inflate(R.layout.mydialog, null);通过此语句获取view“指针”(借用C的术语),在新的Activity中实现调用自定义对话框中的控件。
PopUpDialog newDialog = new PopUpDialog(MsgReView.this, R.style.MyDialog);
newDialog.setCanceledOnTouchOutside(true);
View view = newDialog.getCustomView();
TextView text1 = (TextView)view.findViewById(R.id.textViewTotal);
text1.setText("调查人数:5");
版权声明:本文内容由互联网用户自发贡献,本社区不拥有所有权,也不承担相关法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至: 进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。
用云栖社区APP,舒服~
【云栖快讯】红轴机械键盘、无线鼠标等753个大奖,先到先得,云栖社区首届博主招募大赛9月21日-11月20日限时开启,为你再添一个高端技术交流场所&&
移动测试(Mobile Testing)是为广大企业客户和移动开发者提供真机测试服务的云平台,拥有大量热门机型,...
一项针对阿里云资源和互联网应用进行监控的服务。云监控服务可用于收集获取阿里云资源的监控指标,探测互联网服务可用性...
阿里云移动APP解决方案,助力开发者轻松应对移动app中随时可能出现的用户数量的爆发式增长、复杂的移动安全挑战等...
为您提供简单高效、处理能力可弹性伸缩的计算服务,帮助您快速构建更稳定、安全的应用,提升运维效率,降低 IT 成本...
阿里云双11狂欢,不只是5折
Loading...android 回调接口学习(自定义Dialog 获取数据数据回调) - CSDN博客
android 回调接口学习(自定义Dialog 获取数据数据回调)
将单独的一个Dialog提取出来以复用代码,然后在activity中去new 一个Dialog出来,能够获取Dialog选取的数据;
TopicSingleChoiceDialog.java
private int topicID=-1;
自定义内部类接口
public interface OnTestListening{
void getTopicID(int topicID);
private OnTestListening onTestL
类实现点击按钮监听器(就是我们点击了该按钮后,activity将回调 获取数据)
public class TopicSingleChoiceDialog extends AlertDialog.Builder implements DialogInterface.OnClickListener {
具体怎么做呢,
让该按钮先绑定该监听器
this.setPositiveButton("确定", this);
监听器具体实现
public void onClick(DialogInterface dialogInterface, int i) {
onTestListening.getTopicID(topicID);
this.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
onTestListening.getTopicID(topicID);
但是由于onTestListening在内部类,onTestListening要final,而interface的onTestListening是不能被final的(貌似是这样),最后采用上面的方法 让TopicSingleChoiceDialog 去实现接口
那么到这里后,当点击确定按钮后,就会执行 onTestListening.getTopicID(topicID);
那么 我们只要在activity中实例化dialog(Context cx,new TopicSingleChoiceDialog.OnTestListening())
TopicSingleChoiceDialog topicSingleleChoiceDialog =new TopicSingleChoiceDialog(ct, new TopicSingleChoiceDialog.OnTestListening() {
public void getTopicID(int topicID) {
Log.i("zjx","topicID:"+topicID);
便可以获取到我们要的topicID
当然 对于复杂数据 ,只要将getTopicID中的参数改为Bundle 或者map等即可
完整代码:
package com.france.sharereader.ui.
import android.app.AlertD
import android.content.C
import android.content.DialogI
import android.widget.T
* Created by Administrator on .
public class TopicSingleChoiceDialog extends AlertDialog.Builder implements DialogInterface.OnClickListener {
private int topicID=-1;
private OnTestListening onTestL
public TopicSingleChoiceDialog(Context context,OnTestListening onTestListening) {
super(context);
this.onTestListening=onTestL
this.setTitle("选择所属话题");
final String[] hobbies = {"编译原理", "软件工程", "数据挖掘", "电子设计"};
* 第一个参数指定我们要显示的一组下拉多选框的数据集合
* 第二个参数代表哪几个选项被选择,如果是null,则表示一个都不选择,如果希望指定哪一个多选选项框被选择,
* 需要传递一个boolean[]数组进去,其长度要和第一个参数的长度相同,例如 {true, false, false, true};
* 第三个参数给每一个多选项绑定一个监听器
this.setSingleChoiceItems(hobbies, 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setTopicID(which);
this.setPositiveButton("确定", this);
this.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
this.show();
public interface OnTestListening{
void getTopicID(int topicID);
public void setTopicID(int topicID) {
this.topicID = topicID;
public void onClick(DialogInterface dialogInterface, int i) {
onTestListening.getTopicID(topicID);
activity中:
TopicSingleChoiceDialog topicSingleleChoiceDialog =new TopicSingleChoiceDialog(ct, new TopicSingleChoiceDialog.OnTestListening() {
public void getTopicID(int topicID) {
Log.i("zjx","topicID:"+topicID);
本文已收录于以下专栏:
相关文章推荐
public class MessageDialog {
AlertDialog.Builder bu...
当我们项目需要加入一个或多个Module作为library时,会报如下异常:
Error:Execution failed for task &#39;:app:process_360DebugManife...
基本上所有的app项目都会有自定义dialog,但有时如果把dialog单独写成一个类,我们就需要考虑到如何将dialog的参数回调到activity或者fragment,当然有很多方法,这里主要讲的...
android开发中,往往需要在当前activity中打开一个输入框来获取用户数据,但是怎么将输入框的数据传递到activity中呢?
一种方法是创建一个全局变量,在对话框中将数据传递给静态全局变量...
新的一年开始了,打开朋友圈、QQ空间、微博,一大波虐狗了,晒图的,炫富的又开始了,今天就带大家做这样一个图文小案例。先看下效果。
列表预览页
图片详情页
业务需求很简单,做一个小图预览,...
没事,就简单来写个关于自定义对话框使用HANDLER与TIMERTASK来定时更新其自定义的对话框的数据,由于自定义的对话框是为继承DAILOG来单独实现的,所以在数据更新时会稍微麻烦一点,所以现在我...
主要实现功能:
1、从Activity的TextView中获取字符串设置到AlertDialog的TextView和EditText中
2、将AlertDialog的EditText中的值设置到Act...
他的最新文章
讲师:吴岸城
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)

我要回帖

更多关于 数据库自定义函数 的文章

 

随机推荐