Hi

I found a solution, even if its not exactly obvious.

In the main loop of my script, I do

        progress.percent = count/total
        dt.gui.selection()
        if cancelled then break end

That does it.

The darktable.gui.selection function is marked as implicit_yield so it gives the gui a chance to update, so the progress bar ticks along and if you click the cancel job button, the variable cancelled is true afterwards, and the loop breaks.

I've tried quite a few other things.

I tried using

        coroutine.yield('WAIT_MS', 10)

to put in a delay and leave time for the gui to run, but it gives me a run time error:

        LUA ERROR : attempt to yield across a C-call boundary

I haven't quite understood why.

I tried with the undocumented

        dt.control.sleep(10)

and nothing. If I increase the delay to 1000ms the progress bar updates, but of course the script is very very slow that way.

I tried to open a file that's always readable, like /dev/zero, and use

        dt.control.read(file)

but that did nothing either.

Going through the documentation systematically, I found dt.gui.selection() which implicitly yields and that does the trick.

Its totally not obvious but it works.

René


On 2017-01-30 14:02, Christian Kanzian wrote:
Hi,

I'm not familar with programming and it is often hard for me to
distinguish between LUA core functions and darkable LUA API. You have to
look at LUA docs as well [0].

Am 2017-01-30 12:34, schrieb René Seindal:
On 2017-01-30 12:28, Tobias Ellinghaus wrote:
Am Montag, 30. Januar 2017, 12:04:03 CET schrieb René Seindal:
Hi

[...]

I have put in a progress bar (background job) but the progress bar
doesn't update and the cancel button doesn't work, because I can't
find a way to hand off control to the gui to update, while looping
through the images, looking stuff up in the other sqlite3 database.

From your script
progress.percent = total / count

The API [1] says the value should be between 0 and 1. So I think this
should look like:
progress.percent = count / total

I think it is not enough to break the loop. Also you need to set the
job.valid to false to cancel it, like the script which Tobias mentioned.

Christian

[0] https://www.lua.org/manual/5.3/
[1] https://www.darktable.org/lua-api/ar01s02s30.html.php


--
René Seindal - [email protected]
____________________________________________________________________________
darktable user mailing list
to unsubscribe send a mail to [email protected]

Reply via email to