Commit 5f4f9d48 authored by Clinton Stimpson's avatar Clinton Stimpson
Browse files

ENH: add ability to set properties.

parent ff19930d
......@@ -61,6 +61,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
static pqPythonEventSource* Instance = NULL;
static QString PropertyObject;
static QString PropertyResult;
static QString PropertyValue;
static QWaitCondition WaitResults;
static QStringList ObjectList;
......@@ -138,6 +139,60 @@ QtTesting_getProperty(PyObject* /*self*/, PyObject* args)
PropertyResult.toAscii().data());
}
static PyObject*
QtTesting_setProperty(PyObject* /*self*/, PyObject* args)
{
// string QtTesting.setProperty('object', 'property', 'value')
// returns the string value of the property
const char* object = 0;
const char* property = 0;
const char* value = 0;
if(!PyArg_ParseTuple(args, const_cast<char*>("ss"), &object,
&property, &value))
{
return NULL;
}
PropertyObject = object;
PropertyResult = property;
PropertyValue = value;
if(Instance && QThread::currentThread() != QApplication::instance()->thread())
{
QMutex mut;
mut.lock();
QMetaObject::invokeMethod(Instance, "threadSetProperty", Qt::QueuedConnection);
WaitResults.wait(&mut);
}
else if(QThread::currentThread() == QApplication::instance()->thread())
{
pqPythonEventSource::setProperty(PropertyObject,
PropertyResult,
PropertyValue);
}
else
{
PyErr_SetString(PyExc_AssertionError, "pqPythonEventSource not defined");
return NULL;
}
if(PropertyObject == QString::null)
{
PyErr_SetString(PyExc_ValueError, "object not found");
return NULL;
}
if(PropertyResult == QString::null)
{
PyErr_SetString(PyExc_ValueError, "property not found");
return NULL;
}
return Py_BuildValue(const_cast<char*>("s"), "");
}
static PyObject*
QtTesting_wait(PyObject* /*self*/, PyObject* args)
{
......@@ -226,6 +281,13 @@ static PyMethodDef QtTestingMethods[] = {
METH_VARARGS,
const_cast<char*>("Get a property of an object.")
},
{
const_cast<char*>("setProperty"),
QtTesting_setProperty,
METH_VARARGS,
const_cast<char*>("Set a property of an object.")
},
{
const_cast<char*>("getQtVersion"),
QtTesting_getQtVersion,
......@@ -308,12 +370,42 @@ QString pqPythonEventSource::getProperty(QString& object, const QString& prop)
}
void pqPythonEventSource::threadGetProperty()
{
PropertyResult = this->getProperty(PropertyObject, PropertyResult);
WaitResults.wakeAll();
}
void pqPythonEventSource::setProperty(QString& object, QString& prop,
const QString& value)
{
// ensure other tasks have been completed
QCoreApplication::processEvents();
QVariant ret;
QObject* qobject = pqObjectNaming::GetObject(object);
if(!qobject)
{
object = QString::null;
}
else
{
if(!qobject->setProperty(prop.toAscii().data(), value))
{
prop = QString::null;
}
}
}
void pqPythonEventSource::threadSetProperty()
{
this->setProperty(PropertyObject, PropertyResult, PropertyValue);
WaitResults.wakeAll();
}
QStringList pqPythonEventSource::getChildren(QString& object)
{
// ensure other tasks have been completed
......
......@@ -50,6 +50,7 @@ public:
void setContent(const QString& path);
static QString getProperty(QString& object, const QString& prop);
static void setProperty(QString& object, QString& prop, const QString& value);
static QStringList getChildren(QString& object);
protected:
......@@ -57,6 +58,7 @@ protected:
protected slots:
void threadGetProperty();
void threadSetProperty();
void threadGetChildren();
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment