Open estan opened 8 years ago
Yeah, we can probably do this by making it possible to wrap JS callables as arguments to Python (and vice versa might also make sense), so that we don't need to change the signature of call()
and one could even pass multiple callables as argument for different situations.
Probably not going to have time to implement this in the near future, but feel free to send a pull request or send an e-mail if you actually need this for your commercial project.
I actually began making a patch, but got distracted with some other things. I'll let you know if I dig into it again. At least the wish is here now :) And yea, to make it generally possible to pass callables as args like you say makes much more sense.
Haven't had time to do anything on this yet, but just a question: The docs describe how you can pass QObjects to the Python side and call methods on them from there:
http://pyotherside.readthedocs.org/en/latest/#accessing-qobjects-from-python
Could I perhaps use this mechanism as a "progress callback" for now? I mean, pass in a QObject (QtObject {...}
in QML) and call a progress(int)
method on it to report back progress to the QML side?
Yes, that should work.
When working with several concurrent calls to long-running Python functions it would be very convenient if the
call
API was something like:Where the
on_progress
is a callable that, when provided, would would be made available as anon_progress
kwarg on the Python side.So for example, with a
mymodule.py
:and the call from QML:
which should output:
I know this functionality can be built on top of the existing
send
mechanism, but having it built in like this would save me from a lot of bookkeeping on the QML side to associate sent progress with the corresponding outstanding call.Thanks a lot for
pyotherside
BTW. It looks very promising, and I'm fairly certain that we'll use it for the UI on our product, which is a machine for mineral analysis to be used in the mining industry.