wxPython Events help

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

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

Re: wxPython Events help

 
0
  #11
Sep 23rd, 2009
This is the code that I have working, not exactly sure why self.panel wouldn't work for you.

  1. import smtplib
  2. import time
  3. import os
  4. import wx
  5.  
  6. window=wx.App()
  7.  
  8. class pymailer(wx.Frame):
  9. def __init__(self):
  10. wx.Frame.__init__(self,None,-1,"Pymailer",size=(500,500))
  11.  
  12. self.panel=wx.Panel(self,-1)
  13.  
  14. menubar=wx.MenuBar()
  15.  
  16. filem=wx.Menu()
  17. filem.Append(201,"Quit")
  18. self.Bind(wx.EVT_MENU,self.Quit)
  19.  
  20. viewm=wx.Menu()
  21. viewm.Append(202,"About")
  22. self.Bind(wx.EVT_MENU,self.About)
  23.  
  24. menubar.Append(filem,"File")
  25. menubar.Append(viewm,"Help")
  26.  
  27. self.SetMenuBar(menubar)
  28.  
  29. 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))
  30. wx.StaticText(self.panel,-1,"Please enter your Gmail login ID: ",pos=(10,100))
  31. wx.StaticText(self.panel,-1,"Please enter your Gmail login password:\n(will not be stored)",pos=(10,130))
  32.  
  33. username=wx.TextCtrl(self.panel,101,"Login ID",pos=(220,100))
  34. password=wx.TextCtrl(self.panel,102,"Password",pos=(220,130))
  35.  
  36. login=wx.Button(self.panel,103,label="Login",pos=(10,170))
  37. self.Bind(wx.EVT_BUTTON,self.Login)
  38.  
  39. self.Centre()
  40. self.Show()
  41.  
  42. def Quit(self,event):
  43. self.Close()
  44.  
  45. def Login(self,event):
  46. s=smtplib.SMTP("smtp.gmail.com",587)
  47. s.starttls()
  48. try:
  49. wx.StaticText(self.panel,-1,"Logging in...",pos=(10,200))
  50. s.login(user,passw)
  51. except:
  52. wx.StaticText(self.panel,-1,"Failed",pos=(10,220))
  53.  
  54. def About(self,event):
  55. about=wx.AboutDialogInfo()
  56.  
  57. about.SetName("Py-Mailer")
  58. about.SetCopyright("(c) 2009 Sravan")
  59. about.SetWebSite("http://www.uberpix.wordpress.com")
  60. about.AddDeveloper("Sravan\nDan")
  61.  
  62. wx.AboutBox(about)
  63.  
  64. pymailer()
  65. window.MainLoop()
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 232
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

Re: wxPython Events help

 
0
  #12
Sep 23rd, 2009
Hmm...I too don't know why self.panel isn't working. I will get back to you about that.

Now, what should I do to make a button(called 'Next>'), which on being clicked will 'refresh' the screen and display some new contents? I hope you understand me!
Last edited by sravan953; Sep 23rd, 2009 at 10:40 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

Re: wxPython Events help

 
0
  #13
Sep 23rd, 2009
So I forgot something with events, you can make them respond to a certain id. If you have tried to File->Quit recently you'll see that it will make the about:dialog appear. If you have objects that propagate the same event then you'll want them id specific. so self.Bind(wx.EVT_MENU,self.Quit) becomes self.Bind(wx.EVT_MENU,self.Quit, id=201). The same thing will need to be done for the about menu event, and if you add another button the button event will need to be id specific.

How to add new content really depends on specifically what you want to do. I'm guessing that you want to have completely new content where all old content is destroyed, then you would probably want to create a new wx.Panel and content. I could help a little more if you were a little more specific.

BTW, have you thought about how your going to get the username and password out of the TextCtrl?
Last edited by winmic; Sep 23rd, 2009 at 2:08 pm. Reason: new question
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 944
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 146
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: wxPython Events help

 
1
  #14
Sep 23rd, 2009
Originally Posted by winmic View Post
BTW, have you thought about how your going to get the username and password out of the TextCtrl?
It shouldn't be to hard, have a look at the API for the wx.TextCTRL
http://www.wxpython.org/docs/api/wx.TextCtrl-class.html
One of the functon is GetValue() that returns a string of the value in the textctrl, simple
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 232
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

Re: wxPython Events help

 
0
  #15
Sep 27th, 2009
I don't think getting the values will be a problem, because I've heard of GetValues() and Google it for help.

The problem is: the self.panel doesn't at all work...

