Skip to content

Commit 5094d9e

Browse files
authored
add 'delete thumbnails' button to create_thumbnails.lua
1 parent 1a5f765 commit 5094d9e

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

contrib/create_thumbnails.lua

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ Create thumbnails plugin for darktable
1616
]]
1717

1818
--[[About this Plugin
19-
This plugin adds the button 'create thumbnails' to 'selected image[s]' module of darktable's lighttable view.
19+
This plugin adds the buttons 'create thumbnails' and 'delete thumbnails' to 'selected image[s]' module of darktable's lighttable view.
2020
2121
2222
----USAGE----
2323
Click the 'create thumbnails' button in the 'selected image[s]' module to let the script create full sized previews of all selected images.
24+
Click the 'delete thumbnails' button in the 'selected image[s]' module to let the script delete all previews/thumbnails of all selected images.
2425
25-
To create previews of all images of a collection:
26-
Use CTRL+A to select all images of current collection and then press the button.
26+
To create (or delete) previews of all images of a collection:
27+
Use CTRL+A to select all images of current collection and then press the corresponding button.
2728
]]
2829

2930
local dt = require "darktable"
@@ -86,9 +87,49 @@ dt.gui.libs.image.register_action(
8687
"create full sized previews of all selected images"
8788
)
8889

90+
91+
-- add button to 'selected images' module
92+
dt.gui.libs.image.register_action(
93+
"delete_thumbnails_button",
94+
"delete thumbnails",
95+
function(event, images)
96+
print_and_log("deleting thumbnails of " .. image_count_to_text(#images) .. " ...")
97+
98+
-- create a new progress_bar displayed in darktable.gui.libs.backgroundjobs
99+
job = dt.gui.create_job("deleting thumbnails...", true, stop_job)
100+
101+
for i, image in pairs(images) do
102+
-- delete all thumbnails
103+
image:drop_cache()
104+
105+
-- update progress_bar
106+
job.percent = i / #images
107+
108+
-- sleep for a short moment to give stop_job callback function a chance to run
109+
dt.control.sleep(10)
110+
111+
-- stop early if darktable is shutdown or the cancle button of the progress bar is pressed
112+
if dt.control.ending or not job.valid then
113+
print_and_log("deleting thumbnails canceled after processing " .. i .. "/" .. image_count_to_text(#images) .. "!")
114+
break
115+
end
116+
end
117+
118+
-- if job was not canceled
119+
if(job.valid) then
120+
-- stop job and remove progress_bar from ui
121+
job.valid = false
122+
123+
print_and_log("deleting thumbnails of " .. image_count_to_text(#images) .. " done!")
124+
end
125+
end,
126+
"delete all thumbnails of all selected images"
127+
)
128+
89129
-- clean up function that is called when this module is getting disabled
90130
local function destroy()
91131
dt.gui.libs.image.destroy_action("create_thumbnails_button")
132+
dt.gui.libs.image.destroy_action("delete_thumbnails_button")
92133
end
93134

94135

0 commit comments

Comments
 (0)