From 4648c2d9af5e83a157a6f1c663963a0cf09b43a8 Mon Sep 17 00:00:00 2001 From: dexterlb Date: Sun, 9 Oct 2022 11:54:02 +0300 Subject: [PATCH 1/4] add change_group_leader script --- contrib/change_group_leader.lua | 130 ++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 contrib/change_group_leader.lua diff --git a/contrib/change_group_leader.lua b/contrib/change_group_leader.lua new file mode 100644 index 0000000..a1a842a --- /dev/null +++ b/contrib/change_group_leader.lua @@ -0,0 +1,130 @@ +local dt = require "darktable" +local du = require "lib/dtutils" +local debug = require "darktable.debug" + +local MODULE = "change_group_leader" + +du.check_min_api_version("3.0.0", MODULE) + +-- create a namespace to contain persistent data and widgets +chg_grp_ldr = {} + +local cgl = chg_grp_ldr + +cgl.widgets = {} + +cgl.event_registered = false +cgl.module_installed = false + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- F U N C T I O N S +-- - - - - - - - - - - - - - - - - - - - - - - - + +local function install_module() + if not cgl.module_installed then + dt.register_lib( + MODULE, -- Module name + "change_group_leader", -- Visible name + true, -- expandable + false, -- resetable + {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 700}}, -- containers + cgl.widgets.box, + nil,-- view_enter + nil -- view_leave + ) + cgl.module_installed = true + end +end + +local function find_group_leader(images, mode) + for _, img in ipairs(images) do + dt.print_log("checking image " .. img.id .. " named " .. img.filename) + local found = false + if mode == "jpg" then + if string.match(string.lower(img.filename), "jpg$") then + dt.print_log("jpg matched image " .. img.filename) + found = true + end + elseif mode == "raw" then + if img.is_raw and img.duplicate_index == 0 then + dt.print_log("found raw " .. img.filename) + found = true + end + elseif mode == "non-raw" then + if img.is_ldr then + dt.print_log("found ldr " .. img.filename) + found = true + end + else + dt.print_error(MODULE .. ": unrecognized mode " .. mode) + return + end + if found then + dt.print_log("making " .. img.filename .. " group leader") + img:make_group_leader() + return + end + end +end + +local function process_image_groups(images) + if #images < 1 then + dt.print("No images selected.") + dt.print_log(MODULE .. "no images seletected, returning...") + else + local mode = cgl.widgets.mode.value + for _,img in ipairs(images) do + dt.print_log("checking image " .. img.id) + local group_images = img:get_group_members() + if group_images == 1 then + dt.print_log("only one image in group for image " .. image.id) + else + find_group_leader(group_images, mode) + end + end + end +end + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- W I D G E T S +-- - - - - - - - - - - - - - - - - - - - - - - - + +cgl.widgets.mode = dt.new_widget("combobox"){ + label = "select new group leader", + tooltip = "select type of image to be group leader", + selected = 1, + "jpg", "raw", "non-raw", +} + +cgl.widgets.execute = dt.new_widget("button"){ + label = "Execute", + clicked_callback = function() + process_image_groups(dt.gui.action_images) + end +} + +cgl.widgets.box = dt.new_widget("box"){ + orientation = "vertical", + cgl.widgets.mode, + cgl.widgets.execute, +} + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- D A R K T A B L E I N T E G R A T I O N +-- - - - - - - - - - - - - - - - - - - - - - - - + +if dt.gui.current_view().id == "lighttable" then + install_module() +else + if not cgl.event_registered then + dt.register_event( + "view-changed", + function(event, old_view, new_view) + if new_view.name == "lighttable" and old_view.name == "darkroom" then + install_module() + end + end + ) + cgl.event_registered = true + end +end From 803537c63e328b0eb088b04e8754f729dc6f27dc Mon Sep 17 00:00:00 2001 From: dexterlb Date: Sun, 9 Oct 2022 12:00:29 +0300 Subject: [PATCH 2/4] add comments to change_group_leader --- contrib/change_group_leader.lua | 52 ++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/contrib/change_group_leader.lua b/contrib/change_group_leader.lua index a1a842a..1dedd00 100644 --- a/contrib/change_group_leader.lua +++ b/contrib/change_group_leader.lua @@ -1,3 +1,41 @@ +--[[ + Passport cropping guide for darktable + + copyright (c) 2021 Angel Angelov + + darktable is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + darktable is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with darktable. If not, see . +]] + +--[[ + Original author: github.com/wpferguson +]] + +--[[ +CHANGE GROUP LEADER +automatically change the leader of raw+jpg paired image groups + +INSTALLATION +* copy this file in $CONFIGDIR/lua/ where CONFIGDIR is your darktable configuration directory +* add the following line in the file $CONFIGDIR/luarc + require "change_group_leader" + +USAGE +* in lighttable mode, select the image groups you wish to process, + select whether you want to set the leader to "jpg" or "raw", + and click "Execute" +]] + local dt = require "darktable" local du = require "lib/dtutils" local debug = require "darktable.debug" @@ -16,9 +54,9 @@ cgl.widgets = {} cgl.event_registered = false cgl.module_installed = false --- - - - - - - - - - - - - - - - - - - - - - - - +-- - - - - - - - - - - - - - - - - - - - - - - - -- F U N C T I O N S --- - - - - - - - - - - - - - - - - - - - - - - - +-- - - - - - - - - - - - - - - - - - - - - - - - local function install_module() if not cgl.module_installed then @@ -85,9 +123,9 @@ local function process_image_groups(images) end end --- - - - - - - - - - - - - - - - - - - - - - - - +-- - - - - - - - - - - - - - - - - - - - - - - - -- W I D G E T S --- - - - - - - - - - - - - - - - - - - - - - - - +-- - - - - - - - - - - - - - - - - - - - - - - - cgl.widgets.mode = dt.new_widget("combobox"){ label = "select new group leader", @@ -109,9 +147,9 @@ cgl.widgets.box = dt.new_widget("box"){ cgl.widgets.execute, } --- - - - - - - - - - - - - - - - - - - - - - - - --- D A R K T A B L E I N T E G R A T I O N --- - - - - - - - - - - - - - - - - - - - - - - - +-- - - - - - - - - - - - - - - - - - - - - - - - +-- D A R K T A B L E I N T E G R A T I O N +-- - - - - - - - - - - - - - - - - - - - - - - - if dt.gui.current_view().id == "lighttable" then install_module() From 652606ffb04bf8e63e66aa8d890405b61d9d1879 Mon Sep 17 00:00:00 2001 From: dexterlb Date: Mon, 10 Oct 2022 21:38:30 +0300 Subject: [PATCH 3/4] fix copyright message --- contrib/change_group_leader.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/contrib/change_group_leader.lua b/contrib/change_group_leader.lua index 1dedd00..9d2012a 100644 --- a/contrib/change_group_leader.lua +++ b/contrib/change_group_leader.lua @@ -1,7 +1,7 @@ --[[ Passport cropping guide for darktable - copyright (c) 2021 Angel Angelov + copyright (c) 2022 Bill Ferguson darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,10 +17,6 @@ along with darktable. If not, see . ]] ---[[ - Original author: github.com/wpferguson -]] - --[[ CHANGE GROUP LEADER automatically change the leader of raw+jpg paired image groups From 572a634d90f8b567c07b15c101c835dece5f3f74 Mon Sep 17 00:00:00 2001 From: dexterlb Date: Mon, 10 Oct 2022 21:39:38 +0300 Subject: [PATCH 4/4] fix title --- contrib/change_group_leader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/change_group_leader.lua b/contrib/change_group_leader.lua index 9d2012a..c4eb3f6 100644 --- a/contrib/change_group_leader.lua +++ b/contrib/change_group_leader.lua @@ -1,5 +1,5 @@ --[[ - Passport cropping guide for darktable + change group leader copyright (c) 2022 Bill Ferguson