1
0
mirror of https://github.com/thp/pyotherside.git synced 2025-01-28 23:52:55 +08:00
pyotherside/tests/test_wrapped/test_wrapped.qml
Thomas Perl 5863efcfe9 Simplify API (remove callMethod again, merge into call)
callMethod(o, attr, ...) is just a special case of:
call(getattr(o, attr), ...)

Starting with import version 1.4, call() now accepts a
Python callable as alternative to the function name.
2014-10-08 15:13:54 +02:00

40 lines
1.1 KiB
QML

import QtQuick 2.0
import io.thp.pyotherside 1.4
Rectangle {
id: page
width: 300
height: 300
Python {
Component.onCompleted: {
addImportPath(Qt.resolvedUrl('.'));
importModule('test_wrapped', function () {
console.log('"test_wrapped" imported successfully');
var foo = call_sync('test_wrapped.get_foo', []);
console.log('got foo: ' + foo);
console.log('attribute bar of foo: ' + getattr(foo, 'bar'));
var func = getattr(foo, 'methodman');
call(func, ['the pain'], function (result) {
console.log('methodman() result: ' + result);
});
var mmr = call_sync(func, ['the pain']);
console.log('methodman() sync result: ' + mmr);
var result = call_sync('test_wrapped.set_foo', [foo]);
console.log('got result: ' + result);
});
}
onError: {
console.log('Received error: ' + traceback);
}
}
}