[mousetrap/gnome3-wip: 51/240] Added mouse.py.
- From: Heidi Ellis <heidiellis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetrap/gnome3-wip: 51/240] Added mouse.py.
- Date: Mon, 8 Sep 2014 15:16:49 +0000 (UTC)
commit 24222056fde17d3987f4a5d62d1ddb6b6865aa53
Author: Stoney Jackson <dr stoney gmail com>
Date: Tue May 20 16:51:14 2014 -0400
Added mouse.py.
src/mousetrap/Makefile.am | 3 ++-
src/mousetrap/mouse.py | 23 +++++++++++++++++++++++
src/mousetrap/test_mouse.py | 26 ++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 1 deletions(-)
---
diff --git a/src/mousetrap/Makefile.am b/src/mousetrap/Makefile.am
index 8079824..78deb2d 100644
--- a/src/mousetrap/Makefile.am
+++ b/src/mousetrap/Makefile.am
@@ -5,7 +5,8 @@ mousetrap_pathdir=$(pyexecdir)
mousetrap_python_PYTHON = \
__init__.py \
- camera.py
+ camera.py \
+ mouse.py
#SUBDIRS =
diff --git a/src/mousetrap/mouse.py b/src/mousetrap/mouse.py
new file mode 100644
index 0000000..8b23ef1
--- /dev/null
+++ b/src/mousetrap/mouse.py
@@ -0,0 +1,23 @@
+from gi.repository import Gdk
+
+
+class Mouse:
+ def __init__(self):
+ self._pointer = None
+ self._screen = None
+
+ gdk_display = Gdk.Display.get_default()
+ self._screen = gdk_display.get_default_screen()
+
+ device_manager = gdk_display.get_device_manager()
+ self._pointer = device_manager.get_client_pointer()
+
+ def get_position(self):
+ X_INDEX = 1
+ Y_INDEX = 2
+ position = self._pointer.get_position()
+ return (position[X_INDEX], position[Y_INDEX])
+
+ def set_position(self, x, y):
+ self._pointer.warp(self._screen, x, y)
+
diff --git a/src/mousetrap/test_mouse.py b/src/mousetrap/test_mouse.py
new file mode 100644
index 0000000..d1bf5dc
--- /dev/null
+++ b/src/mousetrap/test_mouse.py
@@ -0,0 +1,26 @@
+import unittest
+from mousetrap.mouse import Mouse
+
+
+class test_mouse(unittest.TestCase):
+
+ def setUp(self):
+ self.mouse = Mouse()
+
+ def test_get_position(self):
+ x, y = self.mouse.get_position()
+ try:
+ x += 1
+ y += 1
+ except TypeError:
+ self.assertTrue(False, msg='x or y is not a number')
+
+ def test_set_position(self):
+ self.mouse.set_position(3, 4)
+ x, y = self.mouse.get_position()
+ self.assertEquals(3, x)
+ self.assertEquals(4, y)
+
+
+if __name__ == '__main__':
+ unittest.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]