コード例 #1
0
    def render(self, size, focus=False):
        maxcol, maxrow = size

        sb_width = self._scrollbar_width
        ow_size = (max(0, maxcol - sb_width), maxrow)
        sb_width = maxcol - ow_size[0]

        ow = self._original_widget
        ow_base = self.scrolling_base_widget
        ow_rows_max = ow_base.rows_max(size, focus)
        if ow_rows_max <= maxrow:
            # Canvas fits without scrolling - no scrollbar needed
            self._original_widget_size = size
            return ow.render(size, focus)
        ow_rows_max = ow_base.rows_max(ow_size, focus)

        ow_canv = ow.render(ow_size, focus)
        self._original_widget_size = ow_size

        pos = ow_base.get_scrollpos(ow_size, focus)
        posmax = ow_rows_max - maxrow

        # Thumb shrinks/grows according to the ratio of
        # <number of visible lines> / <number of total lines>
        thumb_weight = min(1, maxrow / max(1, ow_rows_max))
        thumb_height = max(1, round(thumb_weight * maxrow))

        # Thumb may only touch top/bottom if the first/last row is visible
        top_weight = float(pos) / max(1, posmax)
        top_height = int((maxrow - thumb_height) * top_weight)
        if top_height == 0 and top_weight > 0:
            top_height = 1

        # Bottom part is remaining space
        bottom_height = maxrow - thumb_height - top_height
        assert thumb_height + top_height + bottom_height == maxrow

        # Create scrollbar canvas
        # Creating SolidCanvases of correct height may result in "cviews do not
        # fill gaps in shard_tail!" or "cviews overflow gaps in shard_tail!"
        # exceptions. Stacking the same SolidCanvas is a workaround.
        # https://github.com/urwid/urwid/issues/226#issuecomment-437176837
        top = urwid.SolidCanvas(self._trough_char, sb_width, 1)
        thumb = urwid.SolidCanvas(self._thumb_char, sb_width, 1)
        bottom = urwid.SolidCanvas(self._trough_char, sb_width, 1)
        sb_canv = urwid.CanvasCombine(
            [(top, None, False)] * top_height +
            [(thumb, None, False)] * thumb_height +
            [(bottom, None, False)] * bottom_height,
        )

        combinelist = [(ow_canv, None, True, ow_size[0]),
                       (sb_canv, None, False, sb_width)]
        if self._scrollbar_side != SCROLLBAR_LEFT:
            return urwid.CanvasJoin(combinelist)
        else:
            return urwid.CanvasJoin(reversed(combinelist))
コード例 #2
0
    def render(self, size, focus=False):
        maxcol, maxrow = size

        ow = self._original_widget
        ow_base = self.scrolling_base_widget
        ow_rows_max = ow_base.rows_max(size, focus)
        if ow_rows_max <= maxrow:
            # Canvas fits without scrolling - no scrollbar needed
            self._original_widget_size = size
            return ow.render(size, focus)

        sb_width = self._scrollbar_width
        self._original_widget_size = ow_size = (maxcol - sb_width, maxrow)
        ow_canv = ow.render(ow_size, focus)

        pos = ow_base.get_scrollpos(ow_size, focus)
        posmax = ow_rows_max - maxrow

        # Thumb shrinks/grows according to the ratio of
        # <number of visible lines> / <number of total lines>
        thumb_weight = min(1, maxrow / max(1, ow_rows_max))
        thumb_height = max(1, round(thumb_weight * maxrow))

        # Thumb may only touch top/bottom if the first/last row is visible
        top_weight = float(pos) / max(1, posmax)
        top_height = int((maxrow - thumb_height) * top_weight)
        if top_height == 0 and top_weight > 0:
            top_height = 1

        # Bottom part is remaining space
        bottom_height = maxrow - thumb_height - top_height
        assert thumb_height + top_height + bottom_height == maxrow

        # Create scrollbar canvas
        top = urwid.SolidCanvas(self._trough_char, sb_width, top_height)
        thumb = urwid.SolidCanvas(self._thumb_char, sb_width, thumb_height)
        bottom = urwid.SolidCanvas(self._trough_char, sb_width, bottom_height)
        sb_canv = urwid.CanvasCombine([
            (top, None, False),
            (thumb, None, False),
            (bottom, None, False),
        ])

        combinelist = [(ow_canv, None, True, ow_size[0]),
                       (sb_canv, None, False, sb_width)]
        if self._scrollbar_side != SCROLLBAR_LEFT:
            return urwid.CanvasJoin(combinelist)
        else:
            return urwid.CanvasJoin(reversed(combinelist))
