Ejemplo n.º 1
0
 def paint(self):
     wrapped = self._wrap(self.value, width=self.width)[:self.height]
     wrapped = map(partial(self._align, width=self.width), wrapped)
     wrapped = ''.join(
         self.term.move(idx + self.y, self.x) + value
         for idx, value in enumerate(wrapped))
     echo(wrapped)
Ejemplo n.º 2
0
    def paint(self):
        text = self._text_style(self.value)
        if self.term.length(self.value) < self._max_len:
            text = text + self._cursor
        text = self._align(text, fillchar=self._fill_c, width=self._max_len)

        input_field = self._left_l + text + self._right_l  # [_______]

        echo(self.term.move(self.y, self.x) + self._label +
             input_field)  # label
Ejemplo n.º 3
0
    def __exit__(self, _type, _value, _traceback):
        if not self._widgets:
            raise IndexError('Not widgets found')
        self._is_active = True
        if self._parent is None:
            with self.term.cbreak(), self.term.hidden_cursor():
                self.paint()
                self.listen()
        else:
            self.paint()
            self.listen()

        if self._parent is not None:
            self._parent.paint()
        else:
            echo(self.term.clear)
Ejemplo n.º 4
0
 def paint(self):
     echo(self.term.move(self.y, self.x))
     echo(
         self._render.format(check=self._check(self._state),
                             label=self._label))
Ejemplo n.º 5
0
    def paint(self):
        self._page = ceil((self._index + 1) / self._limit)

        echo(self.term.move(self.y, self.x))

        header_height, footer_height = 0, 0
        if self._header != '':
            header_height = len(self._header.split('\n'))
        if self._footer != '':
            footer_height = len(self._footer.split('\n'))

        items = self.items if self.items else self._empty
        first = floor(self._index / self._limit) * self._limit
        max_page = ceil(len(items) / self._limit)

        items = items[first:self._limit + first]

        vars_op = {
            'page': self._page,
            'last': max_page,
            'count': self._len_items
        }

        # Print header
        if self._header != '':
            echo(self._header.format(**vars_op) + '\n')
        self._height = header_height

        # Print elements
        for idx, item in enumerate(items):
            array_text = self._key(item)
            if isinstance(array_text, str):
                array_text = [array_text]
            for index, text in enumerate(array_text):
                echo(self.term.move_x(self.x))
                tmp = self._formater(**{
                    'text': text,
                    'index': index,
                    'lenght': len(array_text)
                })
                pos = self._index % self._limit == idx
                if pos and self._is_menu and text != '':
                    tmp = self._selector(
                        **{
                            'text': text[:self.width],
                            'index': pos,
                            'lenght': len(array_text)
                        })
                tmp += '\n'
                self._height += tmp.count('\n')
                echo(tmp)

        # Print footer
        if self._footer != '':
            echo(self.term.move_x(self.x))
            echo(self._footer.format(**vars_op))
        self._height += footer_height
Ejemplo n.º 6
0
 def paint(self):
     echo(self.term.clear)
     for widget in self._widgets:
         widget.paint()
Ejemplo n.º 7
0
 def __enter__(self):
     echo(self.term.clear)
     return self
Ejemplo n.º 8
0
 def destroy(self):
     line = (' ' * self.width) + '\n'
     lines = line * self.height
     echo(self.term.move(self.y, self.x) + lines)
Ejemplo n.º 9
0
 def destroy(self):
     wrapped_text = self._wrap(self._prev, width=self.width)[:self.height]
     lines = ''.join(
         self.term.move(idx + self.y, self.x) + ' ' * self.term.length(text)
         for idx, text in enumerate(wrapped_text))
     echo(lines)