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

c.py: add ProgressBar

parent 76b348f3
......@@ -171,12 +171,51 @@ class FocusSwitcher:
break
def progress(window):
# TODO: make it good
win = window.subwin(10, 3, 0, 0)
win.border(0)
win.addstr(1, 1, "#")
win.refresh()
class ProgressBar:
def __init__(self, window, *, row=0, col=0, width=0, height=0, text='',
max_value=100, attr=curses.A_STANDOUT, prev_key=None, next_key=None):
self.row = row
self.col = col
self.width = width
self.height = height
self.max = max_value
self.value = 50
self.attr = attr
self.prev_key = prev_key
self.next_key = next_key
self.window = window.subwin(height, width, row, col)
self.window.border(0)
if len(text) > width:
self.window.addstr(text)
else:
self.window.addstr(0, (width - len(text)) // 2, text)
def toggle_focus(self):
pass
def draw(self):
top = self.height - 1 - int(self.value / self.max * (self.height - 2))
bottom = self.height - 1
for i in range(top, bottom):
self.window.addstr(i, 1, '#' * (self.width - 2), self.attr)
self.window.refresh()
def set(self, value):
self.value = min(value, self.max)
self.value = max(value, 0)
self.draw()
def incr(self):
self.set(self.value + 1)
def decr(self):
self.set(self.value - 1)
def send_key(self, key):
if key == self.prev_key:
self.decr()
elif key == self.next_key:
self.incr()
def main(stdscr):
......@@ -189,23 +228,27 @@ def main(stdscr):
logger.addHandler(CursesHandler(stdscr))
logger.setLevel(logging.INFO)
numbers_text = ['R', 'G', 'B', 'W']
for i in range(len(numbers_text)):
ProgressBar(stdscr, row=0, col=i*8, width=5, height=12, text=numbers_text[i]).draw()
numbers = [
NumberRange(
stdscr,
row=i,
number=i,
prev_key='KEY_LEFT',
next_key='KEY_RIGHT') for i in range(5)]
col = i*8,
row=12,
value=i,
prev_key='KEY_DOWN',
next_key='KEY_UP') for i in range(4)]
checkboxes = [
CheckBox(
stdscr,
row=i,
col=0,
row=i+13,
toggle_key=' ',
text='Toggle' +
str(i)) for i in range(
5,
10)]
fs_n = FocusSwitcher(numbers, prev_key='KEY_UP', next_key='KEY_DOWN')
text='ESP' +
str(i)) for i in range(1,9)]
fs_n = FocusSwitcher(numbers, prev_key='KEY_LEFT', next_key='KEY_RIGHT')
fs_cb = FocusSwitcher(checkboxes, prev_key='KEY_UP', next_key='KEY_DOWN')
fs_main = FocusSwitcher([fs_n, fs_cb], prev_key='\t')
fs_main.toggle_focus()
......
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