title: Using and moving Widgets/Buttons in Kivy
body: <p>I'm just starting off with Kivy and it's different to what I'm used to, apologies if I'm making stupid mistakes!</p>
  
  <p>Right now I'm trying to create an app that does the following:</p>
  
  <ul>
  <li>Allows creation of Nodes (ellipses for now).</li>
  <li>Allows the user to position the nodes by dragging.</li>
  <li>Allows the user to connect the nodes with a line.</li>
  </ul>
  
  <p>So far I've achieved the first, and the second somewhat.</p>
  
  <p>Right now my dragging is not working too well. If I move the mouse too quickly it cancels the move method (as it is no longer in contact). Is there a better way to produce dragging or do I just increase the refresh rate (if so how?).</p>
  
  <pre><code>def on_touch_move(self, touch):
     if self.collide_point(touch.x, touch.y):
         self.pos=[touch.x-25, touch.y-25]
  </code></pre>
  
  <p>I've tried using Buttons instead, using the on_press method to track the moving better. However now I'm having difficulty updating the position of the button (mostly just syntax).</p>
  
  <pre><code>    class GraphNode(Button):
         background_disabled_down=1
         background_disabled_normal=1
  
         def moveNode(self):
             with touch:
                 self.pos=[touch.x-25, touch.y-25]
  </code></pre>
  
  <p>I have no idea how to use the touch value, and keep getting an array of errors. (Obviously the current attempt doesn't work, I just thought it was funny).</p>
  
  <p>As you could probably tell, I also don't know how to get rid of the button graphics, as I want to use the ellipse. As an added bonus if someone could show me how to change the colour of the ellipse on button press that would be cool!</p>
  
  <p>The kv file:</p>
  
  <pre><code>    &lt;GraphNode&gt;:
          size: 50, 50
          canvas:
              Ellipse:
                  pos: self.pos
                 size: self.size
          on_press:
              root.moveNode()
  </code></pre>
  
  <p>I want to be able to use the touch information to update the position, but don't know how to implement it here.</p>
  
  <p>Full core python code:</p>
  
  <pre><code>    from kivy.app import App
      from kivy.uix.widget import Widget
      from kivy.uix.button import Button
      from kivy.properties import NumericProperty, ReferenceListProperty,\
          ObjectProperty
      from kivy.graphics import Color, Ellipse, Line
  
  
      class GraphInterface(Widget):
          node = ObjectProperty(None)
  
  
  
      class GraphApp(App):
  
          def build(self):
              node = GraphNode()
              game = GraphInterface()
  
              createNodeButton = Button(text = 'CreateNode', pos=(100,0))
              createEdgeButton = Button(text = 'CreateEdge')
              game.add_widget(createNodeButton)
              game.add_widget(createEdgeButton)
  
              def createNode(instance):
                  game.add_widget(GraphNode())
                  print "Node Created"
  
              def createEdge(instance):
                  game.add_widget(GraphEdge())
                  print "Edge Created"
  
              createNodeButton.bind(on_press=createNode)
              createEdgeButton.bind(on_press=createEdge)
              return game
  
      class GraphNode(Button):
  
          def moveNode(self):
              with touch:
                  self.pos=[touch.x-25, touch.y-25]
  
  
         #def onTouchMove(self, touch):
         #   if self.collide_point(touch.x, touch.y):
         #       self.pos=[touch.x-25, touch.y-25]
          pass
  
      class GraphEdge(Widget):
  
          def __init__(self, **kwargs):
              super(GraphEdge, self).__init__(**kwargs)
              with self.canvas:
                  Line(points=[100, 100, 200, 100, 100, 200], width=1)
          pass
  
      if __name__ == '__main__':
  
          GraphApp().run()
  </code></pre>
  
  <p>If you need any other info, or anything is unclear, please let me know!</p>
  
  <p>Edit: Second question moved to: <a href="https://stackoverflow.com/questions/25274365/creating-a-dynamically-drawn-line-in-kivy">Creating a dynamically drawn line in Kivy</a>.</p>