469,283 Members | 2,297 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

Python and (n)curses

I need to develop a cross-platform text-mode application. I would like
to do it in Python and I would like to use a mature text-mode library
for the UI stuff.

The obvious choice, I thought, was ncurses. But as far as I can tell,
it is not available for Python on Windows?

Is there a workaround? Or are there alternative libraries that might
be used instead of (n)curses? I know I can use (n)curses on *nix and
console on Windows etc., but that is of course suboptimal.

/David

Jun 19 '07 #1
15 4566
pi************@gmail.com wrote:
I need to develop a cross-platform text-mode application. I would like
to do it in Python and I would like to use a mature text-mode library
for the UI stuff.

The obvious choice, I thought, was ncurses. But as far as I can tell,
it is not available for Python on Windows?

Is there a workaround? Or are there alternative libraries that might
be used instead of (n)curses? I know I can use (n)curses on *nix and
console on Windows etc., but that is of course suboptimal.

This link offers a series of links for console IO...
http://mail.python.org/pipermail/pyt...ry/303984.html

Among them is a link to the 'wcurses' module that has been relocated
here: http://adamv.com/dev/python/curses/ It doesn't actually work in
the console, but it seems as though you can program towards one API.

There is always cygwin + Python + ncurses.

- Josiah
Jun 19 '07 #2
"pi************@gmail.com" <pi************@gmail.comwrites:
The obvious choice, I thought, was ncurses. But as far as I can
tell, it is not available for Python on Windows?
More precisely, curses doesn't work natively on Windows, regardless of
whether Python is involved.

As with many "how do I get Unix feature foo on Windows?", one answer
is to download and install Cygwin <URL:http://www.cygwin.com/>. This
gives you a Unix-like environment where you can run a great many
applications, including ones that depend on curses.

For working with curses in Python you might find the Urwid library
helpful. <URL:http://excess.org/urwid/>

