Ejemplo n.º 1
0
    def draw(self):
        buf = DrawBuffer()

        colorBack = self.getColor(1)
        color = [colorBack, colorBack]
        if not self.solved:
            color[1] = self.getColor(2)

        for i in range(4):
            buf.moveChar(0, ' ', colorBack, 18)
            if i == 1:
                buf.moveStr(13, _('Move'), colorBack)
            if i == 2:
                tmp = '{}'.format(self.moves)
                buf.moveStr(14, tmp, colorBack)

            for j in range(4):
                tmp = ' {} '.format(self.board[i][j])
                if self.board[i][j] == ' ':
                    buf.moveStr(j * 3, tmp, color[0])
                else:
                    buf.moveStr(
                        j * 3, tmp,
                        color[self.boardMap[ord(self.board[i][j]) - ord('A')]])

            self.writeLine(0, i, 18, 1, buf)
Ejemplo n.º 2
0
    def draw(self):
        b = DrawBuffer()
        color = self.getColor(0x0201)

        b.moveChar(0, ' ', color, self.size.x)
        b.moveCStr(1, self.text, color)
        self.writeLine(0, 0, self.size.x, 1, b)
Ejemplo n.º 3
0
    def draw(self):
        b = DrawBuffer()

        if self.state & sfFocused:
            color = self.getColor(2)
        else:
            color = self.getColor(1)

        b.moveChar(0, ' ', color, self.size.x)

        buf = ''.join(
            self.current.data[self.current.firstPos:self.current.firstPos +
                              self.size.x - 2])

        b.moveStr(1, buf, color)

        if self.__canScroll(1):
            b.moveChar(self.size.x - 1, self.rightArrow, self.getColor(4), 1)

        if self.state & sfSelected:
            if self.__canScroll(-1):
                b.moveChar(0, self.leftArrow, self.getColor(4), 1)

            left = self.current.selStart - self.current.firstPos
            right = self.current.selEnd - self.current.firstPos

            left = max(0, left)
            right = min(self.size.x - 2, right)
            if left < right:
                b.moveChar(left + 1, 0, self.getColor(3), right - left)

        self.writeLine(0, 0, self.size.x, self.size.y, b)
        self.setCursor(self.current.pos - self.current.firstPos + 1, 0)
Ejemplo n.º 4
0
    def draw(self):
        minY = min(self.size.y, self.terminal.rows)
        minX = min(self.size.x, self.terminal.cols)

        for y in range(minY):
            buffer = DrawBuffer(True)
            for x in range(minX):
                cell = self.terminal.cells[y][x]
                attr = cell.attr
                c = cell.color
                if attr & curses.A_REVERSE:
                    c = self.reverseColor(c)

                buffer.putAttribute(x, c)
                buffer.putChar(x, chr(cell.char))
            self.writeLine(0, y, minX, 1, buffer)

        self.setCursor(self.terminal.currCol, self.terminal.currRow)

        if self.terminal.state & STATE_CURSOR_INVIS:
            self.hideCursor()
        else:
            self.showCursor()

        if self.terminal.state & STATE_TITLE_CHANGED:
            self.window.setTitle(self.terminal.title)
            self.terminal.state &= ~STATE_TITLE_CHANGED
Ejemplo n.º 5
0
    def draw(self):
        # Assumes FileDialog owner
        path = self.owner.wildCard

        if not (':' in path or '/' in path):
            path = os.path.join(os.path.abspath(self.owner.directory),
                                self.owner.wildCard)
            path = fexpand(path)

        color = self.getColor(0x01)
        b = DrawBuffer()

        b.moveChar(0, ' ', color, self.size.x)
        b.moveStr(1, path, color)
        self.writeLine(0, 0, self.size.x, 1, b)

        b.moveChar(0, ' ', color, self.size.x)
        b.moveStr(0, self.__fileBlock.name[:19], color)

        if self.__fileBlock.name:
            buf = self.getNiceSize(self.__fileBlock.size)
            b.moveStr(26 - len(buf), buf, color)
            dt = self.__fileBlock.time
            b.moveStr(27, dt.strftime('%Y-%m-%d %I:%M %p'), color)

        self.writeLine(0, 1, self.size.x, 1, b)
        b.moveChar(0, ' ', color, self.size.x)
        self.writeLine(0, 2, self.size.x, self.size.y - 2, b)
