示例#1
0
文件: wimp.py 项目: horazont/urwid
 def render(self, size, focus=False):
     canv = self.__super.render(size, focus)
     if self._pop_up_widget:
         canv = CompositeCanvas(canv)
         canv.set_pop_up(self._pop_up_widget,
                         **self.get_pop_up_parameters())
     return canv
示例#2
0
文件: graphics.py 项目: jmcb/urwid
 def render(self, size, focus=False):
     fixed_size(size) # complain if parameter is wrong
     a = None
     ai = ak = 0
     o = []
     rows = self.font.height
     attrib = self.attrib+[(None,len(self.text))]
     for ch in self.text:
         if not ak:
             a, ak = attrib[ai]
             ai += 1
         ak -= 1
         width = self.font.char_width(ch)
         if not width: 
             # ignore invalid characters
             continue
         c = self.font.render(ch)
         if a is not None:
             c = CompositeCanvas(c)
             c.fill_attr(a)
         o.append((c, None, False, width))
     if o:
         canv = CanvasJoin(o)
     else:
         canv = TextCanvas([""]*rows, maxcol=0, 
             check_width=False)
         canv = CompositeCanvas(canv)
     canv.set_depends([])
     return canv
示例#3
0
文件: widget.py 项目: sporkexec/urwid
 def finalize_render(self, size, focus=False):
     canv = fn(self, size, focus=focus)
     if canv.widget_info:
         canv = CompositeCanvas(canv)
     validate_size(self, size, canv)
     canv.finalize(self, size, focus)
     return canv
示例#4
0
 def render(self, size, focus=False):
     """
     Render wrapped widget and apply attribute. Return canvas.
     """
     attr_map = self._attr_map
     if focus and self._focus_map is not None:
         attr_map = self._focus_map
     canv = self._original_widget.render(size, focus=focus)
     canv = CompositeCanvas(canv)
     canv.fill_attr_apply(attr_map)
     return canv
示例#5
0
    def render(self, size, focus=False):
        """Render top_w overlayed on bottom_w."""
        left, right, top, bottom = self.calculate_padding_filler(size, focus)
        bottom_c = self.bottom_w.render(size)
        top_c = self.top_w.render(self.top_w_size(size, left, right, top, bottom), focus)
        top_c = CompositeCanvas(top_c)
        if left < 0 or right < 0:
            top_c.pad_trim_left_right(min(0, left), min(0, right))
        if top < 0 or bottom < 0:
            top_c.pad_trim_top_bottom(min(0, top), min(0, bottom))

        return CanvasOverlay(top_c, bottom_c, left, top)
示例#6
0
文件: widget.py 项目: sporkexec/urwid
    def cached_render(self, size, focus=False):
        focus = focus and not ignore_focus
        canv = CanvasCache.fetch(self, cls, size, focus)
        if canv:
            return canv

        canv = fn(self, size, focus=focus)
        validate_size(self, size, canv)
        if canv.widget_info:
            canv = CompositeCanvas(canv)
        canv.finalize(self, size, focus)
        CanvasCache.store(cls, canv)
        return canv
示例#7
0
文件: graphics.py 项目: vt100/urwid
    def render(self, size, focus=False):
        """
        Render GraphVScale.
        """
        (maxcol, maxrow) = size
        pl = scale_bar_values(self.pos, self.top, maxrow)

        combinelist = []
        rows = 0
        for p, t in zip(pl, self.txt):
            p -= 1
            if p >= maxrow:
                break
            if p < rows:
                continue
            c = t.render((maxcol,))
            if p > rows:
                run = p - rows
                c = CompositeCanvas(c)
                c.pad_trim_top_bottom(run, 0)
            rows += c.rows()
            combinelist.append((c, None, False))
        if not combinelist:
            return SolidCanvas(" ", size[0], size[1])

        c = CanvasCombine(combinelist)
        if maxrow - rows:
            c.pad_trim_top_bottom(0, maxrow - rows)
        return c
示例#8
0
    def render(self, size, focus=False):
        """
        Render all widgets in self.widget_list and return the results
        stacked one on top of the next.
        """
        maxcol = size[0]
        item_rows = None

        combinelist = []
        for i, (w, (f, height)) in enumerate(self.contents):
            item_focus = self.focus_item == w
            canv = None
            if f == 'fixed':
                canv = w.render((maxcol, height), focus=focus and item_focus)
            elif f == 'flow' or len(size) == 1:
                canv = w.render((maxcol, ), focus=focus and item_focus)
            else:
                if item_rows is None:
                    item_rows = self.get_item_rows(size, focus)
                rows = item_rows[i]
                if rows > 0:
                    canv = w.render((maxcol, rows), focus=focus and item_focus)
            if canv:
                combinelist.append((canv, i, item_focus))
        if not combinelist:
            return SolidCanvas(" ", size[0], (size[1:] + (0, ))[0])

        out = CanvasCombine(combinelist)
        if len(size) == 2 and size[1] < out.rows():
            # flow/fixed widgets rendered too large
            out = CompositeCanvas(out)
            out.pad_trim_top_bottom(0, size[1] - out.rows())
        return out
