943,879 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 6455
  • Python RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Sep 23rd, 2009
0

Re: wxPython Events help

This is the code that I have working, not exactly sure why self.panel wouldn't work for you.

Python Syntax (Toggle Plain Text)
  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()
Reputation Points: 26
Solved Threads: 8
Light Poster
winmic is offline Offline
33 posts
since Jun 2009
Sep 23rd, 2009
0

Re: wxPython Events help

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.
Reputation Points: 2
Solved Threads: 30
Posting Whiz in Training
sravan953 is offline Offline
242 posts
since May 2009
Sep 23rd, 2009
0

Re: wxPython Events help

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
Reputation Points: 26
Solved Threads: 8
Light Poster
winmic is offline Offline
33 posts
since Jun 2009
Sep 23rd, 2009
1

Re: wxPython Events help

Click to Expand / Collapse  Quote originally posted by winmic ...
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
Reputation Points: 264
Solved Threads: 183
Veteran Poster
Paul Thompson is offline Offline
1,095 posts
since May 2008
Sep 27th, 2009
0

Re: wxPython Events help

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:
python Syntax (Toggle Plain Text)
  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
Reputation Points: 2
Solved Threads: 30
Posting Whiz in Training
sravan953 is offline Offline
242 posts
since May 2009
Sep 27th, 2009
0

Re: wxPython Events help

Click to Expand / Collapse  Quote originally posted by sravan953 ...
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:
python Syntax (Toggle Plain Text)
  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.
Reputation Points: 625
Solved Threads: 211
Posting Virtuoso
Ene Uran is offline Offline
1,704 posts
since Aug 2005
Sep 27th, 2009
0

Re: wxPython Events help

Click to Expand / Collapse  Quote originally posted by Ene Uran ...
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:

'python Syntax (Toggle Plain Text)
  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.
Reputation Points: 2
Solved Threads: 30
Posting Whiz in Training
sravan953 is offline Offline
242 posts
since May 2009
Sep 27th, 2009
0

Re: wxPython Events help

Also, if I use [icode]self.panel[icode] throughout, it says:
Quote ...
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
python Syntax (Toggle Plain Text)
  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()
Reputation Points: 2
Solved Threads: 30
Posting Whiz in Training
sravan953 is offline Offline
242 posts
since May 2009
Sep 27th, 2009
0

Re: wxPython Events help

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.
Reputation Points: 625
Solved Threads: 211
Posting Virtuoso
Ene Uran is offline Offline
1,704 posts
since Aug 2005
Oct 4th, 2009
0

Re: wxPython Events help

Till now:
python Syntax (Toggle Plain Text)
  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?
Reputation Points: 2
Solved Threads: 30
Posting Whiz in Training
sravan953 is offline Offline
242 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: saving variables to a file in python
Next Thread in Python Forum Timeline: My program (major flaws in it)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC