Example #1
0
class PhlostonThread(threading.Thread):
    """
    Singleton thread that runs the animation
    """
    def run(self):
        self.terminate = False

        # A Phloston string on 1 ButtonHoliday
        self.phloston = PhlostonString([ButtonHoliday(),], color=START_COLOR)

        while True:
            if self.terminate:
                return

            # animate
            self.phloston.animate()
            self.phloston.render()

            # sleep
            time.sleep(SNOOZETIME)
        
        pass

    def set_color(self, newcolor):
        """
        Change the color of the string
        """
        if not hasattr(self, 'phloston'):
            return
        self.phloston.set_pattern( [ newcolor, ] * self.phloston.length )

    def get_color(self):
        if not hasattr(self, 'phloston'):
            return (0,0,0)
        color = self.phloston.pattern[0]
        return color