Commit 76c72865 authored by Fjen Undso's avatar Fjen Undso
Browse files

gui/progressbar: draw bar in subwindow to simplify

parent 18ce8c54
......@@ -5,29 +5,35 @@ from .abstracts.drawable import Drawable
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):
self.width = width
self.height = height
assert(width > 2)
assert(height > 2)
self.value = value
self.max = max_value
self.text = text
self.attr = attr
Drawable.__init__(self, window=window.subwin(height, width, row, col), row=row, col=col)
def draw(self):
# draw frame
self.window.erase()
self.window = window.subwin(height, width, row, col)
self.window.border(0)
if len(self.text) > self.width:
if len(self.text) > width:
self.window.addstr(self.text)
else:
self.window.addstr(
0, (self.width - len(self.text)) // 2, self.text)
0, (width - len(self.text)) // 2, self.text)
# inner box
self.width = width - 2
self.height = height - 2
Drawable.__init__(self,
window=window.subwin(self.height, self.width, row + 1, col + 1),
row=row + 1,
col=col + 1)
def draw(self):
self.window.erase()
# draw bar
top = self.height - 1 - int(self.value / self.max * (self.height - 2))
bottom = self.height - 1
top = self.height - int(self.value / self.max * self.height)
bottom = self.height
for i in range(top, bottom):
self.window.addstr(i, 1, ' ' * (self.width - 2), self.attr)
self.window.insstr(i, 0, ' ' * self.width, self.attr)
self.window.refresh()
def set(self, value):
......
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