Python Forum
Why aren't all curses panel functions supported in python curses.panel?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why aren't all curses panel functions supported in python curses.panel?
#1
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
Reply
#2
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?
Reply
#3
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  QUIZ GUI Form_When admin panel is open, main quiz form is getting freeze Uday 4 707 Aug-25-2023, 08:24 PM
Last Post: deanhystad
  I want to be able to scroll up in curses to see previous text. Caiden 1 716 Jul-28-2023, 01:15 PM
Last Post: deanhystad
  Getting "SSL client not supported by this Python installation" error prabirsarkar 0 915 Mar-13-2023, 05:01 PM
Last Post: prabirsarkar
  curses issue otalado 2 2,684 Jun-29-2021, 02:07 PM
Last Post: tmz
  How to make curses.border() use A_BOLD atttribute? pjfarley3 0 4,776 Feb-03-2021, 11:22 PM
Last Post: pjfarley3
  Curses script doesn't work wavic 1 4,065 Jan-08-2021, 09:11 PM
Last Post: wavic
  Parameters aren't seen inside function Sancho_Pansa 8 2,816 Oct-27-2020, 07:52 AM
Last Post: Sancho_Pansa
  Does anyone have unicurses panel functions working on a Windows 10 platform? pjfarley3 0 1,434 Oct-11-2020, 04:41 AM
Last Post: pjfarley3
  Use nmap inside my python code to get supported cipher suites jimmeh 4 5,160 May-30-2019, 01:07 PM
Last Post: jimmeh
  curses library autompav96 2 2,847 Mar-02-2019, 02:12 AM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020