Jul-22-2020, 11:08 PM
Yes, I am asking why there is no del_panel() function in curses.panel and also why there is no delwin() function in curses. It seems to me that without these functions if a lot of curses windows and panels are created by an application and never deleted, there could possibly be severe memory leaks.
The first simple python curses program below works the same in Windows and in Linux. The next simple python program using curses.panels works in Linux, but in Windows (using the "windows-curses" module installed via pip) generates no output at all and then returns to the command line.
In both Windows python executions cases I am invoking python in a cmd.exe window and have the Windows environment variable TERM set to "xterm-256color". I tested these programs under Win10-64, python 64-bit version 3.8.3 and under Debian linux 9 python version 3.5.3.
Any help you can provide to show me why the simple panels program does not generate any output at all is appreciated.
Peter
The first simple python curses program below works the same in Windows and in Linux. The next simple python program using curses.panels works in Linux, but in Windows (using the "windows-curses" module installed via pip) generates no output at all and then returns to the command line.
In both Windows python executions cases I am invoking python in a cmd.exe window and have the Windows environment variable TERM set to "xterm-256color". I tested these programs under Win10-64, python 64-bit version 3.8.3 and under Debian linux 9 python version 3.5.3.
Any help you can provide to show me why the simple panels program does not generate any output at all is appreciated.
Peter
import curses # Get a C character def CCHAR(ch): if type(ch)==str: return ord(ch) elif type(ch)==int: return ch else: raise Exception("CCHAR: can't parse a non-char/non-int value.") # Alternate character set def ALTCHAR(ch): if type(ch)==str: return ord(ch) | A_ALTCHARSET elif type(ch)==int: return ch | A_ALTCHARSET else: raise Exception("ALTCHAR: can't parse a non-char/non-int value.") def create_newwin(height, width, starty, startx): local_win = curses.newwin(height, width, starty, startx) local_win.box(0, 0) local_win.refresh() return local_win def destroy_win(local_win): local_win.border(CCHAR(' '), CCHAR(' '), CCHAR(' '), CCHAR(' '), CCHAR(' '), CCHAR(' '), CCHAR(' '), CCHAR(' ')) local_win.refresh() local_win.erase() stdscr = curses.initscr() curses.cbreak() curses.noecho() curses.curs_set(0) stdscr.keypad(True) height = 3 width = 10 LINES, COLS = stdscr.getmaxyx() starty = int((LINES - height) / 2) startx = int((COLS - width) / 2) stdscr.addstr("Use cursor keys to move the window, press Q to exit") stdscr.refresh() my_win = create_newwin(height, width, starty, startx) ch = 0 while ( (ch != CCHAR('q')) and (ch != CCHAR('Q')) ): ch = stdscr.getch() if ch == curses.KEY_LEFT: if startx - 1 >= 0: destroy_win(my_win) startx -= 1 my_win = create_newwin(height, width, starty, startx) elif ch == curses.KEY_RIGHT: if startx + width < COLS: destroy_win(my_win) startx += 1 my_win = create_newwin(height, width, starty, startx) elif ch == curses.KEY_UP: if starty - 1 > 0: destroy_win(my_win) starty -= 1 my_win = create_newwin(height, width, starty, startx) elif ch == curses.KEY_DOWN: if starty + height < LINES: destroy_win(my_win) starty += 1 my_win = create_newwin(height, width, starty, startx) curses.endwin()
from curses import * from curses.panel import * lines = 10 cols = 40 y = 2 x = 4 my_wins = [0] * 3 my_panels = [0] * 3 stdscr = initscr() cbreak() noecho() curs_set(0) stdscr.keypad(True) stdscr.erase() my_wins[0] = newwin(lines, cols, y, x) my_wins[1] = newwin(lines, cols, y + 1, x + 5) my_wins[2] = newwin(lines, cols, y + 2, x + 10) for i in range(0, 3): my_wins[i].box(0, 0) my_panels[0] = new_panel(my_wins[0]) my_panels[1] = new_panel(my_wins[1]) my_panels[2] = new_panel(my_wins[2]) my_panels[1].top() update_panels() doupdate() stdscr.getch() endwin()