Ejemplo n.º 6
0
    def draw(self):
        """
        Draws the `ListViewer` object with the default palette by repeatedly
        calling `getText()` for each visible item. Takes into account the
        `focused` and `selected` items and whether the view is `sfActive`.
        """
        focusedColor = 0
        b = DrawBuffer()

        active_ = (self.state & sfSelected | sfActive) == (sfSelected
                                                           | sfActive)
        if active_:
            normalColor = self.getColor(1)
            focusedColor = self.getColor(3)
            selectedColor = self.getColor(4)
        else:
            normalColor = self.getColor(2)
            selectedColor = self.getColor(4)

        if self.hScrollBar:
            indent = self.hScrollBar.value
        else:
            indent = 0

        colWidth = self.size.x // self.numCols + 1

        for i in range(self.size.y):
            for j in range(self.numCols):
                item = j * self.size.y + i + self.topItem
                curCol = j * colWidth

                if active_ and (self.focused == item) and (self._range > 0):
                    color = focusedColor
                    self.setCursor(curCol + 1, i)
                    scOff = 2
                elif item < self._range and self.isSelected(item):
                    color = selectedColor
                    scOff = 2
                else:
                    color = normalColor
                    scOff = 4

                b.moveChar(curCol, ' ', color, colWidth)

                if item < self._range:
                    text = self.getText(item, colWidth +
                                        indent)[indent:indent + colWidth]

                    b.moveStr(curCol + 1, text, color)
                    if showMarkers:
                        b.putChar(curCol, SPECIAL_CHARS[scOff])
                        b.putChar(curCol + colWidth - 2,
                                  SPECIAL_CHARS[scOff + 1])
                elif i == 0 and j == 0:
                    b.moveStr(curCol + 1, self.emptyText, self.getColor(1))

                b.moveChar(curCol + colWidth - 1, self.separatorChar,
                           self.getColor(5), 1)
            self.writeLine(0, i, self.size.x, 1, b)
Ejemplo n.º 7
0
    def drawLines(self, y, count, linePtr):
        color = self.getColor(0x0201)

        for line in range(y, y + count):
            b = DrawBuffer()
            self.formatLine(b, linePtr, self.delta.x + self.size.x, color)
            self.writeBuf(0, line, self.size.x, 1, b[self.delta.x:])
            linePtr = self.nextLine(linePtr)
Ejemplo n.º 8
0
    def draw(self):
        b = DrawBuffer()
        color = self.getColor(0x01)
        offset = self.size.x - len(self._text) if self._rightJustify else 0

        b.moveChar(0, ' ', color, self.size.x)
        b.moveStr(offset, self._text, color)
        self.writeBuf(0, 0, self.size.x, 1, b)
Ejemplo n.º 9
0
    def draw(self):
        b = DrawBuffer()
        s = 'Background Example'
        x = 0
        while x < self.size.x:
            b.moveStr(x, s, 0x17)
            x += len(s)

        self.writeLine(0, 0, self.size.x, self.size.y, b)
Ejemplo n.º 10
0
 def test_moveBuf(self):
     """
     Test Move Buf
     """
     b = DrawBuffer()
     b.moveBuf(0, 'abcdefghijk', 0, 5)
     data = list(b._data[:10])
     result = [ord(c) for c in 'abcde\0\0\0\0\0']
     assert data == result, ("_data is", data, "vs", result)
Ejemplo n.º 11
0
    def draw(self):
        color = self.getColor(1)

        buf = DrawBuffer()
        i = self.size.x - len(self.number) - 2

        buf.moveChar(0, ' ', color, self.size.x)
        buf.moveChar(1, self.sign, color, 1)
        buf.moveStr(i + 1, self.number, color)
        self.writeLine(0, 0, self.size.x, 1, buf)
