2015-04-06 20:42:40 +00:00
|
|
|
import urwid
|
|
|
|
|
2015-04-06 22:11:25 +00:00
|
|
|
from . import select, common, palettes, signals
|
2015-04-06 20:42:40 +00:00
|
|
|
|
|
|
|
footer = [
|
|
|
|
('heading_key', "enter/space"), ":select",
|
|
|
|
]
|
|
|
|
|
2015-04-06 22:11:25 +00:00
|
|
|
|
2015-04-06 20:42:40 +00:00
|
|
|
def _mkhelp():
|
|
|
|
text = []
|
|
|
|
keys = [
|
|
|
|
("enter/space", "select"),
|
|
|
|
]
|
|
|
|
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
|
|
|
|
return text
|
|
|
|
help_context = _mkhelp()
|
|
|
|
|
|
|
|
|
|
|
|
class PalettePicker(urwid.WidgetWrap):
|
|
|
|
def __init__(self, master):
|
|
|
|
self.master = master
|
|
|
|
low, high = [], []
|
|
|
|
for k, v in palettes.palettes.items():
|
|
|
|
if v.high:
|
|
|
|
high.append(k)
|
|
|
|
else:
|
|
|
|
low.append(k)
|
|
|
|
high.sort()
|
|
|
|
low.sort()
|
|
|
|
|
|
|
|
options = [
|
|
|
|
select.Heading("High Colour")
|
|
|
|
]
|
|
|
|
|
|
|
|
def mkopt(name):
|
|
|
|
return select.Option(
|
|
|
|
i,
|
|
|
|
None,
|
2015-04-06 22:11:25 +00:00
|
|
|
lambda: self.master.palette == name,
|
2015-04-06 20:42:40 +00:00
|
|
|
lambda: self.select(name)
|
|
|
|
)
|
|
|
|
|
|
|
|
for i in high:
|
|
|
|
options.append(mkopt(i))
|
|
|
|
options.append(select.Heading("Low Colour"))
|
|
|
|
for i in low:
|
|
|
|
options.append(mkopt(i))
|
|
|
|
|
2015-04-06 22:11:25 +00:00
|
|
|
options.extend(
|
|
|
|
[
|
|
|
|
select.Heading("Options"),
|
|
|
|
select.Option(
|
|
|
|
"Transparent",
|
|
|
|
"T",
|
|
|
|
lambda: master.palette_transparent,
|
|
|
|
self.toggle_palette_transparent
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2015-04-06 20:42:40 +00:00
|
|
|
self.lb = select.Select(options)
|
|
|
|
title = urwid.Text("Palettes")
|
|
|
|
title = urwid.Padding(title, align="left", width=("relative", 100))
|
|
|
|
title = urwid.AttrWrap(title, "heading")
|
|
|
|
self._w = urwid.Frame(
|
|
|
|
self.lb,
|
|
|
|
header = title
|
|
|
|
)
|
2015-04-06 22:11:25 +00:00
|
|
|
signals.update_settings.connect(self.sig_update_settings)
|
|
|
|
|
|
|
|
def sig_update_settings(self, sender):
|
|
|
|
self.lb.walker._modified()
|
2015-04-06 20:42:40 +00:00
|
|
|
|
|
|
|
def select(self, name):
|
|
|
|
self.master.set_palette(name)
|
2015-04-06 22:11:25 +00:00
|
|
|
|
|
|
|
def toggle_palette_transparent(self):
|
|
|
|
self.master.palette_transparent = not self.master.palette_transparent
|
|
|
|
self.master.set_palette(self.master.palette)
|
|
|
|
signals.update_settings.send(self)
|