Skip to content

Commit 1a5f765

Browse files
authored
improve logging and user feedback of create_thumbnails.lua
1 parent eb30836 commit 1a5f765

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

contrib/create_thumbnails.lua

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,30 @@ local function stop_job(job)
3636
job.valid = false
3737
end
3838

39+
-- return "1 image" if amount_of_images is 1 else "<amount_of_images> images"
40+
local function image_count_to_text(amount_of_images)
41+
return amount_of_images .. " image" .. (amount_of_images == 1 and "" or "s")
42+
end
43+
44+
-- print the given message to the user and log the given message
45+
local function print_and_log(message)
46+
dt.print(message)
47+
dt.print_log(message)
48+
end
49+
3950
-- add button to 'selected images' module
4051
dt.gui.libs.image.register_action(
4152
"create_thumbnails_button",
4253
"create thumbnails",
4354
function(event, images)
44-
dt.print_log("creating thumbnails for " .. #images .. " images...")
55+
print_and_log("creating thumbnails for " .. image_count_to_text(#images) .. " ...")
4556

4657
-- create a new progress_bar displayed in darktable.gui.libs.backgroundjobs
4758
job = dt.gui.create_job("creating thumbnails...", true, stop_job)
4859

4960
for i, image in pairs(images) do
5061
-- generate all thumbnails, a max value of 8 means that also a full size preview image is created
51-
-- check if the mipmap cache directories exist only once
62+
-- check only once if the mipmap cache directories exist
5263
image:generate_cache(i == 1, 0, 8)
5364

5465
-- update progress_bar
@@ -59,16 +70,17 @@ dt.gui.libs.image.register_action(
5970

6071
-- stop early if darktable is shutdown or the cancle button of the progress bar is pressed
6172
if dt.control.ending or not job.valid then
62-
dt.print_log("creating thumbnails canceled!")
73+
print_and_log("creating thumbnails canceled after processing " .. i .. "/" .. image_count_to_text(#images) .. "!")
6374
break
6475
end
6576
end
6677

67-
dt.print_log("create thumbnails done!")
68-
69-
-- stop job and remove progress_bar from ui, but only if not alreay canceled
78+
-- if job was not canceled
7079
if(job.valid) then
80+
-- stop job and remove progress_bar from ui
7181
job.valid = false
82+
83+
print_and_log("creating thumbnails for " .. image_count_to_text(#images) .. " done!")
7284
end
7385
end,
7486
"create full sized previews of all selected images"

0 commit comments

Comments
 (0)