Exemple #1
0
def showText(strip,
             text,
             font=None,
             fg_color=None,
             bg_color=None,
             fps=8,
             count=1,
             offset=1):
    '''
        Display text on display
        '''
    if font == None:
        font = os.path.join('/usr/share/fonts/truetype/freefont/',
                            'FreeSans.ttf')
    if fg_color == None: fg_color = Color(255, 255, 255)
    if bg_color == None: bg_color = Color(0, 0, 0)

    text = '    ' + text + '    '

    fnt = fontdemo.Font(font, HEIGHT - offset + 3 if offset > 1 else HEIGHT)
    text_width, text_height, text_max_descent = fnt.text_dimensions(text)
    text_as_pixel = fnt.render_text(text)

    print(text_width)
    print(text_as_pixel)

    # Display text count times
    for i in range(count):

        # Erase previous content
        setColorToAll(strip, bg_color, offset)

        # Assure here correct rendering, if the text does not fill the whole display
        render_range = WIDTH if WIDTH < text_width else text_width
        print(render_range)
        for y in range(text_height):
            for x in range(render_range):
                setColorBy2DCoordinates(
                    strip, x, y,
                    fg_color if text_as_pixel.pixels[y * text_width +
                                                     x] else bg_color, offset)

        # Show first frame for 0.5 seconds
        strip.show()
        time.sleep(0.5)

        print(text_width - WIDTH + 1)
        # Shift text from left to right to show all.
        for cur_offset in range(text_width - WIDTH + 1):
            for y in range(text_height):
                for x in range(WIDTH):
                    setColorBy2DCoordinates(
                        strip, x, y, fg_color if
                        text_as_pixel.pixels[y * text_width + x +
                                             cur_offset] else bg_color, offset)
            strip.show()
            time.sleep(1.0 / fps)
    def showText(self,
                 text,
                 font=None,
                 fg_color=None,
                 bg_color=None,
                 fps=10,
                 count=1):
        """
        Display text on display
        """
        if font is None:
            font = self.default_font
        if fg_color is None:
            fg_color = self.default_fg_color
        if bg_color is None:
            bg_color = self.default_bg_color

        text = '    ' + text + '    '

        fnt = fontdemo.Font(font, self.wcl.WCA_HEIGHT)

        text_width, text_height, text_max_descent = fnt.text_dimensions(text)
        text_as_pixel = fnt.render_text(text)

        # Display text count times
        for i in range(count):

            # Erase previous content
            self.setColorToAll(bg_color, includeMinutes=True)

            # Assure here correct rendering, if the text does not fill the whole display
            render_range = self.wcl.WCA_WIDTH if self.wcl.WCA_WIDTH < text_width else text_width
            for y in range(text_height):
                for x in range(render_range):
                    self.wcl.setColorBy2DCoordinates(
                        self.strip, x, y,
                        fg_color if text_as_pixel.pixels[y * text_width +
                                                         x] else bg_color)

            # Show first frame for 0.5 seconds
            self.show()
            if self.wci.waitForExit(0.5):
                return

            # Shift text from left to right to show all.
            for cur_offset in range(text_width - self.wcl.WCA_WIDTH + 1):
                for y in range(text_height):
                    for x in range(self.wcl.WCA_WIDTH):
                        self.wcl.setColorBy2DCoordinates(
                            self.strip, x, y, fg_color
                            if text_as_pixel.pixels[y * text_width + x +
                                                    cur_offset] else bg_color)
                self.show()
                if self.wci.waitForExit(1.0 / fps):
                    return
    def showTimeAsText(self, fg_color, bg_color, fps=10, count=1):

        # get current time from system
        curTime = datetime.datetime.now()

        # separate time elements
        hour = curTime.hour
        minute = curTime.minute

        # set the displaying text
        # default is time with hours and minutes
        # if customText file exists then display the text within the file
        text = '   ' \
               + format(hour, '02d') \
               + ':' \
               + format(minute, '02d') \
               + '   '

        # customText file readout if exists
        pathToTextFile = os.path.join(self.basePath, 'other', 'customText.txt')
        if os.path.exists(pathToTextFile):
            with open(pathToTextFile, 'r') as f:
                text = '   ' + f.read() + '   '
            os.remove(pathToTextFile)

        # set font
        font = os.path.join(self.basePath, 'other', 'tiny.ttf')

        # setup fontdemo
        fnt = fontdemo.Font(font, self.clock_width)
        txt_width, txt_height, txt_max_descent = fnt.text_dimensions(text)
        txt_as_pixel = fnt.render_text(text)

        # Display text count times
        for i in range(count):

            # Erase previous content
            self.stripFunctions.wipeLEDs(bg_color)

            # Shift text from left to right to show all.
            for cur_offset in range(txt_width - self.clock_width + 1):
                for y in range(txt_height):
                    for x in range(self.clock_width):
                        if txt_as_pixel.pixels[y * txt_width + x + cur_offset]:
                            u_color = fg_color
                        else:
                            u_color = bg_color
                        self.stripFunctions.setColorBy2DCoordinates(
                            x, y, u_color)
                self.strip.show()
                time.sleep(1.0 / fps)
