Python and (n)curses

P

pinkfloydhomer

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
 
J

Josiah Carlson

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/python-list/2005-January/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
 
B

Ben Finney

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/>
 
P

peter

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
 
P

pinkfloydhomer

This link offers a series of links for console IO...http://mail.python.org/pipermail/python-list/2005-January/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
 
P

pinkfloydhomer

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
 
B

Ben Finney

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.
 
J

Jorgen Grahn

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
 
P

pinkfloydhomer

You wouldn't happen to have an answer to this question?
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
 
B

Bjoern Schliessmann

On Jun 19, 3:27 pm, Ben Finney

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
 
P

peter

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!
 
E

Evan Klitzke

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.
 
J

Jorgen Grahn

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
 
N

Neil Cerutti

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.
 
P

peter

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top