Debian Codegraph @

examples/helloworld.qml

raw
1 import QtQuick 2.0
2 import io.thp.pyotherside 1.4
3
4 Rectangle {
5 width: 200
6 height: 200
7 color: 'blue'
8
9 ListView {
10 id: listView
11 anchors.fill: parent
12 delegate: Text { color: 'white'; text: modelData }
13 }
14
15 Python {
16 id: python
17
18 Component.onCompleted: {
19 // Print version of plugin and Python interpreter
20 console.log('PyOtherSide version: ' + pluginVersion());
21 console.log('Python version: ' + pythonVersion());
22
23 // Asynchronous module importing
24 importModule('os', function() {
25 console.log('Python module "os" is now imported');
26
27 // Asynchronous function calls
28 call('os.listdir', [], function(result) {
29 console.log('dir listing: ' + result);
30 listView.model = result;
31 });
32
33 // Synchronous calls - avoid these, they block the UI
34 call_sync('os.chdir', ['/']);
35 console.log('files in /: ' + call_sync('os.listdir', ['.']));
36 });
37
38 // sychronous imports and calls - again, avoid!
39 importModule_sync('pyotherside');
40 call_sync('pyotherside.send', ['hello world!', 123]);
41
42 // error handling
43 importModule_sync('thismoduledoesnotexisthopefully');
44 evaluate('[ 123 [.syntax234-error!');
45 }
46
47 onError: {
48 // when an exception is raised, this error handler will be called
49 console.log('python error: ' + traceback);
50 }
51
52 onReceived: {
53 // asychronous messages from Python arrive here
54 // in Python, this can be accomplished via pyotherside.send()
55 console.log('got message from python: ' + data);
56 }
57 }
58 }