tag_drag.py

"""Drag a text tag around.
   by stephan)
"""
from slut import *

class Atlantis(World):
    def onSetup(self):
        self.name = "Form Follows Computation Here"
        self.width = 800
        self.height = 600

        DragText(self, 'count', 44, 'arial')
        self.tags['count'].moveTo(300, 50)
        DragText(self, 'tag', 36, 'times')
        self.tags['tag'].setText('NUMBERS!')
        self.tags['tag'].moveTo(50, 50)
        self.tags['tag'].moveBy(SineTween(500, 200, 0.7))
        self.count = 0

    def onDraw(self):
        self.tags['count'].setText(str(self.count))
        self.count += 1



class DragText(TagText):
    def __init__(self, parent, name, size, fontface):
        TagText.__init__(self, parent, name, size, fontface)
        self.setColor(1.0, 1.0, 1.0, 0.5)
        self.enableMouseEvents()

    def onMouseIn(self, event):
        self.setColor(1.0, 1.0, 1.0, 1.0)
        self.dirty()

    def onMouseOut(self, event):
        self.setColor(1.0, 1.0, 1.0, 0.5)
        self.dirty()

    def onMouseButtonDown(self, event):
        self.mouseOffX = event.pos[0] - self._trans_x
        self.mouseOffY = event.pos[1] - self._trans_y
        self.setColor(1.0, 0.2, 0.2, 1.0)
        self.dirty()

    def onMouseButtonUp(self, event):
        self.setColor(1.0, 1.0, 1.0, 1.0)
        self.dirty()

    def onMouseDrag(self, event):
        self._trans_x = event.pos[0] - self.mouseOffX
        self._trans_y = event.pos[1] - self.mouseOffY



atlantis = Atlantis()
atlantis.run()
Initiated by Stephan Hechenberger
Thanks to CADRE's 103