views:

498

answers:

2

In my Python script which uses Curses, I have a subwin to which some text is assigned. Because the text length may be longer than the window size, the text should be scrollable.

It doesn't seem that there is any CSS-"overflow" like attribute for Curses windows. The Python/Curses docs are also rather cryptic on this aspect.

Does anybody here have an idea how I can code a scrollable Curses subwindow using Python and actually scroll through it?

\edit: more precise question

A: 

Set the window.scrollok(True).

Documentation

sankoz
That makes the window accept texts that exceed its own size. It is possible to scroll using window.scroll(1). But then the scrolled lines have to be redrawn, which is not explained in the docs. So getting Curses windows scrolling takes several steps, some of which I am still missing...
lecodesportif
+1  A: 

OK with window.scroll it was too complicated to move the content of the window. Instead, curses.newpad did it for me.

Create a pad:

mypad = curses.newpad(40,60)
mypad_pos = 0
mypad.refresh(mypad_pos, 0, 5, 5, 10, 60)

Then you can scroll by increasing/decreasing mypad_pos depending on the input from window.getch() in cmd:

if  cmd == curses.KEY_DOWN:
    mypad_pos += 1
    mypad.refresh(mypad_pos, 0, 5, 5, 10, 60)
elif cmd == curses.KEY_UP:
    mypad_pos -= 1
    mypad.refresh(mypad_pos, 0, 5, 5, 10, 60)
lecodesportif