[mousetrap/gnome3-wip: 88/240] Add custom exception FeatureNotFoundException.



commit 24ad9bb29950fb50ce3fd23f07229aff43ad211d
Author: Stoney Jackson <dr stoney gmail com>
Date:   Thu Jun 12 13:57:56 2014 -0400

    Add custom exception FeatureNotFoundException.

 src/mousetrap/pointers/nose.py |    6 ++----
 src/mousetrap/vision.py        |   10 ++++++++--
 2 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/src/mousetrap/pointers/nose.py b/src/mousetrap/pointers/nose.py
index cec1ff7..9c8e29e 100644
--- a/src/mousetrap/pointers/nose.py
+++ b/src/mousetrap/pointers/nose.py
@@ -1,5 +1,5 @@
 import mousetrap.pointers.interface as interface
-from mousetrap.vision import FeatureDetector
+from mousetrap.vision import FeatureDetector, FeatureNotFoundException
 from mousetrap.gui import Gui
 
 
@@ -16,9 +16,7 @@ class Pointer(interface.Pointer):
             point_image = self._nose_locator.locate(image)
             point_screen = self._convert_image_to_screen_point(*point_image)
             self._location = point_screen
-        except Exception as exception:
-            # FIXME: when FeatureDetector is changed to raise custom exceptions
-            # this should be adjusted to match.
+        except FeatureNotFoundException as error:
             self._location = None
 
     def _convert_image_to_screen_point(self, image_x, image_y):
diff --git a/src/mousetrap/vision.py b/src/mousetrap/vision.py
index 74263f2..8cb7cae 100644
--- a/src/mousetrap/vision.py
+++ b/src/mousetrap/vision.py
@@ -116,8 +116,7 @@ class FeatureDetector(object):
 
     def _exit_if_none_detected(self):
         if len(self._plural) == 0:
-            # FIXME: need custom exception
-            raise Exception('No ' + self._name + 's detected.')
+            raise FeatureNotFoundException('No ' + self._name + 's detected.')
 
     def _unpack_first(self):
         self._single = dict(zip(['x', 'y', 'width', 'height'], self._plural[0]))
@@ -138,3 +137,10 @@ class FeatureDetector(object):
         single["image"] = Image(
                 image_cv_grayscale[from_y:to_y, from_x:to_x],
                 is_grayscale=True)
+
+
+class FeatureNotFoundException(Exception):
+    def __init__(self, message):
+        self.message = message
+    def __str__(self):
+        return repr(self.message)


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