Deciphering
Glyph
( )
PyGTK/win32 hack

Sat 20 December 2003

The following script will allow you to initialize PyGTK on windows the proper way, assuming you're using the PyGTK/win32 installer and the Dropline GTK/win32 installer.




from _winreg import *
from os import environ

def getGtkPath():
subkey = 'Software/GTK/2.0/'.replace('/','\\')
path = None
for hkey in HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER:
reg = OpenKey(HKEY_LOCAL_MACHINE, subkey)
try:
try:
path, value = QueryValueEx(reg, "DllPath")
except WindowsError:
pass
else:
return path
finally:
CloseKey(reg)

def gtkify():
path = getGtkPath()
environ['PATH'] += ';'+path.encode('utf8')
if path is None:
raise ImportError("Couldn't find GTK DLLs.")

if __name__ == '__main__':
gtkify()
import gtk
w = gtk.Window()
w.set_title("Hello Win32!")
w.set_size_request(300,300)
b = gtk.Button("Goodbye, Win32.")
w.add(b)
w.show_all()
b.connect('clicked', gtk.mainquit)
gtk.mainloop()