wxPython Events help

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: May 2009
Posts: 231
Reputation: sravan953 has a little shameless behaviour in the past 
Solved Threads: 28
sravan953's Avatar
sravan953 sravan953 is offline Offline
Posting Whiz in Training
 
0
  #31
Oct 7th, 2009
Originally Posted by winmic View Post
Well, there are two problems.

1) in line 98, user should be self.user which will solve the error message. in line 88 user, passw should be self.user, self.passw

2) After fixing those two lines, try printing self.user and self.passw in the login function. When I did that it said that self.user is 'Login ID' and self.passw is 'Password' even after changing the user and password. The problem lies in where you GetValue(), you have it in __init__ where it will get the starting values when it should be in the functions that use it so user input is read.

Here's the code that seems to be working, with the changes from above. I've also added style=wx.TE_PASSWORD in line 46 to mask the password.

  1. import smtplib
  2. import time
  3. import os
  4. import wx
  5.  
  6. window=wx.App()
  7.  
  8. s=smtplib.SMTP("smtp.gmail.com",587)
  9. s.starttls()
  10.  
  11. class pymailer(wx.Frame):
  12.  
  13. def __init__(self):
  14. wx.Frame.__init__(self,None,-1,"Py-mailer",size=(500,700))
  15.  
  16. self.info={}
  17. self.user=""
  18. self.passw=""
  19. self.to=""
  20. self.subject=""
  21. self.message=""
  22.  
  23. self.panel=wx.Panel(self,-1)
  24.  
  25. menubar=wx.MenuBar()
  26.  
  27. filem=wx.Menu()
  28. filem.Append(201,"Quit")
  29. self.Bind(wx.EVT_MENU,self.Quit,id=201)
  30.  
  31. viewm=wx.Menu()
  32. viewm.Append(202,"About")
  33. self.Bind(wx.EVT_MENU,self.About,id=202)
  34.  
  35. menubar.Append(filem,"File")
  36. menubar.Append(viewm,"Help")
  37.  
  38. self.SetMenuBar(menubar)
  39.  
  40. wx.StaticText(self.panel,-1,"Welcome to Py-mailer.\nLogin with your Gmail credentials and you can send a text-only email to anyone quickly and easily.",pos=(10,10))
  41. wx.StaticText(self.panel,-1,"Please enter your Gmail login ID: ",pos=(10,100))
  42. wx.StaticText(self.panel,-1,"Please enter your Gmail login password:\n(will not be stored)",pos=(10,130))
  43.  
  44. self.username=wx.TextCtrl(self.panel,101,"Login ID",pos=(220,100))
  45.  
  46. self.password=wx.TextCtrl(self.panel,102,"Password",pos=(220,130), style=wx.TE_PASSWORD)
  47.  
  48. login=wx.Button(self.panel,103,label="Login",pos=(10,170))
  49. self.Bind(wx.EVT_BUTTON,self.Login,id=103)
  50.  
  51. wx.StaticText(self.panel,-1,"To:",pos=(10,250))
  52. wx.StaticText(self.panel,-1,"Subject:",pos=(10,280))
  53. wx.StaticText(self.panel,-1,"Message:",pos=(10,310))
  54.  
  55. self.to_info=wx.TextCtrl(self.panel,104,pos=(80,250),size=(240,20))
  56.  
  57. self.sbj_info=wx.TextCtrl(self.panel,105,pos=(80,280),size=(240,20))
  58.  
  59. self.msg_info=wx.TextCtrl(self.panel,106,pos=(80,310),size=(240,150))
  60.  
  61. send=wx.Button(self.panel,107,"Send",pos=(245,470))
  62. self.Bind(wx.EVT_BUTTON,self.Send,id=107)
  63.  
  64. self.Centre()
  65. self.Show()
  66.  
  67. def Quit(self,event):
  68. self.Close()
  69.  
  70. def About(self,event):
  71. about=wx.AboutDialogInfo()
  72.  
  73. about.SetName("Py-Mailer")
  74. about.SetCopyright("(c) 2009 Sravan")
  75. about.SetWebSite("http://www.uberpix.wordpress.com")
  76. about.AddDeveloper("Sravan")
  77. about.AddDeveloper("Dan")
  78.  
  79. wx.AboutBox(about)
  80.  
  81. def Login(self,event):
  82. self.user=self.username.GetValue()
  83. self.passw=self.password.GetValue()
  84. try:
  85. s.login(self.user,self.passw)
  86. wx.StaticText(self.panel,-1,"Logged in...",pos=(10,200))
  87. except:
  88. wx.StaticText(self.panel,-1,"Failed",pos=(10,200))
  89.  
  90. def Send(self,event):
  91. self.info["To"]=self.to_info.GetValue()
  92. self.info["Subject"]=self.sbj_info.GetValue()
  93. self.info["Message"]=self.msg_info.GetValue()
  94. to=self.info["To"]
  95. subject=self.info["Subject"]
  96. message=self.info["Message"]
  97. msg="To: "+to+"\nSubject: "+subject+"\n"+message
  98. s.sendmail(self.user,to,msg)
  99. s.quit()
  100.  
  101. pymailer()
  102. window.MainLoop()