Ejemplo n.º 12
0
    def drawPos(self, pos):
        b = DrawBuffer()
        s = self.getSize() - 1
        b.moveChar(0, self.chars[0], self.getColor(2), 1)

        if self.maxVal == self.minVal:
            b.moveChar(1, self.chars[4], self.getColor(1), s - 1)
        else:
            b.moveChar(1, self.chars[2], self.getColor(1), s - 1)
            b.moveChar(pos, self.chars[3], self.getColor(3), 1)

        b.moveChar(s, self.chars[1], self.getColor(2), 1)
        self.writeBuf(0, 0, self.size.x, self.size.y, b)
Ejemplo n.º 13
0
 def draw(self):
     c = self.getColor(0x0301)
     for i in range(self.size.y):
         b = DrawBuffer()
         b.moveChar(0, ' ', c, self.size.x)
         if self.delta.y + i < len(self.fileLines):
             p = self.fileLines[self.delta.y + i]
             if (not p) or len(p) < self.delta.x:
                 s = ''
             else:
                 s = p[self.delta.x: self.delta.x + self.size.x].rstrip()
             b.moveStr(0, s, c)
         self.writeBuf(0, i, self.size.x, 1, b)
Ejemplo n.º 14
0
    def drawState(self, down):
        b = DrawBuffer()
        ch = ' '

        if self.state & sfDisabled:
            cButton = self.getColor(0x0404)
        else:
            cButton = self.getColor(0x0501)
            if self.state & sfActive:
                if self.state & sfSelected:
                    cButton = self.getColor(0x0703)
                elif self._amDefault:
                    cButton = self.getColor(0x0602)

        cShadow = self.getColor(8)

        s = self.size.x - 1
        titleRow = self.size.y // 2 - 1
        for y in range(self.size.y - 1):
            b.moveChar(0, ' ', cButton, self.size.x)
            b.putAttribute(0, cShadow)
            if down:
                b.putAttribute(1, cShadow)
                ch = ' '
                i = 2
            else:
                b.putAttribute(s, cShadow)
                if self.showMarkers:
                    ch = ' '
                else:
                    if y == 0:
                        b.putChar(s, self.shadows[0])
                    else:
                        b.putChar(s, self.shadows[1])

                    ch = self.shadows[2]
                i = 1

            if y == titleRow and self.title:
                self.__drawTitle(b, s, i, cButton, down)

            if self.showMarkers and down:
                b.putChar(1, self.markers[0])
                b.putChar(s - 1, self.markers[1])

            self.writeLine(0, y, self.size.x, 1, b)

        b.moveChar(0, ' ', cShadow, 2)
        b.moveChar(2, ch, cShadow, s - 1)

        self.writeLine(0, self.size.y - 1, self.size.x, 1, b)
Ejemplo n.º 15
0
    def draw(self):
        b = DrawBuffer()
        b.moveChar(0, ' ', 0x70, self.size.x)
        for y in range(self.size.y + 1):
            if y < 4:
                for x in range(4):
                    c = y * 4 + x
                    b.moveChar(x * 3, self.icon, c, 3)
                    if c == self._color:
                        b.putChar(x * 3 + 1, self.icon_reversed)
                        if c == 0:
                            b.putAttribute(x * 3 + 1, 0x70)

            self.writeLine(0, y, self.size.x, 1, b)
Ejemplo n.º 16
0
    def draw(self):
        b = DrawBuffer()
        focusedColor = self.getColor(3)
        selectedColor = self.getColor(4)

        if self.headingMode:
            normalColor = self.getColor(6)
        elif self.state & (sfSelected | sfActive) == (sfSelected | sfActive):
            normalColor = self.getColor(1)
        else:
            normalColor = self.getColor(2)

        posColumn = 0
        for column in range(self.leftColumn, self.numColumns + 1):
            if posColumn > self.size.x:
                break
            if column < self.numColumns:
                thisWidth = self.columnWidth[column]
            else:
                thisWidth = self.size.x - posColumn + 1
            for i in range(self.size.y):
                row = i + self.topRow
                color = normalColor
                scOff = 0
                if self.headingMode:
                    scOff = 4
                elif (self.state & (sfSelected | sfActive) == (sfSelected | sfActive) and
                      self.focusedRow == row and self.focusedColumn == column and self.numRows):
                    color = focusedColor
                    self.setCursor(posColumn + 1, i)
                    scOff = 0
                elif column < self.numColumns and row < self.numRows and self.isSelected(column, row):
                    color = selectedColor
                    scOff = 4

                b.moveChar(0, ' ', color, thisWidth)
                if column < self.numColumns and row < self.numRows:
                    text = self.getText(column, row, thisWidth)
                    b.moveStr(1, text, color)
                    if self.showMarkers:
                        b.putChar(0, SPECIAL_CHARS[scOff])
                        b.putChar(thisWidth - 2, SPECIAL_CHARS[scOff + 1])
                elif not (i or column):
                    b.moveStr(1, _('<empty>'), self.getColor(1))

                if not self.headingMode and column < self.numColumns - 1 and row < self.numRows:
                    b.moveChar(thisWidth - 1, '│', self.getColor(5), 1)
                self.writeLine(posColumn, i, thisWidth, 1, b)
            posColumn += thisWidth
