New curses module method addchstr, etc.
Hello, I submitted my first patch recently for the curses color_set and wcolor_set functions. I am now working on addchstr, addchnstr, mvaddchstr, mvaddchnstr, mvwaddchstr, mvwaddchnstr, waddchstr and waddchnstr. I have implemented the non window specific methods as follows: /* Window.addchstr Inserted Steve Owens 2/25/2005 */ static PyObject * PyCursesWindow_AddChstr(PyCursesWindowObject *self, PyObject *args) { int x, y, n; PyStringObject *pS; switch (PyTuple_Size(args)) { case 1: if (!PyArg_ParseTuple(args, "S;(String) expected for waddchstr", &pS)) return NULL; return PyCursesCheckERR(waddchstr(self->win, (chtype*)PyString_AsString(pS)), "waddchstr"); case 2: if (!PyArg_ParseTuple(args, "Si;(String, int) expected for waddchnstr", &pS, &n)) return NULL; return PyCursesCheckERR(waddchnstr(self->win, (chtype*)PyString_AsString(pS), n), "waddchnstr"); case 3: if (!PyArg_ParseTuple(args,"iiS;(int, int, String) expected for mvwaddchstr", &y, &x, &pS)) return NULL; return PyCursesCheckERR(mvwaddchstr(self->win, y, x, (chtype*)PyString_AsString(pS)), "mvwaddchstr"); case 4: if (!PyArg_ParseTuple(args,"iiSi;(int, int, String, int) expected for mvwaddchnstr", &y, &x, &pS, &n)) return NULL; return PyCursesCheckERR(mvwaddchnstr(self->win, y, x, (chtype*)PyString_AsString(pS), n), "mvwaddchnstr"); default: PyErr_SetString(PyExc_TypeError, "addchstr requires 1 to 4 arguments"); } return NULL; } Now the thing is that when I make calls from python like so: curses.addchstr(5,10, "@ < Row 5, Col 10") curses.addchstr(8,10, "Below you should see ABCDEFG") curses.addchstr(9,10, "ABCDEFG") curses.addchstr(12,10, "Below you should see ABCD") curses.addchnstr(13,10, "ABCDEFGHI", 4) What prints out on the screen is gobledygook not the strings you would expect below. Any thoughts on how to correctly convert the PyStringObject arguments to chtype* pointers so that the ncurses library will be able to understand them? -- View this message in context: http://www.nabble.com/New-curses-module-method-addchstr%2C-etc.-tp22211983p2... Sent from the Python - python-dev mailing list archive at Nabble.com.
On Wednesday 25 February 2009, Heracles wrote:
addchstr((chtype*)PyString_AsString(pS))
You are effectively disabling the well-deserved warnings with the cast here. Don't do that.
Now the thing is that when I make calls from python like so:
curses.addchstr(5,10, "@ < Row 5, Col 10") [...] What prints out on the screen is gobledygook not the strings you would expect below. [...] Any thoughts on how to correctly convert the PyStringObject arguments to chtype* pointers so that the ncurses library will be able to understand them?
In this case, I suggest man ncurses: | cchar_t | corresponds to chtype. However it is a structure, because more | data is stored than can fit into an integer. The characters are | large enough to require a full integer value - and there may | be more than one character per cell. The video attributes and | color are stored in separate fields of the structure. I'm pretty sure that you can find functions to generate such a string both from a char-string (with whatever encoding) or a wchar_t-string (using Unicode probably) in the curses library. Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 ************************************************************************************** Sator Laser GmbH, Fangdieckstraße 75a, 22547 Hamburg, Deutschland Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 ************************************************************************************** Visit our website at <http://www.satorlaser.de/> ************************************************************************************** Diese E-Mail einschließlich sämtlicher Anhänge ist nur für den Adressaten bestimmt und kann vertrauliche Informationen enthalten. Bitte benachrichtigen Sie den Absender umgehend, falls Sie nicht der beabsichtigte Empfänger sein sollten. Die E-Mail ist in diesem Fall zu löschen und darf weder gelesen, weitergeleitet, veröffentlicht oder anderweitig benutzt werden. E-Mails können durch Dritte gelesen werden und Viren sowie nichtautorisierte Änderungen enthalten. Sator Laser GmbH ist für diese Folgen nicht verantwortlich. **************************************************************************************
Thank you, this is most helpful, and i will heed your advice about the cast. Cheers! Ulrich Eckhardt wrote:
On Wednesday 25 February 2009, Heracles wrote:
addchstr((chtype*)PyString_AsString(pS))
You are effectively disabling the well-deserved warnings with the cast here. Don't do that.
Now the thing is that when I make calls from python like so:
curses.addchstr(5,10, "@ < Row 5, Col 10") [...] What prints out on the screen is gobledygook not the strings you would expect below. [...] Any thoughts on how to correctly convert the PyStringObject arguments to chtype* pointers so that the ncurses library will be able to understand them?
In this case, I suggest man ncurses:
| cchar_t | corresponds to chtype. However it is a structure, because more | data is stored than can fit into an integer. The characters are | large enough to require a full integer value - and there may | be more than one character per cell. The video attributes and | color are stored in separate fields of the structure.
I'm pretty sure that you can find functions to generate such a string both from a char-string (with whatever encoding) or a wchar_t-string (using Unicode probably) in the curses library.
Uli
-- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
************************************************************************************** Sator Laser GmbH, Fangdieckstraße 75a, 22547 Hamburg, Deutschland Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 ************************************************************************************** Visit our website at <http://www.satorlaser.de/> ************************************************************************************** Diese E-Mail einschließlich sämtlicher Anhänge ist nur für den Adressaten bestimmt und kann vertrauliche Informationen enthalten. Bitte benachrichtigen Sie den Absender umgehend, falls Sie nicht der beabsichtigte Empfänger sein sollten. Die E-Mail ist in diesem Fall zu löschen und darf weder gelesen, weitergeleitet, veröffentlicht oder anderweitig benutzt werden. E-Mails können durch Dritte gelesen werden und Viren sowie nichtautorisierte Änderungen enthalten. Sator Laser GmbH ist für diese Folgen nicht verantwortlich. **************************************************************************************
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/lists%40nabble.com
-- View this message in context: http://www.nabble.com/String-conversion-issues-implementing-new-curses-modul... Sent from the Python - python-dev mailing list archive at Nabble.com.
participants (2)
-
Heracles -
Ulrich Eckhardt