console: generalise grideditor help text, only show headers if we have them

This commit is contained in:
Aldo Cortesi 2017-06-11 12:07:02 +12:00
parent a4833a5bbf
commit ecce260542

View File

@ -294,18 +294,20 @@ class BaseGridEditor(urwid.WidgetWrap):
first_width = max(len(r), first_width) first_width = max(len(r), first_width)
self.first_width = min(first_width, FIRST_WIDTH_MAX) self.first_width = min(first_width, FIRST_WIDTH_MAX)
headings = [] h = None
for i, col in enumerate(self.columns): if any(col.heading for col in self.columns):
c = urwid.Text(col.heading) headings = []
if i == 0 and len(self.columns) > 1: for i, col in enumerate(self.columns):
headings.append(("fixed", first_width + 2, c)) c = urwid.Text(col.heading)
else: if i == 0 and len(self.columns) > 1:
headings.append(c) headings.append(("fixed", first_width + 2, c))
h = urwid.Columns( else:
headings, headings.append(c)
dividechars=2 h = urwid.Columns(
) headings,
h = urwid.AttrWrap(h, "heading") dividechars=2
)
h = urwid.AttrWrap(h, "heading")
self.walker = GridWalker(self.value, self) self.walker = GridWalker(self.value, self)
self.lb = GridListBox(self.walker) self.lb = GridListBox(self.walker)
@ -329,9 +331,9 @@ class BaseGridEditor(urwid.WidgetWrap):
self._w.set_footer( self._w.set_footer(
urwid.Text( urwid.Text(
[ [
("highlight", "No values. Press "), ("highlight", "No values - you should add some. Press "),
("key", "a"), ("key", "?"),
("highlight", " to add some."), ("highlight", " for help."),
] ]
) )
) )