Python and (n)curses

Discussion in 'Python' started by pinkfloydhomer@gmail.com, Jun 19, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. 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/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
     
    Josiah Carlson, Jun 19, 2007
    #2
    1. Advertising

  3. Ben Finney Guest

    "" <> writes:

    > 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
     
    Ben Finney, Jun 19, 2007
    #3
  4. peter Guest

    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
     
    peter, Jun 19, 2007
    #4
  5. Guest

    On Jun 19, 2:17 am, Josiah Carlson <>
    wrote:
    >
    > 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
     
    , Jun 19, 2007
    #5
  6. Guest

    On Jun 19, 9:04 am, Ben Finney <>
    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, 2007
    #6
  7. Ben Finney Guest

    "" <> writes:

    > 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
     
    Ben Finney, Jun 19, 2007
    #7
  8. Jorgen Grahn Guest

    On Tue, 19 Jun 2007 02:43:09 -0700, peter <> wrote:
    > 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!
     
    Jorgen Grahn, Jun 19, 2007
    #8
  9. Guest

    On Jun 19, 3:27 pm, Ben Finney <>
    wrote:
    > "" <> writes:
    > > 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, 2007
    #9
  10. 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.
     
    Bjoern Schliessmann, Jun 19, 2007
    #10
  11. Ben Finney Guest

    "" <> writes:

    > On Jun 19, 3:27 pm, Ben Finney <>
    > wrote:
    > > "" <> writes:
    > > > 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
     
    Ben Finney, Jun 20, 2007
    #11
  12. peter Guest


    > > 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!
     
    peter, Jun 20, 2007
    #12
  13. Evan Klitzke Guest

    On 6/20/07, peter <> wrote:
    >
    > > > 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 <>
     
    Evan Klitzke, Jun 20, 2007
    #13
  14. Jorgen Grahn Guest

    On Wed, 20 Jun 2007 00:51:09 -0700, peter <> wrote:
    >
    >> > 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!
     
    Jorgen Grahn, Jun 20, 2007
    #14
  15. Neil Cerutti Guest

    On 2007-06-20, Jorgen Grahn <> wrote:
    > On Wed, 20 Jun 2007 00:51:09 -0700, peter <> wrote:
    >>
    >>> > 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
     
    Neil Cerutti, Jun 20, 2007
    #15
  16. peter Guest

    > 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
     
    peter, Jun 21, 2007
    #16
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pierluigi Fabbris

    Curses and Events and Other

    Pierluigi Fabbris, Dec 12, 2003, in forum: Python
    Replies:
    0
    Views:
    284
    Pierluigi Fabbris
    Dec 12, 2003
  2. Guido
    Replies:
    6
    Views:
    912
    Guido
    May 5, 2004
  3. Konrad Koller
    Replies:
    3
    Views:
    787
    Konrad Koller
    Jan 9, 2005
  4. linuxfreak

    Python and curses

    linuxfreak, Dec 16, 2005, in forum: Python
    Replies:
    3
    Views:
    386
    Thomas Dickey
    Dec 16, 2005
  5. Jean-Paul Calderone
    Replies:
    2
    Views:
    444
    Joel Hedlund
    Feb 9, 2006
Loading...

Share This Page