|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (C) 2011 MeVis Medical Solutions AG All Rights Reserved. |
| 4 | + * |
| 5 | + * This library is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public |
| 7 | + * License as published by the Free Software Foundation; either |
| 8 | + * version 2.1 of the License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This library is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * Further, this software is distributed without any warranty that it is |
| 16 | + * free of the rightful claim of any third person regarding infringement |
| 17 | + * or the like. Any license provided herein, whether implied or |
| 18 | + * otherwise, applies only to this software file. Patent licenses, if |
| 19 | + * any, provided herein do not apply to combinations of this program with |
| 20 | + * other software, or any other product whatsoever. |
| 21 | + * |
| 22 | + * You should have received a copy of the GNU Lesser General Public |
| 23 | + * License along with this library; if not, write to the Free Software |
| 24 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | + * |
| 26 | + * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, |
| 27 | + * 28359 Bremen, Germany or: |
| 28 | + * |
| 29 | + * http://www.mevis.de |
| 30 | + * |
| 31 | + */ |
| 32 | + |
| 33 | +//---------------------------------------------------------------------------------- |
| 34 | +/*! |
| 35 | +// \file PythonQtStdIn.cpp |
| 36 | +// \author Jean-Christophe Fillion-Robin |
| 37 | +// \author Last changed by $Author: jcfr $ |
| 38 | +// \date 2011 |
| 39 | +*/ |
| 40 | +//---------------------------------------------------------------------------------- |
| 41 | + |
| 42 | +#include "PythonQtStdIn.h" |
| 43 | + |
| 44 | +static PyObject *PythonQtStdInRedirect_new(PyTypeObject *type, PyObject * /*args*/, PyObject * /*kwds*/) |
| 45 | +{ |
| 46 | + PythonQtStdInRedirect *self; |
| 47 | + self = (PythonQtStdInRedirect *)type->tp_alloc(type, 0); |
| 48 | + self->_cb = NULL; |
| 49 | + self->_callData = NULL; |
| 50 | + |
| 51 | + return (PyObject *)self; |
| 52 | +} |
| 53 | + |
| 54 | +static PyObject *PythonQtStdInRedirect_readline(PyObject * self, PyObject * args) |
| 55 | +{ |
| 56 | + PythonQtStdInRedirect* s = (PythonQtStdInRedirect*)self; |
| 57 | + QString string; |
| 58 | + if (s->_cb) { |
| 59 | + string = (*s->_cb)(s->_callData); |
| 60 | + } |
| 61 | + return Py_BuildValue(const_cast<char*>("s"), const_cast<char*>(string.toAscii().data())); |
| 62 | +} |
| 63 | + |
| 64 | +static PyMethodDef PythonQtStdInRedirect_methods[] = { |
| 65 | + {"readline", (PyCFunction)PythonQtStdInRedirect_readline, METH_VARARGS, |
| 66 | + "read input line"}, |
| 67 | + {NULL, NULL, 0 , NULL} /* sentinel */ |
| 68 | +}; |
| 69 | + |
| 70 | +static PyMemberDef PythonQtStdInRedirect_members[] = { |
| 71 | + {NULL} /* Sentinel */ |
| 72 | +}; |
| 73 | + |
| 74 | +PyTypeObject PythonQtStdInRedirectType = { |
| 75 | + PyObject_HEAD_INIT(NULL) |
| 76 | + 0, /*ob_size*/ |
| 77 | + "PythonQtStdInRedirect", /*tp_name*/ |
| 78 | + sizeof(PythonQtStdInRedirect), /*tp_basicsize*/ |
| 79 | + 0, /*tp_itemsize*/ |
| 80 | + 0, /*tp_dealloc*/ |
| 81 | + 0, /*tp_print*/ |
| 82 | + 0, /*tp_getattr*/ |
| 83 | + 0, /*tp_setattr*/ |
| 84 | + 0, /*tp_compare*/ |
| 85 | + 0, /*tp_repr*/ |
| 86 | + 0, /*tp_as_number*/ |
| 87 | + 0, /*tp_as_sequence*/ |
| 88 | + 0, /*tp_as_mapping*/ |
| 89 | + 0, /*tp_hash */ |
| 90 | + 0, /*tp_call*/ |
| 91 | + 0, /*tp_str*/ |
| 92 | + 0, /*tp_getattro*/ |
| 93 | + 0, /*tp_setattro*/ |
| 94 | + 0, /*tp_as_buffer*/ |
| 95 | + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
| 96 | + "PythonQtStdInRedirect", /* tp_doc */ |
| 97 | + 0, /* tp_traverse */ |
| 98 | + 0, /* tp_clear */ |
| 99 | + 0, /* tp_richcompare */ |
| 100 | + 0, /* tp_weaklistoffset */ |
| 101 | + 0, /* tp_iter */ |
| 102 | + 0, /* tp_iternext */ |
| 103 | + PythonQtStdInRedirect_methods, /* tp_methods */ |
| 104 | + PythonQtStdInRedirect_members, /* tp_members */ |
| 105 | + 0, /* tp_getset */ |
| 106 | + 0, /* tp_base */ |
| 107 | + 0, /* tp_dict */ |
| 108 | + 0, /* tp_descr_get */ |
| 109 | + 0, /* tp_descr_set */ |
| 110 | + 0, /* tp_dictoffset */ |
| 111 | + 0, /* tp_init */ |
| 112 | + 0, /* tp_alloc */ |
| 113 | + PythonQtStdInRedirect_new, /* tp_new */ |
| 114 | +}; |
0 commit comments