I have finally succeeded in using Python to make test applications. I find the idea pretty interesting to build quick-and-dirty applications to test a specific api. Here is how it can be done.
Get from www.python.org : Python 2.1.1 for windows http://www.python.org/ftp/python/2.1.1/
Get from ftp://ftp.nightmare.com/pub/python/python-ext/
npstruct-2001-05-20.zip calldll-2001-05-20.zip dynwin-2001-05-20.zip
Install python under Wine : ./wine -managed <path to python installer>Python-2.1.1.exe
unzip the 3 additional packages under the Python directory (c:\program files\python21)
add these 3 directories to the Python path. The easier way is to create a dir.pth file in the main Python directory containing :
c:\Program Files\Python21\calldll c:\Program Files\Python21\npstruct c:\Program Files\Python21\dynwin
add the path to the main python directory to the Wine path.
launch python (the command line version, I did not try the gui version) :
wine python
Here are some commands I tried (I edited out most of the Wine Fixme and Err, and removed prompts) :
import windll
(.... 1. Basic example)
user32=windll.module("user32") cstr=windll.cstring MessageBox=user32.MessageBox MessageBox(0,cstr('test'),cstr('example'),0) 1
(1 is the value returned by MessageBox - success)
(.... 2. more involved example, using buffers)
winmm=windll.module('winmm') winmm.mciSendString(cstr('play c:\sound\welcome.wav'),0,0,0) 279
(error 279)
buf=windll.membuf(256) winmm.mciGetErrorString(279,buf,255) 1 import calldll print calldll.read_string(buf) Cannot use 'all' as the device name with the specified command.
(I fix line 516 of mci.c to return a correct error message and compile Wine, try again)
i = winmm.mciSendString(cstr('play c:\sound\welcome.wav'),0,0,0) fixme:mci:MCI_LoadMciDriver Couldn't load driver for type WAVEAUDIO. If you don't have a windows installation accessible from Wine, you perhaps forgot to create a [mci] section in system.ini
print i 306
(I had indeed commented out the waveaudio entry in my system.ini -> fix user error and try again)
winmm.mciSendString(cstr('play c:\sound\welcome.wav'),0,0,0) 0
(well, the mci call returns 0 - success - the sound is not played completely - but that's another story :-//)
(.... 3. complete example of testing a gui function : TextOut)
import windll cstr = windll.cstring
gdi32 = windll.module ('gdi32')
import wingdi import windc import winwin
class test(winwin.python_window):
style = winwin.WS_OVERLAPPEDWINDOW
def WM_DESTROY (self, wparam, lparam): winwin.user32.PostQuitMessage (0)
def WM_PAINT (self, wparam, lparam): dc = self.begin_paint() gdi32.TextOut(dc.handle,50,50,cstr("text output"),11) self.end_paint()
if __name__ == '__main__': import msgloop w = test("test 1").create() w.show_window() msgloop.go()
(in this example most of the code use calls to higher level functions hiding somewhat the Win32 Api, except the api call, that uses the 'handle' member of the dc object to access the Win32 object)
There is a Python error message when the gui app terminates, however this is a problem with the python system (it shows the same under WinNT, for example)
Note : don't begin command by spaces - Python interpreter don't like it. Also, Python don't care for case but Wine does, so writing 'mcisendstring' will fail, for example.