Commit c914320539a3d60dfe9c07e02bf0c9d996d569c9
1 parent
edb69398
Exists in
master
Implementing the "get" method.
Showing
4 changed files
with
61 additions
and
9 deletions
Show diff stats
src/include/py3270.h
@@ -116,6 +116,8 @@ | @@ -116,6 +116,8 @@ | ||
116 | DLL_PRIVATE PyObject * py3270_session_connect(PyObject *self, PyObject *args); | 116 | DLL_PRIVATE PyObject * py3270_session_connect(PyObject *self, PyObject *args); |
117 | DLL_PRIVATE PyObject * py3270_session_disconnect(PyObject *self, PyObject *args); | 117 | DLL_PRIVATE PyObject * py3270_session_disconnect(PyObject *self, PyObject *args); |
118 | 118 | ||
119 | + DLL_PRIVATE PyObject * py3270_session_get(PyObject *self, PyObject *args); | ||
120 | + | ||
119 | /* | 121 | /* |
120 | 122 | ||
121 | DLL_PRIVATE PyObject * py3270_alloc(PyTypeObject *type, PyObject *args, PyObject *kwds); | 123 | DLL_PRIVATE PyObject * py3270_alloc(PyTypeObject *type, PyObject *args, PyObject *kwds); |
src/module/init.c
src/terminal/get.cc
@@ -34,8 +34,56 @@ | @@ -34,8 +34,56 @@ | ||
34 | 34 | ||
35 | #include <py3270.h> | 35 | #include <py3270.h> |
36 | 36 | ||
37 | + using std::string; | ||
38 | + | ||
37 | /*---[ Implement ]----------------------------------------------------------------------------------*/ | 39 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
38 | 40 | ||
41 | + PyObject * py3270_session_get(PyObject *self, PyObject *args) { | ||
42 | + | ||
43 | + return py3270_session_call(self, [args](TN3270::Host &host){ | ||
44 | + | ||
45 | + string text; | ||
46 | + | ||
47 | + switch(PyTuple_Size(args)) { | ||
48 | + case 0: // Get the entire screen | ||
49 | + text = host.toString(); | ||
50 | + break; | ||
51 | + | ||
52 | + case 2: // Address and length. | ||
53 | + { | ||
54 | + int baddr, length; | ||
55 | + | ||
56 | + if (!PyArg_ParseTuple(args, "ii", &baddr, &length)) | ||
57 | + return (PyObject *) NULL; | ||
58 | + | ||
59 | + text = host.toString(baddr, length); | ||
60 | + } | ||
61 | + break; | ||
62 | + | ||
63 | + case 3: // Row, col and length | ||
64 | + { | ||
65 | + unsigned int row, col; | ||
66 | + int length; | ||
67 | + | ||
68 | + if (!PyArg_ParseTuple(args, "IIi", &row, &col, &length)) | ||
69 | + return (PyObject *) NULL; | ||
70 | + | ||
71 | + text = host.toString(row, col, length); | ||
72 | + } | ||
73 | + break; | ||
74 | + | ||
75 | + default: | ||
76 | + throw std::system_error(EINVAL, std::system_category()); | ||
77 | + | ||
78 | + } | ||
79 | + | ||
80 | + return PyUnicode_FromString(text.c_str()); | ||
81 | + | ||
82 | + }); | ||
83 | + | ||
84 | + } | ||
85 | + | ||
86 | + | ||
39 | /* | 87 | /* |
40 | DLL_PRIVATE PyObject * py3270_session_getattr(PyObject *self, char *attr_name) { | 88 | DLL_PRIVATE PyObject * py3270_session_getattr(PyObject *self, char *attr_name) { |
41 | 89 |
testprograms/sample.py
@@ -22,16 +22,11 @@ session.connect('') | @@ -22,16 +22,11 @@ session.connect('') | ||
22 | 22 | ||
23 | print(session.connected) | 23 | print(session.connected) |
24 | 24 | ||
25 | -print('----------------------') | ||
26 | -inspect.getmembers(session) | ||
27 | -print('----------------------') | 25 | +#print('----------------------') |
26 | +#print(dir(session)) | ||
27 | +#print('----------------------') | ||
28 | 28 | ||
29 | - | ||
30 | - | ||
31 | -#print term.IsConnected() | ||
32 | -#print term.IsReady() | ||
33 | - | ||
34 | -#print term.GetStringAt(14,19,38) | 29 | +print(session.get(14,22,38)) |
35 | 30 | ||
36 | #print "-----------------------------------------------------------------------" | 31 | #print "-----------------------------------------------------------------------" |
37 | #print term | 32 | #print term |