0

I have a window in a window. I wish to place the cursor within the inner-most window. I thought that window.move(y,x) would do the trick, but that seems to have no effect unless called in the outer-most window.

What I want to happen:

┌──────────────────────────────────────┐
│                                      │
│ his is win2                        │
│                                      │
│                                      │
│                                      │
└──────────────────────────────────────┘

but what actually happens is that the cursor winds up in the upper-left corner of the screen.

My code:

#!/usr/bin/env python3

import curses
import sys

def main():
    try:
        stdscr = curses.initscr()
        win1 = stdscr.derwin(10,40, 4,4)
        win2 = win1.derwin(1,20, 2,2)
        win1.border()
        win2.clear()
        win2.addstr(0,0, "This is win2")

        win2.move(0,0)          # Doesn't work
        #win1.move(2,2)         # Nor does this
        #stdscr.move(6,6)       # But this does

        stdscr.refresh()
        ic = stdscr.getch()
    finally:
        curses.endwin()
    return 0

if __name__ == '__main__':
    sys.exit(main())

The only way I can make this work is to find the inner window's absolute position on the screen and pass it to stdscr.move(). But in this module, it's a bit of a hassle to track the upper-most window. There doesn't seem to be a way to take an arbitrary window and find the top-level window.

Edward Falk
  • 9,991
  • 11
  • 77
  • 112

0 Answers0