Re: alternatives to mswgui
Thomas Heller <[email protected]> 14 Nov 2002 16:55:36 +0100
| Newsgroups | gmane.comp.python.anygui.devel |
|---|---|
| Message-ID | <[email protected]> |
Robin Becker <[email protected]> writes: > After trying unsuccessfully to determine the cause of leakage in the > dynwin win32 backend I asked for an assist on comp.lang.python. Thomas > Heller then suggested his alternative to calldll called ctypes. > > After about three hours I made an alternate to dwgui.py/mswgui.py using > his framework and this now also seems to work and more importantly it > doesn't seem to leak. This is called ctmswgui.py. > > It's slighly more messy than dwgui (we have to be explicit about using > the A version or the W version of the win32 API), but there're only two > modules _ctypes.pyd & ctypes.py and Thomas says he'll do the debugging > if we encounter serious problems ;) >>> import this ... Explicit is better than implicit. ... It is, of course, easy to hide the A/W problem away. In fact, the idea I have is *not* to use it in this way: from ctypes import windll, WinError kernel32 = windll.kernel32 handle = user32.GetModuleHandleA(None) # note the 'A' here ^ if handle == 0: raise WinError() # use the handle instead I think one should do it in this way: from ctypes import windll, WinError kernel32 = windll.kernel32 def HANDLE(value): # check if the return value is a valid handle if value == 0: raise WinError() return HANDLE GetModuleHandle = kernel32.GetModuleHandleA GetModuleHandle.restype = HANDLE then you can use GetModuleHandle to your hearts content, and you do not have to check for errors. > > What do others think of the competing msw approaches (if anything). Why not use both for a while amd decide later? > -- > Robin Becker Thomas ------------------------------------------------------- This sf.net email is sponsored by: To learn the basics of securing your web site with SSL, click here to get a FREE TRIAL of a Thawte Server Certificate: http://www.gothawte.com/rd524.html