@@ -549,68 +549,141 @@ PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
549549
550550/* Addch, Addstr, Addnstr */
551551
552+ /*[clinic]
553+ module curses
554+
555+ class curses.window
556+
557+ curses.window.addch
558+
559+ [
560+ x: int
561+ X-coordinate.
562+ y: int
563+ Y-coordinate.
564+ ]
565+
566+ ch: object
567+ Character to add.
568+
569+ [
570+ attr: long
571+ Attributes for the character.
572+ ]
573+ /
574+
575+ Paint character ch at (y, x) with attributes attr.
576+
577+ Paint character ch at (y, x) with attributes attr,
578+ overwriting any character previously painted at that location.
579+ By default, the character position and attributes are the
580+ current settings for the window object.
581+ [clinic]*/
582+
583+ PyDoc_STRVAR (curses_window_addch__doc__ ,
584+ "Paint character ch at (y, x) with attributes attr.\n"
585+ "\n"
586+ "curses.window.addch([x, y,] ch, [attr])\n"
587+ " x\n"
588+ " X-coordinate.\n"
589+ " y\n"
590+ " Y-coordinate.\n"
591+ " ch\n"
592+ " Character to add.\n"
593+ " attr\n"
594+ " Attributes for the character.\n"
595+ "\n"
596+ "Paint character ch at (y, x) with attributes attr,\n"
597+ "overwriting any character previously painted at that location.\n"
598+ "By default, the character position and attributes are the\n"
599+ "current settings for the window object." );
600+
601+ #define CURSES_WINDOW_ADDCH_METHODDEF \
602+ {"addch", (PyCFunction)curses_window_addch, METH_VARARGS, curses_window_addch__doc__},
603+
604+ static PyObject *
605+ curses_window_addch_impl (PyObject * self , int group_left_1 , int x , int y , PyObject * ch , int group_right_1 , long attr );
606+
607+ static PyObject *
608+ curses_window_addch (PyObject * self , PyObject * args )
609+ {
610+ PyObject * return_value = NULL ;
611+ int group_left_1 = 0 ;
612+ int x ;
613+ int y ;
614+ PyObject * ch ;
615+ int group_right_1 = 0 ;
616+ long attr ;
617+
618+ switch (PyTuple_Size (args )) {
619+ case 1 :
620+ if (!PyArg_ParseTuple (args , "O:addch" , & ch ))
621+ return NULL ;
622+ break ;
623+ case 2 :
624+ if (!PyArg_ParseTuple (args , "Ol:addch" , & ch , & attr ))
625+ return NULL ;
626+ group_right_1 = 1 ;
627+ break ;
628+ case 3 :
629+ if (!PyArg_ParseTuple (args , "iiO:addch" , & x , & y , & ch ))
630+ return NULL ;
631+ group_left_1 = 1 ;
632+ break ;
633+ case 4 :
634+ if (!PyArg_ParseTuple (args , "iiOl:addch" , & x , & y , & ch , & attr ))
635+ return NULL ;
636+ group_right_1 = 1 ;
637+ group_left_1 = 1 ;
638+ break ;
639+ default :
640+ PyErr_SetString (PyExc_TypeError , "curses.window.addch requires 1 to 4 arguments" );
641+ return NULL ;
642+ }
643+ return_value = curses_window_addch_impl (self , group_left_1 , x , y , ch , group_right_1 , attr );
644+
645+ return return_value ;
646+ }
647+
552648static PyObject *
553- PyCursesWindow_AddCh (PyCursesWindowObject * self , PyObject * args )
649+ curses_window_addch_impl (PyObject * self , int group_left_1 , int x , int y , PyObject * ch , int group_right_1 , long attr )
650+ /*[clinic checksum: 98ade780397a48d0be48439763424b3b00c92089]*/
554651{
555- int rtn , x , y , use_xy = FALSE;
556- PyObject * chobj ;
652+ PyCursesWindowObject * cwself = (PyCursesWindowObject * )self ;
653+ int coordinates_group = group_left_1 ;
654+ int attr_group = group_right_1 ;
655+ int rtn ;
557656 int type ;
558- chtype ch ;
657+ chtype cch ;
559658#ifdef HAVE_NCURSESW
560659 cchar_t wch ;
561660#endif
562- attr_t attr = A_NORMAL ;
563- long lattr ;
564661 const char * funcname ;
565662
566- switch (PyTuple_Size (args )) {
567- case 1 :
568- if (!PyArg_ParseTuple (args , "O;ch or int" , & chobj ))
569- return NULL ;
570- break ;
571- case 2 :
572- if (!PyArg_ParseTuple (args , "Ol;ch or int,attr" , & chobj , & lattr ))
573- return NULL ;
574- attr = lattr ;
575- break ;
576- case 3 :
577- if (!PyArg_ParseTuple (args ,"iiO;y,x,ch or int" , & y , & x , & chobj ))
578- return NULL ;
579- use_xy = TRUE;
580- break ;
581- case 4 :
582- if (!PyArg_ParseTuple (args ,"iiOl;y,x,ch or int, attr" ,
583- & y , & x , & chobj , & lattr ))
584- return NULL ;
585- attr = lattr ;
586- use_xy = TRUE;
587- break ;
588- default :
589- PyErr_SetString (PyExc_TypeError , "addch requires 1 to 4 arguments" );
590- return NULL ;
591- }
663+ if (!attr_group )
664+ attr = A_NORMAL ;
592665
593666#ifdef HAVE_NCURSESW
594- type = PyCurses_ConvertToCchar_t (self , chobj , & ch , & wch );
667+ type = PyCurses_ConvertToCchar_t (cwself , ch , & cch , & wch );
595668 if (type == 2 ) {
596669 funcname = "add_wch" ;
597670 wch .attr = attr ;
598- if (use_xy == TRUE )
599- rtn = mvwadd_wch (self -> win ,y ,x , & wch );
671+ if (coordinates_group )
672+ rtn = mvwadd_wch (cwself -> win ,y ,x , & wch );
600673 else {
601- rtn = wadd_wch (self -> win , & wch );
674+ rtn = wadd_wch (cwself -> win , & wch );
602675 }
603676 }
604677 else
605678#else
606- type = PyCurses_ConvertToCchar_t (self , chobj , & ch );
679+ type = PyCurses_ConvertToCchar_t (cwself , chobj , & cch );
607680#endif
608681 if (type == 1 ) {
609682 funcname = "addch" ;
610- if (use_xy == TRUE )
611- rtn = mvwaddch (self -> win ,y ,x , ch | attr );
683+ if (coordinates_group )
684+ rtn = mvwaddch (cwself -> win ,y ,x , cch | attr );
612685 else {
613- rtn = waddch (self -> win , ch | attr );
686+ rtn = waddch (cwself -> win , cch | attr );
614687 }
615688 }
616689 else {
@@ -1954,7 +2027,7 @@ PyCursesWindow_set_encoding(PyCursesWindowObject *self, PyObject *value)
19542027
19552028
19562029static PyMethodDef PyCursesWindow_Methods [] = {
1957- { "addch" , ( PyCFunction ) PyCursesWindow_AddCh , METH_VARARGS },
2030+ CURSES_WINDOW_ADDCH_METHODDEF
19582031 {"addnstr" , (PyCFunction )PyCursesWindow_AddNStr , METH_VARARGS },
19592032 {"addstr" , (PyCFunction )PyCursesWindow_AddStr , METH_VARARGS },
19602033 {"attroff" , (PyCFunction )PyCursesWindow_AttrOff , METH_VARARGS },
0 commit comments