Mike Driscoll wrote:
Hi,
I finally got done putting together a tutorial using a real live
wxPython application. It is (unfortunately) a Windows-only application
that one can use for sending (but not receiving) emails. It was created
to catch the “mailto” event from internet browsers and redirect that
data to my script. I won’t be too surprised if you find a bug here and
there since I only tested it on XP. You may also need to tell your
firewall(s) to let it send your emails.
I have posted it to my blog here:
The tutorial is a little code heavy, but I think I explain the most
important bits. I am hoping for some constructive comments for making
the code and/or the tutorial better. I could have went into depth on a
lot of what’s in there, but it ended up being so long that I thought it
was a little overwhelming as it was.
Hi Mike,
I happened to look over your class EditDialog. I noticed that the
onDelete method is longer than necessary. Mutable sequences types in
Python have a handy function remove() that correctly removes an object
from the sequence, eliminating the need for the loop at the end of the
function that you have now. So your onDelete method could be as simple
and concise as this (I left out the print statements):
def onDelete(self,_event):
for item in range(len(self.filepaths)):
if self.chkList.IsChecked(item):
self.filepaths.remove(self.chkList.GetString(item))
self.Close()
There is no need to check whether a particular string is in the
filepath list; since you previously built the chkList object from
filepaths.
Also you might want to look into a possible alias issue. You pass the
variable self.filepaths from the parent class (SendMailWx) into the
EditDialog class constructor. There you bind this object to a variable
in EditDialog, also named filepaths. You now have two variables but
only one object. When you delete items in onDelete you are actually
removing them from the original SendMailWx.filepaths, although it
doesn’t look like it. In the onAttachEdit function, you have these
lines:
dialog.ShowModal()
self.filepaths = dialog.filepaths
The second line is actually a no-op, since self.filepaths and
dialog.filepaths are the same object. This program will work, so
that’s not a problem. It’s a matter of style. But I try to avoid
this type of situation, since I just know that I will go to modify the
program in six months and I will screw it up.
Paul Cornelius
···
http://www.blog.pythonlibrary.org/?p=38
http://blog.pythonlibrary.org
http://www.pythonlibrary.org
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users