Exemplo n.º 1
0
 def convert_markup(self, markup: TextMarkup, tty=True) -> str:
     text, attributes = decompose_tagmarkup(markup)
     if not tty:
         return text
     pos, output = 0, []
     for attr, length in attributes:
         try:
             escape = self._palette_escapes[attr]
         except KeyError:
             escape = self._palette_escapes['default']
         chunk = text[pos:pos + length]
         output.append(f'{escape}{chunk}')
         pos += length
     return ''.join(output)
Exemplo n.º 2
0
    def set_text(self,markup):
        """
        Set content of text widget.

        markup -- see __init__() for description.

        >>> t = Text(u"foo")
        >>> print t.text
        foo
        >>> t.set_text(u"bar")
        >>> print t.text
        bar
        >>> t.text = u"baz"  # not supported because text stores text but set_text() takes markup
        Traceback (most recent call last):
        AttributeError: can't set attribute
        """
        self._text, self._attrib = decompose_tagmarkup(markup)
        self._invalidate()
Exemplo n.º 3
0
    def set_text(self, markup):
        """
        Set content of text widget.

        markup -- see __init__() for description.

        >>> t = Text(u"foo")
        >>> print t.text
        foo
        >>> t.set_text(u"bar")
        >>> print t.text
        bar
        >>> t.text = u"baz"  # not supported because text stores text but set_text() takes markup
        Traceback (most recent call last):
        AttributeError: can't set attribute
        """
        self._text, self._attrib = decompose_tagmarkup(markup)
        self._invalidate()
Exemplo n.º 4
0
    def search_prev(self, keyword):
        prev_index = self.prev_index[1]
        if isinstance(keyword, bytes):
            keyword = keyword.decode("utf8")  # pragma: no cover, py3 would not cover here

        if isinstance(self.text, str):
            if keyword in self.text[:prev_index]:
                start_index = self.text[:prev_index].rindex(keyword)
                self._handle_match_plain_text(keyword, start_index)
                return True
        else:
            for index in reversed(range(0, prev_index)):
                plain_text, _ = decompose_tagmarkup(self.text[index])
                if keyword in plain_text:
                    self._handle_match_markup(keyword, plain_text, index)
                    return True

        self.clear()
        return False
Exemplo n.º 5
0
    def set_caption(self, caption):
        """
        Set the caption markup for this widget.

        caption -- see Text.__init__() for description of markup

        >>> e = Edit("")
        >>> e.set_caption("cap1")
        >>> print e.caption
        cap1
        >>> e.set_caption(('bold', "cap2"))
        >>> print e.caption
        cap2
        >>> e.attrib
        [('bold', 4)]
        >>> e.caption = "cap3"  # not supported because caption stores text but set_caption() takes markup
        Traceback (most recent call last):
        AttributeError: can't set attribute
        """
        self._caption, self._attrib = decompose_tagmarkup(caption)
        self._invalidate()
Exemplo n.º 6
0
    def set_caption(self, caption):
        """
        Set the caption markup for this widget.

        caption -- see Text.__init__() for description of markup

        >>> e = Edit("")
        >>> e.set_caption("cap1")
        >>> print e.caption
        cap1
        >>> e.set_caption(('bold', "cap2"))
        >>> print e.caption
        cap2
        >>> e.attrib
        [('bold', 4)]
        >>> e.caption = "cap3"  # not supported because caption stores text but set_caption() takes markup
        Traceback (most recent call last):
        AttributeError: can't set attribute
        """
        self._caption, self._attrib = decompose_tagmarkup(caption)
        self._invalidate()
Exemplo n.º 7
0
 def set_text(self, markup):
     self.text, self.attrib = decompose_tagmarkup(markup)
     self._invalidate()
Exemplo n.º 8
0
 def set_text(self, markup):
     self.text, self.attrib = decompose_tagmarkup(markup)
     self._invalidate()
Exemplo n.º 9
0
 def get_plain_text(self):
     """ Retrieve the plain text from text_markup """
     text, _ = decompose_tagmarkup(self.text_markup)
     return text
Exemplo n.º 10
0
 def get_plain_text(self):
     text, _ = decompose_tagmarkup(self.text)
     if isinstance(text, bytes):
         return text.decode("utf8")
     else:
         return text
Exemplo n.º 11
0
 def __unicode__(self):
     text, _ = decompose_tagmarkup(self.content)
     return unicode_it(text)