osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Solved: Re: Missing python curses functions?


On 19/05/2020 20:53, Alan Gauld via Python-list wrote:

> One of the functions discussed that does not appear to have
> a Python equivalent is attr_get() which gets the current
> attributes.

OK, Using inch() I've written the following function:


def attr_get(win):
    """ return current window attributes.
    If a character exists at the bottom right position it will be lost!
    """
    y,x = win.getmaxyx() # how many lines in the window?
    win.insch(y-1,0,' ') # insert a space at bottom left
    ch = win.inch(y-1,0) # now read the char (including attributes)
    win.delch(y-1,0)     # remove the char from window
    return ch

And it can be used like:

import curses
scr = curses.initscr()
# uncomment next line to test
# scr.attrset(curses.A_UNDERLINE)

atts = attr_get(scr)
if atts & cur.A_UNDERLINE:
    scr.addstr("Underline is on")
else:
    scr.addstr("Underline is off")

scr.refresh()
scr.getch()
curses.endwin()

Just in case its useful to anyone else...
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos