예제 #1
0
    def show(self):
        #
        # Redraw the menu.
        #
        dis.clear()

        #print('cur=%d ypos=%d' % (self.cursor, self.ypos))

        # subclass hook
        self.early_draw(dis)

        x, y = (10, 2)
        h = 14
        for n in range(self.ypos + PER_M + 1):
            if n + self.ypos >= self.count: break
            msg = self.items[n + self.ypos].label
            is_sel = (self.cursor == n + self.ypos)
            if is_sel:
                dis.dis.fill_rect(0, y, 128, h - 1, 1)
                dis.icon(2, y, 'wedge', invert=1)
                dis.text(x, y, msg, invert=1)
            else:
                dis.text(x, y, msg)

            if msg[0] == ' ' and self.space_indicators:
                dis.icon(x - 2, y + 11, 'space', invert=is_sel)

            if self.chosen is not None and (n + self.ypos) == self.chosen:
                dis.icon(108, y, 'selected', invert=is_sel)

            y += h
            if y > 128: break

        # subclass hook
        self.late_draw(dis)

        if self.count > PER_M:
            dis.scroll_bar(self.ypos / (self.count - PER_M))

        dis.show()
예제 #2
0
async def ux_show_story(msg,
                        title=None,
                        escape=None,
                        sensitive=False,
                        strict_escape=False):
    # show a big long string, and wait for XY to continue
    # - returns character used to get out (X or Y)
    # - can accept other chars to 'escape' as well.
    # - accepts a stream or string
    from main import dis, numpad
    from display import FontLarge

    assert not numpad.disabled  # probably inside a CardSlot context

    lines = []
    if title:
        # kinda weak rendering but it works.
        lines.append('\x01' + title)

    if hasattr(msg, 'readline'):
        msg.seek(0)
        for ln in msg:
            if ln[-1] == '\n':
                ln = ln[:-1]

            if len(ln) > CH_PER_W:
                lines.extend(word_wrap(ln, CH_PER_W))
            else:
                # ok if empty string, just a blank line
                lines.append(ln)

        # no longer needed & rude to our caller, but let's save the memory
        msg.close()
        del msg
        gc.collect()
    else:
        for ln in msg.split('\n'):
            if len(ln) > CH_PER_W:
                lines.extend(word_wrap(ln, CH_PER_W))
            else:
                # ok if empty string, just a blank line
                lines.append(ln)

    # trim blank lines at end, add our own marker
    while not lines[-1]:
        lines = lines[:-1]

    lines.append('EOT')

    #print("story:\n\n\"" + '"\n"'.join(lines))
    #lines[0] = '111111111121234567893'

    top = 0
    H = 5
    ch = None
    pr = PressRelease()
    while 1:
        # redraw
        dis.clear()

        y = 0
        for ln in lines[top:top + H]:
            if ln == 'EOT':
                dis.hline(y + 3)
            elif ln and ln[0] == '\x01':
                dis.text(0, y, ln[1:], FontLarge)
                y += 21
            else:
                dis.text(0, y, ln)

                if sensitive and len(ln) > 3 and ln[2] == ':':
                    dis.mark_sensitive(y, y + 13)

                y += 13

        dis.scroll_bar(top / len(lines))
        dis.show()

        # wait to do something
        ch = await pr.wait()
        if escape and (ch == escape or ch in escape):
            # allow another way out for some usages
            return ch
        elif ch in 'xy':
            if not strict_escape:
                return ch
        elif ch == '0':
            top = 0
        elif ch == '7':  # page up
            top = max(0, top - H)
        elif ch == '9':  # page dn
            top = min(len(lines) - 2, top + H)
        elif ch == '5':  # scroll up
            top = max(0, top - 1)
        elif ch == '8':  # scroll dn
            top = min(len(lines) - 2, top + 1)
예제 #3
0
파일: ux.py 프로젝트: Davdegreat/firmware
async def ux_show_story(msg, title=None, escape=None):
    # show a big long string, and wait for XY to continue
    # - returns character used to get out (X or Y)
    # - can accept other chars to 'escape' as well.
    from main import dis, numpad
    from display import FontLarge

    assert not numpad.disabled  # probably inside a CardSlot context

    lines = []
    if title:
        # kinda weak rendering but it works.
        lines.append('\x01' + title)
        #lines.append('')

    for ln in msg.split('\n'):
        if len(ln) > CH_PER_W:
            lines.extend(word_wrap(ln, CH_PER_W))
        else:
            # ok if empty string, just a blank line
            lines.append(ln)

    # trim blank lines at end, add our own marker
    while not lines[-1]:
        lines = lines[:-1]

    lines.append('EOT')

    #print("story:\n\n\"" + '"\n"'.join(lines))
    #lines[0] = '111111111121234567893'

    top = 0
    H = 5
    ch = None
    pr = PressRelease()
    while 1:
        # redraw
        dis.clear()

        y = 0
        for ln in lines[top:top + H]:
            if ln == 'EOT':
                dis.hline(y + 3)
            elif ln and ln[0] == '\x01':
                dis.text(0, y, ln[1:], FontLarge)
                y += 21
            else:
                dis.text(0, y, ln)
                y += 13

        dis.scroll_bar(top / len(lines))
        dis.show()

        # wait to do something
        ch = await pr.wait()
        if escape and (ch == escape or ch in escape):
            # allow another way out for some usages
            return ch
        elif ch in 'xy':
            return ch
        elif ch == '0':
            top = 0
        elif ch == '5':
            top = max(0, top - 1)
        elif ch == '8':
            top = min(len(lines) - 2, top + 1)