From 51d64be68d8d8b75ff374f207a5bc153f787769e Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Fri, 30 Mar 2018 14:06:30 -0700 Subject: Make bulleted lists more robust Errors in pack methods could cause urwid to throw an exception when rendering bullet lists which line-wrapped. --- presentty/slide.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/presentty/slide.py b/presentty/slide.py index 4894f45..06860fc 100644 --- a/presentty/slide.py +++ b/presentty/slide.py @@ -20,6 +20,10 @@ class SlidePile(urwid.Pile): cols = 0 rows = 0 for x in self.contents: + # If we have no columns to use, we won't render, so don't + # erroneously accumulate rows. + if not size[0]: + continue c,r = x[0].pack((size[0],)) if c>cols: cols = c @@ -35,16 +39,25 @@ class SlidePadding(urwid.Padding): class SlideColumns(urwid.Columns): def pack(self, size, focus=False): + # Unlike the normal Columns widget, find the mininum number of + # (character) columns necessary to render. This probably only + # works for the limited 2-column case we have for bulleted + # lists. + # cols is the resulting number of columns needed cols = self.dividechars * (len(self.contents)-1) rows = 0 + # Given our current width, col_budget is the number of columns + # remaining available. + col_budget = size[0]-cols for widget, packing in self.contents: if packing[0] == 'given': allocated_cols = packing[1] else: - allocated_cols = size[0] + allocated_cols = col_budget c,r = widget.pack((allocated_cols,)) if packing[0] == 'given': c = allocated_cols + col_budget -= c if r>rows: rows = r cols += c -- cgit v1.2.3