Пример #1
0
    def _reflowed_text(self):
        """
        The text as should be formatted on the screen.

        This is an array of tuples of the form (text, value line, value column offset) where
        the line and column offsets are indeces into the value (not displayed glyph coordinates).
        """
        if self._reflowed_text_cache is None:
            if self._line_wrap:
                self._reflowed_text_cache = []
                limit = self._w - self._offset
                for i, line in enumerate(self._value):
                    column = 0
                    while self.string_len(str(line)) >= limit:
                        sub_string = _enforce_width(
                            line, limit, self._frame.canvas.unicode_aware)
                        self._reflowed_text_cache.append(
                            (sub_string, i, column))
                        line = line[len(sub_string):]
                        column += len(sub_string)
                    self._reflowed_text_cache.append((line, i, column))
            else:
                self._reflowed_text_cache = [
                    (x, i, 0) for i, x in enumerate(self._value)
                ]

        return self._reflowed_text_cache
Пример #2
0
    def update(self, frame_no):
        self._draw_label()

        # Calculate new visible limits if needed.
        self._start_column = min(self._start_column, self._column)
        self._start_column += _find_min_start(
            self._value[self._start_column:self._column + 1], self.width,
            self._frame.canvas.unicode_aware,
            self._column >= self.string_len(self._value))

        # Render visible portion of the text.
        (colour, attr, background
         ) = self._pick_colours("readonly" if self._readonly else "edit_text")
        text = self._value[self._start_column:]
        text = _enforce_width(text, self.width,
                              self._frame.canvas.unicode_aware)
        if self._hide_char:
            text = self._hide_char[0] * len(text)
        text += " " * (self.width - self.string_len(text))
        self._frame.canvas.print_at(text, self._x + self._offset, self._y,
                                    colour, attr, background)

        # Since we switch off the standard cursor, we need to emulate our own
        # if we have the input focus.
        if self._has_focus:
            text_width = self.string_len(text[:self._column -
                                              self._start_column])
            self._draw_cursor(
                " " if self._column >= len(self._value) else self._hide_char[0]
                if self._hide_char else self._value[self._column], frame_no,
                self._x + self._offset + text_width, self._y)
Пример #3
0
    def _print_cell(self, space, text, align, width, x, y, foreground, attr,
                    background):
        # Sort out spacing first.
        if space:
            self._frame.canvas.print_at(self._space_delimiter * space, x, y,
                                        foreground, attr, background)

        # Now align text, taking into account double space glyphs.
        paint_text = _enforce_width(text, width,
                                    self._frame.canvas.unicode_aware)
        text_size = self.string_len(str(paint_text))
        if text_size < width:
            # Default does no alignment or padding.
            buffer_1 = buffer_2 = ""
            if align == "<":
                buffer_2 = " " * (width - text_size)
            elif align == ">":
                buffer_1 = " " * (width - text_size)
            elif align == "^":
                start_len = int((width - text_size) / 2)
                buffer_1 = " " * start_len
                buffer_2 = " " * (width - text_size - start_len)
            paint_text = paint_text.join([buffer_1, buffer_2])
        self._frame.canvas.paint(str(paint_text),
                                 x + space,
                                 y,
                                 foreground,
                                 attr,
                                 background,
                                 colour_map=paint_text.colour_map if hasattr(
                                     paint_text, "colour_map") else None)
