[Python-checkins] CVS: python/dist/src/Modules _cursesmodule.c,2.25,2.26

A.M. Kuchling python-dev@python.org
Mon, 26 Jun 2000 20:10:45 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv19289

Modified Files:
	_cursesmodule.c 
Log Message:
Added support for mouse functions: mousemask(), mouseinterval(), 
getmouse(), ungetmouse(), and window.enclose().  wmouse_trafo() seems 
of marginal importance at the moment.


Index: _cursesmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_cursesmodule.c,v
retrieving revision 2.25
retrieving revision 2.26
diff -C2 -r2.25 -r2.26
*** _cursesmodule.c	2000/06/23 01:36:21	2.25
--- _cursesmodule.c	2000/06/27 03:10:38	2.26
***************
*** 614,618 ****
--- 614,632 ----
  }
  
+ #ifdef NCURSES_MOUSE_VERSION
  static PyObject *
+ PyCursesWindow_Enclose(self,arg)
+      PyCursesWindowObject *self;
+      PyObject * arg;
+ {
+ 	int x, y;
+ 	if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
+ 		return NULL;
+ 
+ 	return PyInt_FromLong( wenclose(self->win,y,x) );
+ }
+ #endif
+ 
+ static PyObject *
  PyCursesWindow_GetBkgd(self, arg)
       PyCursesWindowObject *self;
***************
*** 1274,1277 ****
--- 1288,1294 ----
  	{"derwin",          (PyCFunction)PyCursesWindow_DerWin},
  	{"echochar",        (PyCFunction)PyCursesWindow_EchoChar},
+ #ifdef NCURSES_MOUSE_VERSION
+ 	{"enclose",         (PyCFunction)PyCursesWindow_Enclose},
+ #endif
  	{"erase",           (PyCFunction)PyCursesWindow_werase},
  	{"getbegyx",        (PyCFunction)PyCursesWindow_getbegyx},
***************
*** 1595,1599 ****
--- 1612,1658 ----
  }
  
+ #ifdef NCURSES_MOUSE_VERSION
  static PyObject *
+ PyCurses_GetMouse(self,arg)
+      PyObject *self;
+      PyObject * arg;
+ {
+ 	int rtn;
+ 	MEVENT event;
+ 
+ 	PyCursesInitialised
+ 	if (!PyArg_NoArgs(arg)) return NULL;
+ 
+ 	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 *
+ PyCurses_UngetMouse(self,args)
+      PyObject *self;
+      PyObject *args;
+ {
+ 	int rtn;
+ 	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
+ 
+ static PyObject *
  PyCurses_GetWin(self,arg)
       PyCursesWindowObject *self;
***************
*** 1866,1869 ****
--- 1925,1958 ----
  }
  
+ #ifdef NCURSES_MOUSE_VERSION
+ static PyObject *
+ PyCurses_MouseInterval(self,arg)
+      PyObject * self;
+      PyObject * arg;
+ {
+ 	int interval;
+ 	PyCursesInitialised 
+ 
+ 	if (!PyArg_Parse(arg,"i;interval",&interval)) 
+ 		return NULL;
+ 	return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
+ }
+ 
+ static PyObject *
+ PyCurses_MouseMask(self,arg)
+      PyObject * self;
+      PyObject * arg;
+ {
+ 	int newmask, rtn;
+ 	mmask_t oldmask, availmask;
+ 
+ 	PyCursesInitialised 
+ 	if (!PyArg_Parse(arg,"i;mousemask",&newmask)) 
+ 		return NULL;
+ 	availmask = mousemask(newmask, &oldmask);
+ 	return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
+ }
+ #endif
+ 
  static PyObject *
  PyCurses_NewPad(self,arg)
***************
*** 2169,2172 ****
--- 2258,2265 ----
    {"flash",               (PyCFunction)PyCurses_flash},
    {"flushinp",            (PyCFunction)PyCurses_flushinp},
+ #ifdef NCURSES_MOUSE_VERSION
+   {"getmouse",            (PyCFunction)PyCurses_GetMouse},
+   {"ungetmouse",          (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
+ #endif
    {"getsyx",              (PyCFunction)PyCurses_getsyx},
    {"getwin",              (PyCFunction)PyCurses_GetWin},
***************
*** 2187,2190 ****
--- 2280,2287 ----
    {"longname",            (PyCFunction)PyCurses_longname}, 
    {"meta",                (PyCFunction)PyCurses_Meta},
+ #ifdef NCURSES_MOUSE_VERSION
+   {"mouseinterval",       (PyCFunction)PyCurses_MouseInterval},
+   {"mousemask",           (PyCFunction)PyCurses_MouseMask},
+ #endif
    {"newpad",              (PyCFunction)PyCurses_NewPad},
    {"newwin",              (PyCFunction)PyCurses_NewWindow},
***************
*** 2270,2273 ****
--- 2367,2403 ----
  	SetDictInt("COLOR_WHITE",       COLOR_WHITE);
  
+ #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
  	/* Now set everything up for KEY_ variables */
  	{