![]() |
Why aren't all curses panel functions supported in python curses.panel? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Why aren't all curses panel functions supported in python curses.panel? (/thread-28512.html) |
Why aren't all curses panel functions supported in python curses.panel? - pjfarley3 - Jul-22-2020 I recently had an idea that would work well with curses panels using python, only to find that python curses.panel does not support all defined curses panel functions (e.g., del_panel() is missing -- why?) Why aren't all curses panel functions supported directly in python? Is it developer resource time / availability / capability that is missing or is it a philosophical issue of some kind? AFAICT the curses menu functions are not supported at all either -- why not? For that matter, why is there no pip3 installable for the unicurses project, which provides a much more complete (though far less "python" in spirit) support for ALL curses functions? Not trying to start any flames here, just need to know what I can safely use for a *full* curses implementation from python across multiple OS's (linux and Win32 at minimum). Peter RE: Why aren't all curses panel functions supported in python curses.panel? - Gribouillis - Jul-22-2020 I don't know much about curses, but the documentation says that panels can be removed, although it doesn't say how. Is it not your question about del_panel ?
RE: Why aren't all curses panel functions supported in python curses.panel? - pjfarley3 - Jul-22-2020 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 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() |