One more question:
  1. viewm=wx.Menu()
  2. viewm.Append(202,"About") self.Bind(wx.EVT_MENU,self.About,id=302)
  3.  
  4. def About(self,event,id=302):
  5. about=wx.AboutDialogInfo()
-but it doesn't work. How do I specify the ID when defining the function?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: wxPython Events help

 
0
  #16
Sep 27th, 2009
Originally Posted by sravan953 View Post
I don't think getting the values will be a problem, because I've heard of GetValues() and Google it for help.

The problem is: the self.panel doesn't at all work...

One more question:
  1. viewm=wx.Menu()
  2. viewm.Append(202,"About") self.Bind(wx.EVT_MENU,self.About,id=302)
  3.  
  4. def About(self,event,id=302):
  5. about=wx.AboutDialogInfo()
-but it doesn't work. How do I specify the ID when defining the function?

Thanks
You don't need the id as a method parameter, but at least try to match the id in the lines above, 202 is not the same as 302.

self.panel will work if you use it throughout the class! Search for 'panel' with your editor.
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 232
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

Re: wxPython Events help

 
0
  #17
Sep 27th, 2009
Originally Posted by Ene Uran View Post
You don't need the id as a method parameter, but at least try to match the id in the lines above, 202 is not the same as 302.

self.panel will work if you use it throughout the class! Search for 'panel' with your editor.
I did what you told:

  1. viewm=wx.Menu()
  2. viewm.Append(202,"About") self.Bind(wx.EVT_MENU,self.About,id=202)
  3.  
  4. def About(self,event):
  5. about=wx.AboutDialogInfo()

But, only "Quit" works, and "About" doesn't.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 232
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

Re: wxPython Events help

 
0
  #18
Sep 27th, 2009
Also, if I use [icode]self.panel[icode] throughout, it says:
Traceback (most recent call last):
File "C:\Documents and Settings\Sravan\My Documents\Sravan\PYTHON\GUI.py", line 72, in <module>
pymailer()
File "C:\Documents and Settings\Sravan\My Documents\Sravan\PYTHON\GUI.py", line 29, in __init__
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))
AttributeError: 'pymailer' object has no attribute 'panel'
Here's the modified code including [icode]self.panel[icode]everywhere
  1. import smtplib
  2. import time
  3. import os
  4. import wx
  5.  
  6. window=wx.App()
  7.  
  8. class pymailer(wx.Frame):
  9. def __init__(self):
  10. wx.Frame.__init__(self,None,-1,"Py-mailer",size=(500,500))
  11.  
  12. panel=wx.Panel(self,-1)
  13.  
  14. menubar=wx.MenuBar()
  15.  
  16. filem=wx.Menu()
  17. filem.Append(201,"Quit")
  18. self.Bind(wx.EVT_MENU,self.Quit,id=201)
  19.  
  20. viewm=wx.Menu()
  21. viewm.Append(202,"About")
  22. self.Bind(wx.EVT_MENU,self.About,id=202)
  23.  
  24. menubar.Append(filem,"File")
  25. menubar.Append(viewm,"Help")
  26.  
  27. self.SetMenuBar(menubar)
  28.  
  29. 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))
  30. wx.StaticText(self.panel,-1,"Please enter your Gmail login ID: ",pos=(10,100))
  31. wx.StaticText(self.panel,-1,"Please enter your Gmail login password:\n(will not be stored)",pos=(10,130))
  32.  
  33. username=wx.TextCtrl(self.panel,101,"Login ID",pos=(220,100))
  34. password=wx.TextCtrl(self.panel,102,"Password",pos=(220,130))
  35.  
  36. login=wx.Button(self.panel,103,label="Login",pos=(10,170))
  37. self.Bind(wx.EVT_BUTTON,self.Login,id=103)
  38.  
  39. wx.StaticText(self.panel,-1,"To:",pos=(10,220))
  40. wx.StaticText(self.panel,-1,"Subject:",pos=(10,250))
  41. wx.StaticText(self.panel,-1,"Message:",pos=(10,280))
  42.  
  43. to=wx.TextCtrl(self.panel,103,"<username@domain.server>",pos=(80,220),size=(240,20))
  44. subject=wx.TextCtrl(self.panel,104,pos=(80,250),size=(240,20))
  45. message=wx.TextCtrl(self.panel,105,pos=(80,280),size=(240,150))
  46.  
  47. self.Centre()
  48. self.Show()
  49.  
  50. def Quit(self,event):
  51. self.Close()
  52.  
  53. def About(self,event):
  54. about=wx.AboutDialogInfo()
  55.  
  56. def Login(self,event,):
  57. wx.StaticText(panel,-1,"Logging in...",pos=(10,200))
  58. s=smtplib.SMTP("smtp.gmail.com",587)
  59. s.starttls()
  60. try:
  61. s.login(user,passw)
  62. except:
  63. wx.StaticText(self.panel,-1,"Failed",pos=(10,200))
  64.  
  65. about.SetName("Py-Mailer")
  66. about.SetCopyright("(c) 2009 Sravan")
  67. about.SetWebSite("http://www.uberpix.wordpress.com")
  68. about.AddDeveloper("Sravan\nDan")
  69.  
  70. wx.AboutBox(about)
  71.  
  72. pymailer()
  73. window.MainLoop()
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: wxPython Events help

 
0
  #19
