1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-29 04:22:16 -05:00
Simba/Projects/MMLLib/pymml/mml.py

73 lines
1.7 KiB
Python
Raw Normal View History

2010-03-30 18:24:16 -04:00
#!/usr/bin/env python
from ctypes import *
from mmlmouse import Mouse
2010-05-31 19:59:48 -04:00
from mmlcolor import Color
2010-04-02 05:36:47 -04:00
from time import sleep
2010-03-30 18:24:16 -04:00
class MMLCoreException(Exception):
def __init__(self, err):
Exception.__init__(self, err)
class MMLCore(object):
2010-04-14 18:13:31 -04:00
'''
The MMLCore object is to be opened only once per Python instance.
It opens the libmml library, and calls init().
'''
2010-03-30 18:24:16 -04:00
def __init__(self, dllpath):
self.dll = CDLL(dllpath)
self.dll.init.restype = c_int
self.dll.init.argtypes = None
self.dll.create_client.restype = c_ulong
self.dll.create_client.argtypes = None
2010-03-30 18:24:16 -04:00
if self.dll.init() != 0:
del self.dll
raise MMLCoreException("Could not initialize the DLL")
def __del__(self):
del self.dll
2010-06-27 18:20:35 -04:00
if __name__ == '__main__':
DLL = MMLCore('../libmml.so')
client = DLL.dll.create_client()
print 'Python Client: %d' % client
if client in (0, 1):
raise Exception('Could create a client');
c = Color(DLL, client)
2010-06-27 18:20:35 -04:00
ret = c.find((0, 0, 100, 100), 0)
print ret
2010-06-27 18:20:35 -04:00
ret = c.findAll((0, 0, 100, 100), 0)
print ret
raise Exception('WAT')
2010-06-27 18:20:35 -04:00
m = Mouse(DLL, client)
2010-06-27 18:20:35 -04:00
2010-06-27 18:20:35 -04:00
print m[(Mouse.Pos, Mouse.Left, Mouse.Right)]
m[(Mouse.Pos, Mouse.Right)] = ((300,300), True)
2010-06-27 18:20:35 -04:00
print m.getButtonStates()
sleep(0.5)
m.setPos((200,200))
2010-06-27 18:20:35 -04:00
sleep(2)
print 'Done'
#
# # Reset all buttons..
2010-06-27 18:20:35 -04:00
m[(Mouse.Left, Mouse.Right, Mouse.Middle)] = [False for x in range(3)]
for v in zip((Mouse.Left, Mouse.Right), m[(Mouse.Left, Mouse.Right)]):
print v
print m.getPos()
# if hasattr(ret,'__iter__'):
# m.setPos(ret)
2010-06-27 18:20:35 -04:00
del DLL