Пример #1
0
 def render(self, size, focus=False):
     if self._cache_size != size:
         old = self.old.render((size[0], size[1]))
         new = self.new.render((size[0], size[1]))
         self._oldbuf = self._to_buf(old)
         self._newbuf = self._to_buf(new)
         self._cache_size = size
     line_list = []
     attr_list = []
     line_text = ''
     line_attrs = []
     current_attr = [None, 0]
     current_rgb = None
     current_props = None
     background = urwid.AttrSpec('light gray', 'black')
     for i in range(len(self._oldbuf)):
         oldattr, oldcs, oldchar = self._oldbuf[i]
         newattr, newcs, newchar = self._newbuf[i]
         oldrgb = oldattr.get_rgb_values()
         newrgb = newattr.get_rgb_values()
         if None in oldrgb:
             oldrgb = background.get_rgb_values()
         if None in newrgb:
             newrgb = background.get_rgb_values()
         if newchar == ' ':
             char = oldchar
             charattr = oldattr
             newrgb = newrgb[3:]*2
         elif oldchar == ' ':
             char = newchar
             charattr = newattr
             oldrgb = oldrgb[3:]*2
         elif self.progress >= 0.5:
             char = newchar
             charattr = newattr
         else:
             char = oldchar
             charattr = oldattr
         char = char.encode('utf8')
         line_text += char
         rgb = []
         props = []
         if charattr.bold:
             props.append('bold')
         if charattr.underline:
             props.append('underline')
         if charattr.standout:
             props.append('standout')
         if charattr.blink:
             props.append('blink')
         for x in range(len(oldrgb)):
             rgb.append(int(((newrgb[x]-oldrgb[x])*self.progress)+oldrgb[x])>>4)
         if current_rgb == rgb and current_props == props:
             current_attr[1] += len(char)
         else:
             if current_attr[0]:
                 line_attrs.append(tuple(current_attr))
             fg = ', '.join(props + ['#%x%x%x' % tuple(rgb[:3])])
             bg = '#%x%x%x' % tuple(rgb[3:])
             attr = urwid.AttrSpec(fg, bg)
             current_attr = [attr, len(char)]
             current_rgb = rgb
             current_props = props
         if (i+1) % size[0] == 0:
             line_attrs.append(tuple(current_attr))
             current_attr = [None, 0]
             current_rgb = None
             line_list.append(line_text)
             line_text = ''
             attr_list.append(line_attrs)
             line_attrs = []
     canvas = urwid.TextCanvas(line_list, attr_list)
     return canvas
Пример #2
0
 def ct2(self, text, attr, left, top, cols, rows, def_attr, exp_content):
     c = urwid.TextCanvas([B(t) for t in text], attr)
     content = list(c.content(left, top, cols, rows, def_attr))
     assert content == exp_content, "got: %r expected: %r" % (content,
                                                              exp_content)
