wxPython入门练习代码 四
自定义Model文件abtractmodel.py:
class AbstractModel(object): def __init__(self):
self.listeners = [] def addListener(self, listenerFunc):
self.listeners.append(listenerFunc) def removeListener(self, listenerFunc):
self.listeners.remove(listenerFunc) def update(self):
for eachFunc in self.listeners:
eachFunc(self)
实例调用MVC文件ModelExample.py:
#!usr/bin/env python import wx
import abstractmodel class SimpleName(abstractmodel.AbstractModel):
def __init__(self,first="",last=""):
abstractmodel.AbstractModel.__init__(self)
self.set(first,last) def set(self,first,last):
self.first = first
self.last = last
self.update() class ModelExample(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Flintstones',size=(340,200))
panel = wx.Panel(self)
panel.SetBackgroundColour("White")
self.Bind(wx.EVT_CLOSE,self.OnCloseWindow)
self.textFields = {}
self.createTextFields(panel)
self.model = SimpleName()
self.model.addListener(self.OnUpdate)
self.createButtonBar(panel) def buttonData(self):
return(("Fredify",self.OnFred),
("Wilmafy",self.OnWilma),
("Barnify",self.OnBarney),
("Bettify",self.OnBetty)) def createButtonBar(self,panel,yPos=0):
xPos=0
for eachLabel,eachHandler in self.buttonData():
pos = (xPos,yPos)
button =self.buildOneButton(panel,eachLabel,eachHandler,pos)
xPos += button.GetSize().width def buildOneButton(self,parent,label,handler,pos=(0,0)):
button = wx.Button(parent,-1,label,pos)
self.Bind(wx.EVT_BUTTON,handler,button)
return button def textFieldData(self):
return (("First Name",(10,50)),("Last Name",(10,80))) def createTextFields(self,panel):
for eachLabel,eachPos in self.textFieldData():
self.createCaptionedText(panel,eachLabel,eachPos) def createCaptionedText(self,panel,label,pos):
static = wx.StaticText(panel,wx.NewId(),label,pos)
static.SetBackgroundColour("White")
textPos = (pos[0]+75,pos[1])
self.textFields[label] = wx.TextCtrl(panel,wx.NewId(),
"",size=(100,-1),pos=textPos,
style=wx.TE_READONLY) def OnUpdate(self,model):
self.textFields["First Name"].SetValue(model.first)
self.textFields["Last Name"].SetValue(model.last) def OnFred(self,event):
self.model.set("Fred","Flintstones") def OnBarney(self,event):
self.model.set("Barney","Rubble") def OnWilma(self,event):
self.model.set("Wilma","Flintstones") def OnBetty(self,event):
self.model.set("Betty","Rubble") def OnCloseWindow(self,event):
self.Destroy() if __name__ == '__main__':
app = wx.PySimpleApp()
frame = ModelExample(parent=None,id=-1)
frame.Show()
app.MainLoop()
wxPython入门练习代码 四的更多相关文章
- wxPython入门练习代码 二
WxPython书籍[摘记] 1.任何wxPython应用程序都需要一个应用程序对象.这个应用程序对象必须是类wx.App或其定制的子类的一个实例.2.在OnInit()方法中将至少创建一个框架对象, ...
- wxPython入门练习代码 一
Bare.py: #1.导入必须的wxPython包 import wx #2.子类化wx应用程序类 class App(wx.App): #3.定义应用程序初始化方法 def OnInit(self ...
- wxPython入门练习代码 三
DoubleEventFrame.py: #!/usr/bin/env/ python import wx class DoubleEventFrame(wx.Frame): def __init__ ...
- WCF入门教程(四)通过Host代码方式来承载服务
WCF入门教程(四)通过Host代码方式来承载服务 之前已经讲过WCF对外发布服务的具体方式. WCF入门教程(一)简介 Host承载,可以是web,也可以是控制台程序等等.比WebService有更 ...
- WCF入门教程(四)通过Host代码方式来承载服务 一个WCF使用TCP协议进行通协的例子 jquery ajax调用WCF,采用System.ServiceModel.WebHttpBinding System.ServiceModel.WSHttpBinding协议 学习WCF笔记之二 无废话WCF入门教程一[什么是WCF]
WCF入门教程(四)通过Host代码方式来承载服务 Posted on 2014-05-15 13:03 停留的风 阅读(7681) 评论(0) 编辑 收藏 WCF入门教程(四)通过Host代码方式来 ...
- 无废话ExtJs 入门教程十四[文本编辑器:Editor]
无废话ExtJs 入门教程十四[文本编辑器:Editor] extjs技术交流,欢迎加群(201926085) ExtJs自带的编辑器没有图片上传的功能,大部分时候能够满足我们的需要. 但有时候这个功 ...
- 【知识整理】这可能是最好的RxJava 2.x 入门教程(四)
这可能是最好的RxJava 2.x入门教程系列专栏 文章链接: 这可能是最好的RxJava 2.x 入门教程(一) 这可能是最好的RxJava 2.x 入门教程(二) 这可能是最好的RxJava 2. ...
- Wxpython入门
Wxpython入门 api文档以及中文教程: https://pan.baidu.com/s/1TDTgHg9Mwc74ODQy68YnlQ 提取码:354n 入门示例 frame=wx.Frame ...
- MyBatis基础入门《十四》ResultMap子元素(association )
MyBatis基础入门<十四>ResultMap子元素(association ) 1. id: >> 一般对应数据库中改行的主键ID,设置此项可以提高Mybatis的性能 2 ...
随机推荐
- svu update 遇到 Node remains in conflict
http://stackoverflow.com/questions/11774868/svn-checkout-without-restoring up vote4down votefavorite ...
- jquery中focus()函数实现当对象获得焦点后自动把光标移到内容最后
代码如下: setFocus=function(id){ var t=$("#"+id).val(); $("#"+id).val(""). ...
- sizeof、strlen、字符串、数组,整到一块,你还清楚吗?
写在前面 sizeof.strlen.字符串.数组,提到这些概念,相信学过C语言的人都能耳熟能详,也能谈得头头是道,但是,在实际运用中,当这些内容交织在一起时,大家却不一定能搞地清清楚楚,本文的目的正 ...
- 自己常用JS和JQ 函数
//验证码函数 <button id="send">点击发送验证码</button> <script src="jquery.min.js& ...
- jpg/png格式图片转eps格式的方法总结
jpg/png格式图片转eps格式的方法总结 转自http://blog.sina.com.cn/s/blog_5410e7b50101lme2.html 用latex写论文的筒子应该遇到这样的问题: ...
- spark的standlone模式安装和application 提交
spark的standlone模式安装 安装一个standlone模式的spark集群,这里是最基本的安装,并测试一下如何进行任务提交. require:提前安装好jdk 1.7.0_80 :scal ...
- 1012. The Best Rank (25)
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- 64位ubuntu下安装微博客户端的方法
最近安装了12.04的ubuntu系统,在unbutu提供的软件中心找不到微博客户端的应用,但在新浪的http://sinatair.sinaapp.com/下找到了官方的客户端. 于是下载了linu ...
- 装逼名词 bottom-half,软中断,preemptive选项
bottom-half http://bbs.csdn.net/topics/60226240 在中断,异常和系统调用里看Linux中断服务一般都是在关闭中断的情况下执行的,以避免嵌套而是控制复杂化L ...
- iOS 开发之使用safari对webview进行调试
转自:http://www.tuicool.com/articles/ZBFnUbz 使用safari对webview进行调试 时间 2016-02-25 14:35:20 陈斌彬的技术博客 原文 ...