I have been working on a terminal GUI using python and Curses for the past few days and feel I am not making any progress. Right now what I need to do is create two panels that both take up half the screen minus 1 - 2 characters as a margin. I want these windows to be able to handle resizing so if the user decides to make their screen larger or smaller my panels resize to adjust to the user's needs.
+---------------------------+ +---------------------------+
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
+---------------------------+ +---------------------------+
At This time I can draw the windows and have them resize. The issue is that if I resize smaller then what my boxes are currently set I get an error.
_curses_panel.error: move_panel() returned ERR
I am not sure if this is due to how I am checking and resizing the window or a limitation of Curses.
Can you please take a look at my code and let me know if I am losing my mind or not?
import curses
import curses.panel
screen = curses.initscr()
curses.start_color()
curses.noecho()
curses.curs_set(1)
screen.keypad(1)
curses.cbreak()
height,width = screen.getmaxyx()
window = curses.newwin(1,1,1,1)
window2 = curses.newwin(height -2 ,(width/2)-10, 1,width/2+1)
left_panel = curses.panel.new_panel(window)
right_panel = curses.panel.new_panel(window2)
window.border('|', '|', '-', '-', '+', '+', '+', '+')
window2.border('|', '|', '-', '-', '+', '+', '+', '+')
curses.panel.update_panels()
curses.doupdate()
running = True
x = 0
while ( running ):
height,width = screen.getmaxyx()
k = window.getch()
if k == curses.KEY_RESIZE:
window2.erase()
window.erase()
h, w = screen.getmaxyx()
window2.resize(height - 2 ,(width/2)-10)
window.resize(height - 2,(width/2) - 10)
left_panel.replace(window)
right_panel.replace(window2)
left_panel.move(0,0)
right_panel.move(0,width/2)
window2.border('|', '|', '-', '-', '+', '+', '+', '+')
window.border('|', '|', '-', '-', '+', '+', '+', '+')
if k == ord('q') or x >= 10:
running = False
curses.endwin()
curses.panel.update_panels()
curses.doupdate()
This code is after I did a lot of trial and error so there may be some code that just does not make sense but all the logic for handling resizing is in this if statement.
if k == curses.KEY_RESIZE: