|
| 1 | +--[[ |
| 2 | +Create thumbnails plugin for darktable |
| 3 | +
|
| 4 | + darktable is free software: you can redistribute it and/or modify |
| 5 | + it under the terms of the GNU General Public License as published by |
| 6 | + the Free Software Foundation, either version 3 of the License, or |
| 7 | + (at your option) any later version. |
| 8 | + |
| 9 | + darktable is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + GNU General Public License for more details. |
| 13 | + |
| 14 | + You should have received a copy of the GNU General Public License |
| 15 | + along with darktable. If not, see <http://www.gnu.org/licenses/>. |
| 16 | +]] |
| 17 | + |
| 18 | +--[[About this Plugin |
| 19 | +This plugin adds the button 'create thumbnails' to 'selected iamge[s]' module of darktable's lighttable view |
| 20 | +
|
| 21 | +
|
| 22 | +----USAGE---- |
| 23 | +Click the 'create thumbnails' button to let the script create full sized previews of all selected images. |
| 24 | +
|
| 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. |
| 27 | +]] |
| 28 | + |
| 29 | +local dt = require "darktable" |
| 30 | +local du = require "lib/dtutils" |
| 31 | + |
| 32 | +du.check_min_api_version("8.0.0", "create_thumbnails_button") |
| 33 | + |
| 34 | +-- stop running thumbnail creation |
| 35 | +local function stop_job(job) |
| 36 | + job.valid = false |
| 37 | +end |
| 38 | + |
| 39 | +-- add button to 'selected images' module |
| 40 | +dt.gui.libs.image.register_action( |
| 41 | + "create_thumbnails_button", |
| 42 | + "create thumbnails", |
| 43 | + function(event, images) |
| 44 | + dt.print_log("creating thumbnails for " .. #images .. " images...") |
| 45 | + |
| 46 | + -- create a new progress_bar displayed in darktable.gui.libs.backgroundjobs |
| 47 | + job = dt.gui.create_job("creating thumbnails...", true, stop_job) |
| 48 | + |
| 49 | + for i, image in pairs(images) do |
| 50 | + -- generate all thumbnails, a max value of 8 means that also a full size preview image is created |
| 51 | + image:generate_cache(true, 0, 8) |
| 52 | + |
| 53 | + -- update progress_bar |
| 54 | + job.percent = i / #images |
| 55 | + |
| 56 | + -- sleep for a short moment to give stop_job callback function a chance to run |
| 57 | + dt.control.sleep(10) |
| 58 | + |
| 59 | + -- stop early if darktable is shutdown or the cancle button of the progress bar is pressed |
| 60 | + if dt.control.ending or not job.valid then |
| 61 | + dt.print_log("creating thumbnails canceled!") |
| 62 | + break |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + dt.print_log("create thumbnails done!") |
| 67 | + |
| 68 | + -- stop job and remove progress_bar from ui, but only if not alreay canceled |
| 69 | + if(job.valid) then |
| 70 | + job.valid = false |
| 71 | + end |
| 72 | + end, |
| 73 | + "create full sized previews of all selected images" |
| 74 | +) |
| 75 | + |
| 76 | +-- clean up function that is called when this module is getting disabled |
| 77 | +local function destroy() |
| 78 | + dt.gui.libs.image.destroy_action("create_thumbnails_button") |
| 79 | +end |
| 80 | + |
| 81 | + |
| 82 | +local script_data = {} |
| 83 | +script_data.destroy = destroy -- function to destory the script |
| 84 | +script_data.destroy_method = nil -- set to hide for libs since we can't destroy them commpletely yet |
| 85 | +script_data.restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again |
| 86 | +return script_data |
0 commit comments