Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
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
Exemplo n.º 10
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'
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
0
 def draw(self):
     buf = DrawBuffer()
     c = self.getColor(2)
     buf.moveChar(0, ' ', c, self.size.x)
     buf.moveStr(0, self.curTime, c)
     self.writeLine(0, 0, self.size.x - 1, 1, buf)
Exemplo n.º 17
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)
Exemplo n.º 18
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)