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

cleanup

parent 62a60fd2
......@@ -7,7 +7,7 @@ class CheckBox(Drawable):
Args:
text: The text to show.
value: An internal name to identify this checkbox.
name: 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.
"""
......
......@@ -16,9 +16,9 @@ class FocusSwitcher(Focusable):
last_focused: Element which had the focus before we lost our focus.
"""
def __init__(self, *, elements=[], prev_key=None, next_key=None):
def __init__(self, *, elements=None, prev_key=None, next_key=None):
Focusable.__init__(self)
self.elements = elements
self.elements = elements if elements else list()
self.prev_key = prev_key
self.next_key = next_key
self.last_focused = None
......@@ -67,4 +67,3 @@ class FocusSwitcher(Focusable):
self.elements[i].toggle_focus()
self.elements[i - 1].toggle_focus()
break
......@@ -7,8 +7,8 @@ from .focusswitcher import FocusSwitcher
class NumberBarContainer(FocusSwitcher):
"""Combine NumberRange and ProgressBar objects to unify their state."""
def __init__(self, *, elements=[], prev_key=None, next_key=None):
super().__init__(elements=elements, prev_key=None, next_key=None)
def __init__(self, *, elements=None):
super().__init__(elements=elements)
def send_key(self, key):
"""Same as FocusSwitcher, but sets ProgressBar.value to NumberRange.value"""
......
......@@ -6,10 +6,10 @@ class CursesHandler(logging.Handler):
def __init__(self, screen):
logging.Handler.__init__(self)
maxy, maxx = screen.getmaxyx()
win_log_border = screen.subwin(5, maxx, maxy - 5, 0)
max_y, max_x = screen.getmaxyx()
win_log_border = screen.subwin(5, max_x, max_y - 5, 0)
win_log_border.border(0)
win_log = win_log_border.subwin(3, maxx - 2, maxy - 4, 1)
win_log = win_log_border.subwin(3, max_x - 2, max_y - 4, 1)
win_log.scrollok(True)
win_log.idlok(True)
win_log.leaveok(True)
......
......@@ -16,8 +16,8 @@ class ProgressBar(Drawable):
def __init__(self, *, window, row=0, col=0, width=0, height=0, value=0,
max_value=100, text='', attr=curses.A_STANDOUT):
assert(width > 2)
assert(height > 2)
assert (width > 2)
assert (height > 2)
self.value = value
self.max = max_value
self.text = text
......@@ -33,10 +33,12 @@ class ProgressBar(Drawable):
# inner box
self.width = width - 2
self.height = height - 2
Drawable.__init__(self,
Drawable.__init__(
self,
window=window.subwin(self.height, self.width, row + 1, col + 1),
row=row + 1,
col=col + 1)
col=col + 1
)
def draw(self):
self.window.erase()
......
#!/usr/bin/env python3
import logging
import time
import curses
from curses import wrapper
import lights
from gui.abstracts.drawable import Drawable
from gui.abstracts.focusable import Focusable
from gui.curseshandler import CursesHandler
from gui.numberrange import NumberRange
from gui.checkbox import CheckBox
......@@ -16,8 +13,8 @@ from gui.container.numberbar import NumberBarContainer
def main(stdscr):
stdscr.clear()
maxy, maxx = stdscr.getmaxyx()
scr_center_x = maxx // 2
max_y, max_x = stdscr.getmaxyx()
scr_center_x = max_x // 2
# hide cursor
curses.curs_set(0)
# init colors
......@@ -36,7 +33,7 @@ def main(stdscr):
# draw title
title = "nchl - ncurses HoneyLight control"
stdscr.addstr(0, scr_center_x - len(title) // 2,title, curses.A_BOLD)
stdscr.addstr(0, scr_center_x - len(title) // 2, title, curses.A_BOLD)
# draw colors
numbers_text = [
......@@ -55,7 +52,8 @@ def main(stdscr):
value=255,
max_value=255,
attr=curses.color_pair(numbers_text[i][1]),
text=numbers_text[i][0]) for i in range(len(numbers_text))]
text=numbers_text[i][0]) for i in range(len(numbers_text))
]
numbers = [
NumberRange(
window=stdscr,
......@@ -63,14 +61,13 @@ def main(stdscr):
row=13,
value=255,
prev_key='KEY_DOWN',
next_key='KEY_UP') for i in range(len(numbers_text))]
next_key='KEY_UP') for i in range(len(numbers_text))
]
fs_pbn = [
NumberBarContainer(
elements=i) for i in zip(numbers, progress_bars)]
fs_n = FocusSwitcher(
elements=fs_pbn,
prev_key='KEY_LEFT',
next_key='KEY_RIGHT')
NumberBarContainer(elements=i) for i in zip(numbers, progress_bars)
]
fs_n = FocusSwitcher(elements=fs_pbn, prev_key='KEY_LEFT',
next_key='KEY_RIGHT')
# draw hosts
checkboxes_top = [
......@@ -81,7 +78,8 @@ def main(stdscr):
toggle_key=' ',
toggle_key_unfocused=str(i),
text='ESP({})'.format(i),
name=i) for i in [1, 3, 5, 7]]
name=i) for i in [1, 3, 5, 7]
]
checkboxes_bottom = [
CheckBox(
window=stdscr,
......@@ -90,11 +88,10 @@ def main(stdscr):
toggle_key=' ',
toggle_key_unfocused=str(i),
text='ESP({})'.format(i),
name=i) for i in [2, 4, 6, 8]]
fs_cb = FocusSwitcher(
elements=checkboxes_top + checkboxes_bottom,
prev_key='KEY_LEFT',
next_key='KEY_RIGHT')
name=i) for i in [2, 4, 6, 8]
]
fs_cb = FocusSwitcher(elements=checkboxes_top + checkboxes_bottom,
prev_key='KEY_LEFT', next_key='KEY_RIGHT')
# draw settings
continous = CheckBox(
......@@ -102,8 +99,11 @@ def main(stdscr):
col=scr_center_x - 12,
row=18,
toggle_key_unfocused='c',
text='(c)ontinuous updating')
stdscr.addstr(19, scr_center_x - 20, '(s)end | all (o)ff | all (w)hite | (q)uit', curses.color_pair(curses.COLOR_YELLOW))
text='(c)ontinuous updating'
)
stdscr.addstr(19, scr_center_x - 20,
'(s)end | all (o)ff | all (w)hite | (q)uit',
curses.color_pair(curses.COLOR_YELLOW))
# focusswitcher
fs_n_cb = FocusSwitcher(elements=[fs_n, fs_cb], prev_key='\t')
......
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