Пример #3
0
    def render(self, size, focus=False):
        from pudb.debugger import CONFIG
        render_line_nr = CONFIG["line_numbers"]

        maxcol = size[0]
        hscroll = self.dbg_ui.source_hscroll_start

        # attrs is a list of words like 'focused' and 'breakpoint'
        attrs = []

        if self.is_current:
            crnt = ">"
            attrs.append("current")
        else:
            crnt = " "

        if self.has_breakpoint:
            bp = "*"
            attrs.append("breakpoint")
        else:
            bp = " "

        if focus:
            attrs.append("focused")
        elif self.highlight:
            if not self.has_breakpoint:
                attrs.append("highlighted")

        text = self.text
        if not attrs and self.attr is not None:
            attr = self.attr + [("source", None)]
        else:
            attr = [(" ".join(attrs + ["source"]), None)]

        from urwid.util import apply_target_encoding, trim_text_attr_cs

        # build line prefix ---------------------------------------------------
        line_prefix = ""
        line_prefix_attr = []

        if render_line_nr:
            line_prefix_attr = [("line number", len(self.line_nr))]
            line_prefix = self.line_nr

        line_prefix = crnt + bp + line_prefix
        line_prefix_attr = [("source", 1), ("breakpoint marker", 1)] \
                + line_prefix_attr

        # assume rendered width is same as len
        line_prefix_len = len(line_prefix)

        encoded_line_prefix, line_prefix_cs = apply_target_encoding(
            line_prefix)

        assert len(encoded_line_prefix) == len(line_prefix)
        # otherwise we'd have to adjust line_prefix_attr... :/

        # shipout, encoding ---------------------------------------------------
        cs = []
        encoded_text_segs = []
        encoded_attr = []

        i = 0
        for seg_attr, seg_len in attr:
            if seg_len is None:
                # means: gobble up remainder of text and rest of line
                # and fill with attribute

                l = hscroll + maxcol
                remaining_text = text[i:]
                encoded_seg_text, seg_cs = apply_target_encoding(
                    remaining_text + l * " ")
                encoded_attr.append((seg_attr, len(remaining_text) + l))
            else:
                unencoded_seg_text = text[i:i + seg_len]
                encoded_seg_text, seg_cs = apply_target_encoding(
                    unencoded_seg_text)

                adjustment = len(encoded_seg_text) - len(unencoded_seg_text)

                encoded_attr.append((seg_attr, seg_len + adjustment))

                i += seg_len

            encoded_text_segs.append(encoded_seg_text)
            cs.extend(seg_cs)

        encoded_text = b"".join(encoded_text_segs)
        encoded_text, encoded_attr, cs = trim_text_attr_cs(
            encoded_text, encoded_attr, cs, hscroll,
            hscroll + maxcol - line_prefix_len)

        encoded_text = encoded_line_prefix + encoded_text
        encoded_attr = line_prefix_attr + encoded_attr
        cs = line_prefix_cs + cs

        return urwid.TextCanvas([encoded_text], [encoded_attr], [cs],
                                maxcol=maxcol)
Пример #4
0
 def cptest(self, desc, ct, ca, l, r, et):
     ct = B(ct)
     c = urwid.CompositeCanvas(urwid.TextCanvas([ct], [ca]))
     c.pad_trim_left_right(l, r)
     result = list(c.content())
     assert result == et, "%s expected %r, got %r" % (desc, et, result)
Пример #5
0
 def ct(self, text, attr, exp_content):
     c = urwid.TextCanvas([B(t) for t in text], attr)
     content = list(c.content())
     assert content == exp_content, "got: %r expected: %r" % (content,
                                                              exp_content)
Пример #6
0
    def render(self, size, focus=False):
        clamp = lambda _min, _max, v: min(_max, max(_min, v))

        (maxcol, ) = size
        if self._recent is None:
            # No data; display nothing
            return ur.SolidCanvas('╌', maxcol, 1)
        min_label = '{label:>{width}}'.format(label=self._format(
            self._minimum),
                                              width=self.label_width)
        max_label = '{label:<{width}}'.format(label=self._format(
            self._maximum),
                                              width=self.label_width)

        bar_range = self._maximum - self._minimum
        if not bar_range:
            # Minimum and maximum are equal; display nothing
            return ur.SolidCanvas('╌', maxcol, 1)

        while True:
            bar_len = maxcol - sum(
                len(s) for s in (min_label, self.left, self.right, max_label))
            bar_len //= len(self.back)
            if bar_len > 4:
                break
            else:
                # Bar is too short to be useful; if the minimum and maximum are
                # trivial attempt to eliminate their labels and if this isn't
                # enough just display >>>>
                if self._minimum == 0:
                    if min_label != '':
                        min_label = ''
                        continue
                    elif self._maximum in (1, 100) and max_label != '':
                        max_label = ''
                        continue
                return ur.SolidCanvas('▸', maxcol, 1)

        pre_len = clamp(
            0, bar_len,
            round(bar_len *
                  ((min(self._recent, self._history) - self._minimum) /
                   bar_range)))
        post_len = clamp(
            0, bar_len,
            round(bar_len *
                  ((self._maximum - max(self._recent, self._history)) /
                   bar_range)))
        trend_len = bar_len - (pre_len + post_len)
        while trend_len < 0:
            # Can happen by rounding; knock 1 off the first largest value.
            trend_len += 1
            if pre_len >= post_len:
                pre_len -= 1
            else:
                post_len -= 1

        s = ''.join((
            self.fore * pre_len,
            (self.falling if self._recent < self._history else
             self.rising if self._recent > self._history else self.fore) *
            trend_len,
            self.back * post_len,
        ))
        if self.show_current:
            latest_pos = clamp(
                0, bar_len - 1,
                round(bar_len * ((self._latest - self._minimum) / bar_range)))
            s = s[:latest_pos] + self.current + s[latest_pos + 1:]
        s = ''.join((min_label, self.left, s, self.right, max_label))
        text, cs = ur.apply_target_encoding(s)
        return ur.TextCanvas([text], [cs], maxcol=maxcol)
