Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e9d23b

Browse files
committed
Added support for mouse functions: mousemask(), mouseinterval(),
getmouse(), ungetmouse(), and window.enclose(). wmouse_trafo() seems of marginal importance at the moment.
1 parent b231e1a commit 8e9d23b

1 file changed

Lines changed: 130 additions & 0 deletions

File tree

Modules/_cursesmodule.c

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,20 @@ PyCursesWindow_EchoChar(self,arg)
613613
"echochar");
614614
}
615615

616+
#ifdef NCURSES_MOUSE_VERSION
617+
static PyObject *
618+
PyCursesWindow_Enclose(self,arg)
619+
PyCursesWindowObject *self;
620+
PyObject * arg;
621+
{
622+
int x, y;
623+
if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
624+
return NULL;
625+
626+
return PyInt_FromLong( wenclose(self->win,y,x) );
627+
}
628+
#endif
629+
616630
static PyObject *
617631
PyCursesWindow_GetBkgd(self, arg)
618632
PyCursesWindowObject *self;
@@ -1273,6 +1287,9 @@ static PyMethodDef PyCursesWindow_Methods[] = {
12731287
{"deleteln", (PyCFunction)PyCursesWindow_wdeleteln},
12741288
{"derwin", (PyCFunction)PyCursesWindow_DerWin},
12751289
{"echochar", (PyCFunction)PyCursesWindow_EchoChar},
1290+
#ifdef NCURSES_MOUSE_VERSION
1291+
{"enclose", (PyCFunction)PyCursesWindow_Enclose},
1292+
#endif
12761293
{"erase", (PyCFunction)PyCursesWindow_werase},
12771294
{"getbegyx", (PyCFunction)PyCursesWindow_getbegyx},
12781295
{"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd},
@@ -1594,6 +1611,48 @@ PyCurses_getsyx(self, arg)
15941611
return Py_BuildValue("(ii)", y, x);
15951612
}
15961613

1614+
#ifdef NCURSES_MOUSE_VERSION
1615+
static PyObject *
1616+
PyCurses_GetMouse(self,arg)
1617+
PyObject *self;
1618+
PyObject * arg;
1619+
{
1620+
int rtn;
1621+
MEVENT event;
1622+
1623+
PyCursesInitialised
1624+
if (!PyArg_NoArgs(arg)) return NULL;
1625+
1626+
rtn = getmouse( &event );
1627+
if (rtn == ERR) {
1628+
PyErr_SetString(PyCursesError, "getmouse() returned ERR");
1629+
return NULL;
1630+
}
1631+
return Py_BuildValue("(hiiil)",
1632+
(short)event.id,
1633+
event.x, event.y, event.z,
1634+
(long) event.bstate);
1635+
}
1636+
1637+
static PyObject *
1638+
PyCurses_UngetMouse(self,args)
1639+
PyObject *self;
1640+
PyObject *args;
1641+
{
1642+
int rtn;
1643+
MEVENT event;
1644+
1645+
PyCursesInitialised
1646+
if (!PyArg_ParseTuple(args, "(hiiil)",
1647+
&event.id,
1648+
&event.x, &event.y, &event.z,
1649+
(int *) &event.bstate))
1650+
return NULL;
1651+
1652+
return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
1653+
}
1654+
#endif
1655+
15971656
static PyObject *
15981657
PyCurses_GetWin(self,arg)
15991658
PyCursesWindowObject *self;
@@ -1865,6 +1924,36 @@ PyCurses_Meta(self,arg)
18651924
return PyCursesCheckERR(meta(stdscr, ch), "meta");
18661925
}
18671926

1927+
#ifdef NCURSES_MOUSE_VERSION
1928+
static PyObject *
1929+
PyCurses_MouseInterval(self,arg)
1930+
PyObject * self;
1931+
PyObject * arg;
1932+
{
1933+
int interval;
1934+
PyCursesInitialised
1935+
1936+
if (!PyArg_Parse(arg,"i;interval",&interval))
1937+
return NULL;
1938+
return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
1939+
}
1940+
1941+
static PyObject *
1942+
PyCurses_MouseMask(self,arg)
1943+
PyObject * self;
1944+
PyObject * arg;
1945+
{
1946+
int newmask, rtn;
1947+
mmask_t oldmask, availmask;
1948+
1949+
PyCursesInitialised
1950+
if (!PyArg_Parse(arg,"i;mousemask",&newmask))
1951+
return NULL;
1952+
availmask = mousemask(newmask, &oldmask);
1953+
return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
1954+
}
1955+
#endif
1956+
18681957
static PyObject *
18691958
PyCurses_NewPad(self,arg)
18701959
PyObject * self;
@@ -2168,6 +2257,10 @@ static PyMethodDef PyCurses_methods[] = {
21682257
{"filter", (PyCFunction)PyCurses_filter},
21692258
{"flash", (PyCFunction)PyCurses_flash},
21702259
{"flushinp", (PyCFunction)PyCurses_flushinp},
2260+
#ifdef NCURSES_MOUSE_VERSION
2261+
{"getmouse", (PyCFunction)PyCurses_GetMouse},
2262+
{"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
2263+
#endif
21712264
{"getsyx", (PyCFunction)PyCurses_getsyx},
21722265
{"getwin", (PyCFunction)PyCurses_GetWin},
21732266
{"has_colors", (PyCFunction)PyCurses_has_colors},
@@ -2186,6 +2279,10 @@ static PyMethodDef PyCurses_methods[] = {
21862279
{"killchar", (PyCFunction)PyCurses_KillChar},
21872280
{"longname", (PyCFunction)PyCurses_longname},
21882281
{"meta", (PyCFunction)PyCurses_Meta},
2282+
#ifdef NCURSES_MOUSE_VERSION
2283+
{"mouseinterval", (PyCFunction)PyCurses_MouseInterval},
2284+
{"mousemask", (PyCFunction)PyCurses_MouseMask},
2285+
#endif
21892286
{"newpad", (PyCFunction)PyCurses_NewPad},
21902287
{"newwin", (PyCFunction)PyCurses_NewWindow},
21912288
{"nl", (PyCFunction)PyCurses_nl},
@@ -2269,6 +2366,39 @@ init_curses()
22692366
SetDictInt("COLOR_CYAN", COLOR_CYAN);
22702367
SetDictInt("COLOR_WHITE", COLOR_WHITE);
22712368

2369+
#ifdef NCURSES_MOUSE_VERSION
2370+
/* Mouse-related constants */
2371+
SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);
2372+
SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);
2373+
SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED);
2374+
SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED);
2375+
SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED);
2376+
2377+
SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED);
2378+
SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED);
2379+
SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED);
2380+
SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED);
2381+
SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED);
2382+
2383+
SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED);
2384+
SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED);
2385+
SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED);
2386+
SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED);
2387+
SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED);
2388+
2389+
SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED);
2390+
SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED);
2391+
SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED);
2392+
SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);
2393+
SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);
2394+
2395+
SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT);
2396+
SetDictInt("BUTTON_CTRL", BUTTON_CTRL);
2397+
SetDictInt("BUTTON_ALT", BUTTON_ALT);
2398+
2399+
SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS);
2400+
SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION);
2401+
#endif
22722402
/* Now set everything up for KEY_ variables */
22732403
{
22742404
int key;

0 commit comments

Comments
 (0)