فهرست منبع

Made test app more fancy.

Taddeus Kroes 13 سال پیش
والد
کامیت
b0639f93c0
2فایلهای تغییر یافته به همراه21 افزوده شده و 13 حذف شده
  1. 0 1
      TODO.txt
  2. 21 12
      tests/testapp.py

+ 0 - 1
TODO.txt

@@ -4,4 +4,3 @@ Code:
 
 Report/appendix reference gesture detection:
 - Point_leave(+point_enter) kan niet -> flaw v/h systeem/driver?
-- "gesture detection component" -> "gesture tracker"

+ 21 - 12
tests/testapp.py

@@ -46,10 +46,11 @@ class Polygon(BoundingBoxArea):
         self.on_pinch(self.handle_pinch)
         self.on_rotate(self.handle_rotate)
         self.on_flick(self.handle_flick)
-        self.on_double_tap(self.circulate_color)
+        self.on_tap(self.circulate_color)
 
     def circulate_color(self, g):
         self.color = self.color[2:] + self.color[:2]
+        refresh()
 
     def flick_drag(self, amt):
         tx, ty = self.flick_direction
@@ -119,6 +120,13 @@ draw_touch_objects = True
 W, H = mt.screen.screen_size
 
 
+def toggle_fullscreen():
+    global fullscreen
+    (window.unfullscreen if fullscreen else window.fullscreen)()
+    fullscreen = not fullscreen
+    refresh()
+
+
 def create_context_window(w, h, callback):
     def create_context(area, event):
         """Add Cairo context to GTK window and draw state."""
@@ -135,9 +143,7 @@ def create_context_window(w, h, callback):
         key = chr(event.keyval)
 
         if key == 'f':
-            global fullscreen
-            (win.unfullscreen if fullscreen else win.fullscreen)()
-            fullscreen = not fullscreen
+            toggle_fullscreen()
         elif key == 'b':
             global draw_bounding_boxes
             draw_bounding_boxes = not draw_bounding_boxes
@@ -149,7 +155,7 @@ def create_context_window(w, h, callback):
         elif key == 'q':
             quit()
 
-    def update_window():
+    def redraw_updated_window():
         refresh()
         return True
 
@@ -160,7 +166,7 @@ def create_context_window(w, h, callback):
     window.connect('destroy', quit)
     window.connect('key-press-event', handle_key)
     window.connect('show', callback)
-    window.on_update(update_window)
+    window.on_update(redraw_updated_window)
     root = window.get_area()
 
     if fullscreen:
@@ -196,7 +202,13 @@ def draw():
         cr.set_source_rgb(*WHITE)
 
         for hand in touch_hands:
-            cx, cy = hand.get_centroid()
+            centroid = hand.get_centroid()
+
+            # Check if all fingers have not been removed already
+            if not centroid:
+                continue
+
+            cx, cy = centroid
 
             # Filled centroid circle
             if len(hand) > 1:
@@ -247,8 +259,8 @@ def triangle_height(width):
 
 
 def on_show(window):
-    def root_dtap(g): print 'double tapped on root'
-    root.on_double_tap(root_dtap)
+    # Toggle fullscreen on double tap
+    root.on_double_tap(lambda g: toggle_fullscreen())
 
     # Create blue rectangle
     x, y, w, h = 0, 0, 250, 150
@@ -256,9 +268,6 @@ def on_show(window):
     draw_objects.append(rect)
     root.add_area(rect)
 
-    def rect_tap(g): print 'tapped on rectangle'
-    rect.on_tap(rect_tap, propagate_up_event=False)
-
     # Create green triangle
     x, y, w = 400, 400, 200
     h = triangle_height(w)