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)])
def render_init(self, size): (maxcol, maxrow) = size bardata, top, hlines = self.get_data((maxcol, maxrow)) back_char = self.char[0] self.column_canvas_list = [] # create the empty bars, for the bar columns that do not have data yet for no_data in range(maxcol - len(bardata)): back_canvas = urwid.SolidCanvas(back_char, 1, maxrow) combine_list_item = [(back_canvas, None, False)] column_canvas = urwid.CanvasCombine(combine_list_item) self.column_canvas_list.append((column_canvas, None, False, 1)) # for each data point, create a single bar graph color_index = 0 data_value = 0 for single_bar_data in bardata: for pallet_index, value in enumerate(single_bar_data): color_index = pallet_index data_value = value if data_value != 0: break self.render_incremental(size, data_value, color_index)
def render(self, size, focus=False): if len(size) < 2: cols, rows = (size[0], None) else: cols, rows = size if len(self._contents) < 1: # No contents - return empty canvas return urwid.SolidCanvas(' ', cols, rows) if rows is not None: size_content = (cols, rows - self._tabbar.rows((cols, ))) else: size_content = (cols, ) combinelist = [] position = self._contents.focus # Always render tab titles as focused to highlight the focused tab canvas = self._tabbar.render((cols, ), focus=True) combinelist.append((canvas, position, True)) # Render and add content of currently selected tab current_widget = self._contents[position] if current_widget is None: canvas = urwid.SolidCanvas(' ', *size_content) else: canvas = current_widget.render(size_content, focus) combinelist.append((canvas, position, focus)) return urwid.CanvasCombine(combinelist)
def render(self, size, focus=False): if len(size) < 2: cols, rows = (size[0], None) else: cols, rows = size if len(self._contents) < 1: # No contents - return empty canvas return urwid.SolidCanvas(' ', cols, rows) combinelist = [] position = self._contents.focus # Render tab bar and add it to combinelist. The tab bar is always # rendered as focused to highlight the focused tab. canvas = self._tabbar_render((cols,), True) combinelist.append((canvas, position, True)) if rows is not None: rows -= 1 # Account for title bar # Render and add content of currently selected tab current_widget = self._contents[position] if current_widget is None: canvas = urwid.SolidCanvas(' ', cols, rows) else: if rows is not None: canvas = current_widget.render((cols,rows), focus) else: canvas = current_widget.render((cols,), focus) combinelist.append((canvas, position, focus)) return urwid.CanvasCombine(combinelist)
def render(self, size, focus=False): 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 == urwid.widget.GIVEN: canv = w.render((maxcol, height), focus=focus) elif f == urwid.widget.PACK or len(size) == 1: canv = w.render((maxcol, ), focus=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) if canv: combinelist.append((canv, i, item_focus)) if not combinelist: return urwid.SolidCanvas(" ", size[0], (size[1:] + (0, ))[0]) out = urwid.CanvasCombine(combinelist) if len(size) == 2 and size[1] != out.rows(): # flow/fixed widgets rendered too large/small out = urwid.CompositeCanvas(out) out.pad_trim_top_bottom(0, size[1] - out.rows()) return out
def render(self, size, focus=False): old = self.old.render((size[0], size[1])) new = self.new.render((size[0], size[1])) c = urwid.CanvasCombine([(old, None, False), (new, None, False)]) offset = int(size[1] * self.progress) c.pad_trim_top_bottom(0-offset, 0-(size[1]-offset)) return c
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))
def render(self, size, focus=False): maxcol, maxrow = size canv = super(ShinyMap, self).render(size, focus) self._rebuild_shiny_cache(maxrow) slivers = [] y = 0 for amap, run in self._shiny_cache: c = urwid.CompositeCanvas(canv) c.trim(y, run) y = y + run c.fill_attr_apply(amap) slivers.append((c, None, False)) return urwid.CanvasCombine(slivers)
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))
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))
def render_incremental(self, size, single_bar_data, color_index): (maxcol, maxrow) = size bardata, top, hlines = self.get_data((maxcol, maxrow)) pallet_index = 1 + color_index data_char = self.char[pallet_index] back_char = self.char[0] data_value = single_bar_data char_cnt_data = 0 if data_value >= top: char_cnt_data = maxrow elif data_value > 0: char_cnt_data = int(ceil(maxrow * (data_value / top))) char_cnt_background = maxrow - char_cnt_data back_canvas = StuiSolidCanvas(back_char, 1, char_cnt_background, self.attr[0]) # check if higher resolution smooth graph is enabled if len(self.satt) is 0: data_canvas = StuiSolidCanvas(data_char, 1, char_cnt_data, self.attr[pallet_index]) if char_cnt_data == 0: combine_list_item = [(back_canvas, None, False)] elif char_cnt_background == 0: combine_list_item = [(data_canvas, None, False)] else: combine_list_item = [(back_canvas, None, False), (data_canvas, None, False)] else: data_canvas = StuiSolidCanvas(data_char, 1, char_cnt_data - 1, self.attr[pallet_index]) last_char_data_span = top / maxrow last_char_data_span_eights = last_char_data_span / 8 last_char_raw_value = char_cnt_data * last_char_data_span last_char_bg_value = last_char_raw_value - data_value last_char_data_residue = last_char_data_span - last_char_bg_value last_char_portion = int( round(last_char_data_residue / last_char_data_span_eights)) - 1 last_char = self.eighths[last_char_portion] edge_canvas = StuiSolidCanvas(last_char, 1, 1, self.satt[(pallet_index, 0)]) if char_cnt_data == 0: combine_list_item = [(back_canvas, None, False)] elif char_cnt_background == 0: combine_list_item = [(edge_canvas, None, False), (data_canvas, None, False)] else: combine_list_item = [(back_canvas, None, False), (edge_canvas, None, False), (data_canvas, None, False)] column_canvas = urwid.CanvasCombine(combine_list_item) self.column_canvas_list.append((column_canvas, None, False, 1))
def render(self, size, focus=False): """ Render frame and return it. """ (maxcol, maxrow) = size (htrim, ctrim, ftrim), (hrows, crows, frows) = self.frame_top_bottom( (maxcol, maxrow), focus) combinelist = [] depends_on = [] head = None if htrim and htrim < hrows: head = urwid.Filler(self.header, 'top').render( (maxcol, htrim), focus and self.focus_part == 'header') elif htrim: head = self.header.render((maxcol, ), focus and self.focus_part == 'header') assert head.rows() == hrows, "rows, render mismatch" if head: combinelist.append((head, 'header', self.focus_part == 'header')) depends_on.append(self.header) if ftrim + htrim + ctrim < maxrow: body = self.body.render((maxcol, maxrow - ftrim - htrim - ctrim), focus and self.focus_part == 'body') combinelist.append((body, 'body', self.focus_part == 'body')) depends_on.append(self.body) columns = None if ctrim and ctrim < crows: if self.focus_part == 'value': columns = urwid.Filler(self.columns_pile, 'columns').render( (maxcol, ftrim), #TODO Changeit it to return command or result focus and self.focus_part == 'value') self.log.debug("render in value %s" % (self.focus_part == 'value')) elif self.focus_part == 'result': columns = urwid.Filler(self.columns_pile, 'columns').render( (maxcol, ftrim), #TODO Changeit it to return command or result focus and self.focus_part == 'result') self.log.debug("render in result %s" % (self.focus_part == 'result')) else: columns = urwid.Filler(self.columns_pile, 'columns').render( (maxcol, ftrim), #TODO Changeit it to return command or result focus and self.focus_part == 'command') self.log.debug("render in command %s" % (self.focus_part == 'command')) elif ctrim: if self.focus_part == 'value': columns = self.columns_pile.render( (maxcol, ), focus and self.focus_part == 'value') self.log.debug("render in value %s" % (self.focus_part == 'value')) elif self.focus_part == 'result': columns = self.columns_pile.render( (maxcol, ), focus and self.focus_part == 'result') self.log.debug("render in result %s" % (self.focus_part == 'result')) else: columns = self.columns_pile.render( (maxcol, ), focus and self.focus_part == 'command') self.log.debug("render in command %s" % (self.focus_part == 'command')) assert columns.rows() == crows, "rows, render mismatch" if columns: newfocus = "%s" % self.focus_part combinelist.append((columns, 'columns', self.focus_part == "command" or self.focus_part == "value" \ or self.focus_part == "result")) depends_on.append(self.columns_pile) foot = None if ftrim and ftrim < frows: foot = urwid.Filler(self.footer, 'bottom').render( (maxcol, ftrim), focus and self.focus_part == 'footer') elif ftrim: foot = self.footer.render((maxcol, ), focus and self.focus_part == 'footer') assert foot.rows() == frows, "rows, render mismatch" if foot: combinelist.append((foot, 'footer', self.focus_part == 'footer')) depends_on.append(self.footer) return urwid.CanvasCombine(combinelist)
def render(self, size, focus=False): """Render listbox and return canvas. """ (maxcol, maxrow) = size middle, top, bottom = self.calculate_visible((maxcol, maxrow), focus=focus) if middle is None: return urwid.SolidCanvas(" ", maxcol, maxrow) _ignore, focus_widget, focus_pos, focus_rows, cursor = middle trim_top, fill_above = top trim_bottom, fill_below = bottom if bottom[1]: self._bottom_pos = bottom[1][-1][1] else: self._bottom_pos = None if top[1]: self._top_pos = top[1][-1][1] else: self._top_pos = None self._focus_pos = focus_pos combinelist = [] rows = 0 fill_above.reverse() # fill_above is in bottom-up order for widget, w_pos, w_rows in fill_above: canvas = widget.render((maxcol, )) attr = self.get_row_attr(w_pos) if attr: canvas = urwid.CompositeCanvas(canvas) canvas.fill_attr(attr) if w_rows != canvas.rows(): raise urwid.ListBoxError, BADROWSMSG % ( ` widget `, ` w_pos `, w_rows, canvas.rows()) rows += w_rows combinelist.append((canvas, w_pos, False)) focus_canvas = focus_widget.render((maxcol, ), focus=focus) focus_attr = None if focus_pos in self.row_attrs: focus_attr = self.get_row_attr(focus_pos) if focus and self.focus_str: focus_attr += self.focus_str elif focus: focus_attr = self.focus_attr if focus_attr: focus_canvas = urwid.CompositeCanvas(focus_canvas) focus_canvas.fill_attr(focus_attr) if focus_canvas.rows() != focus_rows: raise ListBoxError, BADFOCUSROWSMSG % ( ` focus_widget `, ` focus_pos `, focus_rows, focus_canvas.rows()) c_cursor = focus_canvas.cursor if cursor != c_cursor: raise urwid.ListBoxError, BADCURSORMSG % ( ` focus_widget `, ` focus_pos `, ` cursor `, ` c_cursor `) rows += focus_rows combinelist.append((focus_canvas, focus_pos, True)) for widget, w_pos, w_rows in fill_below: canvas = widget.render((maxcol, )) attr = self.get_row_attr(w_pos) if attr: canvas = urwid.CompositeCanvas(canvas) canvas.fill_attr(attr) if w_rows != canvas.rows(): raise urwid.ListBoxError, BADROWSMSG % ( ` widget `, ` w_pos `, w_rows, canvas.rows()) rows += w_rows combinelist.append((canvas, w_pos, False)) final_canvas = urwid.CanvasCombine(combinelist) if trim_top: final_canvas.trim(trim_top) rows -= trim_top if trim_bottom: final_canvas.trim_end(trim_bottom) rows -= trim_bottom assert rows <= maxrow if rows < maxrow: bottom_pos = focus_pos if fill_below: bottom_pos = fill_below[-1][1] assert trim_bottom == 0 and self.body.get_next(bottom_pos) == ( None, None) final_canvas.pad_trim_top_bottom(0, maxrow - rows) return final_canvas