Skip to content

Commit 7012000

Browse files
lassoanfepegar
authored andcommitted
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 commontk#48 Co-authored-by: Fernando Perez-Garcia <[email protected]>
1 parent fa274d2 commit 7012000

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
}
@@ -62,9 +63,20 @@ static PyObject *PythonQtStdInRedirect_readline(PyObject * self, PyObject * args
6263
return Py_BuildValue("s", QStringToPythonConstCharPointer(string));
6364
}
6465

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

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)