示例#1
0
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
0
//----------------------------------------------------------------------------
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
0
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
0
void PythonQtTestSlotCalling::initTestCase()
{
  _helper = new PythonQtTestSlotCallingHelper(this);
  PythonQtObjectPtr main = PythonQt::self()->getMainModule();
  main.evalScript("import PythonQt");
  PythonQt::self()->addObject(main, "obj", _helper);
}
示例#5
0
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
0
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
0
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
0
//----------------------------------------------------------------------------
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
0
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
0
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
0
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
0
//----------------------------------------------------------------------------
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
0
void PyQcsObject::setCsChannel(QString channel, QString stringValue, int index)
{
	CsoundEngine *e = m_qcs->getEngine(index);
	MYFLT *p;
	if (e != NULL) {
		CSOUND *cs = e->getCsound();
		if (cs != NULL && !(csoundGetChannelPtr(cs, &p, channel.toLocal8Bit().constData(), CSOUND_STRING_CHANNEL | CSOUND_INPUT_CHANNEL))) {
			// FIXME not thread safe and not checking string bounds.
			strcpy((char*) p,stringValue.toLocal8Bit().constData() );
			return;
		}
	}
	QString message="Could not set string into channel "+ channel;
	PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
	mainContext.evalScript("print \'"+message+"\'");
}
示例#14
0
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);
}
示例#15
0
//-----------------------------------------------------------------------------
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;
}
示例#16
0
//----------------------------------------------------------------------------
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;
}