コード例 #3
0
    def render(self, size, focus=False):
        # detect graph size change
        new_size = (size[1], size[0])  # reverse tuple order to match _size
        old_size = self._size
        resize = new_size != old_size

        (maxcol, maxrow) = size
        bardata = self.get_data((maxcol, maxrow))[0]
        if resize:
            self.render_init(size)
        elif len(bardata) is not 0:

            # get the most recent data
            color_index = 0
            data_value = 0
            for pallet_index, value in enumerate(bardata[-1]):
                color_index = pallet_index
                data_value = value

                if data_value != 0:
                    break

            logging.info("color_index: " + str(color_index))
            logging.info("data_value: " + str(data_value))
            self.render_incremental(size, data_value, color_index)
            self.column_canvas_list.pop(0)

        canvas = urwid.CanvasJoin(self.column_canvas_list)

        self._size = (int(canvas.rows()), int(canvas.cols()))

        return canvas
コード例 #4
0
ファイル: infobar.py プロジェクト: Alterrien/stig
    def render(self, size, focus=False):
        if not self._connected:
            size = self.pack(size)
            return urwid.AttrMap(urwid.SolidFill(' '), 'bottombar').render(size)

        canv_up_tail = self._mk_tail_canv('up', '↑')
        canv_dn_tail = self._mk_tail_canv('down', '↓')

        # List of (canvas, position, focus) tuples
        combinelist = []

        # Download
        canv_dn = self._attr_dn.render((self._RATE_WIDTH,))
        combinelist.append((canv_dn, None, False, self._RATE_WIDTH))
        if self._dn_limit_width > 0:
            canv_dn_limit = self._attr_dn_limit.render((self._dn_limit_width,))
            combinelist.append((canv_dn_limit, None, False, self._dn_limit_width))
        combinelist.append((canv_dn_tail, None, False, self._TAIL_WIDTH))

        combinelist.append((self._spacer_canvas, None, False, self._SPACER_WIDTH))

        # Upload
        canv_up = self._attr_up.render((self._RATE_WIDTH,))
        combinelist.append((canv_up, None, False, self._RATE_WIDTH))
        if self._up_limit_width > 0:
            canv_up_limit = self._attr_up_limit.render((self._up_limit_width,))
            combinelist.append((canv_up_limit, None, False, self._up_limit_width))
        combinelist.append((canv_up_tail, None, False, self._TAIL_WIDTH))

        return urwid.CanvasJoin(combinelist)
コード例 #5
0
    def render(self, size, focus=False):
        visible = self.ends_visible(size, focus)
        if len(visible) == 2:
            return super().render(size, focus)
        else:
            # This implementation assumes that the number of rows is
            # not too large (and in particular is finite). That's the
            # case for all the listboxes we have in subiquity today.
            maxcol, maxrow = size

            offset, inset = self.get_focus_offset_inset((maxcol - 1, maxrow))

            seen_focus = False
            height = height_before_focus = 0
            focus_widget, focus_pos = self.body.get_focus()
            # Scan through the rows calculating total height and the
            # height of the rows before the focus widget.
            for widget in self.body:
                rows = widget.rows((maxcol - 1, ))
                if widget is focus_widget:
                    seen_focus = True
                elif not seen_focus:
                    height_before_focus += rows
                height += rows

            # Calculate the number of rows off the top and bottom of
            # the listbox.
            if 'top' in visible:
                top = 0
            else:
                top = height_before_focus + inset - offset
            if 'bottom' in visible:
                bottom = 0
            else:
                bottom = height - top - maxrow

            # Prevent the box from being squished to 0 rows. Input of
            #
            #     ('weight', maxrow)
            #
            # gets
            #
            #     round(maxrow / (top + maxrow + bottom))
            #
            # rows and that being < 1 simplifies to the below).
            if maxrow * maxrow < height:
                boxopt = self.bar.options('given', 1)
            else:
                boxopt = self.bar.options('weight', maxrow)

            self.bar.contents[:] = [
                (self.bar.contents[0][0], self.bar.options('weight', top)),
                (self.boxes[focus], boxopt),
                (self.bar.contents[2][0], self.bar.options('weight', bottom)),
            ]
            canvases = [(super().render(
                (maxcol - 1, maxrow),
                focus), self.focus_position, True, maxcol - 1),
                        (self.bar.render((1, maxrow)), None, False, 1)]
            return urwid.CanvasJoin(canvases)
コード例 #6
0
ファイル: transition.py プロジェクト: masayukig/presentty
 def render(self, size, focus=False):
     old = self.old.render((size[0], size[1]))
     new = self.new.render((size[0], size[1]))
     c = urwid.CanvasJoin([(old, None, False, size[0]),
                           (new, None, False, size[0])])
     #c = urwid.CanvasOverlay(new, old, 6, 0)
     offset = int(size[0] * self.progress)
     c.pad_trim_left_right(0-offset, 0-(size[0]-offset))
     return c
