client: Rework select ui with header and centered scroll

master
Felix Stupp 4 years ago
parent c6b7f6636c
commit d8a91749a2
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -8,6 +8,8 @@ from time import sleep
# Configuration
text_album_current = "Aktuelles Album"
text_album_root = "(Alle Fotoalben)"
text_closed_pictures = "Gehe zurück ..."
text_load_pictures = "Bilder werden geladen ..."
text_no_pictures_found = "Hier sind leider noch keine Bilder drinnen."
@ -56,12 +58,40 @@ def search_pictures(out, path):
out(text_closed_pictures)
return ret
def draw_select(win, dirs, sel, y_offset = 0):
y_size, x_size = win.getmaxyx()
y_size -= y_offset
# centered scroll
y_center = y_size // 2
for y in range(y_size):
y_real = y + y_offset
i = sel + y - y_center
if i < 0 or len(dirs) <= i:
win.addstr(y_real, 1, " " * (x_size - 2), curses.A_NORMAL)
else:
text = " "
text += indicator if i == sel else (" " * len(indicator))
text += " "
text += dirs[i].name
text = stretch(text, x_size - 2)
text_format = curses.A_STANDOUT if i == sel else curses.A_NORMAL
win.addstr(y_real, 1, text, text_format)
return True
def draw_header(win, base_dir, path):
x_size = win.getmaxyx()[1]
desc = build_description(base_dir, path)
text = text_album_current + ": "
text += desc if len(desc) > 0 else text_album_root
win.addstr(1, 1, stretch(text, x_size - 2))
def show_select(win, base_dir, path):
if not path.is_dir():
raise Exception("'" + str(path) + "' is not a directory!")
dirs = sorted([d for d in path.iterdir() if d.is_dir()])
win.clear()
if len(dirs) <= 0:
draw_header(win, base_dir, path)
x_size = win.getmaxyx()[1]
def out(text):
win.addstr(3, 1, stretch(text, x_size - 2))
@ -69,8 +99,8 @@ def show_select(win, base_dir, path):
return search_pictures(out, path)
sel = 0
while True:
for y, d in enumerate(dirs):
win.addstr(y, 0, (indicator + " " if y == sel else " ") + d.name + (" " * (curses.COLS - 2 - len(d.name))), curses.A_STANDOUT if y == sel else curses.A_NORMAL)
draw_header(win, base_dir, path)
draw_select(win, dirs, sel, y_offset=3)
c = win.getch()
if c in binding_up:
sel = max(0, sel - 1)

Loading…
Cancel
Save