Skip to content

Commit 0e7a21b

Browse files
Cleaner package-structure and better documentation.
1 parent 3c1e4b6 commit 0e7a21b

8 files changed

Lines changed: 396 additions & 591 deletions

File tree

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include COPYING

README

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
==============================================================
2+
python-uinput - Simple Python API to the Linux uinput-system
3+
==============================================================
4+
5+
:date: 2009-12-13
6+
7+
.. contents::
8+
9+
Description
10+
===========
11+
12+
Uinput allows attaching user-space device drivers into the Linux kernel.
13+
Python-uinput provides a simple and easy to use API to the Linux uinput-system.
14+
15+
General information
16+
===================
17+
18+
- **Author**: `Tuomas Räsänen <http://tuos.codegrove.org/>`_ <tuos@codegrove.org>
19+
- **Homepage**: http://codegrove.org/python-uinput/
20+
- **License**: LGPLv3+ (see COPYING for details)
21+
- **Version**: 0.1
22+
23+
Requirements
24+
============
25+
26+
- `libsuinput <http://codegrove.org/libsuinput/>`_
27+
28+
Example usage
29+
=============
30+
31+
To create and use an uinput driver::
32+
33+
import uinput
34+
driver = uinput.Driver()
35+
driver.move_pointer(100, 100)
36+
driver.click(uinput.codes.BTN_LEFT)
37+
38+
Downloading
39+
===========
40+
41+
- Tarball is available at: http://codegrove.org/python-uinput/python-uinput-0.1.tar.gz
42+
- Public git-repository: http://github.com/tuos/python-uinput/ ::
43+
44+
git clone git://github.com/tuos/python-uinput.git
45+
46+
Install
47+
=======
48+
49+
The install-procedure adheres the "standard"::
50+
51+
python setup build && sudo python setup install

setup.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import os
44
from distutils.core import setup, Extension
55

6-
cUinput_module = Extension('cUinput',
7-
sources=['src/lib/cUinput.c'],
8-
libraries=['suinput'],
9-
)
6+
pysuinput_module = Extension('uinput._suinput',
7+
sources=['src/pysuinput.c'],
8+
libraries=['suinput'],
9+
)
10+
11+
codes_module = Extension('uinput.codes',
12+
sources=['src/codes.c'])
1013

1114
setup(name='python-uinput',
1215
version='0.1',
@@ -15,7 +18,9 @@
1518
author='Tuomas Räsänen',
1619
author_email='tuos@codegrove.org',
1720
url='http://codegrove.org/python-uinput/',
18-
package_dir={'': 'src/lib'},
19-
py_modules=['uinput'],
20-
ext_modules=[cUinput_module],
21+
package_dir={'uinput': 'src'},
22+
packages=['uinput'],
23+
ext_modules=[pysuinput_module, codes_module],
24+
license='LGPLv3+',
25+
platforms=['Linux'],
2126
)

src/__init__.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# -*- coding: utf-8 -*-
2+
# uinput - Simple Python API to the Linux uinput-system
3+
# Copyright (C) 2009 Tuomas Räsänen <tuos@codegrove.org>
4+
5+
# This library is free software; you can redistribute it and/or
6+
# modify it under the terms of the GNU Lesser General Public
7+
# License as published by the Free Software Foundation; either
8+
# version 3 of the License, or (at your option) any later version.
9+
10+
# This library is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# Lesser General Public License for more details.
14+
15+
# You should have received a copy of the GNU Lesser General Public
16+
# License along with this library; if not, write to the Free Software
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
19+
"""Simple Python API to the Linux uinput-system
20+
21+
A high-level API to programmatically generate Linux input events.
22+
23+
Example usage:
24+
>>> import uinput
25+
>>> driver = uinput.Driver()
26+
>>> driver.move_pointer(100, 100)
27+
>>> driver.click(uinput.codes.BTN_LEFT)
28+
"""
29+
30+
import _suinput
31+
from _suinput import BUS_PCI
32+
from _suinput import BUS_ISAPNP
33+
from _suinput import BUS_USB
34+
from _suinput import BUS_HIL
35+
from _suinput import BUS_BLUETOOTH
36+
from _suinput import BUS_VIRTUAL
37+
from _suinput import BUS_ISA
38+
from _suinput import BUS_I8042
39+
from _suinput import BUS_XTKBD
40+
from _suinput import BUS_RS232
41+
from _suinput import BUS_GAMEPORT
42+
from _suinput import BUS_PARPORT
43+
from _suinput import BUS_AMIGA
44+
from _suinput import BUS_ADB
45+
from _suinput import BUS_I2C
46+
from _suinput import BUS_HOST
47+
from _suinput import BUS_GSC
48+
from _suinput import BUS_ATARI
49+
50+
import codes
51+
52+
__all__ = [
53+
"Driver",
54+
]
55+
56+
class Driver(object):
57+
58+
"""Device driver for the Linux uinput-system.
59+
60+
For the documentation of the constructor arguments, see the
61+
documentation of the corresponding properties.
62+
"""
63+
64+
def __init__(self, name="python-uinput", bustype=_suinput.BUS_VIRTUAL,
65+
vendor=0, product=0, version=0):
66+
self._input_fd = _suinput.open(name, bustype, vendor, product, version)
67+
self._name = name
68+
self._bustype = bustype
69+
self._vendor = vendor
70+
self._product = product
71+
self._version = version
72+
73+
@property
74+
def name(self):
75+
"Kernel name of the device."
76+
return self._name
77+
78+
@property
79+
def bustype(self):
80+
"""Bustype of the device.
81+
Must be one of the BUS_ -prefixed constant values.
82+
"""
83+
return self._bustype
84+
85+
@property
86+
def vendor(self):
87+
"""Vendor number of the device."""
88+
return self._vendor
89+
90+
@property
91+
def product(self):
92+
"""Product number of the device."""
93+
return self._product
94+
95+
@property
96+
def version(self):
97+
"""Version number of the device."""
98+
return self._version
99+
100+
def move_pointer(self, x, y):
101+
"""Sends a relative pointer motion event to the event device.
102+
Values increase towards right-bottom.
103+
"""
104+
_suinput.move_pointer(self._input_fd, x, y)
105+
106+
def press(self, uinput_code):
107+
"""Sends a press event to the event device. Event is repeated after
108+
a short delay until a release event is sent.
109+
110+
`uinput_code` must be one of the constant values defined in
111+
uinput.codes -module.
112+
"""
113+
_suinput.press(self._input_fd, uinput_code)
114+
115+
def release(self, uinput_code):
116+
"""Sends a release event to the event device.
117+
118+
`uinput_code` must be one of the constant values defined in
119+
uinput.codes -module.
120+
"""
121+
_suinput.release(self._input_fd, uinput_code)
122+
123+
def click(self, uinput_code):
124+
"""Sends a press and release events to the event device.
125+
126+
`uinput_code` must be one of the constant values defined in
127+
uinput.codes -module.
128+
129+
This method is provided as a convenience and has effectively the
130+
same result as calling press(uinput_fd) and release(uinput_fd)
131+
sequentially.
132+
"""
133+
_suinput.click(self._input_fd, uinput_code)
134+
135+
def __del__(self):
136+
_suinput.close(self._input_fd)
File renamed without changes.

0 commit comments

Comments
 (0)