Path: blob/devel/ElmerGUI/PythonQt/src/PythonQtStdOut.cpp
3206 views
/*1*2* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.3*4* This library is free software; you can redistribute it and/or5* modify it under the terms of the GNU Lesser General Public6* License as published by the Free Software Foundation; either7* version 2.1 of the License, or (at your option) any later version.8*9* This library is distributed in the hope that it will be useful,10* but WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12* Lesser General Public License for more details.13*14* Further, this software is distributed without any warranty that it is15* free of the rightful claim of any third person regarding infringement16* or the like. Any license provided herein, whether implied or17* otherwise, applies only to this software file. Patent licenses, if18* any, provided herein do not apply to combinations of this program with19* other software, or any other product whatsoever.20*21* You should have received a copy of the GNU Lesser General Public22* License along with this library; if not, write to the Free Software23* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA24*25* Contact information: MeVis Research GmbH, Universitaetsallee 29,26* 28359 Bremen, Germany or:27*28* http://www.mevis.de29*30*/3132//----------------------------------------------------------------------------------33/*!34// \file PythonQtStdOut.cpp35// \author Florian Link36// \author Last changed by $Author: florian $37// \date 2006-0538*/39//----------------------------------------------------------------------------------4041#include "PythonQtStdOut.h"4243static PyObject *PythonQtStdOutRedirect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)44{45PythonQtStdOutRedirect *self;46self = (PythonQtStdOutRedirect *)type->tp_alloc(type, 0);4748self->_cb = NULL;4950return (PyObject *)self;51}5253static PyObject *PythonQtStdOutRedirect_write(PyObject *self, PyObject *args)54{55PythonQtStdOutRedirect* s = (PythonQtStdOutRedirect*)self;56if (s->_cb) {57char *string;58if (!PyArg_ParseTuple(args, "s", &string))59return NULL;6061(*s->_cb)(QString(string));62}63return Py_BuildValue("");64}656667static PyMethodDef PythonQtStdOutRedirect_methods[] = {68{"write", (PyCFunction)PythonQtStdOutRedirect_write, METH_VARARGS,69"redirect the writing to a callback"70},71{NULL} /* Sentinel */72};7374PyTypeObject PythonQtStdOutRedirectType = {75PyObject_HEAD_INIT(NULL)760, /*ob_size*/77"PythonQtStdOutRedirect", /*tp_name*/78sizeof(PythonQtStdOutRedirect), /*tp_basicsize*/790, /*tp_itemsize*/800, /*tp_dealloc*/810, /*tp_print*/820, /*tp_getattr*/830, /*tp_setattr*/840, /*tp_compare*/850, /*tp_repr*/860, /*tp_as_number*/870, /*tp_as_sequence*/880, /*tp_as_mapping*/890, /*tp_hash */900, /*tp_call*/910, /*tp_str*/920, /*tp_getattro*/930, /*tp_setattro*/940, /*tp_as_buffer*/95Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/96"PythonQtStdOutRedirect", /* tp_doc */970, /* tp_traverse */980, /* tp_clear */990, /* tp_richcompare */1000, /* tp_weaklistoffset */1010, /* tp_iter */1020, /* tp_iternext */103PythonQtStdOutRedirect_methods, /* tp_methods */1040, /* tp_members */1050, /* tp_getset */1060, /* tp_base */1070, /* tp_dict */1080, /* tp_descr_get */1090, /* tp_descr_set */1100, /* tp_dictoffset */1110, /* tp_init */1120, /* tp_alloc */113PythonQtStdOutRedirect_new, /* tp_new */114};115116117