Improved Python3 compatibility

Many small changes to improve Python 3 compatibility. Better string
formatting, more rigorous use of unicode, handling 'bytes' objects
(returned by some Qt functions) better, getting Qt to do more conversion
of QVariant objects and so on.