Skip to content

Commit

Permalink
AdHocAttrMap: support multiple markups with urwid.Text
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasTomecek committed Jan 2, 2016
1 parent dff3f8c commit ce818af
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion sen/tui/widgets/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import logging

import urwid

from sen.tui.constants import MAIN_LIST_FOCUS

logger = logging.getLogger(__name__)


class AdHocAttrMap(urwid.AttrMap):
"""
Expand All @@ -10,7 +16,18 @@ class AdHocAttrMap(urwid.AttrMap):
def __init__(self, w, maps, init_map='normal'):
self.maps = maps
urwid.AttrMap.__init__(self, w, maps[init_map])
if isinstance(w, urwid.Text):
self.attrs = [x[0] for x in self.original_widget.get_text()[1]]

def set_map(self, attrstring):
self.set_attr_map({None: self.maps[attrstring]})
attr_map = {None: self.maps[attrstring]}

# for urwid.Text only: do hovering for all markups in the widget
if isinstance(self.original_widget, urwid.Text):
if attrstring == "normal":
for a in self.attrs:
attr_map[self.maps["focus"]] = a
elif attrstring == "focus":
for a in self.attrs:
attr_map[a] = self.maps["focus"]
self.set_attr_map(attr_map)

0 comments on commit ce818af

Please sign in to comment.