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

gui: cleanup

parent 837ffb61
......@@ -14,14 +14,17 @@ class CheckBox(Drawable):
if self.focus:
attr = curses.A_STANDOUT
self.window.move(self.row, self.col)
prefix = "( ) "
if self.active:
self.window.addstr("(X) " + self.text, attr)
else:
self.window.addstr("( ) " + self.text, attr)
prefix = "(X) "
self.window.addstr(prefix + self.text, attr)
self.window.refresh()
def send_key(self, key):
if self.focus and key == self.toggle_key:
if not self.focus:
return
if key == self.toggle_key:
self.toggle()
def toggle(self):
......
......@@ -22,23 +22,22 @@ class FocusSwitcher(Focusable):
self.elements.append(element)
def send_key(self, key):
if self.focus:
if key == self.prev_key:
self.prev()
elif key == self.next_key:
self.next()
else:
for e in self.elements:
e.send_key(key)
if not self.focus:
return
if key == self.prev_key:
self.prev()
elif key == self.next_key:
self.next()
else:
for e in self.elements:
e.send_key(key)
def next(self):
for i in range(len(self.elements)):
if self.elements[i].focus:
self.elements[i].toggle_focus()
if i == len(self.elements) - 1:
self.elements[0].toggle_focus()
else:
self.elements[i + 1].toggle_focus()
self.elements[(i + 1) % len(self.elements)].toggle_focus()
break
def prev(self):
......
......@@ -27,18 +27,20 @@ class NumberRange(Drawable):
self.window.refresh()
def send_key(self, key):
if self.focus:
if key == self.prev_key:
self.decr()
elif key == self.next_key:
self.incr()
elif key.isdigit():
if len(str(self.value)) == len(str(self.max)):
# reset number if field is full
self.set(int(key))
else:
# add number on right side
self.set(int(str(self.value) + key))
if not self.focus:
return
if key == self.prev_key:
self.decr()
elif key == self.next_key:
self.incr()
elif key.isdigit():
if len(str(self.value)) == len(str(self.max)):
# reset number if field is full
self.set(int(key))
else:
# add number on right side
self.set(int(str(self.value) + key))
def set(self, value):
self.value = min(value, self.max)
......
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