Oh ofcourse! Just a few days ago, I was working on a program, where I used GetValue() IN the function...don't know why it didn't strike to me!

Anyways thanks...
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 231
Reputation: sravan953 has a little shameless behaviour in the past 
Solved Threads: 28
sravan953's Avatar
sravan953 sravan953 is offline Offline
Posting Whiz in Training
 
0
  #32
Oct 7th, 2009
Another problem, I logged in successfully and I wanted to send the email to myself, but it showed this error:
Traceback (most recent call last):
File "C:\Documents and Settings\sravan953\My Documents\Sravan\PYTHON\Py-mailer_GUI.py", line 92, in Send
self.s.sendmail(self.user,self.to,self.msg)
File "C:\Python26\lib\smtplib.py", line 709, in sendmail
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {u'': (555, '5.5.2 Syntax error. 21sm1238224pxi.7')}
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 23
Reputation: winmic is an unknown quantity at this point 
Solved Threads: 1
winmic winmic is offline Offline
Newbie Poster
 
0
  #33
Oct 7th, 2009
Are you sure you filled in the To: field right? I've been able to send to myself and the only way I got a similar message was to not fill in the To: field.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 231
Reputation: sravan953 has a little shameless behaviour in the past 
Solved Threads: 28
sravan953's Avatar
sravan953 sravan953 is offline Offline
Posting Whiz in Training
 
0
  #34
