How to use the socli.tui.UnicodeText function in socli

To help you get started, we’ve selected a few socli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gautamkrishnar / socli / socli / tui.py View on Github external
def set_description(self):
        """
        We must use a box adapter to get the text to scroll when this widget is already in
        a Pile from the main question page. Scrolling is necessary for long questions which are longer
        than the length of the terminal.
        """
        self.content = self.description.strip("\n").split("\n")
        self._w = ScrollableTextBox(self.content)

    def __len__(self):
        """ return number of rows in this widget """
        return len(self.content)


class QuestionStats(UnicodeText):
    """ Stats of the question,"""

    def __init__(self, stats):
        text = ["\n", ('metadata', stats)]
        UnicodeText.__init__(self, text)


class QuestionURL(UnicodeText):
    """ url of the question """

    def __init__(self, url):
        text = ["\n", ('heading', 'Question URL: '), url]
        UnicodeText.__init__(self, text)
github gautamkrishnar / socli / socli / tui.py View on Github external
self.screenHeight, screenWidth = subprocess.check_output(
            ['stty', 'size']).split()
        self.question_text = urwid.BoxAdapter(QuestionDescription(question_desc),
                                              int(max(1, (int(self.screenHeight) - 9) / 2)))
        answer_frame = urwid.Frame(
            header=urwid.Pile([
                display_header,
                QuestionTitle(question_title),
                self.question_text,
                QuestionStats(question_stats),
                urwid.Divider('-')
            ]),
            body=self.answer_text,
            footer=urwid.Pile([
                QuestionURL(question_url),
                UnicodeText(
                    u'\u2191: previous answer, \u2193: next answer, o: open in browser, \u2190: back, q: quit')
            ])
        )
        return answer_frame
github gautamkrishnar / socli / socli / tui.py View on Github external
self._w = ScrollableTextBox(self.content)

    def __len__(self):
        """ return number of rows in this widget """
        return len(self.content)


class QuestionStats(UnicodeText):
    """ Stats of the question,"""

    def __init__(self, stats):
        text = ["\n", ('metadata', stats)]
        UnicodeText.__init__(self, text)


class QuestionURL(UnicodeText):
    """ url of the question """

    def __init__(self, url):
        text = ["\n", ('heading', 'Question URL: '), url]
        UnicodeText.__init__(self, text)
github gautamkrishnar / socli / socli / tui.py View on Github external
def __init__(self, content):
        """
        :param content: text string to be displayed
        """
        lines = [UnicodeText(line) for line in content]
        body = urwid.SimpleFocusListWalker(lines)
        urwid.ListBox.__init__(self, body)
github gautamkrishnar / socli / socli / tui.py View on Github external
urwid.Text.__init__(self, text)

    @classmethod
    def to_unicode(cls, markup):
        """convert urwid text markup object to utf-8"""
        try:
            return pr.display_str(markup)
        except AttributeError:
            mapped = [cls.to_unicode(i) for i in markup]
            if isinstance(markup, tuple):
                return tuple(mapped)
            else:
                return mapped


class Header(UnicodeText):
    """
    Header of the question page. Event messages are recorded here.
    """

    def __init__(self):
        self.current_event = None
        UnicodeText.__init__(self, '')

    def event(self, event, message):
        self.current_event = event
        self.set_text(message)

    def clear(self, event):
        if self.current_event == event:
            self.set_text('')
github gautamkrishnar / socli / socli / tui.py View on Github external
body = urwid.SimpleFocusListWalker(lines)
        urwid.ListBox.__init__(self, body)

    def mouse_event(self, size, event, button, col, row, focus):
        SCROLL_WHEEL_UP = 4
        SCROLL_WHEEL_DOWN = 5
        if button == SCROLL_WHEEL_DOWN:
            self.keypress(size, 'down')
        elif button == SCROLL_WHEEL_UP:
            self.keypress(size, 'up')
        else:
            return False
        return True


class QuestionTitle(UnicodeText):
    """ Title of the question,"""

    def __init__(self, title):
        text = ["Question: ", ('title', title), "\n"]
        UnicodeText.__init__(self, text)


# Must convert to BoxAdapter object if used as a flow widget.
class QuestionDescription(urwid.WidgetWrap):
    """ Description of the question """

    def __init__(self, description):
        urwid.WidgetWrap.__init__(self, UnicodeText(''))
        self.description = description
        self.set_description()
github gautamkrishnar / socli / socli / tui.py View on Github external
def __init__(self, description):
        urwid.WidgetWrap.__init__(self, UnicodeText(''))
        self.description = description
        self.set_description()