Nov
30
2009
xiao
Python has the ability to alter its sys.stdout as to redirect its print commands to pretty much anything.
If, for instance, you want to print to both standard output and to a log file, you can create a class to handle the stdout like such:
class MyOutput():
def __init__(self, logfile):
self.stdout = sys.stdout
self.log = open(logfile, 'w')
def write(self, text):
self.stdout.write(text)
self.log.write(text)
self.log.flush()
def close(self):
self.stdout.close()
self.log.close()
sys.stdout = MyOutput("log.txt")
print "blah blah blah"
Continue reading
no comments | tags: file, log, output, print, Python, screen, stdout | posted in Tips
Nov
14
2009
xiao
There are some 64-bit related issues when using PyQt and Snow Leopard. There’s the way to resolve it by reverting to 32-bits:
- Get the latest versions of PyQt and SIP. You need Qt installed of course.
- Configure SIP using
python configure.py --arch i386
- Configure PyQt using
python configure.py --use-arch=i386
- Finally, make sure your python is running in 32-bit mode because current Qt doesn’t support 64-bit mode. Add
export VERSIONER_PYTHON_PREFER_32_BIT=yes
to your .bash_profile in your home directory
- If your Python still refuses to run in 32 bit mode, try
no comments | tags: 32, 64, i386, Mac, PyQt, Python, Qt, SIP, Snow Leopard | posted in Tips
May
3
2009
xiao
This simple tutorial shows how you can create a program with Python and Qt to allow for image files from Explorer/Finder/Nautilus to be dropped in a list widget and create list items with thumbnails

First we subclass a QListWidget to handle events
Continue reading
3 comments | tags: drag, drag-and-drop, drop, explorer, file, image, picture, PIL, PyQt, Python, QListWidget, Qt, thumbnail | posted in Tips
Mar
31
2009
xiao

Qt Creator
This is a collection of tutorials I found useful to get into the Qt framework. Being more used to the Microsoft standard, I have always wanted to branch into more cross-platform stuff so that I can at least write tools and programs for my Mac. I never really liked the idea of “reinventing the wheels” feel of C++ unless it was on an embedded system so Python looked like a solid contender to the rather messy Perl. Continue reading
1 comment | tags: Framework, GUI, programming, PyQt, Python, Qt, Tutorial | posted in Tips