X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=client_prototype.py;h=31d66f085c70cfd7d6a434d7a65bbffaa8969968;hb=4efbaf6e0a5936d2bdeaf495db1b49ca9a3724c9;hp=0a2bb0a1d58e9fe361ed9a811ecf49b41db81317;hpb=5e1997b93636a18e2a4b94ce96601170b821ffbd;p=plomrogue diff --git a/client_prototype.py b/client_prototype.py index 0a2bb0a..31d66f0 100644 --- a/client_prototype.py +++ b/client_prototype.py @@ -1,4 +1,5 @@ import curses +import signal def set_window_geometries(): @@ -25,8 +26,7 @@ def set_window_geometries(): if (win_i > 0): # If not, get win's closest predecessor starting a new stack on the - # screen top, fit win's top left corner that predecessor's top - # right corner. + # screen top,fit win's top left to that win_top's top right corner. win_top = None for i in range(win_i - 1, -1, -1): win_top = windows[i] @@ -45,13 +45,11 @@ def set_window_geometries(): win["start"][0] = next_free_y # If that fails, try to fit win's top left corner to the top right - # corner of its closest predecessor win_test that 1) is below - # win_top (win's closest predecessor starting a new stack on the - # screen top) 2) and has enough space open to its right between its - # right edge and the lower edge of a window win_high located - # directly above win_test to fit win there (without growing further - # to the right than win_high does or surpassing the lower edge of - # the screen). + # corner of its closest predecessor win_test 1) below win_top (see + # above) 2) and with enough space open to its right between its + # right edge and the lower edge of a win_high located directly + # above win_test to fit win there (without growing further to the + # right than win_high does or surpassing the screen's lower edge). else: win_test = win_prev win_high = None @@ -72,6 +70,10 @@ def set_window_geometries(): break win_test = win_high + global screen_size, stdscr + curses.endwin() + stdscr = curses.initscr() + screen_size = stdscr.getmaxyx() for win in windows: set_window_size() place_window() @@ -85,8 +87,8 @@ def draw_screen(): j = win["start"][int(k == 0)] - sep_size if (j >= 0 and j < screen_size[int(k == 0)]): start = win["start"][k] - end = win["start"][k] + win["size"][k] start = start if start >= 0 else 0 + end = win["start"][k] + win["size"][k] end = end if end < screen_size[k] else screen_size[k] if k: [stdscr.addch(j, i, '-') for i in range(start, end)] @@ -126,6 +128,7 @@ def draw_screen(): and x_in_screen < screen_size[1]): stdscr.addch(y_in_screen, x_in_screen, cell) + stdscr.clear() draw_window_border_lines() draw_window_border_corners() draw_window_contents() @@ -136,11 +139,14 @@ def main(stdscr): curses.noecho() curses.curs_set(False) # stdscr.keypad(True) + signal.signal(signal.SIGWINCH, + lambda ignore_1, ignore_2: set_window_geometries()) set_window_geometries() while True: draw_screen() - stdscr.getch() - + char = stdscr.getch() + if (char >= 0 and chr(char) == 'Q'): + exit() def foo(): winmap = ['.', 'o', '.', 'o', 'O', 'o', '.', 'o', '.', 'x', 'y', 'x'] @@ -158,7 +164,7 @@ windows = [ ] sep_size = 1 # Width of inter-window borders and title bars. -stdscr = curses.initscr() -screen_size = stdscr.getmaxyx() +stdscr = None +screen_size = [0,0] curses.wrapper(main)