2010-03-31 00:24:16 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from ctypes import *
|
2010-12-01 21:38:20 +01:00
|
|
|
from mouse import Mouse
|
|
|
|
from color import Color
|
2010-04-02 11:36:47 +02:00
|
|
|
from time import sleep
|
2010-12-01 21:38:20 +01:00
|
|
|
from mtypes import PINTEGER
|
2010-03-31 00:24:16 +02:00
|
|
|
|
|
|
|
class MMLCoreException(Exception):
|
|
|
|
def __init__(self, err):
|
|
|
|
Exception.__init__(self, err)
|
|
|
|
|
|
|
|
class MMLCore(object):
|
2010-04-15 00:13:31 +02:00
|
|
|
'''
|
|
|
|
The MMLCore object is to be opened only once per Python instance.
|
|
|
|
It opens the libmml library, and calls init().
|
|
|
|
'''
|
2010-03-31 00:24:16 +02:00
|
|
|
def __init__(self, dllpath):
|
|
|
|
self.dll = CDLL(dllpath)
|
|
|
|
|
|
|
|
self.dll.init.restype = c_int
|
|
|
|
self.dll.init.argtypes = None
|
2010-09-05 20:43:45 +02:00
|
|
|
self.dll.create_client.restype = c_ulong
|
|
|
|
self.dll.create_client.argtypes = None
|
2010-09-12 14:28:19 +02:00
|
|
|
|
|
|
|
self.dll.get_last_error.restype = c_char_p
|
|
|
|
self.dll.get_last_error.argtypes = None
|
|
|
|
|
2010-09-12 15:01:42 +02:00
|
|
|
self.dll.free_ptr.restype = c_bool
|
|
|
|
self.dll.free_ptr.argtypes = [c_void_p]
|
|
|
|
|
2010-03-31 00:24:16 +02:00
|
|
|
if self.dll.init() != 0:
|
|
|
|
del self.dll
|
|
|
|
raise MMLCoreException("Could not initialize the DLL")
|
|
|
|
|
2010-09-12 14:28:19 +02:00
|
|
|
def get_last_error(self):
|
|
|
|
t = self.dll.get_last_error()
|
|
|
|
s = str(t)
|
|
|
|
del t
|
|
|
|
return s
|
|
|
|
|
2010-09-12 15:01:42 +02:00
|
|
|
def free(self, ptr):
|
|
|
|
_ptr = cast(ptr, c_void_p)
|
|
|
|
self.dll.free_ptr(_ptr)
|
|
|
|
|
2010-03-31 00:24:16 +02:00
|
|
|
def __del__(self):
|
|
|
|
del self.dll
|
|
|
|
|