Пример #7
0
            # Right pad
            line_text += ' ' * right_pad
            for fake_attr in range(0, right_pad):
                line_attrs.append((padding_attr, 1))

            line_list.append(line_text)
            line_text = ''
            attr_list.append(line_attrs)
            line_attrs = []

        # Bottom pad
        for padding in range(0, bottom_pad):
            line_list.append(' ' * total_width)
            attr_list.append([(padding_attr, 1)] * total_width)

        canvas = urwid.TextCanvas(line_list, attr_list)
        return canvas


def main():
    import PIL.Image
    img = PIL.Image.open('/tmp/p/8.jpg')
    img.load()
    hinter = slide.ScreenHinter()
    hinter.set_cols_rows((80, 25))
    w = ANSIImage(img, hinter)
    slpile = slide.SlidePile([])
    slpile.contents.append((w, slpile.options()))
    pad = slide.SlidePadding(slpile, align='center', width='pack')
    fill = slide.SlideFiller(pad)
    #w.render((80,25))
Пример #8
0
Файл: ui.py Проект: rayx/pypick
 def render(self, size, focus=False):
     (maxcol, ) = size
     self.set_columns_width(maxcol)
     text, attrs = self.get_text_and_attributes(focus=focus)
     return urwid.TextCanvas(text, attrs, maxcol=maxcol)
Пример #9
0
        if render_line_nr:
            text = self.line_nr + text

        text = crnt + bp + text
        attr = [("source", 1), ("bp_star", 1)] + attr

        # clipping ------------------------------------------------------------
        if len(text) > maxcol:
            text = text[:maxcol]
            attr = rle_subseg(attr, 0, maxcol)

        # shipout -------------------------------------------------------------
        from urwid.util import apply_target_encoding
        txt, cs = apply_target_encoding(text)

        return urwid.TextCanvas([txt], [attr], [cs], maxcol=maxcol)

    def keypress(self, size, key):
        return key


def format_source(debugger_ui, lines, breakpoints):
    lineno_format = "%%%dd " % (len(str(len(lines))))
    try:
        import pygments
    except ImportError:
        return [
            SourceLine(debugger_ui,
                       line.rstrip("\n\r").expandtabs(TABSTOP),
                       lineno_format % (i + 1),
                       None,
Пример #10
0
	def __init__(self):
		self._selectable = True
		self.basic_graphic = urwid.TextCanvas([bytes("asdf", 'utf-8')])
		self.basic_graphic = urwid.TextCanvas([b"asdf"])
		self.coords = [0,0]
Пример #11
0
 def render(self, size, focus=False):
     # pylint: disable-msg=unused-argument
     (maxcol, ) = size
     data = self.keyboard.draw(maxcol)
     data = [d.encode() for d in data]
     return urwid.TextCanvas(data, maxcol=maxcol)
Пример #12
0
 def render(self, size, focus=False):
     (maxcol, ) = size
     num_pudding = maxcol / len("Pudding")
     return urwid.TextCanvas(["Pudding" * num_pudding], maxcol=maxcol)
Пример #13
0
 def render(self, size, focus=False):
     lines = self._cow_lines(self._inner_size(size))
     return urwid.TextCanvas(lines, maxcol=size[0])
Пример #14
0
 def render(self, size, focus=False):
     (maxcol, ) = size
     text = self._fmt.format(self._text).encode("utf-8")
     c = urwid.TextCanvas([text], maxcol=maxcol)
     c.cursor = self.get_cursor_coords(size)
     return c