Пример #4
0
    def update(self, frame_no):
        self._draw_label()

        # Prepare to calculate new visible limits if needed.
        height = self._h
        width = self._w - self._offset

        # Clear out the existing box content
        (colour, attr, background) = self._frame.palette["field"]
        for i in range(height):
            self._frame.canvas.print_at(" " * self.width,
                                        self._x + self._offset, self._y + i,
                                        colour, attr, background)

        # Don't bother with anything else if there are no options to render.
        if len(self._options) <= 0:
            return

        # Decide whether we need to show or hide the scroll bar and adjust width accordingly.
        if self._add_scroll_bar:
            self._add_or_remove_scrollbar(width, height, 0)
        if self._scroll_bar:
            width -= 1

        # Render visible portion of the text.
        y_offset = 0
        if self._centre:
            # Always make selected text the centre - not very compatible with scroll bars, but
            # there's not much else I can do here.
            self._start_line = self._line - (height // 2)
        start_line = self._start_line
        if self._start_line < 0:
            y_offset = -self._start_line
            start_line = 0
        for i, (text, _) in enumerate(self._options):
            if start_line <= i < start_line + height - y_offset:
                colour, attr, background = self._pick_colours(
                    "field", i == self._line)
                if len(text) > width:
                    text = text[:width - 3] + "..."
                paint_text = _enforce_width(text, width,
                                            self._frame.canvas.unicode_aware)
                paint_text += " " * (width - self.string_len(str(paint_text)))
                self._frame.canvas.paint(
                    str(paint_text),
                    self._x + self._offset,
                    self._y + y_offset + i - start_line,
                    colour,
                    attr,
                    background,
                    colour_map=paint_text.colour_map if hasattr(
                        paint_text, "colour_map") else None)

        # And finally draw any scroll bar.
        if self._scroll_bar:
            self._scroll_bar.update()
Пример #5
0
    def update(self, frame_no):
        self._draw_label()

        # This widget only ever needs display the current selection - the separate Frame does all
        # the clever stuff when it has the focus.
        text = "" if self._line is None else self._options[self._line][0]
        (colour, attr,
         background) = self._pick_colours("field", selected=self._has_focus)
        self._frame.canvas.print_at(
            "[{:{}}]".format(
                _enforce_width(text, self.width - 2,
                               self._frame.canvas.unicode_aware),
                self.width - 2), self._x + self._offset, self._y, colour, attr,
            background)
Пример #6
0
    def update(self, frame_no):
        self._draw_label()

        # Calculate new visible limits if needed.
        height = self._h
        if not self._line_wrap:
            self._start_column = min(self._start_column, self._column)
            self._start_column += _find_min_start(
                str(self._value[self._line][self._start_column:self._column +
                                            1]), self.width,
                self._frame.canvas.unicode_aware,
                self._column >= self.string_len(str(self._value[self._line])))

        # Clear out the existing box content
        (colour, attr, background
         ) = self._pick_colours("readonly" if self._readonly else "edit_text")
        self._frame.canvas.clear_buffer(colour, attr, background,
                                        self._x + self._offset, self._y,
                                        self.width, height)

        # Convert value offset to display offsets
        # NOTE: _start_column is always in display coordinates.
        display_text = self._reflowed_text
        display_start_column = self._start_column
        display_line, display_column = 0, 0
        for i, (_, line, col) in enumerate(display_text):
            if line < self._line or (line == self._line
                                     and col <= self._column):
                display_line = i
                display_column = self._column - col

        # Restrict to visible/valid content.
        self._start_line = max(
            0,
            max(display_line - height + 1, min(self._start_line,
                                               display_line)))

        # Render visible portion of the text.
        for line, (text, _, _) in enumerate(display_text):
            if self._start_line <= line < self._start_line + height:
                paint_text = _enforce_width(text[display_start_column:],
                                            self.width,
                                            self._frame.canvas.unicode_aware)
                self._frame.canvas.paint(
                    str(paint_text),
                    self._x + self._offset,
                    self._y + line - self._start_line,
                    colour,
                    attr,
                    background,
                    colour_map=paint_text.colour_map if hasattr(
                        paint_text, "colour_map") else None)

        # Since we switch off the standard cursor, we need to emulate our own
        # if we have the input focus.
        if self._has_focus:
            line = str(display_text[display_line][0])
            logger.debug("Cursor: %d,%d", display_start_column, display_column)
            text_width = self.string_len(
                line[display_start_column:display_column])
            self._draw_cursor(
                " " if display_column >= len(line) else line[display_column],
                frame_no, self._x + self._offset + text_width,
                self._y + display_line - self._start_line)