Skip to content

Instantly share code, notes, and snippets.

@tito
Forked from hansent/gist:321756
Created March 4, 2010 14:52
Show Gist options
  • Save tito/321757 to your computer and use it in GitHub Desktop.
Save tito/321757 to your computer and use it in GitHub Desktop.
class ConnectionButton(MTWidget):
instances = []
def __init__(self, **kwargs):
super().__init__(**kwargs)
ConnectionButton.instances.append(self)
def on_touch_down(self, touch):
if not self.collide_point(*touch.pos):
return
self.connect_touch(touch)
def connect_touch(self, touch):
def touch_up(touch):
for target in ConnectionButton.instances:
if target.collide_point(*touch.pos):
self.connect(target)
def touch_draw(touch):
drawLine([touch.userdata['connection_start'], touch.pos])
touch.userdata['connection_start'] = self.to_window(*self.pos)
touch.grab(self, up=touch_up)
self.connect('on_draw', curry(touch_draw, touch))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment