使用DxVcl为Python的飞信库写一个简单的GUI
2011-04-08 10:51
204 查看
Python的好处,就是类库超多,多到只有你想不到的库,而没有你想到的,他却没有的库。所以飞信,在Python下也有一个开源的类库,这个就是PyFetion,他自己有带一个Demo,不过是一个CGI的程序,没有窗口界面,于是用之前Delphi写的DxVcl为这个飞信库实现了一个简单的界面GUI。代码很简单,就是两个窗口,一个窗口是验证码输入的窗口,还有一个是主窗口。界面信息:
主代码如下:
本代码就是在原作者的Fetion.py上修改来的,仅仅就是套上了一个界面GUI而已,另外发送短信,也就只写了发送给自己而已。如果个人有需要的自行扩展一下吧,嘿嘿,完整代码下载
主代码如下:
class SeriForm(Form): def __init__(self,Owner): self.Caption = '请输入验证码' self.Position = 5 self.BorderStyle = 3 self.Width = 275 self.Height = 162 self.lbl = Label(self) self.lbl.SetProps(Parent = self,Caption = '请输入验证码') self.lbl.SetBounds(24,16,72,13) self.EdtNum = Edit(self) self.EdtNum.Parent = self self.EdtNum.SetBounds(102,11,139,21) self.Img = Image(self) self.Img.Parent = self self.Img.SetBounds(24,35,217,59) self.Img.Center = True self.Img.Picture.LoadFromFile('fetion_verify.jpg') self.BtnOk = Button(self) self.BtnOk.SetProps(Parent = self,Caption='确定') self.BtnOk.SetBounds(24,100,75,25) self.BtnOk.OnClick = self.BtnOkClick self.BtnCancel = Button(self) self.BtnCancel.SetProps(Parent = self,Caption='取消') self.BtnCancel.SetBounds(166,100,75,25) self.BtnCancel.OnClick = self.BtnCancelClick def BtnCancelClick(self,Sender): self.Close() def BtnOkClick(self,Sender): self.ModalResult = mrok def GetSeriCode(self,picFile): """picFile 验证码图片""" SeriFrm = SeriForm(None) if SeriFrm.ShowModal() == mrok: ret = SeriFrm.EdtNum.Text else: ret = '' SeriFrm.Free() return ret class MainForm(Form): def __init__(self,Owner): self.SetProps(Width=492,Height=401,BorderStyle=3) self.lbUser = Label(self) self.lbUser.SetProps(Parent = self,Caption = '用户') self.lbUser.SetBounds(16,8,24,13) self.EdtUser = Edit(self) self.EdtUser.Parent = self self.EdtUser.SetBounds(55,4,121,21) self.lbl = Label(self) self.lbl.SetProps(Parent = self,Caption = '密码') self.lbl.SetBounds(192,8,24,13) self.EdtPwd = Edit(self) self.EdtPwd.SetProps(Parent = self,PasswordChar='*') self.EdtPwd.SetBounds(234,4,121,21) self.lbl1 = Label(self) self.lbl1.SetProps(Parent = self,Caption = '好友列表') self.lbl1.SetBounds(8,27,48,13) self.FriendList = ListBox(self) self.FriendList.Parent = self self.FriendList.SetBounds(8,47,137,314) self.Memo1 = Memo(self) self.Memo1.Parent = self self.Memo1.SetBounds(151,47,325,185) self.Memo2 = Memo(self) self.Memo2.Parent = self self.Memo2.SetBounds(151,238,325,87) self.BtnSend = Button(self) self.BtnSend.SetProps(Parent = self,Caption = '发送') self.BtnSend.SetBounds(401,331,75,25) self.BtnSend.OnClick = self.BtnSendClick self.BtnLog = Button(self) self.BtnLog.SetProps(Parent = self,Caption = '登录') self.BtnLog.SetBounds(361,3,75,25) self.BtnLog.OnClick = self.BtnLogClick self.Phone = PyFetion('','','TCP') self.threads = [] def BtnSendClick(self,Sender): if self.Phone and self.Phone.alive: if self.Phone.send_sms(toUTF8(self.Memo2.Lines.Text)): self.Memo1.Lines.Add('给自己发送短信息成功,目前只写了给自己发送信息') else: ShowMessage('无效的登录') def BtnLogClick(self,Sender): if self.BtnLog.Caption == '登出': self.Phone.logout() self.BtnLog.Caption = '登录' self.FriendList.Items.Clear() return 1 self.Phone.mobile_no = self.EdtUser.Text self.Phone.passwd = self.EdtPwd.Text try: ret = self.Phone.login(FetionOnline) except PyFetionSupportError,e: ShowMessage('手机号未开通飞信') return 1 except PyFetionAuthError,e: ShowMessage('手机号密码错误') return 1 except PyFetionSocketError,e: ShowMessage(e.msg) return 1 finally: pass if ret: ShowMessage('登录成功') #增加好友列表 buddys = self.Phone.get_contactlist() if not buddys: ShowMessage('无好友') else: self.BtnLog.Caption = '登录' for i in buddys: if buddys[i][0]=='': buddys[i][0]=i[4:4+9] for i in range(len(buddys)): s = "%-4d%-8s%-20s" % (i,status[buddys[buddys.keys()[i]][2]].decode('gb2312').encode('utf8'),buddys[buddys.keys()[i]][0],) s = s.decode('utf8').encode('gb2312') self.FriendList.Items.Add(s) self.threads.append(fetion_recv(self)) #启动接收包 self.threads.append(fetion_alive(self.Phone)) #启动心跳 for t in self.threads: t.setDaemon(True) t.start() else: ShowMessage('失败') return 1 def guimain(argv=None): PyFetion.GetSeirCodeEvent = GetSeriCode Application.Initialize() f = MainForm(Application) f.Show() FreeConsole() Application.Run()
本代码就是在原作者的Fetion.py上修改来的,仅仅就是套上了一个界面GUI而已,另外发送短信,也就只写了发送给自己而已。如果个人有需要的自行扩展一下吧,嘿嘿,完整代码下载
相关文章推荐
- python3使用pyqt5制作一个超简单浏览器的实例
- 使用python中的smtplib库,写一个简单的发送qq邮件程序,速成!!
- Python(17)python使用tkinter实现一个简单的CSGO幸运转盘抽奖游戏
- 使用PyQt5编写一个简单的GUI程序(pyside 有 pyside-uic 把ui文件转成py文件,pyside-rcc 把qrc文件转成 py文件导入就行了)
- 如何使用Python为Hadoop编写一个简单的MapReduce程序
- 一个简单的不用cookie的人人网状态爬取的python爬虫,使用beautifulsoup
- urllib库的简单使用 && 一个简单的Python爬虫示例
- Python(16)python使用tkinter实现一个简单的计算器
- 使用Python启动一个简单的服务器
- 使用Python的Twisted框架实现一个简单的服务器
- pyFormUI: 一个简单的Python GUI界面框架
- 使用python构建一个简单的发布系统
- Unity3d修炼之路:GUI按钮简单使用,完成对一个简单对象Cube的移动,旋转
- 在 Eclipse Workbench 之外使用 Eclipse GUI,第 1 部分: 单独使用 JFace 和 SWT构建一个简单的文件资源管理器应用程序
- python使用线程封装的一个简单定时器类实例
- 浅谈Python使用Bottle来提供一个简单的web服务
- 一个简单的语音识别实现---百度在线语音识别REST API SDK(Python)简单使用
- python 之 使用web.py实现一个简单的增删改查应用
- 使用Python的Bottle框架写一个简单的服务接口的示例
- 如何使用Python为Hadoop编写一个简单的MapReduce程序