Skip to content

Commit c306140

Browse files
lassoanfepegar
authored andcommitted
[Backport] Add isatty() method to PythonQtStdIn class
pip and some other Python modules use this attribute to check if they are running in an interactive console. fixes PythonQt-48 Co-authored-by: Fernando Perez-Garcia <[email protected]>
1 parent dafdb72 commit c306140

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/PythonQtStdIn.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static PyObject *PythonQtStdInRedirect_new(PyTypeObject *type, PyObject * /*args
4848
self = (PythonQtStdInRedirect *)type->tp_alloc(type, 0);
4949
self->_cb = NULL;
5050
self->_callData = NULL;
51+
self->_isatty = false;
5152

5253
return (PyObject *)self;
5354
}
@@ -63,9 +64,20 @@ static PyObject *PythonQtStdInRedirect_readline(PyObject * self, PyObject * args
6364
return Py_BuildValue("s", QStringToPythonConstCharPointer(string));
6465
}
6566

67+
static PyObject *PythonQtStdInRedirect_isatty(PyObject * self, PyObject * /*args*/)
68+
{
69+
PythonQtStdInRedirect* s = (PythonQtStdInRedirect*)self;
70+
PyObject* r = s->_isatty ? Py_True : Py_False;
71+
Py_INCREF(r);
72+
return r;
73+
}
74+
6675
static PyMethodDef PythonQtStdInRedirect_methods[] = {
6776
{"readline", (PyCFunction)PythonQtStdInRedirect_readline, METH_VARARGS,
6877
"read input line"},
78+
{"isatty", (PyCFunction)PythonQtStdInRedirect_isatty, METH_NOARGS,
79+
"returns True if this is a tty-like device. False by default."
80+
},
6981
{NULL, NULL, 0 , NULL} /* sentinel */
7082
};
7183

src/PythonQtStdIn.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ typedef struct {
5858
PyObject_HEAD
5959
PythonQtInputChangedCB* _cb;
6060
void * _callData;
61+
bool _isatty;
6162
} PythonQtStdInRedirect;
6263

6364
#endif

0 commit comments

Comments
 (0)