Exemple #4
0
def scroll_text(strip, txt, wait_ms=100, func=None):
    fnt = fontdemo.Font('helvetica.ttf', 11)
    txt = fnt.render_text('  ' + txt + '  ', 14, 8)

    for x in range(txt.width):
        for y in range(8):
            for x2 in range(8):
                c = Color(0, 0, 0)
                if x2 + x < txt.width:
                    if txt.pixels[(y * txt.width) + (x + x2)]:
                        c = Color(255, 255, 255)
                setp(strip, 7 - x2, y, c)
        strip.show()
        if func and func(): return
        time.sleep(wait_ms / 1000.0)
Exemple #5
0
def scroll_text(strip, txt, wait_ms=100, textcolor=(255, 255, 255), func=None):
    #fnt = fontdemo.Font('helvetica.ttf', 11)
    fnt = fontdemo.Font('C64.ttf', 8)
    txt = fnt.render_text('  ' + txt + '  ', 14, 8)

    for x in range(txt.width):
        for y in range(8):
            for x2 in range(8):
                c = Color(0, 0, 0)
                if x2 + x < txt.width:
                    try:
                        if txt.pixels[(y * txt.width) + (x + x2)]:
                            c = Color(textcolor[0], textcolor[1],
                                      textcolor[2])  #Color(255,255,255)
                    except Exception as e:
                        print(e)
                setp(strip, x2, y, c)
        strip.show()
        if func and func(): return
        time.sleep(wait_ms / 1000.0)
    def showCountDown(self):
        '''

               0   1   2   3   4   5  ->--
                                       |
        --<-  11  10   9   8   7   6  -<--
        |
        -->-  12  13  14  15  16  17  ->--
                                       |
              23  22  21  20  19  18  -<--

        '''

        # Erase previous content
        self.stripFunctions.wipeLEDs()

        colors = [
            Color(255, 0, 0),
            Color(255, 96, 0),
            Color(255, 255, 0),
            Color(128, 255, 0),
            Color(0, 255, 0),
            Color(0, 255, 128),
            Color(0, 255, 255),
            Color(0, 178, 255),
            Color(0, 0, 255),
            Color(128, 0, 255),
            Color(255, 0, 255)
        ]

        for i in range(10):

            if i == 0:
                # 10
                self.stripFunctions.setColorBy1DCoordinate(11, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(23, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(1, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(10, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(13, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(22, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(21, colors[i])

                self.stripFunctions.setColorBy1DCoordinate(4, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(8, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(15, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(19, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(17, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(6, colors[i])

            elif i == 1:
                # 9
                self.stripFunctions.setColorBy1DCoordinate(9, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(14, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(3, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(15, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(4, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(7, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(16, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(19, colors[i])

            elif i == 2:
                # 8
                self.stripFunctions.setColorBy1DCoordinate(1, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(10, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(13, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(2, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(14, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(21, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(3, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(8, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(20, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(7, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(16, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(19, colors[i])

            elif i == 3:
                # 7
                self.stripFunctions.setColorBy1DCoordinate(2, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(21, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(3, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(15, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(4, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(7, colors[i])

            elif i == 4:
                # 6
                self.stripFunctions.setColorBy1DCoordinate(9, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(14, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(21, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(3, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(2, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(15, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(20, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(6, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(16, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(19, colors[i])

            elif i == 5:
                # 5
                self.stripFunctions.setColorBy1DCoordinate(2, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(9, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(21, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(3, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(20, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(4, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(16, colors[i])

            elif i == 6:
                # 4
                self.stripFunctions.setColorBy1DCoordinate(9, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(14, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(15, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(4, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(7, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(16, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(19, colors[i])

            elif i == 7:
                # 3
                self.stripFunctions.setColorBy1DCoordinate(2, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(21, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(3, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(8, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(20, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(7, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(16, colors[i])

            elif i == 8:
                # 2
                self.stripFunctions.setColorBy1DCoordinate(2, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(14, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(21, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(3, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(20, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(7, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(19, colors[i])

            elif i == 9:
                # 1
                self.stripFunctions.setColorBy1DCoordinate(11, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(23, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(1, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(10, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(13, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(22, colors[i])
                self.stripFunctions.setColorBy1DCoordinate(21, colors[i])

            self.strip.show()
            time.sleep(1)
            self.stripFunctions.wipeLEDs()

        text = 'Frohes Neues'
        fg_color = colors[10]
        bg_color = Color(0, 0, 0)
        fps = 5
        count = 1

        # set font
        font = os.path.join(self.basePath, 'other', 'tiny.ttf')

        # setup fontdemo
        fnt = fontdemo.Font(font, self.clock_width)
        txt_width, txt_height, txt_max_descent = fnt.text_dimensions(text)
        txt_as_pixel = fnt.render_text(text)

        # Display text count times
        for i in range(count):

            # Erase previous content
            self.stripFunctions.wipeLEDs(bg_color)

            # Shift text from left to right to show all.
            for cur_offset in range(txt_width - self.clock_width + 1):
                for y in range(txt_height):
                    for x in range(self.clock_width):
                        if txt_as_pixel.pixels[y * txt_width + x + cur_offset]:
                            u_color = fg_color
                        else:
                            u_color = bg_color
                        self.stripFunctions.setColorBy2DCoordinates(
                            x, y, u_color)
                self.strip.show()
                time.sleep(1.0 / fps)