[mousetrap/gnome3-wip: 76/240] Move Pointer int moustrap.gui.
- From: Heidi Ellis <heidiellis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetrap/gnome3-wip: 76/240] Move Pointer int moustrap.gui.
- Date: Mon, 8 Sep 2014 15:18:57 +0000 (UTC)
commit 61b723757173107f0253331295e79b6217132a35
Author: Stoney Jackson <dr stoney gmail com>
Date: Thu Jun 12 10:08:30 2014 -0400
Move Pointer int moustrap.gui.
src/mousetrap/gui.py | 18 ++++++++++++++++++
src/mousetrap/main.py | 10 +++++-----
src/mousetrap/pointer.py | 19 -------------------
src/mousetrap/test_pointer.py | 4 ++--
4 files changed, 25 insertions(+), 26 deletions(-)
---
diff --git a/src/mousetrap/gui.py b/src/mousetrap/gui.py
index 20472a4..470b850 100644
--- a/src/mousetrap/gui.py
+++ b/src/mousetrap/gui.py
@@ -1,4 +1,5 @@
from gi.repository import Gtk
+from gi.repository import Gdk
from gi.repository import GdkPixbuf
@@ -75,3 +76,20 @@ def show_image(window_name, image):
def start():
'''Start handling events.'''
Gtk.main()
+
+
+class Pointer(object):
+ def __init__(self):
+ gdk_display = Gdk.Display.get_default()
+ device_manager = gdk_display.get_device_manager()
+ self._pointer = device_manager.get_client_pointer()
+ self._screen = gdk_display.get_default_screen()
+
+ 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, point):
+ self._pointer.warp(self._screen, point[0], point[1])
diff --git a/src/mousetrap/main.py b/src/mousetrap/main.py
index e2dd9d4..c51ddd3 100644
--- a/src/mousetrap/main.py
+++ b/src/mousetrap/main.py
@@ -1,9 +1,9 @@
from gi.repository import GObject
from gi.repository import Gtk
-import mousetrap.vision as vision
+from mousetrap.vision import Camera, NoseLocator
+from mousetrap.gui import Pointer
import mousetrap.gui as gui
-import mousetrap.pointer as pointer
FPS = 5
@@ -14,10 +14,10 @@ class Main(object):
def __init__(self):
self.image = None
self.timeout_id = None
- self.camera = vision.Camera()
+ self.camera = Camera()
self.camera.set_dimensions(300, 200)
- self.locator = vision.NoseLocator()
- self.pointer = pointer.Pointer()
+ self.locator = NoseLocator()
+ self.pointer = Pointer()
self.screen = Gtk.Window().get_screen()
def run(self):
diff --git a/src/mousetrap/test_pointer.py b/src/mousetrap/test_pointer.py
index 861326e..f099dc6 100644
--- a/src/mousetrap/test_pointer.py
+++ b/src/mousetrap/test_pointer.py
@@ -1,11 +1,11 @@
import unittest
-import mousetrap.pointer as pointer
+from mousetrap.gui import Pointer
class test_pointer(unittest.TestCase):
def setUp(self):
- self.pointer = pointer.Pointer()
+ self.pointer = Pointer()
def test_get_position(self):
pointer_x, pointer_y = self.pointer.get_position()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]