473,418 Members | 3,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

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 4786
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brian | last post by:
Hello; I'm writing a program with curses in python and having a bit of trouble understanding how to use unittest. So far, I have used testing successfully -- as long as the report goes to stdout...
0
by: Matthew Alton | last post by:
The appended program freaks python 2.2 & 2.3 completely out. To reproduce the wierdness: i) copy the source to a file called consarn.py ii) $ python consarn.py; iii) the program is now doing a...
1
by: spanov | last post by:
i've got problem installing python-2.3.5 from sources on FreeBSD 5.3 root@server# ./configure > conf_log configure: WARNING: curses.h: present but cannot be compiled configure: WARNING:...
9
by: David Bear | last post by:
I need python 2.3. I have freebsd 4.10-releng. when configuring python I received the following: ../configure --prefix=/home/webenv > config-results configure: WARNING: curses.h: present but...
1
by: Jerry Fleming | last post by:
Hi, I have wrote a game with python curses. The problem is that I want to confirm before quitting, while my implementation doesn't seem to work. Anyone can help me? #!/usr/bin/python # #...
3
by: skip | last post by:
I'm having no success building the curses module on Solaris 8 (yes, I know it's ancient - advancing the state-of-the-art is not yet an option) for Python 2.4. Sun provides an apparently ancient...
3
by: Maxim Veksler | last post by:
Hi list, I'm working on writing sanity check script, and for aesthetic reasons I would like the output be in the formatted like the gentoo init script output, that is: """ Check for something...
1
by: shrek2099 | last post by:
Hi All, Recently I ran into a problem with UTF-8 surrport when using curses library in python 2.5 in Fedora 7. I found out that the program using curses cannot print out unicode characters...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.