2000-05-23 16:18:03 +00:00
|
|
|
/*
|
2000-05-23 16:24:54 +00:00
|
|
|
* This is a curses module for Python.
|
2000-05-23 16:18:03 +00:00
|
|
|
*
|
2000-05-23 16:24:54 +00:00
|
|
|
* Based on prior work by Lance Ellinghaus and Oliver Andrich
|
|
|
|
* Version 1.2 of this module: Copyright 1994 by Lance Ellinghouse,
|
|
|
|
* Cathedral City, California Republic, United States of America.
|
2000-05-23 16:18:03 +00:00
|
|
|
*
|
2000-05-23 16:24:54 +00:00
|
|
|
* Version 1.5b1, heavily extended for ncurses by Oliver Andrich:
|
|
|
|
* Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany.
|
|
|
|
*
|
|
|
|
* Tidied for Python 1.6, and currently maintained by AMK (amk1@bigfoot.com)
|
2000-05-23 16:18:03 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this source file to use, copy, modify, merge, or publish it
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or in any new file that contains a substantial portion of
|
|
|
|
* this file.
|
|
|
|
*
|
|
|
|
* THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF
|
|
|
|
* THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
|
|
|
|
* EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE
|
|
|
|
* AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR
|
|
|
|
* ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
/* CVS: $Id$ */
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
/* Release Number */
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:24:54 +00:00
|
|
|
char *PyCursesVersion = "1.6";
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
/* Includes */
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
#include "Python.h"
|
2000-05-23 16:24:54 +00:00
|
|
|
|
2000-06-27 21:49:47 +00:00
|
|
|
#ifdef __osf__
|
|
|
|
#define _XOPEN_SOURCE_EXTENDED /* Define macro for OSF/1 */
|
2000-07-25 12:37:41 +00:00
|
|
|
#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
|
2000-06-27 21:49:47 +00:00
|
|
|
#endif
|
|
|
|
|
2000-05-23 16:24:54 +00:00
|
|
|
#ifdef HAVE_NCURSES_H
|
|
|
|
#include <ncurses.h>
|
|
|
|
#else
|
2000-05-23 16:18:03 +00:00
|
|
|
#include <curses.h>
|
2000-05-23 16:24:54 +00:00
|
|
|
#endif
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:24:54 +00:00
|
|
|
#if defined(__sgi__) || defined(__sun__)
|
2000-07-25 12:37:41 +00:00
|
|
|
#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
|
2000-06-27 21:49:47 +00:00
|
|
|
typedef chtype attr_t; /* No attr_t type is available */
|
1996-12-05 23:43:35 +00:00
|
|
|
#endif
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
/* Definition of exception curses.error */
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
static PyObject *PyCursesError;
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
/* general error messages */
|
1995-02-17 13:50:17 +00:00
|
|
|
static char *catchall_ERR = "curses function returned ERR";
|
|
|
|
static char *catchall_NULL = "curses function returned NULL";
|
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
/* Tells whether initscr() has been called to initialise curses. */
|
1995-02-24 13:45:43 +00:00
|
|
|
static int initialised = FALSE;
|
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
/* Tells whether start_color() has been called to initialise colorusage. */
|
|
|
|
static int initialisedcolors = FALSE;
|
|
|
|
|
|
|
|
/* Utility Macros */
|
1995-02-17 13:50:17 +00:00
|
|
|
#define ARG_COUNT(X) \
|
|
|
|
(((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1))
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
#define PyCursesInitialised \
|
|
|
|
if (initialised != TRUE) { \
|
|
|
|
PyErr_SetString(PyCursesError, \
|
|
|
|
"must call initscr() first"); \
|
|
|
|
return NULL; }
|
1994-08-31 22:05:27 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
#define PyCursesInitialisedColor \
|
|
|
|
if (initialisedcolors != TRUE) { \
|
|
|
|
PyErr_SetString(PyCursesError, \
|
|
|
|
"must call start_color() first"); \
|
|
|
|
return NULL; }
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
/* Utility Functions */
|
1994-08-31 22:05:27 +00:00
|
|
|
|
1995-02-17 13:50:17 +00:00
|
|
|
/*
|
|
|
|
* Check the return code from a curses function and return None
|
|
|
|
* or raise an exception as appropriate.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesCheckERR(int code, char *fname)
|
1995-02-17 13:50:17 +00:00
|
|
|
{
|
|
|
|
if (code != ERR) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
} else {
|
|
|
|
if (fname == NULL) {
|
|
|
|
PyErr_SetString(PyCursesError, catchall_ERR);
|
|
|
|
} else {
|
2000-05-23 16:24:54 +00:00
|
|
|
PyErr_Format(PyCursesError, "%s() returned ERR", fname);
|
1995-02-17 13:50:17 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-23 16:24:54 +00:00
|
|
|
static int
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
|
1995-02-24 13:45:43 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
if (PyInt_Check(obj)) {
|
|
|
|
*ch = (chtype) PyInt_AsLong(obj);
|
|
|
|
} else if(PyString_Check(obj) &
|
|
|
|
(PyString_Size(obj) == 1)) {
|
|
|
|
*ch = (chtype) *PyString_AsString(obj);
|
|
|
|
} else {
|
1995-02-24 13:45:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2000-05-23 16:18:03 +00:00
|
|
|
return 1;
|
1995-02-24 13:45:43 +00:00
|
|
|
}
|
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
The Window Object
|
|
|
|
******************************************************************************/
|
1995-02-24 13:45:43 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
/* Definition of the window object and window type */
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
WINDOW *win;
|
|
|
|
} PyCursesWindowObject;
|
|
|
|
|
|
|
|
PyTypeObject PyCursesWindow_Type;
|
|
|
|
|
|
|
|
#define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
/* Function Prototype Macros - They are ugly but very, very useful. ;-)
|
|
|
|
|
|
|
|
X - function name
|
|
|
|
TYPE - parameter Type
|
|
|
|
ERGSTR - format string for construction of the return value
|
|
|
|
PARSESTR - format string for argument parsing
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define Window_NoArgNoReturnFunction(X) \
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
|
|
|
|
{ if (!PyArg_NoArgs(args)) return NULL; \
|
2000-05-23 16:18:03 +00:00
|
|
|
return PyCursesCheckERR(X(self->win), # X); }
|
|
|
|
|
|
|
|
#define Window_NoArgTrueFalseFunction(X) \
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
|
2000-05-23 16:18:03 +00:00
|
|
|
{ \
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) return NULL; \
|
2000-05-23 16:18:03 +00:00
|
|
|
if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
|
|
|
|
else { Py_INCREF(Py_True); return Py_True; } }
|
|
|
|
|
|
|
|
#define Window_NoArgNoReturnVoidFunction(X) \
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
|
2000-05-23 16:18:03 +00:00
|
|
|
{ \
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) return NULL; \
|
2000-05-23 16:18:03 +00:00
|
|
|
X(self->win); Py_INCREF(Py_None); return Py_None; }
|
|
|
|
|
|
|
|
#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
|
2000-05-23 16:18:03 +00:00
|
|
|
{ \
|
|
|
|
TYPE arg1, arg2; \
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) return NULL; \
|
2000-05-23 16:18:03 +00:00
|
|
|
X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
|
|
|
|
|
|
|
|
#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
|
2000-05-23 16:18:03 +00:00
|
|
|
{ \
|
|
|
|
TYPE arg1; \
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, PARSESTR, &arg1)) return NULL; \
|
2000-05-23 16:18:03 +00:00
|
|
|
X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
|
|
|
|
|
|
|
|
#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
|
2000-05-23 16:18:03 +00:00
|
|
|
{ \
|
|
|
|
TYPE arg1; \
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,PARSESTR, &arg1)) return NULL; \
|
2000-05-23 16:18:03 +00:00
|
|
|
return PyCursesCheckERR(X(self->win, arg1), # X); }
|
|
|
|
|
|
|
|
#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
|
2000-05-23 16:18:03 +00:00
|
|
|
{ \
|
|
|
|
TYPE arg1, arg2; \
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,PARSESTR, &arg1, &arg2)) return NULL; \
|
2000-05-23 16:18:03 +00:00
|
|
|
return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
|
1995-02-17 13:50:17 +00:00
|
|
|
|
1994-08-30 12:25:20 +00:00
|
|
|
/* ------------- WINDOW routines --------------- */
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
Window_NoArgNoReturnFunction(untouchwin)
|
|
|
|
Window_NoArgNoReturnFunction(touchwin)
|
|
|
|
Window_NoArgNoReturnFunction(redrawwin)
|
|
|
|
Window_NoArgNoReturnFunction(winsertln)
|
|
|
|
Window_NoArgNoReturnFunction(werase)
|
|
|
|
Window_NoArgNoReturnFunction(wdeleteln)
|
|
|
|
|
|
|
|
Window_NoArgTrueFalseFunction(is_wintouched)
|
|
|
|
|
|
|
|
Window_NoArgNoReturnVoidFunction(wsyncup)
|
|
|
|
Window_NoArgNoReturnVoidFunction(wsyncdown)
|
|
|
|
Window_NoArgNoReturnVoidFunction(wstandend)
|
|
|
|
Window_NoArgNoReturnVoidFunction(wstandout)
|
|
|
|
Window_NoArgNoReturnVoidFunction(wcursyncup)
|
|
|
|
Window_NoArgNoReturnVoidFunction(wclrtoeol)
|
|
|
|
Window_NoArgNoReturnVoidFunction(wclrtobot)
|
|
|
|
Window_NoArgNoReturnVoidFunction(wclear)
|
|
|
|
|
|
|
|
Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)")
|
|
|
|
Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)")
|
2000-06-21 01:41:48 +00:00
|
|
|
Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay")
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
Window_NoArg2TupleReturnFunction(getyx, int, "(ii)")
|
|
|
|
Window_NoArg2TupleReturnFunction(getbegyx, int, "(ii)")
|
|
|
|
Window_NoArg2TupleReturnFunction(getmaxyx, int, "(ii)")
|
|
|
|
Window_NoArg2TupleReturnFunction(getparyx, int, "(ii)")
|
|
|
|
|
|
|
|
Window_OneArgNoReturnFunction(wattron, attr_t, "l;attr")
|
|
|
|
Window_OneArgNoReturnFunction(wattroff, attr_t, "l;attr")
|
|
|
|
Window_OneArgNoReturnFunction(wattrset, attr_t, "l;attr")
|
|
|
|
Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")
|
|
|
|
Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")
|
|
|
|
Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)")
|
|
|
|
Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)")
|
|
|
|
Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)")
|
|
|
|
Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)")
|
|
|
|
Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)")
|
2000-05-23 16:24:54 +00:00
|
|
|
Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines")
|
2000-05-23 16:18:03 +00:00
|
|
|
Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)")
|
|
|
|
|
|
|
|
Window_TwoArgNoReturnFunction(mvwin, int, "(ii);y,x")
|
|
|
|
Window_TwoArgNoReturnFunction(mvderwin, int, "(ii);y,x")
|
|
|
|
Window_TwoArgNoReturnFunction(wmove, int, "(ii);y,x")
|
2000-06-27 21:49:47 +00:00
|
|
|
#ifndef STRICT_SYSV_CURSES
|
2000-05-23 16:18:03 +00:00
|
|
|
Window_TwoArgNoReturnFunction(wresize, int, "(ii);lines,columns")
|
|
|
|
#endif
|
|
|
|
|
2000-05-23 16:24:54 +00:00
|
|
|
/* Allocation and deallocation of Window Objects */
|
2000-05-23 16:18:03 +00:00
|
|
|
|
1994-08-30 12:25:20 +00:00
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_New(WINDOW *win)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
|
|
|
PyCursesWindowObject *wo;
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
|
|
|
|
if (wo == NULL) return NULL;
|
1994-08-30 12:25:20 +00:00
|
|
|
wo->win = win;
|
|
|
|
return (PyObject *)wo;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
if (wo->win != stdscr) delwin(wo->win);
|
|
|
|
PyMem_DEL(wo);
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
/* Addch, Addstr, Addnstr */
|
1994-08-30 12:25:20 +00:00
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int rtn, x, y, use_xy = FALSE;
|
|
|
|
PyObject *temp;
|
|
|
|
chtype ch = 0;
|
|
|
|
attr_t attr = A_NORMAL;
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "O;ch or int", &temp))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "(Ol);ch or int,attr", &temp, &attr))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case 3:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(iiO);y,x,ch or int", &y, &x, &temp))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
use_xy = TRUE;
|
|
|
|
break;
|
|
|
|
case 4:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(iiOl);y,x,ch or int, attr",
|
2000-05-23 16:18:03 +00:00
|
|
|
&y, &x, &temp, &attr))
|
|
|
|
return NULL;
|
|
|
|
use_xy = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "addch requires 1 or 4 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
if (!PyCurses_ConvertToChtype(temp, &ch)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (use_xy == TRUE)
|
|
|
|
rtn = mvwaddch(self->win,y,x, ch | attr);
|
|
|
|
else {
|
|
|
|
rtn = waddch(self->win, ch | attr);
|
|
|
|
}
|
|
|
|
return PyCursesCheckERR(rtn, "addch");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int rtn;
|
1994-08-30 12:25:20 +00:00
|
|
|
int x, y;
|
2000-05-23 16:18:03 +00:00
|
|
|
char *str;
|
|
|
|
attr_t attr = A_NORMAL , attr_old = A_NORMAL;
|
|
|
|
int use_xy = FALSE, use_attr = FALSE;
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"s;str", &str))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(sl);str,attr", &str, &attr))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
use_attr = TRUE;
|
|
|
|
break;
|
|
|
|
case 3:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(iis);int,int,str", &y, &x, &str))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
use_xy = TRUE;
|
|
|
|
break;
|
|
|
|
case 4:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(iisl);int,int,str,attr", &y, &x, &str, &attr))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
use_xy = use_attr = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (use_attr == TRUE) {
|
|
|
|
attr_old = getattrs(self->win);
|
|
|
|
wattrset(self->win,attr);
|
|
|
|
}
|
|
|
|
if (use_xy == TRUE)
|
|
|
|
rtn = mvwaddstr(self->win,y,x,str);
|
|
|
|
else
|
|
|
|
rtn = waddstr(self->win,str);
|
|
|
|
if (use_attr == TRUE)
|
|
|
|
wattrset(self->win,attr_old);
|
|
|
|
return PyCursesCheckERR(rtn, "addstr");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int rtn, x, y, n;
|
|
|
|
char *str;
|
|
|
|
attr_t attr = A_NORMAL , attr_old = A_NORMAL;
|
|
|
|
int use_xy = FALSE, use_attr = FALSE;
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
1995-02-17 13:50:17 +00:00
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(si);str,n", &str, &n))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case 3:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(sil);str,n,attr", &str, &n, &attr))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
use_attr = TRUE;
|
1995-02-17 13:50:17 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(iisi);y,x,str,n", &y, &x, &str, &n))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
use_xy = TRUE;
|
|
|
|
break;
|
|
|
|
case 5:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(iisil);y,x,str,n,attr", &y, &x, &str, &n, &attr))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
use_xy = use_attr = TRUE;
|
1995-02-17 13:50:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
if (use_attr == TRUE) {
|
|
|
|
attr_old = getattrs(self->win);
|
|
|
|
wattrset(self->win,attr);
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
2000-05-23 16:18:03 +00:00
|
|
|
if (use_xy == TRUE)
|
|
|
|
rtn = mvwaddnstr(self->win,y,x,str,n);
|
|
|
|
else
|
|
|
|
rtn = waddnstr(self->win,str,n);
|
|
|
|
if (use_attr == TRUE)
|
|
|
|
wattrset(self->win,attr_old);
|
|
|
|
return PyCursesCheckERR(rtn, "addnstr");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
PyObject *temp;
|
|
|
|
chtype bkgd;
|
|
|
|
attr_t attr = A_NORMAL;
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
1995-02-17 13:50:17 +00:00
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "O;ch or int", &temp))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
1994-08-30 12:25:20 +00:00
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
1994-08-30 12:25:20 +00:00
|
|
|
default:
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
|
|
|
|
return NULL;
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
return PyCursesCheckERR(wbkgd(self->win, bkgd | A_NORMAL), "bkgd");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
PyObject *temp;
|
|
|
|
chtype bkgd;
|
|
|
|
attr_t attr = A_NORMAL;
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
1995-02-17 13:50:17 +00:00
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "O;ch or int", &temp))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
1994-08-30 12:25:20 +00:00
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
1994-08-30 12:25:20 +00:00
|
|
|
default:
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
|
2000-05-23 16:24:54 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
wbkgdset(self->win, bkgd | attr);
|
|
|
|
return PyCursesCheckERR(0, "bkgdset");
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
chtype ls, rs, ts, bs, tl, tr, bl, br;
|
|
|
|
ls = rs = ts = bs = tl = tr = bl = br = 0;
|
|
|
|
if (!PyArg_Parse(args,"|llllllll;ls,rs,ts,bs,tl,tr,bl,br",
|
|
|
|
&ls, &rs, &ts, &bs, &tl, &tr, &bl, &br))
|
|
|
|
return NULL;
|
|
|
|
wborder(self->win, ls, rs, ts, bs, tl, tr, bl, br);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
chtype ch1=0,ch2=0;
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_Clear();
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ll);vertint,horint", &ch1, &ch2))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
box(self->win,ch1,ch2);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
|
|
|
int rtn;
|
|
|
|
int x, y;
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
1995-02-17 13:50:17 +00:00
|
|
|
case 0:
|
1994-08-30 12:25:20 +00:00
|
|
|
rtn = wdelch(self->win);
|
1995-02-17 13:50:17 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);y,x", &y, &x))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
rtn = mvwdelch(self->win,y,x);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
|
|
|
|
return NULL;
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
1995-02-17 13:50:17 +00:00
|
|
|
return PyCursesCheckERR(rtn, "[mv]wdelch");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
WINDOW *win;
|
|
|
|
int nlines, ncols, begin_y, begin_x;
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
nlines = 0;
|
|
|
|
ncols = 0;
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);begin_y,begin_x",&begin_y,&begin_x))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
2000-05-23 16:18:03 +00:00
|
|
|
case 4:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x",
|
2000-05-23 16:18:03 +00:00
|
|
|
&nlines,&ncols,&begin_y,&begin_x))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
default:
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
win = derwin(self->win,nlines,ncols,begin_y,begin_x);
|
|
|
|
|
|
|
|
if (win == NULL) {
|
|
|
|
PyErr_SetString(PyCursesError, catchall_NULL);
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
return (PyObject *)PyCursesWindow_New(win);
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
PyObject *temp;
|
|
|
|
chtype ch;
|
|
|
|
attr_t attr = A_NORMAL;
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
1995-02-17 13:50:17 +00:00
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"O;ch or int", &temp))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
default:
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
|
|
|
|
|
|
|
|
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
if (!PyCurses_ConvertToChtype(temp, &ch)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
|
|
|
|
return NULL;
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
if (self->win->_flags & _ISPAD)
|
|
|
|
return PyCursesCheckERR(pechochar(self->win, ch | attr),
|
|
|
|
"echochar");
|
1994-08-30 12:25:20 +00:00
|
|
|
else
|
2000-05-23 16:18:03 +00:00
|
|
|
return PyCursesCheckERR(wechochar(self->win, ch | attr),
|
|
|
|
"echochar");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
2000-06-27 03:10:38 +00:00
|
|
|
#ifdef NCURSES_MOUSE_VERSION
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args)
|
2000-06-27 03:10:38 +00:00
|
|
|
{
|
|
|
|
int x, y;
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);y,x", &y, &x))
|
2000-06-27 03:10:38 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return PyInt_FromLong( wenclose(self->win,y,x) );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1994-08-30 12:25:20 +00:00
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_GetBkgd(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
return PyInt_FromLong((long) getbkgd(self->win));
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int x, y;
|
|
|
|
chtype rtn;
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 0:
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
rtn = wgetch(self->win);
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_END_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
rtn = mvwgetch(self->win,y,x);
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_END_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return PyInt_FromLong(rtn);
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int x, y;
|
|
|
|
chtype rtn;
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 0:
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
rtn = wgetch(self->win);
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_END_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
rtn = mvwgetch(self->win,y,x);
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_END_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-05-23 16:24:54 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments");
|
1995-02-24 13:45:43 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
|
|
|
if (rtn<=255)
|
|
|
|
return Py_BuildValue("c", rtn);
|
|
|
|
else
|
|
|
|
return PyString_FromString((char *)keyname(rtn));
|
1995-02-24 13:45:43 +00:00
|
|
|
}
|
|
|
|
|
1994-08-30 12:25:20 +00:00
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int x, y, n;
|
|
|
|
char rtn[1024]; /* This should be big enough.. I hope */
|
|
|
|
int rtn2;
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 0:
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
rtn2 = wgetstr(self->win,rtn);
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_END_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"i;n", &n))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
rtn2 = wgetnstr(self->win,rtn,n);
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_END_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
1995-02-24 13:45:43 +00:00
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
|
1995-02-24 13:45:43 +00:00
|
|
|
return NULL;
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
rtn2 = mvwgetstr(self->win,y,x,rtn);
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_END_ALLOW_THREADS
|
1995-02-24 13:45:43 +00:00
|
|
|
break;
|
2000-05-23 16:18:03 +00:00
|
|
|
case 3:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(iii);y,x,n", &y, &x, &n))
|
1995-02-24 13:45:43 +00:00
|
|
|
return NULL;
|
2000-06-27 21:49:47 +00:00
|
|
|
#ifdef STRICT_SYSV_CURSES
|
2000-05-23 16:18:03 +00:00
|
|
|
/* Untested */
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
rtn2 = wmove(self->win,y,x)==ERR ? ERR :
|
|
|
|
wgetnstr(self->win, rtn, n);
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_END_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
#else
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
rtn2 = mvwgetnstr(self->win, y, x, rtn, n);
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_END_ALLOW_THREADS
|
2000-05-23 16:18:03 +00:00
|
|
|
#endif
|
1995-02-24 13:45:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 2 arguments");
|
1995-02-24 13:45:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-23 16:18:03 +00:00
|
|
|
if (rtn2 == ERR)
|
|
|
|
rtn[0] = 0;
|
|
|
|
return PyString_FromString(rtn);
|
1995-02-24 13:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args)
|
1995-02-24 13:45:43 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
PyObject *temp;
|
|
|
|
chtype ch;
|
|
|
|
int n, x, y, code = OK;
|
|
|
|
attr_t attr = A_NORMAL;
|
|
|
|
|
1995-02-24 13:45:43 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
|
|
|
case 2:
|
2000-05-23 16:18:03 +00:00
|
|
|
if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n))
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr))
|
1995-02-24 13:45:43 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case 4:
|
2000-05-23 16:24:54 +00:00
|
|
|
if (!PyArg_Parse(args, "(iiOi);y,x,ch or int,n", &y, &x, &temp, &n))
|
1995-02-24 13:45:43 +00:00
|
|
|
return NULL;
|
|
|
|
code = wmove(self->win, y, x);
|
|
|
|
break;
|
2000-05-23 16:18:03 +00:00
|
|
|
case 5:
|
|
|
|
if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr",
|
|
|
|
&y, &x, &temp, &n, &attr))
|
|
|
|
return NULL;
|
|
|
|
code = wmove(self->win, y, x);
|
1995-02-24 13:45:43 +00:00
|
|
|
default:
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "hline requires 2 or 5 arguments");
|
1995-02-24 13:45:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
if (code != ERR) {
|
|
|
|
if (!PyCurses_ConvertToChtype(temp, &ch)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"argument 1 or 3 must be a ch or an int");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
|
|
|
return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
|
|
|
|
} else
|
|
|
|
return PyCursesCheckERR(code, "wmove");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int rtn, x, y, use_xy = FALSE;
|
|
|
|
PyObject *temp;
|
|
|
|
chtype ch = 0;
|
|
|
|
attr_t attr = A_NORMAL;
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "O;ch or int", &temp))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "(Ol);ch or int,attr", &temp, &attr))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(iiO);y,x,ch or int", &y, &x, &temp))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
use_xy = TRUE;
|
1999-01-05 17:16:46 +00:00
|
|
|
break;
|
2000-05-23 16:18:03 +00:00
|
|
|
case 4:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(iiOl);y,x,ch or int, attr", &y, &x, &temp, &attr))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
use_xy = TRUE;
|
1999-01-05 17:16:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
|
1999-01-05 17:16:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
if (!PyCurses_ConvertToChtype(temp, &ch)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"argument 1 or 3 must be a ch or an int");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_xy == TRUE)
|
|
|
|
rtn = mvwinsch(self->win,y,x, ch | attr);
|
|
|
|
else {
|
|
|
|
rtn = winsch(self->win, ch | attr);
|
|
|
|
}
|
|
|
|
return PyCursesCheckERR(rtn, "insch");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int x, y, rtn;
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
1995-02-17 13:50:17 +00:00
|
|
|
case 0:
|
2000-05-23 16:18:03 +00:00
|
|
|
rtn = winch(self->win);
|
1995-02-17 13:50:17 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
rtn = mvwinch(self->win,y,x);
|
1995-02-17 13:50:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return PyInt_FromLong((long) rtn);
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int x, y, n;
|
1994-08-30 12:25:20 +00:00
|
|
|
char rtn[1024]; /* This should be big enough.. I hope */
|
|
|
|
int rtn2;
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
1995-02-17 13:50:17 +00:00
|
|
|
case 0:
|
2000-05-23 16:18:03 +00:00
|
|
|
rtn2 = winstr(self->win,rtn);
|
|
|
|
break;
|
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"i;n", &n))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
rtn2 = winnstr(self->win,rtn,n);
|
1995-02-17 13:50:17 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
rtn2 = mvwinstr(self->win,y,x,rtn);
|
1995-02-17 13:50:17 +00:00
|
|
|
break;
|
2000-05-23 16:18:03 +00:00
|
|
|
case 3:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "(iii);y,x,n", &y, &x, &n))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
rtn2 = mvwinnstr(self->win, y, x, rtn, n);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1994-08-30 12:25:20 +00:00
|
|
|
if (rtn2 == ERR)
|
|
|
|
rtn[0] = 0;
|
1995-02-17 13:50:17 +00:00
|
|
|
return PyString_FromString(rtn);
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int rtn;
|
|
|
|
int x, y;
|
|
|
|
char *str;
|
|
|
|
attr_t attr = A_NORMAL , attr_old = A_NORMAL;
|
|
|
|
int use_xy = FALSE, use_attr = FALSE;
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"s;str", &str))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
1995-02-17 13:50:17 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(sl);str,attr", &str, &attr))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
use_attr = TRUE;
|
|
|
|
break;
|
|
|
|
case 3:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(iis);y,x,str", &y, &x, &str))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
use_xy = TRUE;
|
|
|
|
break;
|
|
|
|
case 4:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(iisl);y,x,str,attr", &y, &x, &str, &attr))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
use_xy = use_attr = TRUE;
|
1995-02-17 13:50:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
if (use_attr == TRUE) {
|
|
|
|
attr_old = getattrs(self->win);
|
|
|
|
wattrset(self->win,attr);
|
|
|
|
}
|
|
|
|
if (use_xy == TRUE)
|
|
|
|
rtn = mvwinsstr(self->win,y,x,str);
|
|
|
|
else
|
|
|
|
rtn = winsstr(self->win,str);
|
|
|
|
if (use_attr == TRUE)
|
|
|
|
wattrset(self->win,attr_old);
|
|
|
|
return PyCursesCheckERR(rtn, "insstr");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int rtn, x, y, n;
|
|
|
|
char *str;
|
|
|
|
attr_t attr = A_NORMAL , attr_old = A_NORMAL;
|
|
|
|
int use_xy = FALSE, use_attr = FALSE;
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(si);str,n", &str, &n))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case 3:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(sil);str,n,attr", &str, &n, &attr))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
use_attr = TRUE;
|
|
|
|
break;
|
|
|
|
case 4:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(iisi);y,x,str,n", &y, &x, &str, &n))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
use_xy = TRUE;
|
|
|
|
break;
|
|
|
|
case 5:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(iisil);y,x,str,n,attr", &y, &x, &str, &n, &attr))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
use_xy = use_attr = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (use_attr == TRUE) {
|
|
|
|
attr_old = getattrs(self->win);
|
|
|
|
wattrset(self->win,attr);
|
|
|
|
}
|
|
|
|
if (use_xy == TRUE)
|
|
|
|
rtn = mvwinsnstr(self->win,y,x,str,n);
|
|
|
|
else
|
|
|
|
rtn = winsnstr(self->win,str,n);
|
|
|
|
if (use_attr == TRUE)
|
|
|
|
wattrset(self->win,attr_old);
|
|
|
|
return PyCursesCheckERR(rtn, "insnstr");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int line, erg;
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"i;line", &line))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
erg = is_linetouched(self->win, line);
|
|
|
|
if (erg == ERR) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"is_linetouched: line number outside of boundaries");
|
|
|
|
return NULL;
|
|
|
|
} else
|
|
|
|
if (erg == FALSE) {
|
|
|
|
Py_INCREF(Py_False);
|
|
|
|
return Py_False;
|
|
|
|
} else {
|
|
|
|
Py_INCREF(Py_True);
|
|
|
|
return Py_True;
|
|
|
|
}
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
|
2000-06-23 01:36:21 +00:00
|
|
|
int rtn;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
if (self->win->_flags & _ISPAD) {
|
2000-07-09 14:35:00 +00:00
|
|
|
switch(ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 6:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,
|
2000-05-23 16:18:03 +00:00
|
|
|
"(iiiiii);" \
|
|
|
|
"pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
|
|
|
|
&pminrow, &pmincol, &sminrow,
|
|
|
|
&smincol, &smaxrow, &smaxcol))
|
|
|
|
return NULL;
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
rtn = pnoutrefresh(self->win,
|
|
|
|
pminrow, pmincol, sminrow,
|
2000-06-27 15:01:10 +00:00
|
|
|
smincol, smaxrow, smaxcol);
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_END_ALLOW_THREADS
|
|
|
|
return PyCursesCheckERR(rtn, "pnoutrefresh");
|
2000-05-23 16:18:03 +00:00
|
|
|
default:
|
|
|
|
PyErr_SetString(PyCursesError,
|
2000-06-23 01:36:21 +00:00
|
|
|
"noutrefresh() called for a pad "
|
2000-05-23 16:18:03 +00:00
|
|
|
"requires 6 arguments");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
2000-06-23 01:36:21 +00:00
|
|
|
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
rtn = wnoutrefresh(self->win);
|
|
|
|
Py_END_ALLOW_THREADS
|
|
|
|
return PyCursesCheckERR(rtn, "wnoutrefresh");
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
PyObject *temp;
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "O;fileobj", &temp))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
if (!PyFile_Check(temp)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "argument must be a file object");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return PyCursesCheckERR(putwin(self->win, PyFile_AsFile(temp)),
|
|
|
|
"putwin");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int beg, num;
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);beg,num", &beg, &num))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
|
2000-06-23 01:36:21 +00:00
|
|
|
int rtn;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
if (self->win->_flags & _ISPAD) {
|
2000-07-09 14:35:00 +00:00
|
|
|
switch(ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 6:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,
|
2000-05-23 16:18:03 +00:00
|
|
|
"(iiiiii);" \
|
|
|
|
"pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
|
|
|
|
&pminrow, &pmincol, &sminrow,
|
|
|
|
&smincol, &smaxrow, &smaxcol))
|
|
|
|
return NULL;
|
2000-06-23 01:36:21 +00:00
|
|
|
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
rtn = prefresh(self->win,
|
|
|
|
pminrow, pmincol, sminrow,
|
2000-06-27 15:01:10 +00:00
|
|
|
smincol, smaxrow, smaxcol);
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_END_ALLOW_THREADS
|
|
|
|
return PyCursesCheckERR(rtn, "prefresh");
|
2000-05-23 16:18:03 +00:00
|
|
|
default:
|
|
|
|
PyErr_SetString(PyCursesError,
|
2000-06-23 01:36:21 +00:00
|
|
|
"refresh() for a pad requires 6 arguments");
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
2000-06-23 01:36:21 +00:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
rtn = wrefresh(self->win);
|
|
|
|
Py_END_ALLOW_THREADS
|
2000-07-09 14:35:00 +00:00
|
|
|
return PyCursesCheckERR(rtn, "prefresh");
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
|
|
|
int x, y;
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);top, bottom",&y,&x))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
|
|
|
return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
WINDOW *win;
|
|
|
|
int nlines, ncols, begin_y, begin_x;
|
|
|
|
|
2000-05-23 16:24:54 +00:00
|
|
|
nlines = 0;
|
|
|
|
ncols = 0;
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
2000-05-23 16:24:54 +00:00
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);begin_y,begin_x",&begin_y,&begin_x))
|
2000-05-23 16:24:54 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case 4:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x",
|
2000-05-23 16:18:03 +00:00
|
|
|
&nlines,&ncols,&begin_y,&begin_x))
|
2000-05-23 16:24:54 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:24:54 +00:00
|
|
|
}
|
2000-05-23 16:18:03 +00:00
|
|
|
|
2000-05-23 16:24:54 +00:00
|
|
|
printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x);
|
2000-05-23 16:18:03 +00:00
|
|
|
if (self->win->_flags & _ISPAD)
|
|
|
|
win = subpad(self->win, nlines, ncols, begin_y, begin_x);
|
|
|
|
else
|
2000-05-23 16:24:54 +00:00
|
|
|
win = subwin(self->win, nlines, ncols, begin_y, begin_x);
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
if (win == NULL) {
|
|
|
|
PyErr_SetString(PyCursesError, catchall_NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (PyObject *)PyCursesWindow_New(win);
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int lines;
|
2000-07-09 14:35:00 +00:00
|
|
|
switch(ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 0:
|
|
|
|
return PyCursesCheckERR(scroll(self->win), "scroll");
|
|
|
|
break;
|
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "i;lines", &lines))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
return PyCursesCheckERR(wscrl(self->win, lines), "scroll");
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int st, cnt, val;
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);start,count",&st,&cnt))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
|
|
|
|
break;
|
|
|
|
case 3:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "(iii);start,count,val", &st, &cnt, &val))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline");
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
PyObject *temp;
|
|
|
|
chtype ch;
|
|
|
|
int n, x, y, code = OK;
|
|
|
|
attr_t attr = A_NORMAL;
|
|
|
|
|
|
|
|
switch (ARG_COUNT(args)) {
|
|
|
|
case 2:
|
|
|
|
if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n))
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr))
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case 4:
|
2000-05-23 16:24:54 +00:00
|
|
|
if (!PyArg_Parse(args, "(iiOi);y,x,ch or int,n", &y, &x, &temp, &n))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
code = wmove(self->win, y, x);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr",
|
|
|
|
&y, &x, &temp, &n, &attr))
|
|
|
|
return NULL;
|
|
|
|
code = wmove(self->win, y, x);
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "vline requires 2 or 5 arguments");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (code != ERR) {
|
|
|
|
if (!PyCurses_ConvertToChtype(temp, &ch)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"argument 1 or 3 must be a ch or an int");
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-23 16:24:54 +00:00
|
|
|
return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline");
|
2000-05-23 16:18:03 +00:00
|
|
|
} else
|
|
|
|
return PyCursesCheckERR(code, "wmove");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyMethodDef PyCursesWindow_Methods[] = {
|
1995-03-17 12:18:38 +00:00
|
|
|
{"addch", (PyCFunction)PyCursesWindow_AddCh},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"addnstr", (PyCFunction)PyCursesWindow_AddNStr},
|
1995-03-17 12:18:38 +00:00
|
|
|
{"addstr", (PyCFunction)PyCursesWindow_AddStr},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"attroff", (PyCFunction)PyCursesWindow_wattroff},
|
2000-05-23 16:24:54 +00:00
|
|
|
{"attron", (PyCFunction)PyCursesWindow_wattron},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"attrset", (PyCFunction)PyCursesWindow_wattrset},
|
|
|
|
{"bkgd", (PyCFunction)PyCursesWindow_Bkgd},
|
|
|
|
{"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet},
|
1995-03-17 12:18:38 +00:00
|
|
|
{"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
|
|
|
|
{"box", (PyCFunction)PyCursesWindow_Box},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"clear", (PyCFunction)PyCursesWindow_wclear},
|
|
|
|
{"clearok", (PyCFunction)PyCursesWindow_clearok},
|
|
|
|
{"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot},
|
|
|
|
{"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol},
|
|
|
|
{"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup},
|
|
|
|
{"delch", (PyCFunction)PyCursesWindow_DelCh},
|
|
|
|
{"deleteln", (PyCFunction)PyCursesWindow_wdeleteln},
|
|
|
|
{"derwin", (PyCFunction)PyCursesWindow_DerWin},
|
|
|
|
{"echochar", (PyCFunction)PyCursesWindow_EchoChar},
|
2000-06-27 03:10:38 +00:00
|
|
|
#ifdef NCURSES_MOUSE_VERSION
|
|
|
|
{"enclose", (PyCFunction)PyCursesWindow_Enclose},
|
|
|
|
#endif
|
2000-05-23 16:18:03 +00:00
|
|
|
{"erase", (PyCFunction)PyCursesWindow_werase},
|
|
|
|
{"getbegyx", (PyCFunction)PyCursesWindow_getbegyx},
|
|
|
|
{"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd},
|
1995-03-17 12:18:38 +00:00
|
|
|
{"getch", (PyCFunction)PyCursesWindow_GetCh},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"getkey", (PyCFunction)PyCursesWindow_GetKey},
|
|
|
|
{"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx},
|
|
|
|
{"getparyx", (PyCFunction)PyCursesWindow_getparyx},
|
1995-03-17 12:18:38 +00:00
|
|
|
{"getstr", (PyCFunction)PyCursesWindow_GetStr},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"getyx", (PyCFunction)PyCursesWindow_getyx},
|
|
|
|
{"hline", (PyCFunction)PyCursesWindow_Hline},
|
|
|
|
{"idcok", (PyCFunction)PyCursesWindow_idcok},
|
2000-05-23 16:24:54 +00:00
|
|
|
{"idlok", (PyCFunction)PyCursesWindow_idlok},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"immedok", (PyCFunction)PyCursesWindow_immedok},
|
1995-03-17 12:18:38 +00:00
|
|
|
{"inch", (PyCFunction)PyCursesWindow_InCh},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"insch", (PyCFunction)PyCursesWindow_InsCh},
|
|
|
|
{"insdelln", (PyCFunction)PyCursesWindow_winsdelln},
|
|
|
|
{"insertln", (PyCFunction)PyCursesWindow_winsertln},
|
|
|
|
{"insnstr", (PyCFunction)PyCursesWindow_InsNStr},
|
|
|
|
{"insstr", (PyCFunction)PyCursesWindow_InsStr},
|
|
|
|
{"instr", (PyCFunction)PyCursesWindow_InStr},
|
|
|
|
{"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched},
|
|
|
|
{"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched},
|
|
|
|
{"keypad", (PyCFunction)PyCursesWindow_keypad},
|
|
|
|
{"leaveok", (PyCFunction)PyCursesWindow_leaveok},
|
|
|
|
{"move", (PyCFunction)PyCursesWindow_wmove},
|
|
|
|
{"mvderwin", (PyCFunction)PyCursesWindow_mvderwin},
|
2000-05-23 16:24:54 +00:00
|
|
|
{"mvwin", (PyCFunction)PyCursesWindow_mvwin},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"nodelay", (PyCFunction)PyCursesWindow_nodelay},
|
|
|
|
{"notimeout", (PyCFunction)PyCursesWindow_notimeout},
|
2000-05-23 16:24:54 +00:00
|
|
|
{"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"putwin", (PyCFunction)PyCursesWindow_PutWin},
|
|
|
|
{"redrawln", (PyCFunction)PyCursesWindow_RedrawLine},
|
2000-05-23 16:24:54 +00:00
|
|
|
{"redrawwin", (PyCFunction)PyCursesWindow_redrawwin},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"refresh", (PyCFunction)PyCursesWindow_Refresh},
|
2000-06-27 21:49:47 +00:00
|
|
|
#ifndef STRICT_SYSV_CURSES
|
2000-05-23 16:18:03 +00:00
|
|
|
{"resize", (PyCFunction)PyCursesWindow_wresize},
|
|
|
|
#endif
|
|
|
|
{"scroll", (PyCFunction)PyCursesWindow_Scroll},
|
|
|
|
{"scrollok", (PyCFunction)PyCursesWindow_scrollok},
|
1995-03-17 12:18:38 +00:00
|
|
|
{"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"standend", (PyCFunction)PyCursesWindow_wstandend},
|
|
|
|
{"standout", (PyCFunction)PyCursesWindow_wstandout},
|
|
|
|
{"subpad", (PyCFunction)PyCursesWindow_SubWin},
|
|
|
|
{"subwin", (PyCFunction)PyCursesWindow_SubWin},
|
|
|
|
{"syncdown", (PyCFunction)PyCursesWindow_wsyncdown},
|
|
|
|
{"syncok", (PyCFunction)PyCursesWindow_syncok},
|
|
|
|
{"syncup", (PyCFunction)PyCursesWindow_wsyncup},
|
2000-06-21 01:41:48 +00:00
|
|
|
{"timeout", (PyCFunction)PyCursesWindow_wtimeout},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"touchline", (PyCFunction)PyCursesWindow_TouchLine},
|
|
|
|
{"touchwin", (PyCFunction)PyCursesWindow_touchwin},
|
|
|
|
{"untouchwin", (PyCFunction)PyCursesWindow_untouchwin},
|
|
|
|
{"vline", (PyCFunction)PyCursesWindow_Vline},
|
1995-02-24 13:45:43 +00:00
|
|
|
{NULL, NULL} /* sentinel */
|
1994-08-30 12:25:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-21 06:00:07 +00:00
|
|
|
PyCursesWindow_GetAttr(PyCursesWindowObject *self, char *name)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
1995-01-10 20:56:29 +00:00
|
|
|
return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------------------*/
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
PyTypeObject PyCursesWindow_Type = {
|
1994-08-30 12:25:20 +00:00
|
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
|
|
|
0, /*ob_size*/
|
|
|
|
"curses window", /*tp_name*/
|
|
|
|
sizeof(PyCursesWindowObject), /*tp_basicsize*/
|
|
|
|
0, /*tp_itemsize*/
|
|
|
|
/* methods */
|
|
|
|
(destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
|
|
|
|
0, /*tp_print*/
|
|
|
|
(getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
|
|
|
|
(setattrfunc)0, /*tp_setattr*/
|
|
|
|
0, /*tp_compare*/
|
|
|
|
0, /*tp_repr*/
|
|
|
|
0, /*tp_as_number*/
|
|
|
|
0, /*tp_as_sequence*/
|
|
|
|
0, /*tp_as_mapping*/
|
|
|
|
0, /*tp_hash*/
|
|
|
|
};
|
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
/*********************************************************************
|
|
|
|
Global Functions
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static PyObject *ModDict;
|
|
|
|
|
|
|
|
/* Function Prototype Macros - They are ugly but very, very useful. ;-)
|
|
|
|
|
|
|
|
X - function name
|
|
|
|
TYPE - parameter Type
|
|
|
|
ERGSTR - format string for construction of the return value
|
|
|
|
PARSESTR - format string for argument parsing
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NoArgNoReturnFunction(X) \
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
|
2000-05-23 16:18:03 +00:00
|
|
|
{ \
|
|
|
|
PyCursesInitialised \
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) return NULL; \
|
2000-05-23 16:18:03 +00:00
|
|
|
return PyCursesCheckERR(X(), # X); }
|
|
|
|
|
|
|
|
#define NoArgOrFlagNoReturnFunction(X) \
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
|
2000-05-23 16:18:03 +00:00
|
|
|
{ \
|
|
|
|
int flag = 0; \
|
|
|
|
PyCursesInitialised \
|
2000-07-09 14:35:00 +00:00
|
|
|
switch(ARG_COUNT(args)) { \
|
2000-05-23 16:18:03 +00:00
|
|
|
case 0: \
|
|
|
|
return PyCursesCheckERR(X(), # X); \
|
|
|
|
case 1: \
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "i;True(1) or False(0)", &flag)) return NULL; \
|
2000-05-23 16:18:03 +00:00
|
|
|
if (flag) return PyCursesCheckERR(X(), # X); \
|
|
|
|
else return PyCursesCheckERR(no ## X (), # X); \
|
|
|
|
default: \
|
2000-05-23 16:24:54 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL; } }
|
|
|
|
|
|
|
|
#define NoArgReturnIntFunction(X) \
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
|
2000-05-23 16:18:03 +00:00
|
|
|
{ \
|
|
|
|
PyCursesInitialised \
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) return NULL; \
|
2000-05-23 16:18:03 +00:00
|
|
|
return PyInt_FromLong((long) X()); }
|
|
|
|
|
|
|
|
|
|
|
|
#define NoArgReturnStringFunction(X) \
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
|
2000-05-23 16:18:03 +00:00
|
|
|
{ \
|
|
|
|
PyCursesInitialised \
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) return NULL; \
|
2000-05-23 16:18:03 +00:00
|
|
|
return PyString_FromString(X()); }
|
|
|
|
|
|
|
|
#define NoArgTrueFalseFunction(X) \
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
|
2000-05-23 16:18:03 +00:00
|
|
|
{ \
|
|
|
|
PyCursesInitialised \
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) return NULL; \
|
2000-05-23 16:18:03 +00:00
|
|
|
if (X () == FALSE) { \
|
|
|
|
Py_INCREF(Py_False); \
|
|
|
|
return Py_False; \
|
|
|
|
} \
|
|
|
|
Py_INCREF(Py_True); \
|
|
|
|
return Py_True; }
|
|
|
|
|
|
|
|
#define NoArgNoReturnVoidFunction(X) \
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
|
2000-05-23 16:18:03 +00:00
|
|
|
{ \
|
|
|
|
PyCursesInitialised \
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) return NULL; \
|
2000-05-23 16:18:03 +00:00
|
|
|
X(); \
|
|
|
|
Py_INCREF(Py_None); \
|
|
|
|
return Py_None; }
|
|
|
|
|
|
|
|
NoArgNoReturnFunction(beep)
|
|
|
|
NoArgNoReturnFunction(def_prog_mode)
|
|
|
|
NoArgNoReturnFunction(def_shell_mode)
|
|
|
|
NoArgNoReturnFunction(doupdate)
|
|
|
|
NoArgNoReturnFunction(endwin)
|
|
|
|
NoArgNoReturnFunction(flash)
|
|
|
|
NoArgNoReturnFunction(nocbreak)
|
|
|
|
NoArgNoReturnFunction(noecho)
|
|
|
|
NoArgNoReturnFunction(nonl)
|
|
|
|
NoArgNoReturnFunction(noraw)
|
|
|
|
NoArgNoReturnFunction(reset_prog_mode)
|
|
|
|
NoArgNoReturnFunction(reset_shell_mode)
|
|
|
|
NoArgNoReturnFunction(resetty)
|
|
|
|
NoArgNoReturnFunction(savetty)
|
|
|
|
|
|
|
|
NoArgOrFlagNoReturnFunction(cbreak)
|
|
|
|
NoArgOrFlagNoReturnFunction(echo)
|
|
|
|
NoArgOrFlagNoReturnFunction(nl)
|
|
|
|
NoArgOrFlagNoReturnFunction(raw)
|
|
|
|
|
|
|
|
NoArgReturnIntFunction(baudrate)
|
|
|
|
NoArgReturnIntFunction(termattrs)
|
|
|
|
|
|
|
|
NoArgReturnStringFunction(termname)
|
|
|
|
NoArgReturnStringFunction(longname)
|
|
|
|
|
|
|
|
NoArgTrueFalseFunction(can_change_color)
|
|
|
|
NoArgTrueFalseFunction(has_colors)
|
|
|
|
NoArgTrueFalseFunction(has_ic)
|
|
|
|
NoArgTrueFalseFunction(has_il)
|
|
|
|
NoArgTrueFalseFunction(isendwin)
|
|
|
|
NoArgNoReturnVoidFunction(filter)
|
|
|
|
NoArgNoReturnVoidFunction(flushinp)
|
|
|
|
NoArgNoReturnVoidFunction(noqiflush)
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_Color_Content(PyObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
short color,r,g,b;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
PyCursesInitialisedColor
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (ARG_COUNT(args) != 1) {
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"color_content requires 1 argument");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "h;color", &color)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
if (color_content(color, &r, &g, &b) != ERR)
|
|
|
|
return Py_BuildValue("(iii)", r, g, b);
|
|
|
|
else {
|
|
|
|
PyErr_SetString(PyCursesError,
|
|
|
|
"Argument 1 was out of range. Check value of COLORS.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_color_pair(PyObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
PyCursesInitialisedColor
|
|
|
|
|
2000-07-24 23:54:49 +00:00
|
|
|
if (ARG_COUNT(args) != 1) {
|
2000-05-23 16:24:54 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "color_pair requires 1 argument");
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "i;number", &n)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
return PyInt_FromLong((long) (n << 8));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_Curs_Set(PyObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
int vis,erg;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-24 23:54:49 +00:00
|
|
|
if (ARG_COUNT(args)!=1) {
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "curs_set requires 1 argument");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "i;int", &vis)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
erg = curs_set(vis);
|
|
|
|
if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
|
|
|
|
|
|
|
|
return PyInt_FromLong((long) erg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_Delay_Output(PyObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
int ms;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-24 23:54:49 +00:00
|
|
|
if (ARG_COUNT(args) != 1) {
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "delay_output requires 1 argument");
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "i;ms", &ms)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
return PyCursesCheckERR(delay_output(ms), "delay_output");
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_EraseChar(PyObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
ch = erasechar();
|
|
|
|
|
|
|
|
return PyString_FromString(&ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_getsyx(PyObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
int x,y;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
getsyx(y, x);
|
|
|
|
|
|
|
|
return Py_BuildValue("(ii)", y, x);
|
|
|
|
}
|
|
|
|
|
2000-06-27 03:10:38 +00:00
|
|
|
#ifdef NCURSES_MOUSE_VERSION
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_GetMouse(PyObject *self, PyObject *args)
|
2000-06-27 03:10:38 +00:00
|
|
|
{
|
|
|
|
int rtn;
|
|
|
|
MEVENT event;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) return NULL;
|
2000-06-27 03:10:38 +00:00
|
|
|
|
|
|
|
rtn = getmouse( &event );
|
|
|
|
if (rtn == ERR) {
|
|
|
|
PyErr_SetString(PyCursesError, "getmouse() returned ERR");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return Py_BuildValue("(hiiil)",
|
|
|
|
(short)event.id,
|
|
|
|
event.x, event.y, event.z,
|
|
|
|
(long) event.bstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_UngetMouse(PyObject *self, PyObject *args)
|
2000-06-27 03:10:38 +00:00
|
|
|
{
|
|
|
|
MEVENT event;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
if (!PyArg_ParseTuple(args, "(hiiil)",
|
|
|
|
&event.id,
|
|
|
|
&event.x, &event.y, &event.z,
|
|
|
|
(int *) &event.bstate))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_GetWin(PyCursesWindowObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
WINDOW *win;
|
|
|
|
PyObject *temp;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "O;fileobj", &temp)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
if (!PyFile_Check(temp)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "argument must be a file object");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
win = getwin(PyFile_AsFile(temp));
|
|
|
|
|
|
|
|
if (win == NULL) {
|
|
|
|
PyErr_SetString(PyCursesError, catchall_NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PyCursesWindow_New(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_HalfDelay(PyObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
unsigned char tenths;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch(ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "b;tenths", &tenths)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "halfdelay requires 1 argument");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
|
|
|
|
}
|
|
|
|
|
2000-07-25 12:37:41 +00:00
|
|
|
#ifndef STRICT_SYSV_CURSES
|
2000-05-23 16:18:03 +00:00
|
|
|
/* No has_key! */
|
2000-07-09 14:35:00 +00:00
|
|
|
static PyObject * PyCurses_has_key(PyObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"i",&ch)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
if (has_key(ch) == FALSE) {
|
|
|
|
Py_INCREF(Py_False);
|
|
|
|
return Py_False;
|
|
|
|
}
|
|
|
|
Py_INCREF(Py_True);
|
|
|
|
return Py_True;
|
|
|
|
}
|
2000-07-25 12:37:41 +00:00
|
|
|
#endif /* STRICT_SYSV_CURSES */
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_Init_Color(PyObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
short color, r, g, b;
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
PyCursesInitialised
|
|
|
|
PyCursesInitialisedColor
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch(ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 4:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "(hhhh);color,r,g,b", &color, &r, &g, &b)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PyCursesCheckERR(init_color(color, r, g, b), "init_color");
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_Init_Pair(PyObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
short pair, f, b;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
PyCursesInitialisedColor
|
|
|
|
|
2000-07-24 23:54:49 +00:00
|
|
|
if (ARG_COUNT(args) != 3) {
|
2000-05-23 16:18:03 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "(hhh);pair, f, b", &pair, &f, &b)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
return PyCursesCheckERR(init_pair(pair, f, b), "init_pair");
|
|
|
|
}
|
1994-09-07 14:32:49 +00:00
|
|
|
|
1994-08-30 12:25:20 +00:00
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_InitScr(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
1994-08-31 22:06:24 +00:00
|
|
|
WINDOW *win;
|
2000-05-23 16:18:03 +00:00
|
|
|
PyObject *lines, *cols;
|
|
|
|
|
|
|
|
if (!PyArg_NoArgs(args)) return NULL;
|
|
|
|
|
1995-02-24 13:45:43 +00:00
|
|
|
if (initialised == TRUE) {
|
1994-08-30 12:25:20 +00:00
|
|
|
wrefresh(stdscr);
|
|
|
|
return (PyObject *)PyCursesWindow_New(stdscr);
|
|
|
|
}
|
1994-08-31 22:06:24 +00:00
|
|
|
|
|
|
|
win = initscr();
|
2000-05-23 16:18:03 +00:00
|
|
|
|
1995-02-17 13:50:17 +00:00
|
|
|
if (win == NULL) {
|
|
|
|
PyErr_SetString(PyCursesError, catchall_NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1995-02-24 13:45:43 +00:00
|
|
|
initialised = TRUE;
|
1994-08-31 22:06:24 +00:00
|
|
|
|
2000-05-23 16:24:54 +00:00
|
|
|
/* This was moved from initcurses() because it core dumped on SGI,
|
|
|
|
where they're not defined until you've called initscr() */
|
|
|
|
#define SetDictInt(string,ch) \
|
|
|
|
PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch)));
|
|
|
|
|
|
|
|
/* Here are some graphic symbols you can use */
|
|
|
|
SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));
|
|
|
|
SetDictInt("ACS_LLCORNER", (ACS_LLCORNER));
|
|
|
|
SetDictInt("ACS_URCORNER", (ACS_URCORNER));
|
|
|
|
SetDictInt("ACS_LRCORNER", (ACS_LRCORNER));
|
|
|
|
SetDictInt("ACS_LTEE", (ACS_LTEE));
|
|
|
|
SetDictInt("ACS_RTEE", (ACS_RTEE));
|
|
|
|
SetDictInt("ACS_BTEE", (ACS_BTEE));
|
|
|
|
SetDictInt("ACS_TTEE", (ACS_TTEE));
|
|
|
|
SetDictInt("ACS_HLINE", (ACS_HLINE));
|
|
|
|
SetDictInt("ACS_VLINE", (ACS_VLINE));
|
|
|
|
SetDictInt("ACS_PLUS", (ACS_PLUS));
|
|
|
|
SetDictInt("ACS_S1", (ACS_S1));
|
|
|
|
SetDictInt("ACS_S9", (ACS_S9));
|
|
|
|
SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
|
|
|
|
SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
|
|
|
|
SetDictInt("ACS_DEGREE", (ACS_DEGREE));
|
|
|
|
SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
|
|
|
|
SetDictInt("ACS_BULLET", (ACS_BULLET));
|
|
|
|
SetDictInt("ACS_LARROW", (ACS_LARROW));
|
|
|
|
SetDictInt("ACS_RARROW", (ACS_RARROW));
|
|
|
|
SetDictInt("ACS_DARROW", (ACS_DARROW));
|
|
|
|
SetDictInt("ACS_UARROW", (ACS_UARROW));
|
|
|
|
SetDictInt("ACS_BOARD", (ACS_BOARD));
|
|
|
|
SetDictInt("ACS_LANTERN", (ACS_LANTERN));
|
|
|
|
SetDictInt("ACS_BLOCK", (ACS_BLOCK));
|
|
|
|
SetDictInt("ACS_BSSB", (ACS_ULCORNER));
|
|
|
|
SetDictInt("ACS_SSBB", (ACS_LLCORNER));
|
|
|
|
SetDictInt("ACS_BBSS", (ACS_URCORNER));
|
|
|
|
SetDictInt("ACS_SBBS", (ACS_LRCORNER));
|
|
|
|
SetDictInt("ACS_SBSS", (ACS_RTEE));
|
|
|
|
SetDictInt("ACS_SSSB", (ACS_LTEE));
|
|
|
|
SetDictInt("ACS_SSBS", (ACS_BTEE));
|
|
|
|
SetDictInt("ACS_BSSS", (ACS_TTEE));
|
|
|
|
SetDictInt("ACS_BSBS", (ACS_HLINE));
|
|
|
|
SetDictInt("ACS_SBSB", (ACS_VLINE));
|
|
|
|
SetDictInt("ACS_SSSS", (ACS_PLUS));
|
2000-06-27 21:49:47 +00:00
|
|
|
#ifndef STRICT_SYSV_CURSES
|
|
|
|
/* The following are never available with strict SYSV curses */
|
2000-05-23 16:24:54 +00:00
|
|
|
SetDictInt("ACS_S3", (ACS_S3));
|
|
|
|
SetDictInt("ACS_LEQUAL", (ACS_LEQUAL));
|
|
|
|
SetDictInt("ACS_GEQUAL", (ACS_GEQUAL));
|
|
|
|
SetDictInt("ACS_PI", (ACS_PI));
|
|
|
|
SetDictInt("ACS_NEQUAL", (ACS_NEQUAL));
|
|
|
|
SetDictInt("ACS_STERLING", (ACS_STERLING));
|
|
|
|
#endif
|
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
lines = PyInt_FromLong((long) LINES);
|
|
|
|
PyDict_SetItemString(ModDict, "LINES", lines);
|
|
|
|
Py_DECREF(lines);
|
|
|
|
cols = PyInt_FromLong((long) COLS);
|
|
|
|
PyDict_SetItemString(ModDict, "COLS", cols);
|
|
|
|
Py_DECREF(cols);
|
1994-08-31 22:06:24 +00:00
|
|
|
|
|
|
|
return (PyObject *)PyCursesWindow_New(win);
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_IntrFlush(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int ch;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch(ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"i;True(1), False(0)",&ch)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_KeyName(PyObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
const char *knp;
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"i",&ch)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
knp = keyname(ch);
|
|
|
|
|
|
|
|
return PyString_FromString((knp == NULL) ? "" : (char *)knp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_KillChar(PyObject *self, PyObject *args)
|
2000-05-23 16:18:03 +00:00
|
|
|
{
|
|
|
|
char ch;
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
ch = killchar();
|
|
|
|
|
|
|
|
return PyString_FromString(&ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_Meta(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int ch;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch(ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"i;True(1), False(0)",&ch)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "meta requires 1 argument");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
return PyCursesCheckERR(meta(stdscr, ch), "meta");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
2000-06-27 03:10:38 +00:00
|
|
|
#ifdef NCURSES_MOUSE_VERSION
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_MouseInterval(PyObject *self, PyObject *args)
|
2000-06-27 03:10:38 +00:00
|
|
|
{
|
|
|
|
int interval;
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"i;interval",&interval))
|
2000-06-27 03:10:38 +00:00
|
|
|
return NULL;
|
|
|
|
return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_MouseMask(PyObject *self, PyObject *args)
|
2000-06-27 03:10:38 +00:00
|
|
|
{
|
2000-07-06 18:14:03 +00:00
|
|
|
int newmask;
|
2000-06-27 03:10:38 +00:00
|
|
|
mmask_t oldmask, availmask;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"i;mousemask",&newmask))
|
2000-06-27 03:10:38 +00:00
|
|
|
return NULL;
|
|
|
|
availmask = mousemask(newmask, &oldmask);
|
|
|
|
return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1994-08-30 12:25:20 +00:00
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_NewPad(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
WINDOW *win;
|
|
|
|
int nlines, ncols;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);nlines,ncols",&nlines,&ncols)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
win = newpad(nlines, ncols);
|
|
|
|
|
|
|
|
if (win == NULL) {
|
|
|
|
PyErr_SetString(PyCursesError, catchall_NULL);
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (PyObject *)PyCursesWindow_New(win);
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_NewWindow(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
|
|
|
WINDOW *win;
|
|
|
|
int nlines, ncols, begin_y, begin_x;
|
1995-02-17 13:50:17 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch (ARG_COUNT(args)) {
|
1995-02-17 13:50:17 +00:00
|
|
|
case 2:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"(ii);nlines,ncols",&nlines,&ncols))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
win = newpad(nlines, ncols);
|
1995-02-17 13:50:17 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x",
|
1994-08-30 12:25:20 +00:00
|
|
|
&nlines,&ncols,&begin_y,&begin_x))
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
win = newwin(nlines,ncols,begin_y,begin_x);
|
1995-02-17 13:50:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1994-08-30 12:25:20 +00:00
|
|
|
if (win == NULL) {
|
1995-02-17 13:50:17 +00:00
|
|
|
PyErr_SetString(PyCursesError, catchall_NULL);
|
|
|
|
return NULL;
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
1995-02-17 13:50:17 +00:00
|
|
|
|
1994-08-30 12:25:20 +00:00
|
|
|
return (PyObject *)PyCursesWindow_New(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_Pair_Content(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
short pair,f,b;
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
PyCursesInitialised
|
|
|
|
PyCursesInitialisedColor
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch(ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "h;pair", &pair)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
if (!pair_content(pair, &f, &b)) {
|
|
|
|
PyErr_SetString(PyCursesError,
|
|
|
|
"Argument 1 was out of range. (1..COLOR_PAIRS-1)");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
return Py_BuildValue("(ii)", f, b);
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_pair_number(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int n;
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
PyCursesInitialised
|
|
|
|
PyCursesInitialisedColor
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch(ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "i;pairvalue", &n)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
2000-05-23 16:24:54 +00:00
|
|
|
"pair_number requires 1 argument");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return PyInt_FromLong((long) ((n & A_COLOR) >> 8));
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_Putp(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
char *str;
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"s;str", &str)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
return PyCursesCheckERR(putp(str), "putp");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_QiFlush(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int flag = 0;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch(ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 0:
|
|
|
|
qiflush();
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "i;True(1) or False(0)", &flag)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
if (flag) qiflush();
|
|
|
|
else noqiflush();
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
default:
|
2000-05-23 16:24:54 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_setsyx(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int y,x;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (ARG_COUNT(args)!=2) {
|
2000-05-23 16:24:54 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args, "(ii);y, x", &y, &x)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
setsyx(y,x);
|
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_Start_Color(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int code;
|
|
|
|
PyObject *c, *cp;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_NoArgs(args)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
code = start_color();
|
|
|
|
if (code != ERR) {
|
|
|
|
initialisedcolors = TRUE;
|
|
|
|
c = PyInt_FromLong((long) COLORS);
|
|
|
|
PyDict_SetItemString(ModDict, "COLORS", c);
|
|
|
|
Py_DECREF(c);
|
|
|
|
cp = PyInt_FromLong((long) COLOR_PAIRS);
|
|
|
|
PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
|
|
|
|
Py_DECREF(cp);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
} else {
|
|
|
|
PyErr_SetString(PyCursesError, "start_color() returned ERR");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
2000-07-26 02:57:20 +00:00
|
|
|
static PyObject *
|
|
|
|
PyCurses_tigetflag(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
char *capname;
|
|
|
|
|
|
|
|
PyCursesInitialised;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "z", &capname))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return PyInt_FromLong( (long) tigetflag( capname ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
PyCurses_tigetnum(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
char *capname;
|
|
|
|
|
|
|
|
PyCursesInitialised;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "z", &capname))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return PyInt_FromLong( (long) tigetnum( capname ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
PyCurses_tigetstr(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
char *capname;
|
|
|
|
|
|
|
|
PyCursesInitialised;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "z", &capname))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
capname = tigetstr( capname );
|
|
|
|
if (capname == 0 || capname == (char*) -1) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
return PyString_FromString( capname );
|
|
|
|
}
|
|
|
|
|
2000-06-21 01:41:48 +00:00
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_TypeAhead(PyObject *self, PyObject *args)
|
2000-06-21 01:41:48 +00:00
|
|
|
{
|
2000-07-06 18:14:03 +00:00
|
|
|
int fd;
|
2000-06-21 01:41:48 +00:00
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"i;fd",&fd)) return NULL;
|
2000-06-21 01:41:48 +00:00
|
|
|
|
|
|
|
PyCursesCheckERR(typeahead( fd ), "typeahead");
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
1994-08-30 12:25:20 +00:00
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_UnCtrl(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
PyObject *temp;
|
|
|
|
chtype ch;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"O;ch or int",&temp)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
if (PyInt_Check(temp))
|
|
|
|
ch = (chtype) PyInt_AsLong(temp);
|
|
|
|
else if (PyString_Check(temp))
|
|
|
|
ch = (chtype) *PyString_AsString(temp);
|
|
|
|
else {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return PyString_FromString(unctrl(ch));
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_UngetCh(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
PyObject *temp;
|
|
|
|
chtype ch;
|
|
|
|
|
|
|
|
PyCursesInitialised
|
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"O;ch or int",&temp)) return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
if (PyInt_Check(temp))
|
|
|
|
ch = (chtype) PyInt_AsLong(temp);
|
|
|
|
else if (PyString_Check(temp))
|
|
|
|
ch = (chtype) *PyString_AsString(temp);
|
|
|
|
else {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
|
1995-02-17 13:50:17 +00:00
|
|
|
return NULL;
|
2000-05-23 16:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return PyCursesCheckERR(ungetch(ch), "ungetch");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2000-07-09 14:35:00 +00:00
|
|
|
PyCurses_Use_Env(PyObject *self, PyObject *args)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
2000-05-23 16:18:03 +00:00
|
|
|
int flag;
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
PyCursesInitialised
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-07-09 14:35:00 +00:00
|
|
|
switch(ARG_COUNT(args)) {
|
2000-05-23 16:18:03 +00:00
|
|
|
case 1:
|
2000-07-09 14:35:00 +00:00
|
|
|
if (!PyArg_Parse(args,"i;True(1), False(0)",&flag))
|
2000-05-23 16:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
use_env(flag);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* List of functions defined in the module */
|
|
|
|
|
|
|
|
static PyMethodDef PyCurses_methods[] = {
|
2000-05-23 16:18:03 +00:00
|
|
|
{"baudrate", (PyCFunction)PyCurses_baudrate},
|
|
|
|
{"beep", (PyCFunction)PyCurses_beep},
|
|
|
|
{"can_change_color", (PyCFunction)PyCurses_can_change_color},
|
|
|
|
{"cbreak", (PyCFunction)PyCurses_cbreak},
|
|
|
|
{"color_content", (PyCFunction)PyCurses_Color_Content},
|
2000-05-23 16:24:54 +00:00
|
|
|
{"color_pair", (PyCFunction)PyCurses_color_pair},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"curs_set", (PyCFunction)PyCurses_Curs_Set},
|
|
|
|
{"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode},
|
|
|
|
{"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode},
|
|
|
|
{"delay_output", (PyCFunction)PyCurses_Delay_Output},
|
|
|
|
{"doupdate", (PyCFunction)PyCurses_doupdate},
|
|
|
|
{"echo", (PyCFunction)PyCurses_echo},
|
|
|
|
{"endwin", (PyCFunction)PyCurses_endwin},
|
|
|
|
{"erasechar", (PyCFunction)PyCurses_EraseChar},
|
|
|
|
{"filter", (PyCFunction)PyCurses_filter},
|
|
|
|
{"flash", (PyCFunction)PyCurses_flash},
|
|
|
|
{"flushinp", (PyCFunction)PyCurses_flushinp},
|
2000-06-27 03:10:38 +00:00
|
|
|
#ifdef NCURSES_MOUSE_VERSION
|
|
|
|
{"getmouse", (PyCFunction)PyCurses_GetMouse},
|
|
|
|
{"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
|
|
|
|
#endif
|
2000-05-23 16:18:03 +00:00
|
|
|
{"getsyx", (PyCFunction)PyCurses_getsyx},
|
|
|
|
{"getwin", (PyCFunction)PyCurses_GetWin},
|
|
|
|
{"has_colors", (PyCFunction)PyCurses_has_colors},
|
|
|
|
{"has_ic", (PyCFunction)PyCurses_has_ic},
|
|
|
|
{"has_il", (PyCFunction)PyCurses_has_il},
|
2000-07-25 12:37:41 +00:00
|
|
|
#ifndef STRICT_SYSV_CURSES
|
2000-05-23 16:18:03 +00:00
|
|
|
{"has_key", (PyCFunction)PyCurses_has_key},
|
1994-08-30 12:25:20 +00:00
|
|
|
#endif
|
2000-05-23 16:18:03 +00:00
|
|
|
{"halfdelay", (PyCFunction)PyCurses_HalfDelay},
|
|
|
|
{"init_color", (PyCFunction)PyCurses_Init_Color},
|
|
|
|
{"init_pair", (PyCFunction)PyCurses_Init_Pair},
|
|
|
|
{"initscr", (PyCFunction)PyCurses_InitScr},
|
|
|
|
{"intrflush", (PyCFunction)PyCurses_IntrFlush},
|
|
|
|
{"isendwin", (PyCFunction)PyCurses_isendwin},
|
|
|
|
{"keyname", (PyCFunction)PyCurses_KeyName},
|
|
|
|
{"killchar", (PyCFunction)PyCurses_KillChar},
|
|
|
|
{"longname", (PyCFunction)PyCurses_longname},
|
|
|
|
{"meta", (PyCFunction)PyCurses_Meta},
|
2000-06-27 03:10:38 +00:00
|
|
|
#ifdef NCURSES_MOUSE_VERSION
|
|
|
|
{"mouseinterval", (PyCFunction)PyCurses_MouseInterval},
|
|
|
|
{"mousemask", (PyCFunction)PyCurses_MouseMask},
|
|
|
|
#endif
|
2000-05-23 16:18:03 +00:00
|
|
|
{"newpad", (PyCFunction)PyCurses_NewPad},
|
|
|
|
{"newwin", (PyCFunction)PyCurses_NewWindow},
|
|
|
|
{"nl", (PyCFunction)PyCurses_nl},
|
|
|
|
{"nocbreak", (PyCFunction)PyCurses_nocbreak},
|
|
|
|
{"noecho", (PyCFunction)PyCurses_noecho},
|
|
|
|
{"nonl", (PyCFunction)PyCurses_nonl},
|
|
|
|
{"noqiflush", (PyCFunction)PyCurses_noqiflush},
|
|
|
|
{"noraw", (PyCFunction)PyCurses_noraw},
|
|
|
|
{"pair_content", (PyCFunction)PyCurses_Pair_Content},
|
2000-05-23 16:24:54 +00:00
|
|
|
{"pair_number", (PyCFunction)PyCurses_pair_number},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"putp", (PyCFunction)PyCurses_Putp},
|
|
|
|
{"qiflush", (PyCFunction)PyCurses_QiFlush},
|
|
|
|
{"raw", (PyCFunction)PyCurses_raw},
|
|
|
|
{"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode},
|
|
|
|
{"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode},
|
2000-07-06 18:14:03 +00:00
|
|
|
{"resetty", (PyCFunction)PyCurses_resetty},
|
|
|
|
{"savetty", (PyCFunction)PyCurses_savetty},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"setsyx", (PyCFunction)PyCurses_setsyx},
|
|
|
|
{"start_color", (PyCFunction)PyCurses_Start_Color},
|
|
|
|
{"termattrs", (PyCFunction)PyCurses_termattrs},
|
|
|
|
{"termname", (PyCFunction)PyCurses_termname},
|
2000-07-26 02:57:20 +00:00
|
|
|
{"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS},
|
|
|
|
{"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS},
|
|
|
|
{"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS},
|
2000-06-21 01:41:48 +00:00
|
|
|
{"typeahead", (PyCFunction)PyCurses_TypeAhead},
|
2000-05-23 16:18:03 +00:00
|
|
|
{"unctrl", (PyCFunction)PyCurses_UnCtrl},
|
|
|
|
{"ungetch", (PyCFunction)PyCurses_UngetCh},
|
|
|
|
{"use_env", (PyCFunction)PyCurses_Use_Env},
|
|
|
|
{NULL, NULL} /* sentinel */
|
1994-08-30 12:25:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization function for the module */
|
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
void
|
2000-07-21 06:00:07 +00:00
|
|
|
init_curses(void)
|
1994-08-30 12:25:20 +00:00
|
|
|
{
|
1995-02-17 13:54:04 +00:00
|
|
|
PyObject *m, *d, *v;
|
1994-08-30 12:25:20 +00:00
|
|
|
|
|
|
|
/* Create the module and add the functions */
|
2000-06-10 23:12:32 +00:00
|
|
|
m = Py_InitModule("_curses", PyCurses_methods);
|
1994-08-30 12:25:20 +00:00
|
|
|
|
|
|
|
/* Add some symbolic constants to the module */
|
|
|
|
d = PyModule_GetDict(m);
|
1994-09-07 14:32:49 +00:00
|
|
|
ModDict = d; /* For PyCurses_InitScr */
|
1994-08-31 22:05:27 +00:00
|
|
|
|
1995-02-17 13:50:17 +00:00
|
|
|
/* For exception curses.error */
|
2000-07-06 19:38:49 +00:00
|
|
|
PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
|
1995-02-17 13:50:17 +00:00
|
|
|
PyDict_SetItemString(d, "error", PyCursesError);
|
1994-08-31 22:05:27 +00:00
|
|
|
|
1995-02-17 13:50:17 +00:00
|
|
|
/* Make the version available */
|
1995-02-17 13:54:04 +00:00
|
|
|
v = PyString_FromString(PyCursesVersion);
|
|
|
|
PyDict_SetItemString(d, "version", v);
|
|
|
|
PyDict_SetItemString(d, "__version__", v);
|
|
|
|
Py_DECREF(v);
|
1994-08-30 12:25:20 +00:00
|
|
|
|
|
|
|
/* Here are some attributes you can add to chars to print */
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES);
|
2000-05-23 16:24:54 +00:00
|
|
|
SetDictInt("A_NORMAL", A_NORMAL);
|
|
|
|
SetDictInt("A_STANDOUT", A_STANDOUT);
|
|
|
|
SetDictInt("A_UNDERLINE", A_UNDERLINE);
|
|
|
|
SetDictInt("A_REVERSE", A_REVERSE);
|
|
|
|
SetDictInt("A_BLINK", A_BLINK);
|
|
|
|
SetDictInt("A_DIM", A_DIM);
|
|
|
|
SetDictInt("A_BOLD", A_BOLD);
|
|
|
|
SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
|
2000-05-23 16:18:03 +00:00
|
|
|
SetDictInt("A_INVIS", A_INVIS);
|
|
|
|
SetDictInt("A_PROTECT", A_PROTECT);
|
2000-05-23 16:24:54 +00:00
|
|
|
SetDictInt("A_CHARTEXT", A_CHARTEXT);
|
|
|
|
SetDictInt("A_COLOR", A_COLOR);
|
2000-06-27 21:49:47 +00:00
|
|
|
#ifndef STRICT_SYSV_CURSES
|
2000-05-23 16:18:03 +00:00
|
|
|
SetDictInt("A_HORIZONTAL", A_HORIZONTAL);
|
|
|
|
SetDictInt("A_LEFT", A_LEFT);
|
|
|
|
SetDictInt("A_LOW", A_LOW);
|
|
|
|
SetDictInt("A_RIGHT", A_RIGHT);
|
|
|
|
SetDictInt("A_TOP", A_TOP);
|
|
|
|
SetDictInt("A_VERTICAL", A_VERTICAL);
|
|
|
|
#endif
|
2000-05-23 16:24:54 +00:00
|
|
|
|
2000-05-23 16:18:03 +00:00
|
|
|
SetDictInt("COLOR_BLACK", COLOR_BLACK);
|
|
|
|
SetDictInt("COLOR_RED", COLOR_RED);
|
|
|
|
SetDictInt("COLOR_GREEN", COLOR_GREEN);
|
|
|
|
SetDictInt("COLOR_YELLOW", COLOR_YELLOW);
|
|
|
|
SetDictInt("COLOR_BLUE", COLOR_BLUE);
|
|
|
|
SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA);
|
|
|
|
SetDictInt("COLOR_CYAN", COLOR_CYAN);
|
|
|
|
SetDictInt("COLOR_WHITE", COLOR_WHITE);
|
1994-08-30 12:25:20 +00:00
|
|
|
|
2000-06-27 03:10:38 +00:00
|
|
|
#ifdef NCURSES_MOUSE_VERSION
|
|
|
|
/* Mouse-related constants */
|
|
|
|
SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);
|
|
|
|
SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);
|
|
|
|
SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED);
|
|
|
|
SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED);
|
|
|
|
SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED);
|
|
|
|
|
|
|
|
SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED);
|
|
|
|
SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED);
|
|
|
|
SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED);
|
|
|
|
SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED);
|
|
|
|
SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED);
|
|
|
|
|
|
|
|
SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED);
|
|
|
|
SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED);
|
|
|
|
SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED);
|
|
|
|
SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED);
|
|
|
|
SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED);
|
|
|
|
|
|
|
|
SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED);
|
|
|
|
SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED);
|
|
|
|
SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED);
|
|
|
|
SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);
|
|
|
|
SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);
|
|
|
|
|
|
|
|
SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT);
|
|
|
|
SetDictInt("BUTTON_CTRL", BUTTON_CTRL);
|
|
|
|
SetDictInt("BUTTON_ALT", BUTTON_ALT);
|
|
|
|
|
|
|
|
SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS);
|
|
|
|
SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION);
|
|
|
|
#endif
|
1994-08-30 12:25:20 +00:00
|
|
|
/* Now set everything up for KEY_ variables */
|
|
|
|
{
|
|
|
|
int key;
|
|
|
|
char *key_n;
|
|
|
|
char *key_n2;
|
|
|
|
for (key=KEY_MIN;key < KEY_MAX; key++) {
|
|
|
|
key_n = (char *)keyname(key);
|
1995-02-07 15:38:32 +00:00
|
|
|
if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
|
1994-08-30 12:25:20 +00:00
|
|
|
continue;
|
|
|
|
if (strncmp(key_n,"KEY_F(",6)==0) {
|
|
|
|
char *p1, *p2;
|
|
|
|
key_n2 = malloc(strlen(key_n)+1);
|
|
|
|
p1 = key_n;
|
|
|
|
p2 = key_n2;
|
|
|
|
while (*p1) {
|
|
|
|
if (*p1 != '(' && *p1 != ')') {
|
|
|
|
*p2 = *p1;
|
|
|
|
p2++;
|
|
|
|
}
|
|
|
|
p1++;
|
|
|
|
}
|
|
|
|
*p2 = (char)0;
|
|
|
|
} else
|
|
|
|
key_n2 = key_n;
|
1995-02-17 13:50:17 +00:00
|
|
|
PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key));
|
1994-08-30 12:25:20 +00:00
|
|
|
if (key_n2 != key_n)
|
|
|
|
free(key_n2);
|
|
|
|
}
|
1995-02-17 13:50:17 +00:00
|
|
|
SetDictInt("KEY_MIN", KEY_MIN);
|
|
|
|
SetDictInt("KEY_MAX", KEY_MAX);
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|
2000-05-23 16:18:03 +00:00
|
|
|
|
|
|
|
/* Check for errors */
|
|
|
|
if (PyErr_Occurred())
|
2000-06-10 23:12:32 +00:00
|
|
|
Py_FatalError("can't initialize module _curses");
|
1994-08-30 12:25:20 +00:00
|
|
|
}
|