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?
#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


Messages In This Thread
RE: Why aren't all curses panel functions supported in python curses.panel? - by pjfarley3 - Jul-22-2020, 11:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I want to be able to scroll up in curses to see previous text. Caiden 2 2,080 Jul-11-2024, 02:21 PM
Last Post: bsmorgan
  QUIZ GUI Form_When admin panel is open, main quiz form is getting freeze Uday 4 1,696 Aug-25-2023, 08:24 PM
Last Post: deanhystad
  Getting "SSL client not supported by this Python installation" error prabirsarkar 0 1,591 Mar-13-2023, 05:01 PM
Last Post: prabirsarkar
  curses issue otalado 2 3,765 Jun-29-2021, 02:07 PM
Last Post: tmz
  How to make curses.border() use A_BOLD atttribute? pjfarley3 0 6,363 Feb-03-2021, 11:22 PM
Last Post: pjfarley3
  Curses script doesn't work wavic 1 5,411 Jan-08-2021, 09:11 PM
Last Post: wavic
  Parameters aren't seen inside function Sancho_Pansa 8 4,231 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,897 Oct-11-2020, 04:41 AM
Last Post: pjfarley3
  Use nmap inside my python code to get supported cipher suites jimmeh 4 6,794 May-30-2019, 01:07 PM
Last Post: jimmeh
  curses library autompav96 2 4,001 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