diff --git a/src/include/py3270.h b/src/include/py3270.h index f667c65..514f786 100644 --- a/src/include/py3270.h +++ b/src/include/py3270.h @@ -116,6 +116,8 @@ DLL_PRIVATE PyObject * py3270_session_connect(PyObject *self, PyObject *args); DLL_PRIVATE PyObject * py3270_session_disconnect(PyObject *self, PyObject *args); + DLL_PRIVATE PyObject * py3270_session_get(PyObject *self, PyObject *args); + /* DLL_PRIVATE PyObject * py3270_alloc(PyTypeObject *type, PyObject *args, PyObject *kwds); diff --git a/src/module/init.c b/src/module/init.c index d67e269..c0e9e58 100644 --- a/src/module/init.c +++ b/src/module/init.c @@ -88,6 +88,13 @@ static PyMethodDef py3270_session_methods[] = { }, { + "get", + (PyCFunction) py3270_session_get, + METH_VARARGS, + "" + }, + + { NULL } }; diff --git a/src/terminal/get.cc b/src/terminal/get.cc index 73f0660..14d5ba6 100644 --- a/src/terminal/get.cc +++ b/src/terminal/get.cc @@ -34,8 +34,56 @@ #include + using std::string; + /*---[ Implement ]----------------------------------------------------------------------------------*/ + PyObject * py3270_session_get(PyObject *self, PyObject *args) { + + return py3270_session_call(self, [args](TN3270::Host &host){ + + string text; + + switch(PyTuple_Size(args)) { + case 0: // Get the entire screen + text = host.toString(); + break; + + case 2: // Address and length. + { + int baddr, length; + + if (!PyArg_ParseTuple(args, "ii", &baddr, &length)) + return (PyObject *) NULL; + + text = host.toString(baddr, length); + } + break; + + case 3: // Row, col and length + { + unsigned int row, col; + int length; + + if (!PyArg_ParseTuple(args, "IIi", &row, &col, &length)) + return (PyObject *) NULL; + + text = host.toString(row, col, length); + } + break; + + default: + throw std::system_error(EINVAL, std::system_category()); + + } + + return PyUnicode_FromString(text.c_str()); + + }); + + } + + /* DLL_PRIVATE PyObject * py3270_session_getattr(PyObject *self, char *attr_name) { diff --git a/testprograms/sample.py b/testprograms/sample.py index b4bf282..5df8be2 100644 --- a/testprograms/sample.py +++ b/testprograms/sample.py @@ -22,16 +22,11 @@ session.connect('') print(session.connected) -print('----------------------') -inspect.getmembers(session) -print('----------------------') +#print('----------------------') +#print(dir(session)) +#print('----------------------') - - -#print term.IsConnected() -#print term.IsReady() - -#print term.GetStringAt(14,19,38) +print(session.get(14,22,38)) #print "-----------------------------------------------------------------------" #print term -- libgit2 0.21.2