Oct 7th, 2009
Yes, I entered my own email ID (sravan953@gmail.com) and I tried, but it didn't work, is there anything wrong?
  1. import smtplib
  2. import time
  3. import os
  4. import wx
  5.  
  6. window=wx.App()
  7.  
  8. class pymailer(wx.Frame):
  9.  
  10. def __init__(self):
  11. wx.Frame.__init__(self,None,-1,"Py-mailer",size=(500,700))
  12.  
  13. self.info={}
  14.  
  15. self.s=smtplib.SMTP("smtp.gmail.com",587)
  16. self.s.starttls()
  17.  
  18. self.panel=wx.Panel(self,-1)
  19.  
  20. menubar=wx.MenuBar()
  21.  
  22. filem=wx.Menu()
  23. filem.Append(201,"Quit")
  24. self.Bind(wx.EVT_MENU,self.Quit,id=201)
  25.  
  26. viewm=wx.Menu()
  27. viewm.Append(202,"About")
  28. self.Bind(wx.EVT_MENU,self.About,id=202)
  29.  
  30. menubar.Append(filem,"File")
  31. menubar.Append(viewm,"Help")
  32.  
  33. self.SetMenuBar(menubar)
  34.  
  35. wx.StaticText(self.panel,-1,"Welcome to Py-mailer.\nLogin with your Gmail credentials and you can send a text-only email to anyone quickly and easily.",pos=(10,10))
  36. wx.StaticText(self.panel,-1,"Please enter your Gmail login ID: ",pos=(10,100))
  37. wx.StaticText(self.panel,-1,"Please enter your Gmail login password:\n(will not be stored)",pos=(10,130))
  38.  
  39. self.username=wx.TextCtrl(self.panel,101,"Login ID",pos=(220,100))
  40. self.password=wx.TextCtrl(self.panel,102,"Password",style=(wx.TE_PASSWORD),pos=(220,130))
  41.  
  42. login=wx.Button(self.panel,103,label="Login",pos=(10,170))
  43. self.Bind(wx.EVT_BUTTON,self.Login,id=103)
  44.  
  45. wx.StaticText(self.panel,-1,"To:",pos=(10,250))
  46. wx.StaticText(self.panel,-1,"Subject:",pos=(10,280))
  47. wx.StaticText(self.panel,-1,"Message:",pos=(10,310))
  48.  
  49. to_info=wx.TextCtrl(self.panel,104,pos=(80,250),size=(240,20))
  50. self.info["To"]=to_info.GetValue()
  51.  
  52. sbj_info=wx.TextCtrl(self.panel,105,pos=(80,280),size=(240,20))
  53. self.info["Subject"]=sbj_info.GetValue()
  54.  
  55. msg_info=wx.TextCtrl(self.panel,106,pos=(80,310),size=(240,150))
  56. self.info["Message"]=msg_info.GetValue()
  57.  
  58. send=wx.Button(self.panel,107,"Send",pos=(245,470))
  59. self.Bind(wx.EVT_BUTTON,self.Send,id=107)
  60.  
  61. self.Centre()
  62. self.Show()
  63.  
  64. def Quit(self,event):
  65. self.Close()
  66.  
  67. def About(self,event):
  68. about=wx.AboutDialogInfo()
  69.  
  70. about.SetName("Py-Mailer")
  71. about.SetCopyright("(c) 2009 Sravan")
  72. about.SetWebSite("http://www.uberpix.wordpress.com")
  73. about.AddDeveloper("Sravan")
  74. about.AddDeveloper("Dan")
  75.  
  76. wx.AboutBox(about)
  77.  
  78. def Login(self,event):
  79. self.user=self.username.GetValue()
  80. self.passw=self.password.GetValue()
  81. try:
  82. self.s.login(self.user,self.passw)
  83. wx.StaticText(self.panel,-1,"Logged in...",pos=(10,200))
  84. except:
  85. wx.StaticText(self.panel,-1,"Failed",pos=(10,200))
  86.  
  87. def Send(self,event):
  88. self.to=self.info["To"]
  89. self.subject=self.info["Subject"]
  90. self.message=self.info["Message"]
  91. self.msg="To: "+self.to+"\nSubject: "+self.subject+"\n"+self.message
  92. self.s.sendmail(self.user,self.to,self.msg)
  93. self.s.quit()
  94.  
  95. pymailer()
  96. window.MainLoop()
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 231
Reputation: sravan953 has a little shameless behaviour in the past 
Solved Threads: 28
sravan953's Avatar
sravan953 sravan953 is offline Offline
Posting Whiz in Training
 
0
  #35
Oct 7th, 2009
I scrutinized the error and found out it mentioned a 'syntax error'?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 163
Reputation: snippsat is an unknown quantity at this point 
Solved Threads: 49
snippsat snippsat is online now Online
Junior Poster
 
0
  #36
Oct 7th, 2009
Put this in and try again.
  1. s=smtplib.SMTP("smtp.gmail.com",587)
  2. s.ehlo()
  3. s.starttls()
  4. s.ehlo()
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 231
Reputation: sravan953 has a little shameless behaviour in the past 
Solved Threads: 28
sravan953's Avatar
sravan953 sravan953 is offline Offline
Posting Whiz in Training
 
0
  #37
Oct 7th, 2009
Same thing, shows the error
Last edited by sravan953; Oct 7th, 2009 at 11:39 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 23
Reputation: winmic is an unknown quantity at this point 
Solved Threads: 1
winmic winmic is offline Offline
Newbie Poster
 
1
  #38
Oct 7th, 2009
The GetValues() for the fields to, subject and message are still in __init__ not in the Send function
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 231
Reputation: sravan953 has a little shameless behaviour in the past 
Solved Threads: 28
sravan953's Avatar
sravan953 sravan953 is offline Offline
Posting Whiz in Training
 
0
  #39
Oct 7th, 2009
OH! So stupid of me! I fixed that winmic!
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 231
Reputation: sravan953 has a little shameless behaviour in the past 
Solved Threads: 28
sravan953's Avatar
sravan953 sravan953 is offline Offline
Posting Whiz in Training
 
0
  #40
Oct 7th, 2009
FINALLY! It works! Thanks a lot you guys! Couldn't have done it without you!
Reply With Quote Quick reply to this message  
Reply

Tags
event, leftmouse, python, wxpython

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC