1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# Copyright (C) 2011-2012 Patrick Totzke <patricktotzke@gmail.com>
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file
"""
Utility Widgets not specific to alot
"""
import urwid
class AttrFlipWidget(urwid.AttrMap):
"""
An AttrMap that can remember attributes to set
"""
def __init__(self, w, maps, init_map='normal'):
self.maps = maps
urwid.AttrMap.__init__(self, w, maps[init_map])
def set_map(self, attrstring):
self.set_attr_map({None: self.maps[attrstring]})
class DialogBox(urwid.WidgetWrap):
def __init__(self, body, title, bodyattr=None, titleattr=None):
self.body = urwid.LineBox(body)
self.title = urwid.Text(title)
if titleattr is not None:
self.title = urwid.AttrMap(self.title, titleattr)
if bodyattr is not None:
self.body = urwid.AttrMap(self.body, bodyattr)
box = urwid.Overlay(self.title, self.body,
align='center',
valign='top',
width=len(title),
height=None)
urwid.WidgetWrap.__init__(self, box)
def selectable(self):
return self.body.selectable()
def keypress(self, size, key):
return self.body.keypress(size, key)
|