Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/PythonQt/src/PythonQtStdOut.cpp
3206 views
1
/*
2
*
3
* Copyright (C) 2006 MeVis Research GmbH 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 Research GmbH, Universitaetsallee 29,
27
* 28359 Bremen, Germany or:
28
*
29
* http://www.mevis.de
30
*
31
*/
32
33
//----------------------------------------------------------------------------------
34
/*!
35
// \file PythonQtStdOut.cpp
36
// \author Florian Link
37
// \author Last changed by $Author: florian $
38
// \date 2006-05
39
*/
40
//----------------------------------------------------------------------------------
41
42
#include "PythonQtStdOut.h"
43
44
static PyObject *PythonQtStdOutRedirect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
45
{
46
PythonQtStdOutRedirect *self;
47
self = (PythonQtStdOutRedirect *)type->tp_alloc(type, 0);
48
49
self->_cb = NULL;
50
51
return (PyObject *)self;
52
}
53
54
static PyObject *PythonQtStdOutRedirect_write(PyObject *self, PyObject *args)
55
{
56
PythonQtStdOutRedirect* s = (PythonQtStdOutRedirect*)self;
57
if (s->_cb) {
58
char *string;
59
if (!PyArg_ParseTuple(args, "s", &string))
60
return NULL;
61
62
(*s->_cb)(QString(string));
63
}
64
return Py_BuildValue("");
65
}
66
67
68
static PyMethodDef PythonQtStdOutRedirect_methods[] = {
69
{"write", (PyCFunction)PythonQtStdOutRedirect_write, METH_VARARGS,
70
"redirect the writing to a callback"
71
},
72
{NULL} /* Sentinel */
73
};
74
75
PyTypeObject PythonQtStdOutRedirectType = {
76
PyObject_HEAD_INIT(NULL)
77
0, /*ob_size*/
78
"PythonQtStdOutRedirect", /*tp_name*/
79
sizeof(PythonQtStdOutRedirect), /*tp_basicsize*/
80
0, /*tp_itemsize*/
81
0, /*tp_dealloc*/
82
0, /*tp_print*/
83
0, /*tp_getattr*/
84
0, /*tp_setattr*/
85
0, /*tp_compare*/
86
0, /*tp_repr*/
87
0, /*tp_as_number*/
88
0, /*tp_as_sequence*/
89
0, /*tp_as_mapping*/
90
0, /*tp_hash */
91
0, /*tp_call*/
92
0, /*tp_str*/
93
0, /*tp_getattro*/
94
0, /*tp_setattro*/
95
0, /*tp_as_buffer*/
96
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
97
"PythonQtStdOutRedirect", /* tp_doc */
98
0, /* tp_traverse */
99
0, /* tp_clear */
100
0, /* tp_richcompare */
101
0, /* tp_weaklistoffset */
102
0, /* tp_iter */
103
0, /* tp_iternext */
104
PythonQtStdOutRedirect_methods, /* tp_methods */
105
0, /* tp_members */
106
0, /* tp_getset */
107
0, /* tp_base */
108
0, /* tp_dict */
109
0, /* tp_descr_get */
110
0, /* tp_descr_set */
111
0, /* tp_dictoffset */
112
0, /* tp_init */
113
0, /* tp_alloc */
114
PythonQtStdOutRedirect_new, /* tp_new */
115
};
116
117