python - Obscure curses error message when creating a sub window -


i have simple python curses code creates subwindow. however, in process of running function window.subwin() fails message:

here test case:

import curses  if __name__ == '__main__':     curses.initscr()      window = curses.newwin(15, 40, 7, 20)     window.box()     window.refresh()      subwindow = window.subwin(5, 10, 2, 2)     subwindow.box()     subwindow.refresh()      subwindow.getkey()      curses.endwin() 

produces following output:

traceback (most recent call last): file "c.py", line 12, in <module>   subwindow = window.subwin(5, 10, 2, 2) _curses.error: curses function returned null 

is there way more descriptive message?

the error happens when not possible create sub-window (illegal operation). can happen because asking paint sub-window outside of window.

the method subwin receives absolute coordinates (with respect screen, not parent window). fail if subwin coordinates outside of window. reason fail: width or height overflows window.

instead of subwin, can use derwin (derivated window), receives relatives coordinates (less prone error).

import curses  if __name__ == '__main__':     curses.initscr()      window = curses.newwin(15, 40, 7, 20)     window.box()     window.refresh()      subwindow = window.derwin(5, 10, 2, 2)  # <- here change     subwindow.box()     subwindow.refresh()      subwindow.getkey()      curses.endwin() 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -