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


Groups > comp.lang.python > #18275

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!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <magawake@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.041
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'cleanup': 0.07; 'python': 0.08; 'subject:python': 0.10; 'exception': 0.12; 'def': 0.13; 'atexit': 0.16; 'curses': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'exists': 0.18; 'seems': 0.20; 'cc:no real name:2**0': 0.20; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.24; 'sat,': 0.25; 'function': 0.27; 'import': 0.27; 'url:mailman': 0.28; 'message-id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'example': 0.29; 'url:library': 0.31; 'thanks': 0.31; 'url:listinfo': 0.32; 'someone': 0.34; 'received:209.85.212': 0.34; 'url:python': 0.36; 'hello,': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'url:docs': 0.39; 'url:org': 0.39; 'should': 0.39; 'why': 0.39; 'called': 0.40; 'received:209': 0.40; 'according': 0.61; '2011': 0.61; 'your': 0.61; 'world': 0.62; 'skip:w 30': 0.63; '31,': 0.64; 'care': 0.71; 'doing.': 0.73; 'skip:\xc2 10': 0.74; 'mag': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=rX74q8lHnrcx5555Ax6zIODbwlmjHc3uWjXnCJJVjm8=; b=OQEnwIg6dFrvuX7OjvwszMTd67SCoeF28ty/+LHfb9fxY/LAo/h1I6dl7dXr/dK1Uq rfJcV7Aaz/6RYDY3Vwhx7oCRtKQtp4L0GaS3PhCHFR0GspcGSXMXsgEdhFTn9iOrNg5j cx0w8riRSFwvwyuPUj2R0tlIWEoB0mKozwe0A=
MIME-Version 1.0
In-Reply-To <4EFF63D9.5010100@web.de>
References <CAPG7Zsg1w=3tpyAiwRieriC7EBAMgXjKLd3=s7j6W_3rkdcHAg@mail.gmail.com> <4EFF63D9.5010100@web.de>
Date Sat, 31 Dec 2011 14:52:10 -0500
Subject Re: python curses wrapper
From Mag Gam <magawake@gmail.com>
To Alexander Kapps <alex.kapps@web.de>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
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.4280.1325361133.27778.python-list@python.org> (permalink)
Lines 59
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1325361133 news.xs4all.nl 6989 [2001:888:2000:d::a6]:58046
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18275

Show key headers only | View raw


thanks for your prompt reply. Why would I have to use atexeit?
According to the documentation, curses.wrapper should handle what
cleanup() should be doing.

Neverthless, good to know it exists :p


On Sat, Dec 31, 2011 at 2:34 PM, Alexander Kapps <alex.kapps@web.de> wrote:
> 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()
>
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Thread

Re: python curses wrapper Mag Gam <magawake@gmail.com> - 2011-12-31 14:52 -0500

csiph-web