[mousetrap/gnome3-wip: 113/240] Introduced History class to manage length of histories.
- From: Heidi Ellis <heidiellis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetrap/gnome3-wip: 113/240] Introduced History class to manage length of histories.
- Date: Mon, 8 Sep 2014 15:22:03 +0000 (UTC)
commit 716cdeff2fc2cea76d6c181e4451311686522b58
Author: Stoney Jackson <dr stoney gmail com>
Date: Sun Jun 22 00:46:57 2014 -0400
Introduced History class to manage length of histories.
src/mousetrap/plugins/eyes.py | 28 +++++++++++++++++++---------
1 files changed, 19 insertions(+), 9 deletions(-)
---
diff --git a/src/mousetrap/plugins/eyes.py b/src/mousetrap/plugins/eyes.py
index ce25b51..0aa8aa2 100644
--- a/src/mousetrap/plugins/eyes.py
+++ b/src/mousetrap/plugins/eyes.py
@@ -9,15 +9,15 @@ LOGGER = log.get_logger(__name__)
class EyesPlugin(interface.Plugin):
def __init__(self):
self._left_locator = LeftEyeLocator()
- self._eye_detection_history = []
- self._pointer_history = []
+ self._eye_detection_history = History(max_length=15)
+ self._pointer_history = History(max_length=5)
self._is_closed = False
def run(self, app):
self._eye_detection_history.append(self._left_locator.locate(app.image))
if self._stationary(app) and self._detect_closed():
- self._eye_detection_history = []
+ self._eye_detection_history.clear()
app.pointer.click()
def _stationary(self, app):
@@ -25,9 +25,6 @@ class EyesPlugin(interface.Plugin):
last_point = app.pointer.get_position()
- while len(self._pointer_history) > 5:
- del self._pointer_history[0]
-
for point in self._pointer_history:
if point != last_point:
return False
@@ -35,9 +32,6 @@ class EyesPlugin(interface.Plugin):
return True
def _detect_closed(self):
- while len(self._eye_detection_history) > 15:
- del self._eye_detection_history[0]
-
misses = self._eye_detection_history.count(False)
return misses > 12
@@ -65,3 +59,19 @@ class LeftEyeLocator(object):
return True
except FeatureNotFoundException:
return False
+
+
+class History(list):
+ def __init__(self, max_length):
+ super(History, self).__init__()
+ self._max_length = max_length
+
+ def append(self, value):
+ super(History, self).append(value)
+ while len(self) > self._max_length:
+ del self[0]
+
+ def clear(self):
+ del self[:]
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]