[ Web Proxy ]
URL:
Viewing: https://bugs.python.org/file8077/_cursesmodule.diff [Back]  [Original]

--- _cursesmodule-svn.c	2007-07-10 15:09:57.000000000 +0200
+++ _cursesmodule.c	2007-07-10 23:14:40.000000000 +0200
@@ -42,9 +42,9 @@
 
 Here's a list of currently unsupported functions:
 
-	addchnstr addchstr color_set define_key
+	color_set define_key
 	del_curterm delscreen dupwin inchnstr inchstr innstr keyok
-	mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr
+	mcprint mvcur mvinchnstr
 	mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr 
 	mvwinchnstr mvwinchstr mvwinnstr newterm
 	restartterm ripoffline scr_dump
@@ -505,6 +505,86 @@
 }
 
 static PyObject *
+PyCursesWindow_AddChStr(PyCursesWindowObject *self, PyObject *args)
+{
+  int rtn;
+  int x, y;
+  int len;
+  char *str;
+
+  int use_xy = FALSE;
+
+  switch (PyTuple_Size(args)) {
+  case 1:
+    if (!PyArg_ParseTuple(args,"s#", &str, &len))
+      return NULL;
+    break;
+  case 3:
+    if (!PyArg_ParseTuple(args,"iis#;int,int,str", &y, &x, &str, &len))
+      return NULL;
+    use_xy = TRUE;
+    break;
+  default:
+    PyErr_SetString(PyExc_TypeError, "addchstr requires 1 or 3 arguments");
+    return NULL;
+  }
+
+  if (len % sizeof(chtype)) {
+    PyErr_SetString(PyExc_ValueError, "string length must be multiply of curses.chtype_size");
+    return NULL;
+  }
+  
+  if (use_xy == TRUE)
+    rtn = mvwaddchnstr(self->win,y,x,(chtype*)str,len/sizeof(chtype));
+  else
+    rtn = waddchnstr(self->win,(chtype*)str,len/sizeof(chtype));
+  
+  return PyCursesCheckERR(rtn, "addchstr");
+}
+
+static PyObject *
+PyCursesWindow_AddChNStr(PyCursesWindowObject *self, PyObject *args)
+{
+  int rtn;
+  int x, y;
+  int len;
+  int n;
+  char *str;
+
+  int use_xy = FALSE;
+
+  switch (PyTuple_Size(args)) {
+  case 2:
+    if (!PyArg_ParseTuple(args,"s#i;str,int", &str, &len, &n))
+      return NULL;
+    break;
+  case 4:
+    if (!PyArg_ParseTuple(args,"iis#i;int,int,str,int", &y, &x, &str, &len, &n))
+      return NULL;
+    use_xy = TRUE;
+    break;
+  default:
+    PyErr_SetString(PyExc_TypeError, "addchnstr requires 2 or 4 arguments");
+    return NULL;
+  }
+
+  if (len % sizeof(chtype)) {
+    PyErr_SetString(PyExc_ValueError, "string length must be multiply of curses.chtype_size");
+    return NULL;
+  }
+
+  if (n > len/sizeof(chtype))
+  	n = len/sizeof(chtype);
+
+  if (use_xy == TRUE)
+    rtn = mvwaddchnstr(self->win,y,x,(chtype*)str,n);
+  else
+    rtn = waddchnstr(self->win,(chtype*)str,n);
+  
+  return PyCursesCheckERR(rtn, "addchnstr");
+}
+
+static PyObject *
 PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args)
 {
   PyObject *temp;
@@ -1477,6 +1557,8 @@
 	{"addch",           (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS},
 	{"addnstr",         (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS},
 	{"addstr",          (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS},
+	{"addchstr",        (PyCFunction)PyCursesWindow_AddChStr, METH_VARARGS},
+	{"addchnstr",       (PyCFunction)PyCursesWindow_AddChNStr, METH_VARARGS},
 	{"attroff",         (PyCFunction)PyCursesWindow_wattroff, METH_VARARGS},
 	{"attron",          (PyCFunction)PyCursesWindow_wattron, METH_VARARGS},
 	{"attrset",         (PyCFunction)PyCursesWindow_wattrset, METH_VARARGS},
@@ -2774,6 +2856,9 @@
 	SetDictInt("ALL_MOUSE_EVENTS",         ALL_MOUSE_EVENTS);
 	SetDictInt("REPORT_MOUSE_POSITION",    REPORT_MOUSE_POSITION);
 #endif
+	/* Set size of chtype (addchstr/addnstr) */
+	SetDictInt("chtype_size",              sizeof(chtype));
+
 	/* Now set everything up for KEY_ variables */
 	{
 	  int key;

 	  	 

Web Proxy Viewer  |  New URL  |  Original Page