From 8bf3b31f489e0fe5f05ef1e949ae70f8156e3356 Mon Sep 17 00:00:00 2001 From: slack Date: Tue, 17 Nov 2009 15:37:00 +0100 Subject: [PATCH] screen refresh timing using halfdelay and getch in a loop --- melon-view.py | 96 ++++++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/melon-view.py b/melon-view.py index 6e6df71..dd28627 100755 --- a/melon-view.py +++ b/melon-view.py @@ -7,7 +7,7 @@ import os import time log_dirs = sys.argv[1:] -refresh_interval = 2 +refresh_interval = 10 # tenths of a second class AppInfo: def __init__(self, name, user, machine, status, progress): @@ -45,6 +45,7 @@ def get_apps_info(): def main(stdscr): curses.use_default_colors() + curses.halfdelay(refresh_interval) rows, cols = stdscr.getmaxyx() if cols < 80: print "Terminal is too narrow" @@ -62,49 +63,56 @@ def main(stdscr): exit = False while not exit: - if time.time() - last_refresh > refresh_interval: - last_refresh = time.time() - apps = get_apps_info() - - stdscr.erase() - if len(apps) > 0: - for i in xrange(min(numboxes, len(apps)-cur_pos)): - app = apps[cur_pos + i] - stdscr.attrset(curses.color_pair(1) | curses.A_NORMAL) - stdscr.addstr(3*i+1, 2, "..."+app.name[-57:], curses.A_BOLD) - stdscr.addstr(3*i+1, 65, (app.user+"@"+app.machine)[:barsize]) - stdscr.addstr(3*i+2, 2, app.status[cur_x_pos:cur_x_pos+57]) - - stdscr.addch(3*i+2, 65, "[", curses.A_BOLD) - stdscr.addch(3*i+2, cols-2, "]", curses.A_BOLD) - # PROGRESS BAR - stdscr.attrset(curses.color_pair(3) | curses.A_BOLD) - stdscr.hline(3*i+2, 66, "|", barsize) - stdscr.attrset(curses.color_pair(2) | curses.A_BOLD) - stdscr.hline(3*i+2, 66, "|", int((app.progress/100.0)*barsize)) - stdscr.attrset(curses.color_pair(1) | curses.A_BOLD) - stdscr.addstr(3*i+2, 60, str(app.progress)+"%", curses.A_BOLD) - stdscr.hline(3*(i+1),1,curses.ACS_HLINE, cols-2) - - stdscr.box() - try: - cmd = stdscr.getch() - except: - pass - if cmd == ord('q'): - exit = True - elif cmd == curses.KEY_DOWN: - if cur_pos < len(apps)-numboxes: - cur_pos += 1 - elif cmd == curses.KEY_UP: - if cur_pos > 0: - cur_pos -= 1 - elif cmd == curses.KEY_RIGHT: - cur_x_pos += 10 - elif cmd == curses.KEY_LEFT: - if cur_x_pos > 0: - cur_x_pos -= 10 - stdscr.refresh() + apps = get_apps_info() + + stdscr.erase() + stdscr.attrset(curses.color_pair(1) | curses.A_NORMAL) + if len(apps) > 0: + for i in xrange(min(numboxes, len(apps)-cur_pos)): + app = apps[cur_pos + i] + stdscr.addstr(3*i+1, 2, "..."+app.name[-57:], curses.A_BOLD) + stdscr.addstr(3*i+1, 65, (app.user+"@"+app.machine)[:barsize]) + stdscr.addstr(3*i+2, 2, app.status[cur_x_pos:cur_x_pos+57]) + + # PROGRESS BAR + stdscr.addch(3*i+2, 65, "[", curses.A_BOLD) + stdscr.addch(3*i+2, cols-2, "]", curses.A_BOLD) + stdscr.attrset(curses.color_pair(3) | curses.A_BOLD) + stdscr.hline(3*i+2, 66, "|", barsize) + stdscr.attrset(curses.color_pair(2) | curses.A_BOLD) + stdscr.hline(3*i+2, 66, "|", int((app.progress/100.0)*barsize)) + stdscr.attrset(curses.color_pair(1) | curses.A_BOLD) + stdscr.addstr(3*i+2, 60, str(app.progress)+"%", curses.A_BOLD) + stdscr.hline(3*(i+1),1,curses.ACS_HLINE, cols-2) + stdscr.attrset(curses.color_pair(1) | curses.A_NORMAL) + else: + stdscr.addstr(2,2, "No log files found. All tasks are finished or you forgot the directory name :)") + + # BORDER + stdscr.attrset(curses.color_pair(1) | curses.A_BOLD) + stdscr.box() + stdscr.attrset(curses.color_pair(1) | curses.A_NORMAL) + + # STATUS BAR + stdscr.addstr(rows-1, 3, " viewing [%d-%d] of %d apps "%(cur_pos, min(cur_pos+numboxes-1, len(apps)-1), len(apps)) ) + try: + cmd = stdscr.getch() + except: + pass + if cmd == ord('q'): + exit = True + elif cmd == curses.KEY_DOWN: + if cur_pos < len(apps)-numboxes: + cur_pos += 1 + elif cmd == curses.KEY_UP: + if cur_pos > 0: + cur_pos -= 1 + elif cmd == curses.KEY_RIGHT: + cur_x_pos += 10 + elif cmd == curses.KEY_LEFT: + if cur_x_pos > 0: + cur_x_pos -= 10 + stdscr.refresh() curses.wrapper(main) -- 2.34.1