[mousetrap/gnome3-wip: 112/240] Simplify eyes.py



commit 02ac8e07619dc95a6232b438838d6a89c4b71bb8
Author: Stoney Jackson <dr stoney gmail com>
Date:   Sun Jun 22 00:38:20 2014 -0400

    Simplify eyes.py
    
    * LeftEyeLocator.locate() now returns a boolean instead of raising an exception.
    * _eye_detection_history now stores booleans instead of None and locations.

 src/mousetrap/plugins/eyes.py |   27 +++++++++------------------
 1 files changed, 9 insertions(+), 18 deletions(-)
---
diff --git a/src/mousetrap/plugins/eyes.py b/src/mousetrap/plugins/eyes.py
index f628038..ce25b51 100644
--- a/src/mousetrap/plugins/eyes.py
+++ b/src/mousetrap/plugins/eyes.py
@@ -14,22 +14,12 @@ class EyesPlugin(interface.Plugin):
         self._is_closed = False
 
     def run(self, app):
-        try:
-            point_image = self._left_locator.locate(app.image)
-            self._hit(point_image)
-        except FeatureNotFoundException:
-            self._miss()
+        self._eye_detection_history.append(self._left_locator.locate(app.image))
 
         if self._stationary(app) and self._detect_closed():
             self._eye_detection_history = []
             app.pointer.click()
 
-    def _hit(self, point):
-        self._eye_detection_history.append(point)
-
-    def _miss(self):
-        self._eye_detection_history.append(None)
-
     def _stationary(self, app):
         self._pointer_history.append(app.pointer.get_position())
 
@@ -48,7 +38,7 @@ class EyesPlugin(interface.Plugin):
         while len(self._eye_detection_history) > 15:
             del self._eye_detection_history[0]
 
-        misses = self._eye_detection_history.count(None)
+        misses = self._eye_detection_history.count(False)
 
         return misses > 12
 
@@ -68,9 +58,10 @@ class LeftEyeLocator(object):
         )
 
     def locate(self, image):
-        face = self._face_detector.detect(image)
-        eye = self._eye_detector.detect(face["image"])
-
-        LOGGER.debug(eye)
-
-        return (0, 0)
+        try:
+            face = self._face_detector.detect(image)
+            eye = self._eye_detector.detect(face["image"])
+            LOGGER.debug(eye)
+            return True
+        except FeatureNotFoundException:
+            return False


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]