Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18271

Re: python curses wrapper

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <alex.kapps@web.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.014
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'cleanup': 0.07; 'python': 0.08; 'message-id:@web.de': 0.09; 'subject:python': 0.10; 'exception': 0.12; 'def': 0.13; 'atexit': 0.16; 'curses': 0.16; 'received:10.249': 0.16; 'wrote:': 0.18; 'seems': 0.20; 'header :In-Reply-To:1': 0.22; 'from:addr:web.de': 0.23; 'function': 0.27; 'import': 0.27; 'example': 0.29; 'url:library': 0.31; 'header :User-Agent:1': 0.33; 'to:addr:python-list': 0.34; 'someone': 0.34; 'url:python': 0.36; 'hello,': 0.37; 'url:docs': 0.39; 'received:de': 0.39; 'url:org': 0.39; 'called': 0.40; 'to:addr:python.org': 0.40; 'world': 0.62; 'skip:w 30': 0.63; 'care': 0.71; 'mag': 0.84
Date Sat, 31 Dec 2011 20:34:49 +0100
From Alexander Kapps <alex.kapps@web.de>
User-Agent Mozilla/5.0 (X11; U; Linux i686; de-DE; rv:1.9.2.21) Gecko/20110831 Thunderbird/3.1.13
MIME-Version 1.0
To python-list@python.org
Subject Re: python curses wrapper
References <CAPG7Zsg1w=3tpyAiwRieriC7EBAMgXjKLd3=s7j6W_3rkdcHAg@mail.gmail.com>
In-Reply-To <CAPG7Zsg1w=3tpyAiwRieriC7EBAMgXjKLd3=s7j6W_3rkdcHAg@mail.gmail.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:dj/ZzcWCSTjpiFABkiXno2YrU48X3DSP+1Dw6HTt3fg 6NUaOgk+KbQcCP5kHb9N83dBuJ7KIXhwsVAYcHM+bZBEd3qWNy rtClqnPXScR3601j3E0PvduZASxIwtM1zHU6YOKn0zYnoywa+z ghqY50Y/0aV9ds4SCMbOyxglrV6M2QYel9MCRHMShWUqcuxl1A D7PEZUwDJonGwwqB8r9/Q==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4276.1325360075.27778.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1325360075 news.xs4all.nl 6909 [2001:888:2000:d::a6]:37386
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18271

Show key headers only | View raw


On 31.12.2011 20:24, Mag Gam wrote:
> Hello,
>
> I have been struggling reseting the terminal when I try to do
> KeyboardInterrupt exception therefore I read the documentation for
> curses.wrapper and it seems to take care of it for me,
> http://docs.python.org/library/curses.html#curses.wrapper.
>
> Can someone please provide a Hello World example with python curses wrapper?
>
> tia

Use atexit.register() to register a cleanup function which is called 
when the program exits:

import atexit
import curses

def cleanup():
     curses.nocbreak()
     stdscr.keypad(0)
     curses.echo()
     curses.endwin()

atexit.register(cleanup)

stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(1)

curses.start_color()
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLUE)
curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK)

stdscr.bkgd(curses.color_pair(1))
stdscr.refresh()

win = curses.newwin(5, 20, 5, 5)
win.bkgd(curses.color_pair(2))
win.box()
win.addstr(2, 2, "Hallo, Welt!")
win.refresh()

c = stdscr.getch()

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: python curses wrapper Alexander Kapps <alex.kapps@web.de> - 2011-12-31 20:34 +0100

csiph-web