示例#9
0
文件: graphics.py 项目: Julian/urwid
    def render(self, size, focus=False):
        """
        Render GraphVScale.
        """
        (maxcol, maxrow) = size
        pl = scale_bar_values(self.pos, self.top, maxrow)

        combinelist = []
        rows = 0
        for p, t in zip(pl, self.txt):
            p -= 1
            if p >= maxrow:
                break
            if p < rows:
                continue
            c = t.render((maxcol,))
            if p > rows:
                run = p - rows
                c = CompositeCanvas(c)
                c.pad_trim_top_bottom(run, 0)
            rows += c.rows()
            combinelist.append((c, None, False))
        if not combinelist:
            return SolidCanvas(" ", size[0], size[1])

        c = CanvasCombine(combinelist)
        if maxrow - rows:
            c.pad_trim_top_bottom(0, maxrow - rows)
        return c
示例#10
0
    def render(self, size, focus=False):
        """Render self.original_widget with space above and/or below."""
        (maxcol, maxrow) = size
        top, bottom = self.filler_values(size, focus)

        if self.height_type == PACK:
            canv = self._original_widget.render((maxcol,), focus)
        else:
            canv = self._original_widget.render((maxcol,maxrow-top-bottom),focus)
        canv = CompositeCanvas(canv)

        if maxrow and canv.rows() > maxrow and canv.cursor is not None:
            cx, cy = canv.cursor
            if cy >= maxrow:
                canv.trim(cy-maxrow+1,maxrow-top-bottom)
        if canv.rows() > maxrow:
            canv.trim(0, maxrow)
            return canv
        canv.pad_trim_top_bottom(top, bottom)
        return canv
示例#11
0
    def render(self, size, focus=False):
        left, right = self.padding_values(size, focus)

        maxcol = size[0]
        maxcol -= left + right

        if self._width_type == CLIP:
            canv = self._original_widget.render((), focus)
        else:
            canv = self._original_widget.render((maxcol, ) + size[1:], focus)
        if canv.cols() == 0:
            canv = SolidCanvas(' ', size[0], canv.rows())
            canv = CompositeCanvas(canv)
            canv.set_depends([self._original_widget])
            return canv
        canv = CompositeCanvas(canv)
        canv.set_depends([self._original_widget])
        if left != 0 or right != 0:
            canv.pad_trim_left_right(left, right)

        return canv
示例#12
0
    def render(self, size, focus=False):
        """
        Render the text content of this widget with a cursor when
        in focus.

        >>> si = SelectableIcon(u"[!]")
        >>> si
        <SelectableIcon selectable flow widget '[!]'>
        >>> si.render((4,), focus=True).cursor
        (1, 0)
        >>> si = SelectableIcon("((*))", 2)
        >>> si.render((8,), focus=True).cursor
        (2, 0)
        >>> si.render((2,), focus=True).cursor
        (0, 1)
        """
        c = self.__super.render(size, focus)
        if focus:
            # create a new canvas so we can add a cursor
            c = CompositeCanvas(c)
            c.cursor = self.get_cursor_coords(size)
        return c
示例#13
0
文件: wimp.py 项目: eykd/urwid
    def render(self, size, focus=False):
        """
        Render the text content of this widget with a cursor when
        in focus.

        >>> si = SelectableIcon(u"[!]")
        >>> si
        <SelectableIcon selectable flow widget '[!]'>
        >>> si.render((4,), focus=True).cursor
        (1, 0)
        >>> si = SelectableIcon("((*))", 2)
        >>> si.render((8,), focus=True).cursor
        (2, 0)
        >>> si.render((2,), focus=True).cursor
        (0, 1)
        """
        c = self.__super.render(size, focus)
        if focus:
            # create a new canvas so we can add a cursor
            c = CompositeCanvas(c)
            c.cursor = self.get_cursor_coords(size)
        return c