Sep 27th, 2009
self.panel everywhere except the most important line 12

panel=wx.Panel(self,-1)
needs to be
self.panel=wx.Panel(self,-1)
Last edited by Ene Uran; Sep 27th, 2009 at 1:24 pm.
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 232
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

Re: wxPython Events help

 
0
  #20
Oct 4th, 2009
Till now:
  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. def __init__(self):
  13. wx.Frame.__init__(self,None,-1,"Py-mailer",size=(500,700))
  14.  
  15. self.panel=wx.Panel(self,-1)
  16.  
  17. menubar=wx.MenuBar()
  18.  
  19. filem=wx.Menu()
  20. filem.Append(201,"Quit")
  21. self.Bind(wx.EVT_MENU,self.Quit,id=201)
  22.  
  23. viewm=wx.Menu()
  24. viewm.Append(202,"About")
  25. self.Bind(wx.EVT_MENU,self.About,id=202)
  26.  
  27. menubar.Append(filem,"File")
  28. menubar.Append(viewm,"Help")
  29.  
  30. self.SetMenuBar(menubar)
  31.  
  32. 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))
  33. wx.StaticText(self.panel,-1,"Please enter your Gmail login ID: ",pos=(10,100))
  34. wx.StaticText(self.panel,-1,"Please enter your Gmail login password:\n(will not be stored)",pos=(10,130))
  35.  
  36. username=wx.TextCtrl(self.panel,101,"Login ID",pos=(220,100))
  37. user=username.GetValue()
  38. password=wx.TextCtrl(self.panel,102,"Password",pos=(220,130))
  39. passw=password.GetValue()
  40.  
  41. login=wx.Button(self.panel,103,label="Login",pos=(10,170))
  42. self.Bind(wx.EVT_BUTTON,self.Login,id=103)
  43.  
  44. wx.StaticText(self.panel,-1,"To:",pos=(10,250))
  45. wx.StaticText(self.panel,-1,"Subject:",pos=(10,280))
  46. wx.StaticText(self.panel,-1,"Message:",pos=(10,310))
  47.  
  48. toadd=wx.TextCtrl(self.panel,104,"<username@domain.server>",pos=(80,250),size=(240,20))
  49. to=toadd.GetValue()
  50. subj=wx.TextCtrl(self.panel,105,pos=(80,280),size=(240,20))
  51. subject=subj.GetValue()
  52. mess=wx.TextCtrl(self.panel,106,pos=(80,310),size=(240,150))
  53. message=mess.GetValue()
  54.  
  55. send=wx.Button(self.panel,107,"Send",pos=(245,470))
  56. self.Bind(wx.EVT_BUTTON,self.Send,id=107)
  57.  
  58. self.Centre()
  59. self.Show()
  60.  
  61. def Quit(self,event):
  62. self.Close()
  63.  
  64. def About(self,event):
  65. about=wx.AboutDialogInfo()
  66.  
  67. about.SetName("Py-Mailer")
  68. about.SetCopyright("(c) 2009 Sravan")
  69. about.SetWebSite("http://www.uberpix.wordpress.com")
  70. about.AddDeveloper("Sravan\nDan")
  71.  
  72. wx.AboutBox(about)
  73.  
  74. def Login(self,event):
  75. try:
  76. s.login(user,passw)
  77. wx.StaticText(self.panel,-1,"Logged in",pos=(10,200))
  78. except:
  79. wx.StaticText(self.panel,-1,"Failed",pos=(10,200))
  80.  
  81. def Send(self,event):
  82. msg="To: "+to+"\nSubject: "+subject+"\n"+message
  83. s.sendmail(us,to,msg)
  84. s.quit()
  85.  
  86. pymailer()
  87. window.MainLoop()

No matter what I enter, it doesn't login and says "Failed". Why?
Also, how do I mask the password input?
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



Tag cloud for event, leftmouse, python, wxpython
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC