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
Sep
13
2009
xiao

Just got Snow Leopard and installed Boot Camp 3.0 on Windows? Boot Camp 3.0 is definitely a well welcomed update. The trackpad works much better now with 2 finger tap for secondary click, it finally works like in OS X. Even better, you can now access HFS+ without third party apps in Windows. Definitely nice for Windows 7 x64 users that MacDrive doesn’t even support. But one problem that seems to trouble people in the forums is that navigating to /Users/[yourname] in Windows shows an empty folder. You can’t access your music or pictures or anything from Windows.
One possibility is the presence of a .Xauthority file in your $HOME directory. Delete the file and you may access your home directory in Windows. Remember that running X11 will recreate the file. Delete it again. Continue reading
no comments | tags: .Xauthority, access, AppleScript, application, bash, Boot Camp, bootcamp, directory, empty, file, home, Snow Leopard, Windows, X11 | 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