示例#14
0
 def render(self, size, focus=False):
     """Render self.original_widget with space above and/or below."""
     (maxcol, maxrow) = size
     top, bottom = self.filler_values(size, focus)
     
     if self.height_type is None:
         canv = self._original_widget.render((maxcol,), focus)
     else:
         canv = self._original_widget.render((maxcol,maxrow-top-bottom),focus)
     canv = CompositeCanvas(canv)
     
     if maxrow and canv.rows() > maxrow and canv.cursor is not None:
         cx, cy = canv.cursor
         if cy >= maxrow:
             canv.trim(cy-maxrow+1,maxrow-top-bottom)
     if canv.rows() > maxrow:
         canv.trim(0, maxrow)
         return canv
     canv.pad_trim_top_bottom(top, bottom)
     return canv
示例#15
0
    def render(self, size, focus=False):
        """
        Render edit widget and return canvas.  Include cursor when in
        focus.

        >>> c = Edit("? ","yes").render((10,), focus=True)
        >>> c.text # ... = b in Python 3
        [...'? yes     ']
        >>> c.cursor
        (5, 0)
        """
        (maxcol, ) = size
        self._shift_view_to_cursor = bool(focus)

        canv = self._render(size, focus)
        if focus:
            canv = CompositeCanvas(canv)
            canv.cursor = self.get_cursor_coords(size)

        # .. will need to FIXME if I want highlight to work again
        # if self.highlight:
        #    hstart, hstop = self.highlight_coords()
        #    d.coords['highlight'] = [ hstart, hstop ]
        return canv
示例#16
0
文件: widget.py 项目: sporkexec/urwid
    def render(self, size, focus=False):
        """
        Render edit widget and return canvas.  Include cursor when in
        focus.

        >>> c = Edit("? ","yes").render((10,), focus=True)
        >>> c.text # ... = b in Python 3
        [...'? yes     ']
        >>> c.cursor
        (5, 0)
        """
        (maxcol,) = size
        self._shift_view_to_cursor = bool(focus)

        canv = Text.render(self,(maxcol,))
        if focus:
            canv = CompositeCanvas(canv)
            canv.cursor = self.get_cursor_coords((maxcol,))

        # .. will need to FIXME if I want highlight to work again
        #if self.highlight:
        #    hstart, hstop = self.highlight_coords()
        #    d.coords['highlight'] = [ hstart, hstop ]
        return canv
示例#17
0
    def render(self, size, focus=False):
        """
        Render the divider as a canvas and return it.

        >>> Divider().render((10,)).text # ... = b in Python 3
        [...'          ']
        >>> Divider(u'-', top=1).render((10,)).text
        [...'          ', ...'----------']
        >>> Divider(u'x', bottom=2).render((5,)).text
        [...'xxxxx', ...'     ', ...'     ']
        """
        (maxcol, ) = size
        canv = SolidCanvas(self.div_char, maxcol, 1)
        canv = CompositeCanvas(canv)
        if self.top or self.bottom:
            canv.pad_trim_top_bottom(self.top, self.bottom)
        return canv
示例#18
0
    def render(self, size, focus=False):
        """Render top_w overlayed on bottom_w."""
        left, right, top, bottom = self.calculate_padding_filler(size, focus)
        bottom_c = self.bottom_w.render(size)
        top_c = self.top_w.render(
            self.top_w_size(size, left, right, top, bottom), focus)
        top_c = CompositeCanvas(top_c)
        if left < 0 or right < 0:
            top_c.pad_trim_left_right(min(0, left), min(0, right))
        if top < 0 or bottom < 0:
            top_c.pad_trim_top_bottom(min(0, top), min(0, bottom))

        return CanvasOverlay(top_c, bottom_c, left, top)
示例#19
0
 def render(self, size, focus=False):
     canv = get_delegate(self).render(size, focus=focus)
     return CompositeCanvas(canv)
示例#20
0
 def finalize_render(size, focus=False):
     canv = fn(self, size, focus=focus)
     if canv.widget_info:
         canv = CompositeCanvas(canv)
     canv.finalize(self, size, focus)
     return canv
示例#21
0
 def render(self, size, focus=False):
     (maxcol, ) = size
     canv = self._original_widget.render((maxcol, self.height), focus)
     canv = CompositeCanvas(canv)
     return canv
示例#22
0
 def render(self, size, focus=False):
     canv = self.__super.render(size, focus)
     if self._pop_up_widget:
         canv = CompositeCanvas(canv)
         canv.set_pop_up(self._pop_up_widget, **self.get_pop_up_parameters())
     return canv
示例#23
0
 def render(self, size, focus=False):
     canv = self._original_widget.render(size, False)
     return CompositeCanvas(canv)