message_dialog.py
1 #! /usr/bin/env python3 2 # -*- coding: utf-8 -*- 3 4 5 import urwid 6 7 8 class MessageDialog(urwid.WidgetWrap): 9 """Wraps 'urwid.Overlay' to show a message and expects a reaction from the user.""" 10 11 def __init__(self, contents, btns, overlay_size, *, contents_align="left", space_between_btns=2, title="", title_align="center", 12 background=urwid.SolidFill("#"), overlay_align=("center", "middle"), overlay_min_size=(None, None), left=0, right=0, 13 top=0, bottom=0): 14 # Message part 15 texts = [urwid.Text(content, align=contents_align) 16 for content in contents] 17 18 # Lower part 19 lower_part = [urwid.Divider(" "), 20 urwid.Columns(btns, dividechars=space_between_btns)] 21 22 # frame 23 line_box = urwid.LineBox(urwid.Pile(texts + lower_part), 24 title=title, 25 title_align=title_align) 26 27 # Wrap 'urwid.Overlay' 28 super().__init__(urwid.Overlay(urwid.Filler(line_box), 29 background, 30 overlay_align[0], 31 overlay_size[0], 32 overlay_align[1], 33 overlay_size[1], 34 min_width=overlay_min_size[0], 35 min_height=overlay_min_size[1], 36 left=left, 37 right=right, 38 top=top, 39 bottom=bottom)) 40