Glyph Lefkowitz ([info]glyf) wrote,
  • Mood: apathetic

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()



  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    Your reply will be screened

    Your IP address will be recorded 

  • 2 comments

[info]moshez

December 20 2003, 23:31:03 UTC 8 years ago

You should check if path is None before encoding it.
Please edit :)

[info]jdahlin

January 26 2004, 03:39:49 UTC 8 years ago

Coolio

Maybe this could be incorporated upstream, as a partly maintainer I'm all in favor for this.

Perhaps even by the pygtk script so everything that's necessary, for both unix and win32 would be:

import pygtk
pygtk.require('2.0')
import gtk

glyph, care to submit this to bugzilla.gnome.org ?
Create an Account
Forgot your login or password?
Facebook Twitter More login options
English • Español • Deutsch • Русский…