You are viewing glyf

entries friends calendar profile Scribbles in the Dark Previous Previous Next Next
Please Visit http://glyph.twistedmatrix.com/ - This Blog Is Closed. - PyGTK/win32 hack
Sorry about the ads, I can't turn them off.
glyf
glyf
Add to Memories
Share
PyGTK/win32 hack
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()


Current Mood: apathetic apathetic

Comments
moshez From: moshez Date: December 20th, 2003 11:31 pm (UTC) (Link)
You should check if path is None before encoding it.
Please edit :)
1 comment or Leave a comment
profile
Glyph Lefkowitz
User: glyf
Name: Glyph Lefkowitz
calendar
Back December 2010
1234
567891011
12131415161718
19202122232425
262728293031
page summary
tags