from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ListProperty

"""
Having both of these functions is redundant and you should generally
only use one of the methods of
listening/reacting to property changes.

"""

class RootWidget(BoxLayout):

    def __init__(self, **kwargs):
        super(RootWidget, self).__init__(**kwargs)
        self.add_widget(Button(text='btn1'))
        cb = CustomBtn()
        cb.bind(pressed=self.btn_pressed)
        self.add_widget(cb)
        self.add_widget(Button(text="btn2"))

    def btn_pressed(self, instance, pos):
        print "pos: printed from root widget: %s" % str(pos)


class CustomBtn(Widget):

    pressed = ListProperty([0,0])

    def on_touch_down(self, touch):
        if self.collide_point(*touch.pos):
            self.pressed = touch.pos
            return True
        return super(CustomBtn, self).on_touch_down(touch)

    def on_pressed(self, instance, pos):
        print "pressed at %s" % str(pos)

class TestApp(App):

    def build(self):
        return RootWidget()

if __name__ == "__main__":
    TestApp().run()

