'''
Show a circle under all touchs
'''

import os
from kivy import MTWidget, set_color, getCurrentTouches, kivy_data_dir, Image

if not 'KIVY_DOC' in os.environ:
    ring_fn = os.path.join(kivy_data_dir, 'ring.png')
    ring_img = Image(ring_fn)
    ring_img.scale = .30
    ring_img.anchor_x = ring_img.width / 2
    ring_img.anchor_y = ring_img.height / 2

class TouchRing(MTWidget):
    def __init__(self, **kwargs):
        super(TouchRing, self).__init__(**kwargs)

    def on_update(self):
        self.bring_to_front()

    def draw(self):
        color = self.style.get('color')
        ring_img.color = color
        for touch in getCurrentTouches():
            alpha = color[3]
            if 'kinetic' in touch.profile:
                alpha = .2

            # draw touch
            ring_img.opacity = alpha
            ring_img.pos = touch.pos
            ring_img.draw()

def start(win, ctx):
    ctx.w = TouchRing()
    win.add_widget(ctx.w)

def stop(win, ctx):
    win.remove_widget(ctx.w)

@@ -1,38 +1,178 @@
 '''%0A
-Show a circle under all
+Touchring module%0A================%0A%0AShow ring around every touch on the table. You can use this module for checking%0Aif you don't have any calibration trouble with
  touch
-s
+es.
 %0A'''
@@ -204,67 +204,97 @@
 ort 
-MTWidget, set_color, getCurrentTouches, kivy_data_dir, Imag
+kivy_data_dir%0Afrom kivy.core.image import Image%0Afrom kivy.graphics import Color, Rectangl
 e%0A%0Ai
@@ -366,16 +366,26 @@
 ata_dir,
+ 'images',
  'ring.p
@@ -423,767 +423,1049 @@
 fn)%0A
-    ring_img.scale = .30%0A    ring_img.anchor_x = ring_img.width / 2%0A    ring_img.anchor_y = ring_img.height / 2%0A%0Aclass TouchRing(MTWidget):%0A    def __init__(self, **kwargs):%0A        super(TouchRing, self).__init__(**kwargs)%0A%0A    def on_update(self):%0A        self.bring_to_front()%0A%0A    def draw(self):%0A        color = self.style.get('color')%0A        ring_img.color = color%0A        for touch in getCurrentTouches():%0A            alpha = color%5B3%5D%0A            if 'kinetic' 
+%0Adef _touch_down(win, touch):%0A    ud = touch.userdata%0A    touch.scale_for_screen(win.width, win.height)%0A    with win.canvas.after:%0A        ud%5B'tr.color'%5D = Color(1, 1, 1, .7)%0A        iw, ih = ring_img.size%0A        ud%5B'tr.rect'%5D = Rectangle(%0A            pos=(%0A                touch.x - (ring_img.width / 2. * 0.3),%0A                touch.y - (ring_img.height / 2. * 0.3)),%0A            size=(iw * 0.3, ih * 0.3),%0A            texture=ring_img.texture)%0A%0Adef _touch_move(w
 in
+,
  touch
-.profile:%0A                alpha = .2%0A%0A            # draw touch%0A            ring_img.opacity = alpha%0A            ring_img.pos = touch.pos%0A        
+):%0A    ud = touch.userdata%0A    ud%5B'tr.rect'%5D.pos = (%0A        touch.x - (ring_img.width / 2. * 0.3),%0A        touch.y - (ring_img.height / 2. * 0.3)%0A    )%0A%0Adef _touch_up(win, touch):%0A    ud = touch.userdata%0A
     
-ring_img.draw()%0A%0Adef start(win, ctx):%0A    ctx.w = TouchRing()%0A    win.add_widget(ctx.w)%0A%0Adef stop(win, ctx):%0A    win.remove_widget(ctx.w
+win.canvas.after.remove(ud%5B'tr.color'%5D)%0A    win.canvas.after.remove(ud%5B'tr.rect'%5D)%0A%0A%0Adef start(win, ctx):%0A    win.bind(on_touch_down=_touch_down,%0A             on_touch_move=_touch_move,%0A             on_touch_up=_touch_up)%0A%0Adef stop(win, ctx):%0A    win.unbind(on_touch_down=_touch_down,%0A             on_touch_move=_touch_move,%0A             on_touch_up=_touch_up
 )%0A

convert touchring module for kivy