Search

Items tagged with: pyotherside

CSX 6400
9 years ago from Diaspora

Really strange behavior QML/PyOtherSide/Python



I don't know where to put this really so I thought I'd share it here.

I'm rewriting my #scalefish app to a python version (so no update yet unfortunately) when I noticed this strange behavior. I have this python code in a file named random.py:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pyotherside

def ran_func():
return "Hello World!"

So far so good ... Then in the QML file in the same folder i have this:
import QtQuick 2.0
import Sailfish.Silica 1.0
import io.thp.pyotherside 1.4

Page {
id: page
TextArea {
}
Python {
id: python
Component.onCompleted: {
addImportPath(Qt.resolvedUrl('.'));
importModule('random', function() {});
}
function ran_func() {
return call_sync('random.ran_func', []);
}
}
Component.onCompleted: {
console.log(python.ran_func())
}
}
// Notice the empty TextArea

Nothing suspicious I'd say. When the Component page has instantiated it should log Hello World! to the console. And indeed, running this gives the result:
[D]onCompleted:42 - Hello World!

But now it gets strange. When I removed the (property-less) TextArea, it throws an Error:
[D]QPythonPriv::formatExc:612 - "PyOtherSide error: Traceback (most recent call last):

File "<string>", line 1, in <module>

NameError: name 'random' is not defined
"
[W]QPython::emitError:380 - Unhandled PyOtherSide error: Function not found: 'random.ran_func' (Traceback (most recent call last):

File "<string>", line 1, in <module>

NameError: name 'random' is not defined
)
[D]onCompleted:53 - undefined

And I don't understand why. Even stranger is the fact it will only run correctly when you use the TextArea object. Replace it with e.g. Button, or Rectangle it won't succeed and gives the same error. Anyone an idea?

#qml #pyotherside #python #sailfishos #jolla #linux
newer older