0

I've written the following basic python curses application using Eclipse and PyDev.

#!/usr/bin/python

import curses

myscreen = curses.initscr()
curses.noecho()
curses.curs_set(0)
myscreen.keypad(1) 

myscreen.border(0)
myscreen.addstr(12, 25, "Python Curses")
myscreen.refresh()

while True:
    event = myscreen.getch()
    if event == ord("q"): break
    if event == ord("a"):
        myscreen.addstr(12, 25, "You Pressed A")
        myscreen.refresh()
    if event == ord("b"):
        myscreen.addstr(12, 25, "You Pressed B")
        myscreen.refresh()

curses.endwin()

The program runs fine in the linux terminal but throws up an error when I try to run it in Eclipse PyDev "curses.curs_set(0) _curses.error: curs_set() returned ERR" If I remove that line I just end up with lots of dashes and it waits for input.

Is it possible to debug python curses code in eclipse or is their another IDE better suited for python curses development?

Also is curses the right thing to be using for interactive console applications? (I'm looking todo a lot more that just basic user input which can be done with readlines.)

James
  • 241
  • 3
  • 13

3 Answers3

3

As PyDev does not have a real terminal replacement (i.e.: the console output is not a real tty), you have to launch your program externally in a terminal and debug with the remote debugger. See: http://pydev.org/manual_adv_remote_debugger.html

Note that you can configure an external launch in Eclipse to launch the external shell which launches your program.

Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78
2

Thanks to Fabio for his answer. This worked for me, but the PyDev manual "Remote Debugger" page didn't make it quite straight forward, so this is the extra I had to do.

I had to put the plugin "pysrc" directory in my PyDev PYTHONPATH before anything else, otherwise the PyDev debug server button mentioned wasn't available (I think I also had to do a restart of Eclipse).

Putting pysrc directory in your PYTHONPATH

I am using python under cygwin on Windows to develop my curses application, so I setup an external tool configuration (again as Fabio suggested) to open MinTTY and run my python programme from a bash script. The bash script also contains a sleep so I can see any exit errors.

Setting up the external tool run

Also set 2 environment variables: INSIDE_PYDEV_DEBUGGER (this will tell my application to contact the debug server), and PYTHONPATH with the directory of the plugin module it will require.

Setting up the external tool environment vars

Then in the start of my python program I put:

import os
if 'INSIDE_PYDEV_DEBUGGER' in os.environ:
    import pydevd
    pydevd.settrace()

Then I start the PyDev debug server and run the external tool, the terminal opens and the program stops in the debugger.

Reg Whitton
  • 655
  • 8
  • 9
0

Try using Kate. It's a programmer's text editor with a built-in terminal emulator, so curses should work normally.

Maz
  • 3,375
  • 1
  • 22
  • 27