コード例 #7
0
    def render(self, size, focus=False):
        if self.tab_state is None:
            return urwid.TextCanvas([('-' * size[0]).encode('utf-8')] *
                                    size[1])
        off_digits = self.get_offset_digits()
        self._app_state.window_size = size
        self.tab_state.offset_digits = off_digits

        cur_off = self.tab_state.current_offset
        top_off = self.tab_state.top_offset
        vis_col = self.tab_state.visible_columns
        vis_row = self.tab_state.visible_rows

        vis_bytes = min(vis_col * vis_row + top_off,
                        self.tab_state.size) - top_off

        buffer = self.tab_state.file_buffer.get(top_off, vis_bytes)
        off_lines, hex_lines, asc_lines = self._render_lines(buffer)
        off_hilight, hex_hilight, asc_hilight = self._render_hilight(
            off_lines, hex_lines, asc_lines)

        rel_cur_off = cur_off - top_off
        cursor_pos = (rel_cur_off % vis_col, rel_cur_off // vis_col)
        if self.tab_state.pane == self.tab_state.PANE_HEX:
            cursor_pos = (cursor_pos[0] * 3, cursor_pos[1])

        if self._user_byte_input:
            assert self.tab_state.pane == self.tab_state.PANE_HEX
            cursor_pos = (cursor_pos[0] + len(self._user_byte_input),
                          cursor_pos[1])
            pos_x, pos_y = cursor_pos
            hex_lines[pos_y] = hex_lines[pos_y][:pos_x-1] \
                + self._user_byte_input.encode('utf-8') \
                + hex_lines[pos_y][pos_x:]

        canvas_def = []
        Dump.pos = 0

        def append(widget, width):
            canvas_def.append((widget, Dump.pos, False, width))
            Dump.pos += width

        append(urwid.TextCanvas(off_lines, off_hilight), off_digits + 1)
        append(urwid.TextCanvas(hex_lines, hex_hilight), vis_col * 3)
        append(urwid.TextCanvas(asc_lines, asc_hilight), vis_col)

        if not self._ui.blocked:
            if self.tab_state.pane == self.tab_state.PANE_ASC:
                canvas_def[2][0].cursor = cursor_pos
            else:
                canvas_def[1][0].cursor = cursor_pos

        multi_canvas = urwid.CanvasJoin(canvas_def)
        multi_canvas.pad_trim_left_right(0, size[0] - multi_canvas.cols())
        return multi_canvas
コード例 #8
0
    def render(self, szie, focus=False):
        maxcol, maxrow = size
        ow = self._original_widget
        ow_base = self._scrolling_base_widget
        ow_rows_max = ow_base.rows_max(size, focus)
        if ow_rows_max <= maxrow:
            self._original_widget_size = size
            return ow.render(size, focus)

        sb_width = self._scrollbar_width
        self._original_widget_size = ow_size = (maxcol - sb_width, maxrow)
        ow_canv = ow.render(ow_size, focus)

        pos = ow_base.get_scrollpos(ow_size, focus)
        posmax = ow_rows_max - maxrow

        thumb_weight = min(1, maxrow / max(1, ow_rows_max))
        thumb_height = max(1, round(thumb_weight * maxrow))

        top_weight = float(pos) / max(1, posmax)
        top_height = int((maxrow - thumb_height) * top_weight)
        if top_height == 0 and top_weight > 0:
            top_height = 1

        bottom_height = maxrow - thumb_height - top_height
        assert thumb_height + top_height + bottom_height == maxrow

        top = urwid.SolidCanvas(self._trough_char, sb_width, top_height)
        thumb = urwid.SolidCanvas(self._thumb_char, sb_width, thumb_height)
        bottom = urwid.SolidCanvas(self._trough_char, sb_width, bottom_height)
        sb_canv = urwid.CanvasCombine([
            (top, None, False),
            (thumb, None, False),
            (bottom, None, False),
        ])
        combinelist = [(ow_canv, None, True, ow_size[0]),
                       (sb_canv, None, False, sb_widt)]
        if self._scrollbar_side != SCROLLBAR_LEFT:
            return urwid.CanvasJoin(combinelist)
        else:
            return urwid.CanvasJoin(reversed(combinelist))
コード例 #9
0
 def render(self, size, focus=False):
     (areax, areay) = self._get_area_size(size)
     area = self._area.render((areax, areay), focus)
     # join the lot together top to bottom, left to right
     vscroll_width = self._vscroll.pack(size)[0]
     hscroll_height = self._hscroll.pack(size)[1]
     col1 = urwid.CanvasCombine([
         (area, None, False),
         (self._hscroll.render((areax, hscroll_height)), None, False)
     ])
     col2 = urwid.CanvasCombine([(self._vscroll.render(
         (vscroll_width, areay)), None, False),
                                 (self._corner, None, False)])
     return urwid.CanvasJoin([(col1, None, False, areax),
                              (col2, None, False, vscroll_width)])
コード例 #10
0
ファイル: status_bar.py プロジェクト: rr-/hexvi
    def render(self, size, focus=False):
        off_sep = ' / '
        off1 = util.fmt_hex(self._tab_manager.current_tab.current_offset)
        off2 = util.fmt_hex(self._tab_manager.current_tab.size)
        percent = ' (%d%%)' % (
            self._tab_manager.current_tab.current_offset * (
                100.0 / max(1, self._tab_manager.current_tab.size)))

        right_size = len(off1) + len(off2) + len(off_sep) + len(percent)
        left = '[%s] ' % self._app_state.mode.upper()
        left += util.trim_left(
            self._tab_manager.current_tab.long_name,
            size[0] - (right_size + len(left) + 3))

        composite_canvas = urwid.CanvasJoin([
            (
                urwid.TextCanvas([left.encode('utf-8')]),
                None, False, size[0] - right_size,
            ),
            (
                urwid.TextCanvas([off1.encode('utf-8')], [_hilight(off1)]),
                None, False, len(off1),
            ),
            (
                urwid.TextCanvas([off_sep.encode('utf-8')]),
                None, False, len(off_sep),
            ),
            (
                urwid.TextCanvas([off2.encode('utf-8')], [_hilight(off2)]),
                None, False, len(off2),
            ),
            (
                urwid.TextCanvas([percent.encode('utf-8')]),
                None, False, len(percent),
            )])
        return composite_canvas
コード例 #11
0
ファイル: container.py プロジェクト: vish74/subiquity
    def render(self, size, focus=False):
        lb = self.original_widget
        visible = lb.ends_visible(size, focus)
        if len(visible) == 2:
            return lb.render(size, focus)
        else:
            # This implementation assumes that the number of rows is
            # not too large (and in particular is finite). That's the
            # case for all the listboxes we have in subiquity today.
            maxcol, maxrow = size

            offset, inset = lb.get_focus_offset_inset((maxcol - 1, maxrow))

            seen_focus = False
            height = height_before_focus = 0
            focus_widget, focus_pos = lb.body.get_focus()
            # Scan through the rows calculating total height and the
            # height of the rows before the focus widget.
            for widget in lb.body:
                rows = widget.rows((maxcol - 1, ))
                if widget is focus_widget:
                    seen_focus = True
                elif not seen_focus:
                    height_before_focus += rows
                height += rows

            # Calculate the number of rows off the top and bottom of
            # the listbox.
            if 'top' in visible:
                top = 0
            else:
                top = height_before_focus + inset - offset
            if 'bottom' in visible:
                bottom = 0
            else:
                bottom = height - top - maxrow

            # Prevent the box from being squished to 0 rows. Input of
            #
            #     ('weight', maxrow)
            #
            # gets
            #
            #     round(maxrow / (top + maxrow + bottom))
            #
            # rows and that being < 1 simplifies to the below.
            o = self.bar.base_widget.options
            if maxrow < top + bottom:
                boxopt = o('given', 1)
            else:
                boxopt = o('weight', maxrow)

            top_arrow = self.top
            if top == 0:
                top_arrow = urwid.AttrMap(top_arrow, 'scrollbar')
            bot_arrow = self.bot
            if bottom == 0:
                bot_arrow = urwid.AttrMap(bot_arrow, 'scrollbar')

            self.bar.base_widget.contents[:] = [
                (top_arrow, o('given', 1)),
                (self.bg, o('weight', top)),
                (self.box, boxopt),
                (self.bg, o('weight', bottom)),
                (bot_arrow, o('given', 1)),
            ]
            lb_canvas = lb.render((maxcol - 1, maxrow), focus)
            bar_canvas = self.bar.render((1, maxrow), focus)
            return urwid.CanvasJoin([
                (lb_canvas, lb.focus_position, True, maxcol - 1),
                (bar_canvas, None, False, 1),
            ])
コード例 #12
0
ファイル: test_canvas.py プロジェクト: nadeesha90/quantathon
    def cjtest(self, desc, l, expected):
        l = [(c, None, False, n) for c, n in l]
        result = list(urwid.CanvasJoin(l).content())

        assert result == expected, "%s expected %r, got %r" % (desc, expected,
                                                               result)