Code:
#ifndef QPYTHON_H
#define QPYTHON_H
#endif // QPYTHON_H
#include "python2.4/Python.h"
#include "QString"
#include "QFile"
#include "QTextStream"
#include "QSound"
#include "QMessageBox"
#include "phonon/AbstractAudioOutput"
#include "phonon/AbstractMediaStream"
#include "phonon/phonon"
class QPython
{
private:
QString strScript;
static QString strANI;
static QString strDNIS;
public:
QPython(){}
QPython(QString _strScript)
{strScript = _strScript;}
~QPython(){}
int PythonInitialize()
{
Py_Initialize();
return Py_IsInitialized();
}
int process_expression(char* cScript, char* cKeyNum)
{
PyObject *pValue;
static PyMethodDef dvoice[] = {
// "Python name", C Ffunction Code, Argument Flags, __doc__ description
{"playwave", playwave, METH_VARARGS, ""},
{"ClearDigitBuffer", ClearDigitBuffer, METH_NOARGS, ""},
{NULL, NULL, 0, NULL}
};
cKeyNum = "1";
try
{
PyObject *objModule = PyImport_ImportModule("main");
//PyObject *objArg = Py_BuildValue("(s)", cKeyNum);
//PyObject *objFunc = PyObject_GetAttrString(objModule, "main");
pValue = PyEval_CallObject(PyObject_GetAttrString(objModule, "main")
, Py_BuildValue("(s)", cKeyNum));
Py_DECREF(pValue);}
catch(QString strError)
{QMessageBox msg;
msg.setText(strError);
msg.exec();}
Py_InitModule("dvoice", dvoice);
return PyRun_SimpleString(cScript);
}
int process_expression_FILE(char *cFile, char* cKeyNum)
{
static PyMethodDef dvoice[] = {
// "Python name", C Ffunction Code, Argument Flags, __doc__ description
{"Init", Init, METH_VARARGS, ""},
{"playwave", playwave, METH_VARARGS, ""},
{"ClearDigitBuffer", ClearDigitBuffer, METH_NOARGS, ""},
{NULL, NULL, 0, NULL}
};
PyObject* objArg = Py_BuildValue("(0)", cKeyNum);
PyObject* objFunc = (PyObject*)Init;
PyEval_CallObject(objFunc, objArg);
Py_InitModule("dvoice", dvoice);
FILE* file_1 = fopen(cFile, "r");
return PyRun_SimpleFile(file_1, cFile);
}
void PythonFinalize()
{Py_Finalize();}
//, QString strWaveFile, QBool bSkip, int iFuture
static PyObject* playwave(PyObject* pSelf, PyObject* pArgs)
{
char* strWaveFile;
int *iSkip;
int *iFuture;
PyArg_ParseTuple(pArgs, "sii", &strWaveFile, &iSkip, &iFuture);
QString ster(strWaveFile);
Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource(ster));
music->play();
}
static PyObject* ClearDigitBuffer(PyObject* pSelf, PyObject* pArgs)
{
}
};