from drawable import drawable
from PIL import Image, ImageDraw


class slideLeft(drawable):
    """
    slides text in from left
    """

    def __init__(self, feed, font):
        self.image = Image.new('RGB', (128, 32))
        self.drw = ImageDraw.Draw(self.image)
        self.done = False
        self.font = font
        self.delay = 80
        self.dummy_data = ["cujomalainey1", "cujomalainey2",
                           "cujomalainey3", "cujomalainey4",
                           "cujomalainey5", "cujomalainey6",
                           "cujomalainey7", "cujomalainey8"]
        self.update()

    def nextFrame(self):
        self.drw.rectangle([(0, 0), (128, 32)], fill=(0, 0, 0))
        i = 0
        self.done = True
        for line in self.data:
            if line["x"] > (int(i/4))*64:
                self.done = False
                line["x"] -= 1
                break
            i += 1
        if self.done is True and self.delay > 0:
            self.delay -= 1
            self.done = False
        i = 1
        for line in self.data:
            self.drw.text((line["x"], line["y"] + drawable.fontYoffset),
                          str(i) + "." + line["text"] + " ",
                          font=self.font, fill=(255, 255, 255))
            i += 1

    def update(self):
        self.data = [{"text": text, "x": 129} for text in self.dummy_data]
        i = 0
        for line in self.data:
            line["y"] = 8 * (i % 4)
            i += 1

    def draw(self):
        self.nextFrame()
        return self.image if not self.done else None

@@ -56,16 +56,28 @@
 ageDraw%0A
+import time%0A
 %0A%0Aclass 
@@ -843,32 +843,72 @@
 lf.done = False%0A
+                self.time = time.time()%0A
                 
@@ -1000,51 +1000,37 @@
 and 
-self.delay %3E 0:%0A            self.delay -= 1
+time.time() - self.time %3C 10:
 %0A   

use real time instead of frames for pi 2