Revert "Change group leader"

This commit is contained in:
wpferguson
2024-01-14 22:13:38 -05:00
committed by GitHub
parent 4b99d00ab5
commit 8bfab0325b

View File

@@ -1,158 +1,201 @@
--[[ --[[
change group leader
change_group_leader.lua - change image grouip leader copyright (c) 2020, 2022 Bill Ferguson <wpferguson@gmail.com>
copyright (c) 2021 Angel Angelov
Copyright (C) 2024 Bill Ferguson <wpferguson@gmail.com> 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.
This program is free software: you can redistribute it and/or modify darktable is distributed in the hope that it will be useful,
it under the terms of the GNU General Public License as published by but WITHOUT ANY WARRANTY; without even the implied warranty of
the Free Software Foundation; either version 3 of the License, or MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(at your option) any later version. GNU General Public License for more details.
This program is distributed in the hope that it will be useful, You should have received a copy of the GNU General Public License
but WITHOUT ANY WARRANTY; without even the implied warranty of along with darktable. If not, see <http://www.gnu.org/licenses/>.
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 this program. If not, see <http://www.gnu.org/licenses/>.
]] ]]
--[[ --[[
change_group_leader - change image grouip leader CHANGE GROUP LEADER
automatically change the leader of raw+jpg paired image groups
change_group_leader changes the group leader to the next INSTALLATION
image in the group. If the end of the group is reached * copy this file in $CONFIGDIR/lua/ where CONFIGDIR is your darktable configuration directory
then the next image is wrapped around to the first image. * add the following line in the file $CONFIGDIR/luarc
require "change_group_leader"
ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT USAGE
None * in lighttable mode, select the image groups you wish to process,
select whether you want to set the leader to "jpg" or "raw",
USAGE and click "Execute"
* enable with script_manager
* assign a key to the shortcut
BUGS, COMMENTS, SUGGESTIONS
Bill Ferguson <wpferguson@gmail.com>
CHANGES
]] ]]
local dt = require "darktable" local dt = require "darktable"
local du = require "lib/dtutils" local du = require "lib/dtutils"
local df = require "lib/dtutils.file"
-- - - - - - - - - - - - - - - - - - - - - - - - local gettext = dt.gettext
-- C O N S T A N T S
-- - - - - - - - - - - - - - - - - - - - - - - -
local MODULE = "change_group_leader" local MODULE = "change_group_leader"
-- - - - - - - - - - - - - - - - - - - - - - - - du.check_min_api_version("3.0.0", MODULE)
-- A P I C H E C K
-- - - - - - - - - - - - - - - - - - - - - - - -
du.check_min_api_version("7.0.0", MODULE) -- return data structure for script_manager
-- - - - - - - - - - - - - - - - - - - - - - - - - -
-- S C R I P T M A N A G E R I N T E G R A T I O N
-- - - - - - - - - - - - - - - - - - - - - - - - - -
local script_data = {} local script_data = {}
script_data.destroy = nil -- function to destory the script script_data.destroy = nil -- function to destory the script
script_data.destroy_method = nil -- set to hide for libs since we can't destroy them commpletely yet script_data.destroy_method = nil -- set to hide for libs since we can't destroy them commpletely yet, otherwise leave as nil
script_data.restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again script_data.restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again
script_data.show = nil -- only required for libs since the destroy_method only hides them script_data.show = nil -- only required for libs since the destroy_method only hides them
-- - - - - - - - - - - - - - - - - - - - - - - - - -
-- I 1 8 N
-- - - - - - - - - - - - - - - - - - - - - - - - - -
local gettext = dt.gettext
-- Tell gettext where to find the .mo file translating messages for a particular domain -- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain(MODULE, dt.configuration.config_dir .. "/lua/locale/") gettext.bindtextdomain(MODULE, dt.configuration.config_dir.."/lua/locale/")
local function _(msgid) local function _(msgid)
return gettext.dgettext(MODULE, msgid) return gettext.dgettext(MODULE, msgid)
end end
-- - - - - - - - - - - - - - - - - - - - - - - - -- 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 -- F U N C T I O N S
-- - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - -
local function toggle_global_toolbox_grouping() local function install_module()
dt.gui.libs.global_toolbox.grouping = false if not cgl.module_installed then
dt.gui.libs.global_toolbox.grouping = true 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 end
local function hinter_msg(msg) local function find_group_leader(images, mode)
dt.print_hinter(msg) for _, img in ipairs(images) do
dt.control.sleep(1500) dt.print_log("checking image " .. img.id .. " named " .. img.filename)
dt.print_hinter(" ") local found = false
end if mode == "jpg" then
if string.match(string.lower(img.filename), "jpg$") then
-- - - - - - - - - - - - - - - - - - - - - - - - dt.print_log("jpg matched image " .. img.filename)
-- M A I N P R O G R A M found = true
-- - - - - - - - - - - - - - - - - - - - - - - - end
elseif mode == "raw" then
local function change_group_leader(image) if img.is_raw and img.duplicate_index == 0 then
local group_images = image:get_group_members() dt.print_log("found raw " .. img.filename)
if #group_images < 2 then found = true
hinter_msg(_("No images to change to in group")) end
return elseif mode == "non-raw" then
else if img.is_ldr then
local position = nil dt.print_log("found ldr " .. img.filename)
for i, img in ipairs(group_images) do found = true
if image == img then
position = i
end end
end
if position == #group_images then
position = 1
else else
position = position + 1 dt.print_error(MODULE .. ": unrecognized mode " .. mode)
return
end end
if found then
new_leader = group_images[position] dt.print_log("making " .. img.filename .. " group leader")
new_leader:make_group_leader() img:make_group_leader()
dt.gui.selection({new_leader}) return
if dt.gui.libs.global_toolbox.grouping then
-- toggle the grouping to make the new leader show
toggle_global_toolbox_grouping()
end end
end end
end end
-- - - - - - - - - - - - - - - - - - - - - - - - local function process_image_groups(images)
-- D A R K T A B L E I N T E G R A T I O N 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
-- - - - - - - - - - - - - - - - - - - - - - - -
-- S C R I P T M A N A G E R I N T E G R A T I O N
-- - - - - - - - - - - - - - - - - - - - - - - -
local function destroy() local function destroy()
-- put things to destroy (events, storages, etc) here dt.gui.libs[MODULE].visible = false
dt.destroy_event(MODULE, "shortcut") end
local function restart()
dt.gui.libs[MODULE].visible = true
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 end
script_data.destroy = destroy script_data.destroy = destroy
script_data.restart = restart
-- - - - - - - - - - - - - - - - - - - - - - - - script_data.destroy_method = "hide"
-- E V E N T S script_data.show = restart
-- - - - - - - - - - - - - - - - - - - - - - - -
dt.register_event(MODULE, "shortcut",
function(event, shortcut)
-- ignore the film roll, it contains all the images, not just the imported
local images = dt.gui.selection()
if #images < 1 then
dt.print(_("No image selected. Please select an image and try again"))
else
change_group_leader(images[1])
end
end,
_("Change group leader")
)
return script_data return script_data