Index: python/trunk/Demo/curses/rain.py =================================================================== --- python/trunk/Demo/curses/rain.py (revision 63184) +++ python/trunk/Demo/curses/rain.py (working copy) @@ -5,6 +5,7 @@ # somebody should probably check the randrange()s... import curses +from curses.ascii import ESC from random import randrange def next_j(j): @@ -82,7 +83,7 @@ ypos[j] = y ch = stdscr.getch() - if ch == ord('q') or ch == ord('Q'): + if ch == ord('q') or ch == ord('Q') or ch == ESC: return elif ch == ord('s'): stdscr.nodelay(0) Index: python/trunk/Modules/_cursesmodule.c =================================================================== --- python/trunk/Modules/_cursesmodule.c (revision 63185) +++ python/trunk/Modules/_cursesmodule.c (working copy) @@ -119,7 +119,11 @@ #defines many common symbols (such as "lines") which breaks the curses module in other ways. So the code will just specify explicit prototypes here. */ + +#ifndef _WIN32 +/* windows version of PDCurses doesn't export it */ extern int setupterm(char *,int,int *); +#endif #ifdef __sgi #include #endif @@ -133,6 +137,34 @@ #define STRICT_SYSV_CURSES #endif + +#ifdef PDCURSES + +#ifdef WINDOW_HAS_FLAGS +/* PDCurses 3.3 doesn't not expose these window flags in curses.h */ +# define _SUBWIN 0x01 /* window is a subwindow */ +# define _ISPAD 0x10 /* X/Open Pad. */ +# define _SUBPAD 0x20 /* X/Open subpad. */ +#endif + +/* PDCurses contains two mouse interfaces - classic SysV and ncurses compatible. + Unfortunately, they both define getmouse() API function. To be compatible + with ncurses we need some defines from curses.h + TODO - port native interface +*/ +# define NCURSES_MOUSE_VERSION 2 +# undef BUTTON_SHIFT +# undef BUTTON_CONTROL +# undef BUTTON_ALT +# define BUTTON_SHIFT BUTTON_MODIFIER_SHIFT +# define BUTTON_CONTROL BUTTON_MODIFIER_CONTROL +# define BUTTON_CTRL BUTTON_MODIFIER_CONTROL +# define BUTTON_ALT BUTTON_MODIFIER_ALT +# define getmouse(x) nc_getmouse(x) + +#endif + + /* Definition of exception curses.error */ static PyObject *PyCursesError; @@ -1718,7 +1750,13 @@ PyCursesInitialisedColor if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL; + +#ifndef PDCURSES return PyInt_FromLong((long) (n << 8)); +#else + return PyInt_FromLong(COLOR_PAIR(n)); +#endif /* PDCURSES */ + } static PyObject * @@ -2036,6 +2074,7 @@ } } +#ifndef _WIN32 if (setupterm(termstr,fd,&err) == ERR) { char* s = "setupterm: unknown error"; @@ -2048,6 +2087,7 @@ PyErr_SetString(PyCursesError,s); return NULL; } +#endif initialised_setupterm = TRUE; @@ -2284,6 +2324,7 @@ return PyInt_FromLong((long) ((n & A_COLOR) >> 8)); } +#ifndef _WIN32 static PyObject * PyCurses_Putp(PyObject *self, PyObject *args) { @@ -2292,6 +2333,7 @@ if (!PyArg_ParseTuple(args,"s;str", &str)) return NULL; return PyCursesCheckERR(putp(str), "putp"); } +#endif static PyObject * PyCurses_QiFlush(PyObject *self, PyObject *args) @@ -2455,6 +2497,7 @@ } } +#ifndef _WIN32 static PyObject * PyCurses_tigetflag(PyObject *self, PyObject *args) { @@ -2522,6 +2565,7 @@ return PyString_FromString(result); } +#endif static PyObject * PyCurses_TypeAhead(PyObject *self, PyObject *args) @@ -2682,7 +2726,10 @@ {"noraw", (PyCFunction)PyCurses_noraw, METH_NOARGS}, {"pair_content", (PyCFunction)PyCurses_Pair_Content, METH_VARARGS}, {"pair_number", (PyCFunction)PyCurses_pair_number, METH_VARARGS}, +#ifndef _WIN32 + /* TODO: document win32 function availability */ {"putp", (PyCFunction)PyCurses_Putp, METH_VARARGS}, +#endif {"qiflush", (PyCFunction)PyCurses_QiFlush, METH_VARARGS}, {"raw", (PyCFunction)PyCurses_raw, METH_VARARGS}, {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS}, @@ -2701,10 +2748,12 @@ {"start_color", (PyCFunction)PyCurses_Start_Color, METH_NOARGS}, {"termattrs", (PyCFunction)PyCurses_termattrs, METH_NOARGS}, {"termname", (PyCFunction)PyCurses_termname, METH_NOARGS}, +#ifndef _WIN32 {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS}, {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS}, {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS}, {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS}, +#endif {"typeahead", (PyCFunction)PyCurses_TypeAhead, METH_VARARGS}, {"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS}, {"ungetch", (PyCFunction)PyCurses_UngetCh, METH_VARARGS},