diff options
| author | James E. Blair <corvus@gnu.org> | 2018-03-30 14:06:30 -0700 |
|---|---|---|
| committer | James E. Blair <corvus@gnu.org> | 2018-03-30 14:06:30 -0700 |
| commit | 51d64be68d8d8b75ff374f207a5bc153f787769e (patch) | |
| tree | 5a63bfa452279d136f373b550df775fc254a8bb5 | |
| parent | 8384c6de2cd3e170191ed0e90d35648eda179a7c (diff) | |
Make bulleted lists more robust0.2.1
Errors in pack methods could cause urwid to throw an exception
when rendering bullet lists which line-wrapped.
| -rw-r--r-- | presentty/slide.py | 15 |
1 files changed, 14 insertions, 1 deletions
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): | |||
| 20 | cols = 0 | 20 | cols = 0 |
| 21 | rows = 0 | 21 | rows = 0 |
| 22 | for x in self.contents: | 22 | for x in self.contents: |
| 23 | # If we have no columns to use, we won't render, so don't | ||
| 24 | # erroneously accumulate rows. | ||
| 25 | if not size[0]: | ||
| 26 | continue | ||
| 23 | c,r = x[0].pack((size[0],)) | 27 | c,r = x[0].pack((size[0],)) |
| 24 | if c>cols: | 28 | if c>cols: |
| 25 | cols = c | 29 | cols = c |
| @@ -35,16 +39,25 @@ class SlidePadding(urwid.Padding): | |||
| 35 | 39 | ||
| 36 | class SlideColumns(urwid.Columns): | 40 | class SlideColumns(urwid.Columns): |
| 37 | def pack(self, size, focus=False): | 41 | def pack(self, size, focus=False): |
| 42 | # Unlike the normal Columns widget, find the mininum number of | ||
| 43 | # (character) columns necessary to render. This probably only | ||
| 44 | # works for the limited 2-column case we have for bulleted | ||
| 45 | # lists. | ||
| 46 | # cols is the resulting number of columns needed | ||
| 38 | cols = self.dividechars * (len(self.contents)-1) | 47 | cols = self.dividechars * (len(self.contents)-1) |
| 39 | rows = 0 | 48 | rows = 0 |
| 49 | # Given our current width, col_budget is the number of columns | ||
| 50 | # remaining available. | ||
| 51 | col_budget = size[0]-cols | ||
| 40 | for widget, packing in self.contents: | 52 | for widget, packing in self.contents: |
| 41 | if packing[0] == 'given': | 53 | if packing[0] == 'given': |
| 42 | allocated_cols = packing[1] | 54 | allocated_cols = packing[1] |
| 43 | else: | 55 | else: |
| 44 | allocated_cols = size[0] | 56 | allocated_cols = col_budget |
| 45 | c,r = widget.pack((allocated_cols,)) | 57 | c,r = widget.pack((allocated_cols,)) |
| 46 | if packing[0] == 'given': | 58 | if packing[0] == 'given': |
| 47 | c = allocated_cols | 59 | c = allocated_cols |
| 60 | col_budget -= c | ||
| 48 | if r>rows: | 61 | if r>rows: |
| 49 | rows = r | 62 | rows = r |
| 50 | cols += c | 63 | cols += c |