Ejemplo n.º 17
0
def confirmExit(stdscr):
    # Break current circular dependency
    from vindauga.types.screen import Screen
    b = DrawBuffer()
    msg = _('Warning: are you sure you want to quit ?')

    height, width = stdscr.getmaxyx()
    b.moveChar(0, ' ', 0x4F, width)

    b.moveStr(max((width - (len(msg) - 1)) // 2, 0), msg, 0x4f)
    Screen.writeRow(0, 0, b._data, width)
    stdscr.timeout(-1)
    key = stdscr.getch()
    stdscr.timeout(0)
    return chr(key & 0xFF).upper() == 'Y'
Ejemplo n.º 18
0
    def draw(self):
        b = DrawBuffer()

        if self._light:
            color = self.getColor(0x0402)
            scOff = 0
        else:
            color = self.getColor(0x0301)
            scOff = 4

        b.moveChar(0, ' ', color, self.size.x)
        if self._text:
            b.moveCStr(1, self._text, color)

        if self.showMarkers:
            b.putChar(0, SPECIAL_CHARS[scOff])

        self.writeLine(0, 0, self.size.x, 1, b)
Ejemplo n.º 19
0
    def draw(self):
        b = DrawBuffer()

        if not self.state & sfDragging:
            color = self.getColor(1)
            frame = self.dragFrame
        else:
            color = self.getColor(2)
            frame = self.normalFrame

        b.moveChar(0, frame, color, self.size.x)

        if self._modified:
            b.putChar(0, '☼')

        s = ' {:3d}:{:3d} '.format(self._location.y + 1, self._location.x + 1)

        b.moveCStr(8 - s.find(':'), s, color)
        self.writeBuf(0, 0, self.size.x, 1, b)
Ejemplo n.º 20
0
    def __drawSelect(self, selected):
        b = DrawBuffer()
        cNormal = self.getColor(0x0301)
        cSelect = self.getColor(0x0604)
        cNormDisabled = self.getColor(0x0202)
        cSelDisabled = self.getColor(0x0505)

        b.moveChar(0, ' ', cNormal, self.size.x)
        i = 0

        textItems = (item for item in self._items if item.text)
        for item in textItems:
            textLen = nameLength(item.text)
            if i + textLen < self.size.x:
                if self.commandEnabled(item.command):
                    if item is selected:
                        color = cSelect
                    else:
                        color = cNormal
                else:
                    if item is selected:
                        color = cSelDisabled
                    else:
                        color = cNormDisabled

                b.moveChar(i, ' ', color, 1)
                b.moveCStr(i + 1, item.text, color)
                b.moveChar(i + textLen + 1, ' ', color, 1)
            i += textLen + 2

        if i < self.size.x - 2:
            hintBuf = self.hint(self.helpCtx)
            if hintBuf:
                b.moveStr(i, self.hintSeparator, cNormal)
                i += len(self.hintSeparator)
                if len(hintBuf) + i > self.size.x:
                    hintBuf = hintBuf[:self.size.x - i]

                b.moveStr(i, hintBuf, cNormal)
                i += len(hintBuf)

        self.writeLine(0, 0, self.size.x, 1, b)
Ejemplo n.º 21
0
    def draw(self):
        nBuf = DrawBuffer()
        text = '{:-3d} %'.format(self.curPercent)
        colorNormal = self.getColor(1)
        dill = 0

        if self.total:
            fill = self.progress * self.size.x / self.total
            dill = int(fill)
            diff = fill - dill
            nBuf.moveChar(0, self.FILL_CHAR, colorNormal, dill)
            if diff > .125:
                f = int(diff * 8) - 1
                nBuf.moveChar(dill, self.CHARS[f], colorNormal, 1)
                dill += 1

        nBuf.moveChar(dill, self.backChar, colorNormal, self.size.x - dill)
        numOffset = max(0, (dill // 2) - 3)
        nBuf.moveStr(numOffset, text, colorNormal)
        self.writeLine(0, 0, self.size.x, 1, nBuf)
Ejemplo n.º 22
0
    def draw(self):
        """
        Draws the framed menu box and associated menu items in the default
        colors.
        """
        b = DrawBuffer()
        cSelect = self.getColor(0x0604)
        cNormDisabled = self.getColor(0x0202)
        cSelDisabled = self.getColor(0x0505)
        y = 0
        color = self.cNormal
        self.__frameLine(b, 0, color)
        self.writeBuf(0, y, self.size.x, 1, b)
        y += 1

        if self.menu:
            for p in self.menu.items:
                color = self.cNormal
                if not p.name:
                    self.__frameLine(b, 15, color)
                else:
                    if p.disabled:
                        if p is self._current:
                            color = cSelDisabled
                        else:
                            color = cNormDisabled
                    elif p is self._current:
                        color = cSelect

                    self.__frameLine(b, 10, color)
                    b.moveCStr(3, p.name, color)
                    if not p.command:
                        b.putChar(self.size.x - 4, self.subMenuIndicator)
                    elif p.param:
                        b.moveStr(self.size.x - 3 - len(p.param), p.param,
                                  color)
                self.writeBuf(0, y, self.size.x, 1, b)
                y += 1
        color = self.cNormal
        self.__frameLine(b, 5, color)
        self.writeBuf(0, y, self.size.x, 1, b)
Ejemplo n.º 23
0
    def draw(self):
        color = self.getColor(1)
        s = self.getText()
        b = DrawBuffer()
        lines = s.splitlines()
        y = 0

        # For each line, wrap at width, until we get to our height
        for line in lines:
            if y > self.size.y:
                return

            center = False
            # line = line.strip()
            if not line:
                # Empty
                self.drawEmptyLine(y, color)
                y += 1
                continue

            # Centered
            if line[0] == '\x03':
                center = True
                line = line[1:]

            # Wrap the lines
            for subLine in textwrap.wrap(line, self.size.x):
                if center:
                    subLine = subLine.center(self.size.x, ' ')
                else:
                    subLine = subLine.ljust(self.size.x)
                b.moveStr(0, subLine, color)
                self.writeLine(0, y, self.size.x, 1, b)
                y += 1
                if y > self.size.y:
                    return

        # Draw the rest of the empty lines
        b.moveChar(0, ' ', color, self.size.x)
        for yy in range(y, self.size.y + 1):
            self.writeLine(0, yy, self.size.x, 1, b)
Ejemplo n.º 24
0
    def draw(self):
        current = 1 - dayOfWeek(1, self.month, self.year)
        days = daysInMonth[self.month]
        if self.month == 2:
            if (self.year % 4) == 0:
                days += 1

        buf = DrawBuffer()

        color = self.getColor(6)
        boldColor = self.getColor(7)

        buf.moveChar(0, ' ', color, 22)
        s1 = ' ▲ {:>9} {:4d} ▼ '.format(monthNames[self.month], self.year)
        buf.moveStr(0, s1, self.getColor(8))
        self.writeLine(0, 0, 22, 1, buf)

        buf.moveChar(0, ' ', color, 22)
        buf.moveStr(0, 'Su Mo Tu We Th Fr Sa', self.getColor(5))
        self.writeLine(0, 1, 22, 1, buf)

        for i in range(1, 7):
            buf.moveChar(0, ' ', color, 22)
            for j in range(7):
                if current < 1 or current > days:
                    buf.moveStr(j * 3, '   ', color)
                else:
                    s2 = '{:2d}'.format(current)

                    if (self.year == self.curYear and
                            self.month == self.curMonth and
                            current == self.curDay):
                        buf.moveStr(j * 3, s2, boldColor)
                    else:
                        buf.moveStr(j * 3, s2, color)
                current += 1

            self.writeLine(0, i + 1, 22, 1, buf)
Ejemplo n.º 25
0
    def draw(self):
        w = len(lines[0])
        h = len(lines)
        b = DrawBuffer()
        # leftX = (self.size.x - 80) // 2
        # rightX = leftX + 80
        leftX = (self.size.x - w) // 2
        rightX = leftX + w

        # topY = (self.size.y - 23) // 2
        # bottomY = topY + 23
        topY = (self.size.y - h) // 2
        bottomY = topY + h

        for i in range(self.size.y):
            for j in range(self.size.x):

                if leftX <= j < rightX and topY <= i < bottomY:
                    b.moveChar(j, lines[i - topY][j - leftX],
                               self.getColor(0x01), 1)
                else:
                    b.moveChar(j, self._pattern, self.getColor(0x01), 1)
            self.writeLine(0, i, self.size.x, 1, b)
Ejemplo n.º 26
0
    def drawMultiBox(self, icon, marker):
        b = DrawBuffer()

        cNorm = self.getColor(0x0301)
        cSel = self.getColor(0x0402)
        cDis = self.getColor(0x0505)

        for i in range(self.size.y):
            b.moveChar(0, ' ', cNorm, self.size.x)

            for j in range((len(self._strings) - 1) // self.size.y + 1):
                cur = j * self.size.y + i
                if cur < len(self._strings):
                    col = self.__column(cur)

                    if col < self.size.x:
                        if not self.buttonState(cur):
                            color = cDis
                        elif (cur == self._sel) and (self.state & sfSelected):
                            color = cSel
                        else:
                            color = cNorm
                        b.moveChar(col, ' ', color, self.size.x - col)
                        b.moveCStr(col, icon, color)
                        b.putChar(col + 2, marker[self.multiMark(cur)])
                        b.moveCStr(col + 5, self._strings[cur], color)

                        if (self.showMarkers
                                and ((self.state & sfSelected) != 0
                                     and cur == self._sel)):
                            b.putChar(col, SPECIAL_CHARS[0])
                            b.putChar(
                                self.__column(cur + self.size.y) - 1,
                                SPECIAL_CHARS[1])

            self.writeBuf(0, i, self.size.x, 1, b)
        self.setCursor(self.__column(self._sel) + 2, self.__row(self._sel))
Ejemplo n.º 27
0
    def draw(self):
        """
        Draws the menu bar with the default palette. The `MenuItem.name`
        and `MenuItem.disabled` data members of each `MenuItem`
        object in the menu linked list are read to give the menu legends in
        the correct colors.

        The current (selected) item is highlighted.
        """
        b = DrawBuffer()
        cNormal = self.getColor(0x0301)
        b.moveChar(0, ' ', cNormal, self.size.x)
        if self.menu and self.menu.items:
            x = 1
            items = (item for item in self.menu.items if item.name)
            for p in items:
                nameLen = nameLength(p.name)
                if x + nameLen < self.size.x:
                    color = self._chooseColor(p)
                    b.moveChar(x, ' ', color, 1)
                    b.moveCStr(x + 1, p.name, color)
                    b.moveChar(x + nameLen + 1, ' ', color, 1)
                x += (nameLen + 2)
        self.writeBuf(0, 0, self.size.x, 1, b)
Ejemplo n.º 28
0
 def draw(self):
     b = DrawBuffer()
     b.moveStr(0, self.icon, self.getColor(0x01))
     self.writeLine(0, 0, self.size.x, self.size.y, b)
Ejemplo n.º 29
0
 def draw(self):
     buf = DrawBuffer()
     c = self.getColor(int(self.clicked) + 1)
     buf.moveChar(0, ' ', c, self.size.x)
     buf.moveStr(0, self._text, c)
     self.writeLine(0, 0, self.size.x, 1, buf)
Ejemplo n.º 30
0
 def drawEmptyLine(self, y, color):
     b = DrawBuffer()
     b.moveChar(0, ' ', color, self.size.x)
     self.writeLine(0, y, self.size.x, 1, b)