Exemple #1
0
def lineSplit(message, width=None, font=version.font_default):
    words = message.split(" ")
    lines = []
    line = ""

    if width == None:
        width = display.width()

    for word in words:
        display.font(font)
        wordLength = display.get_string_width(word)
        lineLength = display.get_string_width(line)
        if wordLength > width:
            lines.append(line)
            lines.append(word)
            line = ""
        elif lineLength + wordLength < width:
            if (line == ""):
                line = word
            else:
                line += " " + word
        else:
            lines.append(line)
            line = word
    if len(line) > 0:
        lines.append(line)
    return lines
def string_box(x, y, w, h, text, font, color, align):
    if font:
        display.font(font)
    if align == justifyRight:
        x = x + w - display.get_string_width(text)
    elif align == justifyCenter:
        x = x + int((w - display.get_string_width(text)) / 2)
    if x < 0:
        x = 0
    string(x, y, text, font, color)
def string_box(x, y, w, h, text, font, color, justify):
    display.textColor(color)
    display.font(font)
    if justify == justifyCenter:
        display.cursor(x + int(display.get_string_width(text) / 2),
                       y + int(display.get_string_height(text) / 2))
    elif justify == justifyRight:
        display.cursor(x + display.get_string_width(text),
                       y + int(display.get_string_height(text) / 2))
    else:
        display.cursor(x, y + int(display.get_string_height(text) / 2))
    display.print(text)
Exemple #4
0
def nickname(y=5, font="freesansbold12", color=0x000000, unusedParameter=None):
    nick = machine.nvs_getstr("owner", "name")
    if not nick:
        return y
    lines = lineSplit(nick, display.width(), font)
    for i in range(len(lines)):
        line = lines[len(lines) - i - 1]
        display.font(font)
        pos_x = int((display.width() - display.get_string_width(line)) / 2)
        lineHeight = display.get_string_height(line)
        display.cursor(pos_x, y + lineHeight * (len(lines) - i - 1))
        display.textColor(color)
        display.print(line)
    return len(lines) * lineHeight
 def __init__(self, x, y, w, h):
     self.x = x
     self.y = y
     self.w = w
     self.h = h
     self.items = []
     self.selected = 0
     global activeList
     activeList = self
     display.font("freesans9")
     self.lines = int(self.h / display.get_string_height(" "))
     self.offset = 0
     self.visible(True)
     self.enabled(True)
 def _draw(self):
     if self._visible:
         display.rect(self.x, self.y, self.w, self.h, True, 0xFFFFFF)
         display.rect(self.x, self.y, self.w, self.h, False, 0x000000)
         display.font("freesans9")
         _ = display.textColor(0x000000)
         display.cursor(self.x + 1, self.y + 1)
         totalHeight = 0
         for i in range(self.offset, len(self.items)):
             display.cursor(self.x + 1, display.cursor()[1])
             item = self.items[i]
             lineHeight = display.get_string_height(item)
             totalHeight += lineHeight
             if totalHeight < self.h:
                 if i == self.selected:
                     display.rect(self.x,
                                  display.cursor()[1], self.w, lineHeight,
                                  True, 0x000000)
                     _ = display.textColor(0xFFFFFF)
                 else:
                     _ = display.textColor(0x000000)
                 display.cursor(self.x + 1, display.cursor()[1] + 3)
                 display.print(item + "\n")
                 display.cursor(self.x + 1, display.cursor()[1] - 3)
Exemple #7
0
def msg_nosplit(message, title='Loading...', reset=False):
    global NUM_LINES
    """Show a terminal style loading screen with title

	title can be optionaly set when resetting or first call
	"""
    global messageHistory

    try:
        messageHistory
        if reset:
            raise exception
    except:
        display.greyscale(False)
        display.fill(0xFFFFFF)
        display.textColor(0x000000)
        display.font(version.font_header)
        display.cursor(0, 0)
        display.print(title)
        messageHistory = []

    display.font(version.font_default)
    lineHeight = display.get_string_height(" ")

    if len(messageHistory) < NUM_LINES:
        display.textColor(0x000000)
        display.cursor(0, 19 + (len(messageHistory) * lineHeight))
        display.print(message)
        messageHistory.append(message)
    else:
        messageHistory.pop(0)
        messageHistory.append(message)
        display.rect(0, 15, display.width(),
                     display.height() - 15, True, 0xFFFFFF)
        for i, message in enumerate(messageHistory):
            display.textColor(0x000000)
            display.font(version.font_default)
            display.cursor(0, 19 + (i * lineHeight))
            display.print(message)

    display.flush()
Exemple #8
0
def lineCentered(pos_y, line, font, color):
    display.font(font)
    pos_x = int((display.width() - display.get_string_width(line)) / 2)
    display.cursor(pos_x, pos_y)
    display.textColor(color)
    display.print(line)