--
\ "I was in a bar the other night, hopping from barstool to |
`\ barstool, trying to get lucky, but there wasn't any gum under |
_o__) any of them." -- Emo Philips |
Ben Finney
Jun 19 '07 #3
I've said it before and I'll say it again. Why does Python have no
platform neutral commands for simple screen manipulation? yabasic (a
'hobby' type language - http://www.yabasic.de/) has commands clear
screen, inkey$ and putscreen$ which perform the basic functions of
clearing the screen, reading a key press and printing a string at an
arbitrary xy position in either Windows or Linux, leaving all the
messy implementation away from the user. For me, introducing similar
commands in Python would be by far the biggest single improvement that
could be made to the language.

Yes, I know the argument that it's up to me to contribute such a
module. But I'm afraid my knowledge and skill are way below the
threshold needed for such work. Which is why I need it as an addition
to the core language!

Peter

Jun 19 '07 #4
On Jun 19, 2:17 am, Josiah Carlson <josiah.carl...@sbcglobal.net>
wrote:
>
This link offers a series of links for console IO...http://mail.python.org/pipermail/pyt...ry/303984.html
Thanks.
Among them is a link to the 'wcurses' module that has been relocated
here:http://adamv.com/dev/python/curses/ It doesn't actually work in
the console, but it seems as though you can program towards one API.
Yep.
There is always cygwin + Python + ncurses.
Of course, but I want to be able to distribute the resulting
application easily. Can I do that with this solution?

/David

Jun 19 '07 #5
On Jun 19, 9:04 am, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:
>
More precisely, curses doesn't work natively on Windows, regardless of
whether Python is involved.
True. But then: are there other multi-platform console libraries out
there? I want to code to a single API.
As with many "how do I get Unix feature foo on Windows?", one answer
is to download and install Cygwin <URL:http://www.cygwin.com/>. This
gives you a Unix-like environment where you can run a great many
applications, including ones that depend on curses.
Yes, but will I be able to easily distribute my finished application?
For working with curses in Python you might find the Urwid library
helpful. <URL:http://excess.org/urwid/>
Thanks.

Just to be more precise: curses is not a requirement, a multi-platform
console library with a single API is. So are there alternatives to
curses? Python-only or not.

And as "peter" mentions, Python _could_ have such a library,
abstracting away the implementation details of the particular
platform. Can't see why that would be hard at all.

/David

Jun 19 '07 #6
"pi************@gmail.com" <pi************@gmail.comwrites:
Just to be more precise: curses is not a requirement, a
multi-platform console library with a single API is. So are there
alternatives to curses? Python-only or not.

And as "peter" mentions, Python _could_ have such a library,
abstracting away the implementation details of the particular
platform. Can't see why that would be hard at all.
And as "peter" mentions, it awaits only someone doing that work and
contributing it to Python. Those who can't see why it would be hard
are welcome to do so.

--
\ "The most common way people give up their power is by thinking |
`\ they don't have any." -- Alice Walker |
_o__) |
Ben Finney
Jun 19 '07 #7
On Tue, 19 Jun 2007 02:43:09 -0700, peter <pe**********@talk21.comwrote:
I've said it before and I'll say it again. Why does Python have no
platform neutral commands for simple screen manipulation? yabasic (a
'hobby' type language - http://www.yabasic.de/) has commands clear
screen, inkey$ and putscreen$ which perform the basic functions of
clearing the screen, reading a key press and printing a string at an
arbitrary xy position in either Windows or Linux, leaving all the
messy implementation away from the user.
Curses is much more than that, though. One cool feature is its redraw
optimizations -- do a lot of changes, and call a "commit"-type method,
and curses chooses the most optimal (for your terminal) way of changing
the display according to your wishes.
For me, introducing similar
commands in Python would be by far the biggest single improvement that
could be made to the language.
If it should be done, it should be done as a compatible subset of
curses, IMHO. It has such a long history as the standard "GUI toolkit"
for text terminals.

try:
import curses
except ImportError:
import inferior_curses as curses

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org R'lyeh wgah'nagl fhtagn!
Jun 19 '07 #8
On Jun 19, 3:27 pm, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:
"pinkfloydho...@gmail.com" <pinkfloydho...@gmail.comwrites:
Just to be more precise: curses is not a requirement, a
multi-platform console library with a single API is. So are there
alternatives to curses? Python-only or not.
You wouldn't happen to have an answer to this question?
And as "peter" mentions, Python _could_ have such a library,
abstracting away the implementation details of the particular
platform. Can't see why that would be hard at all.

And as "peter" mentions, it awaits only someone doing that work and
contributing it to Python. Those who can't see why it would be hard
are welcome to do so.
The classic answer.

/David

Jun 19 '07 #9
pi************@gmail.com wrote:
On Jun 19, 3:27 pm, Ben Finney
>And as "peter" mentions, it awaits only someone doing that work
and contributing it to Python. Those who can't see why it would
be hard are welcome to do so.

The classic answer.
Yes, because of the classic problem with unsalaried software
development. The top guys have more than enough to do, so the task
is finding someone who will implement that. Or do it yourself.
Don't you agree?

BTW, this is no paid support. IMHO, you would do good reconsidering
your attitude.

Regards,
Björn

--
BOFH excuse #255:

Standing room only on the bus.

Jun 19 '07 #10
"pi************@gmail.com" <pi************@gmail.comwrites:
On Jun 19, 3:27 pm, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:
"pinkfloydho...@gmail.com" <pinkfloydho...@gmail.comwrites:
Just to be more precise: curses is not a requirement, a
multi-platform console library with a single API is. So are there
alternatives to curses? Python-only or not.

You wouldn't happen to have an answer to this question?
No.

--
\ "Most people, I think, don't even know what a rootkit is, so |
`\ why should they care about it?" -- Thomas Hesse, Sony BMG, 2006 |
_o__) |
Ben Finney
Jun 20 '07 #11
For me, introducing similar commands in Python would be by far the biggest single improvement that could be made to the language.
If it should be done, it should be done as a compatible subset of
curses, IMHO. It has such a long history as the standard "GUI toolkit"
But curses doesn't run under Windows - thats the whole point!

Jun 20 '07 #12
On 6/20/07, peter <pe**********@talk21.comwrote:
>
For me, introducing similar commands in Python would be by far the biggest single improvement that could be made to the language.
If it should be done, it should be done as a compatible subset of
curses, IMHO. It has such a long history as the standard "GUI toolkit"

But curses doesn't run under Windows - thats the whole point!
I know of at least one curses implementation that runs on Windows --
PDCurses. You can find its home page at
http://pdcurses.sourceforge.net/. I have the fortune not to have a
need to do Windows curses programming ;-) so I'm not sure how good the
Python support is, but a quick Google search showed a number of ad hoc
Python wrappers for it.

--
Evan Klitzke <ev**@yelp.com>
Jun 20 '07 #13
On Wed, 20 Jun 2007 00:51:09 -0700, peter <pe**********@talk21.comwrote:
>
For me, introducing similar commands in Python would be by far the biggest single improvement that could be made to the language.
>If it should be done, it should be done as a compatible subset of
curses, IMHO. It has such a long history as the standard "GUI toolkit"

But curses doesn't run under Windows - thats the whole point!
I meant to say "as a compatible subset of the Python 'curses' module
API".

I don't know what's so difficult about porting curses. Maybe it's that
the DOS console is too broken, or maybe too many Unixisms are exposed by
the API (can you get a signal when the DOS console window is resized?).

(Alex Martelli simply wrote something like this in his Python book:
"I hear about curses ports to Windows now and then, but I've never
seen one that worked". Something like that.)

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org R'lyeh wgah'nagl fhtagn!
Jun 20 '07 #14
On 2007-06-20, Jorgen Grahn <gr********@snipabacken.dyndns.orgwrote:
On Wed, 20 Jun 2007 00:51:09 -0700, peter <pe**********@talk21.comwrote:
>>
>For me, introducing similar commands in Python would be by far the biggest single improvement that could be made to the language.
>>If it should be done, it should be done as a compatible subset of
curses, IMHO. It has such a long history as the standard "GUI toolkit"

But curses doesn't run under Windows - thats the whole point!

I meant to say "as a compatible subset of the Python 'curses' module
API".

I don't know what's so difficult about porting curses. Maybe
it's that the DOS console is too broken, or maybe too many
Unixisms are exposed by the API (can you get a signal when the
DOS console window is resized?).
I think it's just a ton of work that wouldn't benefit that many
people. If you're using curses on Windows, what are the chances
you end up needing some other part of cygwin for the same
program?
(Alex Martelli simply wrote something like this in his Python
book: "I hear about curses ports to Windows now and then, but
I've never seen one that worked". Something like that.)
There's a curses emulator written for python called wcurses, that
might provide enough functionality to allow a Windows
implementation of your Python curses program.

It doesn't actually use the windows console, however.

You could write your own little console interface, tailored to
your needs, which is implemented using curses on Unix, and the
effbot's 'console' on Windows.

--
Neil Cerutti
Symphonies of the Romantic era were a lot longer in length.
--Music Lit Essay
Jun 20 '07 #15
You could write your own little console interface, tailored to
your needs, which is implemented using curses on Unix, and the
effbot's 'console' on Windows.
Indeed, that's basically what I have done. Just can't help thinking
how much simpler (and so less error prone) it would have been had
there been some pre-existing crossplatform module.

Peter

Jun 21 '07 #16

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Brian | last post: by
reply views Thread by Matthew Alton | last post: by
1 post views Thread by spanov | last post: by
9 posts views Thread by David Bear | last post: by
1 post views Thread by Jerry Fleming | last post: by
3 posts views Thread by Maxim Veksler | last post: by
1 post views Thread by shrek2099 | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.