PyQt Designer Video Tutorial
While working on an application I'm writing using PyQt, I was surprised by the lack of up-to-date PyQt tutorials showing a real project being created from start to finish.
So I decided to document my journey, hoping to get some feedback on what I am doing and showing other people how to do things at the same time.
Most of this tutorial isn't close to being finished, but I did already record 2 screen casts to show you how I designed the following screen using Qt Designer.
It covers resources, actions, layouts, tool bars, several controls & tab order. The icons come from the fantastic FatCow icon set.
update: : I moved the videos from Vimeo to youtube, but it's still not that great. Any suggestions on this are welcome!
The video tutorial consists of 2 parts:
The screen casts were recorder using CamStudio, edited with Windows Live Movie Maker and hosted by Youtube.
Python smtplib progress indication
A few days ago I was in wanted to send an email with attachments through Python's smtplib, when I realised there was no way of keeping track of the sending progress.
After some analysis of smtplib, I finally made the choice to subclass and extend the smtplib.SMTP class.
It feels like a big dirty hack and I just wanted to throw it out there to see if anyone knows of a better way to accomplish this.
from smtplib import SMTP, quotedata, CRLF, SMTPDataError
from sys import stderr
class ExtendedSMTP(SMTP):
def data(self,msg):
"""
This is a modified copy of smtplib.SMTP.data()
Sending data in chunks and calling self.callback
to keep track of progress,
"""
self.putcmd("data")
(code,repl)=self.getreply()
if self.debuglevel >0 : print>>stderr, "data:", (code,repl)
if code != 354:
raise SMTPDataError(code,repl)
else:
q = quotedata(msg)
if q[-2:] != CRLF:
q = q + CRLF
q = q + "." + CRLF
# begin modified send code
chunk_size = 2048
bytes_sent = 0
while bytes_sent != len(q):
chunk = q[bytes_sent:bytes_sent+chunk_size]
self.send(chunk)
bytes_sent += len(chunk)
if hasattr(self, "callback"):
self.callback(bytes_sent, len(q)):
# end modified send code
(code,msg)=self.getreply()
if self.debuglevel >0 : print>>stderr, "data:", (code,msg)
return (code,msg)
To use this, we instantiate the class as normal and attach a callback function to it, which will be called by the data() method.
def callback(progress, total):
print "%s bytes sent of %s" % (progress, total)
s = ExtendedSMTP() # instead of smtplib.SMTP()
s.callback = callback
s.sendmail("billg@microsoft.com", "steveb@microsoft.com", msg)
s.quit()
Let me know if there are better ways to do this.
Javascript word clock
I saw this word clock on Gizmodo and loved the idea.
It's a 5-minute interval, using written words, clock with a very nice design.
Because I don't have the cash to purchase a real one I decided to at least copy the idea in Javascript using jQuery.
There's not a lot of clever code to it really, but it works as far as I can see. It's basically one big ugly if/else tree showing the time, written in plain English and a pulsating hearts symbol indicating the seconds passing.
Check it out here.