Exemple #9
0
def disp_string_right_bottom(y, s, font="freesans9"):
    display.font(font)
    l = display.get_string_width(s)
    display.cursor(display.width() - l, display.height() - (y + 1) * 14)
    display.textColor(0x000000)
    display.print(s)
def start():
    ugfx.input_init()
    ugfx.set_lut(ugfx.LUT_FASTER)
    ugfx.clear(ugfx.WHITE)

    # Instructions
    if orientation.isLandscape():
        x0 = int(display.width() / 2)
        display.font("fairlight8")
        currentY = 20
        display.cursor(
            x0 + int((display.width() - x0) / 2) -
            int(display.get_string_width("BADGE.TEAM") / 2), currentY)
        display.print("BADGE.TEAM\n")
        display.font("pixelade9")
        (_, currentY) = display.cursor()
        display.cursor(
            x0 + int((display.width() - x0) / 2) -
            int(display.get_string_width("ESP32 platform") / 2), currentY)
        display.print("ESP32 platform\n")
        display.line(x0, 0, x0, display.height() - 1, 0x000000)
        display.textColor(0x000000)
        display.font("pixelade9")
        currentY = display.get_string_height(" ") * 5 - 5
        display.line(x0, currentY, display.width() - 1, currentY, 0x000000)
        display.cursor(x0 + 5, currentY + 5)
        display.print("A: Run\n")
        display.print("B: Return to home\n")
        display.print("SELECT: Uninstall app\n")
        (_, currentY) = display.cursor()
        display.line(x0, currentY, display.width() - 1, currentY, 0x000000)
        _ = display.cursor(x0 + 5, currentY + 5)
        display.print(consts.INFO_FIRMWARE_NAME)
    else:
        ugfx.line(0,
                  ugfx.height() - 18 * 4, ugfx.width(),
                  ugfx.height() - 18 * 4, ugfx.BLACK)
        ugfx.string_box(0,
                        ugfx.height() - 18 * 4, ugfx.width(), 18, " A: Run",
                        "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft)
        ugfx.string_box(0,
                        ugfx.height() - 18 * 3, ugfx.width(), 18,
                        " B: Return to home", "Roboto_Regular12", ugfx.BLACK,
                        ugfx.justifyLeft)
        ugfx.string_box(0,
                        ugfx.height() - 18 * 2, ugfx.width(), 18,
                        " SELECT: Uninstall", "Roboto_Regular12", ugfx.BLACK,
                        ugfx.justifyLeft)
        ugfx.line(0,
                  ugfx.height() - 18 * 1, ugfx.width(),
                  ugfx.height() - 18 * 1, ugfx.BLACK)
        ugfx.string_box(0,
                        ugfx.height() - 18 * 1, ugfx.width(), 18,
                        " " + consts.INFO_FIRMWARE_NAME, "Roboto_Regular12",
                        ugfx.BLACK, ugfx.justifyLeft)

    global options
    global install_path
    options = None
    install_path = None

    ugfx.input_attach(ugfx.BTN_A, input_a)
    ugfx.input_attach(ugfx.BTN_B, input_b)
    ugfx.input_attach(ugfx.BTN_SELECT, input_select)
    ugfx.input_attach(ugfx.JOY_UP, input_other)
    ugfx.input_attach(ugfx.JOY_DOWN, input_other)
    ugfx.input_attach(ugfx.JOY_LEFT, input_other)
    ugfx.input_attach(ugfx.JOY_RIGHT, input_other)
    ugfx.input_attach(ugfx.BTN_START, input_other)

    populate_apps()
    populate_category()
    populate_options()

    # do a greyscale flush on start
    ugfx.flush(ugfx.GREYSCALE)
Exemple #11
0
######################### MAIN LOOP ##############################

titlefile = open("/show_titles.txt", "r")

# Read first title
mode = 2
title = titlefile.readline()
init = False
while True:

    # Draw Titles
    if mode == 1:
        if init == False:
            fb = display.FrameBuffer(24 * 8, 5)
            ledfont = display.font(5, 5, font_5x5_data)
            fb.clear_buffer()
            led.draw_framebuffer(fb, 0)
            time.sleep(2)
            play_movie(False)
            led.set_scrolling(True)
            led.play_movie(True)
            init = True
        fb.clear_buffer()

        string_length = fb.draw_string(0, 0, title[:-1], ledfont)  # remove CR

        title = titlefile.readline()
        if title == "":
            titlefile.seek(0, 0)
            title = titlefile.readline()
def get_string_height(arg, font=None):
    if font:
        display.font(font)
    return display.get_string_height(arg)
def get_string_width(arg, font=None):
    if font:
        display.font(font)
    return display.get_string_width(arg)
def string(x, y, text, font, color):
    if font:
        display.font(font)
    _ = display.cursor(x, y)
    _ = display.textColor(color)
    display.print(text)