aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--PySide/QtScript/typesystem_script.xml13
-rw-r--r--tests/QtScript/CMakeLists.txt1
-rw-r--r--tests/QtScript/qscriptvalue_test.py20
3 files changed, 34 insertions, 0 deletions
diff --git a/PySide/QtScript/typesystem_script.xml b/PySide/QtScript/typesystem_script.xml
index 870aec089..8c7ac10b2 100644
--- a/PySide/QtScript/typesystem_script.xml
+++ b/PySide/QtScript/typesystem_script.xml
@@ -49,6 +49,19 @@
<enum-type name="PropertyFlag" flags="PropertyFlags"/>
<enum-type name="ResolveFlag" flags="ResolveFlags"/>
<enum-type name="SpecialValue"/>
+ <add-function signature="__mgetitem__">
+ <inject-code>
+ Shiboken::AutoDecRef key(PyObject_Str(_key));
+ QVariant res = %CPPSELF.property(PyString_AS_STRING(key.object())).toVariant();
+ if (res.isValid()) {
+ return %CONVERTTOPYTHON[QVariant](res);
+ } else {
+ PyObject* errorType = PyInt_Check(_key) ? PyExc_IndexError : PyExc_KeyError;
+ PyErr_SetString(errorType, "Key not found.");
+ return 0;
+ }
+ </inject-code>
+ </add-function>
</value-type>
<object-type name="QScriptValueIterator"/>
</typesystem>
diff --git a/tests/QtScript/CMakeLists.txt b/tests/QtScript/CMakeLists.txt
index 41fc2c444..a3c7c7ded 100644
--- a/tests/QtScript/CMakeLists.txt
+++ b/tests/QtScript/CMakeLists.txt
@@ -1,3 +1,4 @@
PYSIDE_TEST(base_test.py)
PYSIDE_TEST(engine_test.py)
PYSIDE_TEST(property_test.py)
+PYSIDE_TEST(qscriptvalue_test.py)
diff --git a/tests/QtScript/qscriptvalue_test.py b/tests/QtScript/qscriptvalue_test.py
new file mode 100644
index 000000000..3a03e96e2
--- /dev/null
+++ b/tests/QtScript/qscriptvalue_test.py
@@ -0,0 +1,20 @@
+import unittest
+from PySide.QtCore import *
+from PySide.QtScript import *
+
+class TestQScriptValue (unittest.TestCase):
+
+ def testOperator(self):
+ app = QCoreApplication([])
+
+ engine = QScriptEngine()
+ value = engine.evaluate('x = {"a": 1, "b":2}')
+ self.assertEqual(value['a'], 1)
+ self.assertRaises(KeyError, value.__getitem__, 'c')
+ value = engine.evaluate('x = ["x", "y", "z"]')
+ self.assertEqual(value[2], 'z')
+ self.assertRaises(IndexError, value.__getitem__, 23)
+
+
+if __name__ == '__main__':
+ unittest.main()