Commit 99352034 authored by Fjen Undso's avatar Fjen Undso
Browse files

gui/checkbox.py: add name and change style

parent 5b58ec58
......@@ -7,13 +7,15 @@ class CheckBox(Drawable):
Args:
text: The text to show.
value: An internal name to identify this checkbox.
toggle_key: Key to toggle the state on focus.
toggle_key_unfocused: Key to toggle the state without focus.
"""
def __init__(self, *, window, row=0, col=0, text=None, toggle_key=None,
toggle_key_unfocused=None):
def __init__(self, *, window, row=0, col=0, text=None, name=None,
toggle_key=None, toggle_key_unfocused=None):
self.text = text
self.name = name
self.toggle_key = toggle_key
self.toggle_key_unfocused = toggle_key_unfocused
self.active = False
......@@ -24,9 +26,7 @@ class CheckBox(Drawable):
if self.focus:
attr = curses.A_STANDOUT
self.window.move(self.row, self.col)
prefix = "( ) "
if self.active:
prefix = "(X) "
prefix = "[X] " if self.active else "[ ] "
self.window.addstr(prefix + self.text, attr)
self.window.refresh()
......
......@@ -72,19 +72,21 @@ def main(stdscr):
checkboxes_top = [
CheckBox(
window=stdscr,
col=i // 2 * 10,
col=i // 2 * 11,
row=15,
toggle_key=' ',
toggle_key_unfocused=str(i),
text='ESP' + str(i)) for i in [1, 3, 5, 7]]
text='ESP({})'.format(i),
name='ESP{}'.format(i)) for i in [1, 3, 5, 7]]
checkboxes_bottom = [
CheckBox(
window=stdscr,
col=(i - 1) // 2 * 10,
col=(i - 1) // 2 * 11,
row=16,
toggle_key=' ',
toggle_key_unfocused=str(i),
text='ESP' + str(i)) for i in [2, 4, 6, 8]]
text='ESP({})'.format(i),
name='ESP{}'.format(i)) for i in [2, 4, 6, 8]]
fs_cb = FocusSwitcher(
elements=checkboxes_top + checkboxes_bottom,
prev_key='KEY_LEFT',
......@@ -113,7 +115,7 @@ def main(stdscr):
if k == 's' or continous.active:
colors = lights.make_stripe_data(
[numbers[1].value, numbers[0].value, numbers[2].value, numbers[3].value] * 42)
esps = [e.text for e in checkboxes_top + checkboxes_bottom if e.active]
esps = [e.name for e in checkboxes_top + checkboxes_bottom if e.active]
lights.send_to_many(colors, esps)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment