本文整理汇总了C++中PythonQtObjectPtr::evalScript方法的典型用法代码示例。如果您正苦于以下问题:C++ PythonQtObjectPtr::evalScript方法的具体用法?C++ PythonQtObjectPtr::evalScript怎么用?C++ PythonQtObjectPtr::evalScript使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PythonQtObjectPtr
的用法示例。
在下文中一共展示了PythonQtObjectPtr::evalScript方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testDynamicProperties
void PythonQtTestApi::testDynamicProperties()
{
PythonQtObjectPtr main = PythonQt::self()->getMainModule();
// this fails and should fail, but how could that be tested?
// main.evalScript("obj.testProp = 1");
// create a new dynamic property
main.evalScript("obj.setProperty('testProp','testValue')");
// read the property
QVERIFY(QString("testValue") == main.getVariable("obj.testProp").toString());
// modify and read again
main.evalScript("obj.testProp = 12");
QVERIFY(12 == main.getVariable("obj.testProp").toInt());
// check if dynamic property is in dict
QVERIFY(12 == main.evalScript("obj.__dict__['testProp']", Py_eval_input).toInt());
// check if dynamic property is in introspection
QStringList l = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), "obj", PythonQt::Anything);
QVERIFY(l.contains("testProp"));
// check with None, previous value expected
main.evalScript("obj.testProp = None");
QVERIFY(12 == main.getVariable("obj.testProp").toInt());
// remove the dynamic property
main.evalScript("obj.setProperty('testProp', None)");
// check if dynamic property is really gone
QStringList l2 = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), "obj", PythonQt::Anything);
QVERIFY(!l2.contains("testProp"));
}
示例2: updateGeometry
//----------------------------------------------------------------------------
void DolfinGui::updateGeometry(Geometry *geometry)
{
// Use python script to obtain values in QLineEdit boxes
PythonQt::init();
PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule();
mainModule.addObject("infoBox", geometry->getInfoBox());
double *points = new double[geometry->getPointCount()];
double *radius = new double[geometry->getRadiusCount()];
std::cout << "Points: " << std::endl;
for (int i=0; i < geometry->getPointCount(); ++i){
points[i] = mainModule.evalScript(QString("eval(infoBox.pointEdit%1.text)").arg(i),
Py_eval_input).toDouble();
std::cout << i << ": " << points[i] << std::endl;
}
if (geometry->getRadiusCount() > 0){
for (int i=0; i < geometry->getRadiusCount(); ++i){
radius[i] = mainModule.evalScript(QString("eval(infoBox.radiusEdit%1.text)").arg(i),
Py_eval_input).toDouble();
}
}
geometry->setPoints(points);
geometry->setRadius(radius);
geometry->setGeometryPointer(generateGeometry(geometry));
std::cout << "Point count: " << geometry->getPointCount() << std::endl;
plotGeometry();
}
示例3: testProperties
void PythonQtTestApi::testProperties()
{
PythonQtObjectPtr main = PythonQt::self()->getMainModule();
// check for name alias (for backward comp to Qt3)
main.evalScript("obj.name = 'hello'");
QVERIFY(QString("hello") == main.getVariable("obj.name").toString());
main.evalScript("obj.objectName = 'hello2'");
QVERIFY(QString("hello2") == main.getVariable("obj.objectName").toString());
}
示例4: initTestCase
void PythonQtTestSlotCalling::initTestCase()
{
_helper = new PythonQtTestSlotCallingHelper(this);
PythonQtObjectPtr main = PythonQt::self()->getMainModule();
main.evalScript("import PythonQt");
PythonQt::self()->addObject(main, "obj", _helper);
}
示例5: getCsStringChannel
QString PyQcsObject::getCsStringChannel(QString channel, int index)
{
CsoundEngine *e = m_qcs->getEngine(index);
if (e != NULL) {
CSOUND *cs = e->getCsound();
if (cs != NULL) {
#ifdef CSOUND6
int maxlen = csoundGetChannelDatasize(cs, channel.toLocal8Bit());
#else
int maxlen = csoundGetStrVarMaxLen(cs);
#endif
char *value = new char[maxlen];
if ( !( csoundGetChannelPtr(cs,(MYFLT **) &value,channel.toLocal8Bit(),
CSOUND_STRING_CHANNEL | CSOUND_OUTPUT_CHANNEL))) {
return QString(value);
}
}
}
QString message="Could not read from channel "+channel;
PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
mainContext.evalScript("print \'"+message+"\'");
return QString();//m_qcs->getCsChannel(channel, index);
}
示例6: setCsChannel
void PyQcsObject::setCsChannel(QString channel, double value, int index)
{
CsoundEngine *e = m_qcs->getEngine(index);
MYFLT *p;
if (e != NULL) {
CSOUND *cs = e->getCsound();
#ifndef CSOUND6
if (cs != NULL && !(csoundGetChannelPtr(cs, &p, channel.toLocal8Bit(), CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL))) {
*p = (MYFLT) value;
return;
}
#else
if (cs) {
controlChannelHints_t hints; // this does not work with csound5
int ret = csoundGetControlChannelHints(cs, channel.toLocal8Bit(), &hints);
if (ret == 0) {
csoundSetControlChannel(cs, channel.toLocal8Bit(), (MYFLT) value);
return;
}
}
#endif
}
QString message="Channel '" + channel + "' does not exist or is not exposed with chn_k.";
PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
mainContext.evalScript("print \'"+message+"\'");
}
示例7: setDocument
void PyQcsObject::setDocument(int index)
{
QString name = m_qcs->setDocument(index);
PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
QString path = name.left(name.lastIndexOf("/"));
mainContext.call("os.chdir", QVariantList() << path );
mainContext.evalScript("print 'cd \"" + path + "\"'");
}
示例8: updateSphere
//----------------------------------------------------------------------------
void DolfinGui::updateSphere(SphereGeometry *sphere){
std::cout << "In method updateSphere(): \n";
std::cout << "-------- HELLO!!! --------" << std::endl;
// Use python script to obtain values for corner points
PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule();
mainModule.addObject("sphereInfoBox", sphere->getInfoBox());
for (int i=0; i<sphere->getPointCount(); ++i)
sphere->getPoints()[i] = mainModule.evalScript(QString("eval(sphereInfoBox.sphereEdit%1.text)").arg(i),
Py_eval_input).toDouble();
// Use python script to obtain values for radius
for (int i=0; i<sphere->getRadiusCount(); ++i)
sphere->getRadius()[i] = mainModule.evalScript(QString("eval(sphereInfoBox.radiusEdit%1.text)").arg(i),
Py_eval_input).toDouble();
plotSphere(sphere);
sphereSelected = false;
}
示例9: newDocument
int PyQcsObject::newDocument(QString name)
{
PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
if (name.isEmpty()) {
mainContext.evalScript("print 'Please specify a filename'");
return -1;
}
QDir d(name);
qDebug() << d;
if (QFile::exists(d.absolutePath())) {
mainContext.evalScript("print 'File already exists. Use loadDocument()'");
return -1;
}
m_qcs->newFile();
if (!m_qcs->saveFile(d.absolutePath())) {
mainContext.evalScript("print 'Error saving file.'");
}
return m_qcs->getDocument(name);
}
示例10: loadDocument
int PyQcsObject::loadDocument(QString name, bool runNow)
{
QDir d(name);
d.makeAbsolute();
qDebug() << d.absolutePath();
if (!QFile::exists(d.absolutePath())) {
PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
mainContext.evalScript("print 'File not found.'");
return -1;
} else {
return m_qcs->loadFile(d.absolutePath(), runNow);
}
}
示例11: getWidgetProperty
QVariant PyQcsObject::getWidgetProperty(QString widgetid, QString property, int index)
{
QStringList properties = listWidgetProperties(widgetid,index);
if ( properties.contains(property) ) {
return m_qcs->getWidgetProperty(widgetid, property, index);
} else {
QString message="Widget "+widgetid+" does not have property "+property+" available properties are: "+properties.join(", ")+".";
PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
mainContext.evalScript("print \'"+message+"\'");
}
return (int) -1;
}
示例12: updateCone
//----------------------------------------------------------------------------
void DolfinGui::updateCone(ConeGeometry *cone){
std::cout << "In method updateCone(): \n";
std::cout << "-------- HELLO!!! --------" << std::endl;
for (int i=0; i<6; ++i)
std::cout << cone->getPoints()[i] << " " << std::endl;
// Use python script to obtain values for corner points
PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule();
mainModule.addObject("coneInfoBox", cone->getInfoBox());
for (int i=0; i<cone->getPointCount(); ++i)
cone->getPoints()[i] = mainModule.evalScript(QString("eval(coneInfoBox.coneEdit%1.text)").arg(i),
Py_eval_input).toDouble();
// Use python script to obtain values for radius
for (int i=0; i<cone->getRadiusCount(); ++i)
cone->getRadius()[i] = mainModule.evalScript(QString("eval(coneInfoBox.radiusEdit%1.text)").arg(i),
Py_eval_input).toDouble();
plotCone(cone);
std::cout << "Ferdig" << std::endl;
//coneSelected = false;
}
示例13: getCsChannel
double PyQcsObject::getCsChannel(QString channel, int index)
{
CsoundEngine *e = m_qcs->getEngine(index);
MYFLT *value = new MYFLT;
//*value = 0;
if (e != NULL) {
CSOUND *cs = e->getCsound();
if (cs != NULL ) {
if ( !( csoundGetChannelPtr(cs,&value,channel.toLocal8Bit(),
CSOUND_CONTROL_CHANNEL | CSOUND_OUTPUT_CHANNEL)))
return (double) *value;
}
}
QString message="Could not read from channel "+channel;
PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
mainContext.evalScript("print \'"+message+"\'");
return 0;//m_qcs->getCsChannel(channel, index);
}
示例14: executeString
//-----------------------------------------------------------------------------
QVariant ctkAbstractPythonManager::executeString(const QString& code,
ctkAbstractPythonManager::ExecuteStringMode mode)
{
int start = -1;
switch(mode)
{
case ctkAbstractPythonManager::FileInput: start = Py_file_input; break;
case ctkAbstractPythonManager::SingleInput: start = Py_single_input; break;
case ctkAbstractPythonManager::EvalInput:
default: start = Py_eval_input; break;
}
QVariant ret;
PythonQtObjectPtr main = ctkAbstractPythonManager::mainContext();
if (main)
{
ret = main.evalScript(code, start);
}
return ret;
}
示例15: updateCube
//----------------------------------------------------------------------------
void DolfinGui::updateCube(CubeGeometry *cube)
{
// Set up arrays to hold information about corner points
//GeometryInfo *cubeInfo = new GeometryInfo(6);
//double dataList[cube->getPointCount()];
//cube->setPoints(dataList);
updateRequested = true;
std::cout << "In method updateCube(): \n";
std::cout << "-------- HELLO!!! --------" << std::endl;
//for (int i=0; i<6; ++i)
// std::cout << cube->getPoints()[i] << " " << std::endl;
// Use python script to obtain new values for corner points
PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule();
mainModule.addObject("cubeInfoBox", cube->getInfoBox());
for (int i=0; i<cube->getPointCount(); ++i){
cube->getPoints()[i] = mainModule.evalScript(QString("eval(cubeInfoBox.cubeEdit%1.text)").arg(i),
Py_eval_input).toDouble();
}
plotCube(cube);
cubeSelected = false;
}