From 1907f9a1f5ec876edc2edb1e1643487a5a5c063c Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Tue, 24 Mar 2026 22:57:45 -0400 Subject: [PATCH 1/5] official/toggle_group_view - added a script to view a group as a collection when toggled from lighttable --- official/toggle_group_view.lua | 206 +++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 official/toggle_group_view.lua diff --git a/official/toggle_group_view.lua b/official/toggle_group_view.lua new file mode 100644 index 00000000..476c2929 --- /dev/null +++ b/official/toggle_group_view.lua @@ -0,0 +1,206 @@ +--[[ + + toggle_group_view.lua - toggle only group visible in lighttable + + Copyright (C) 2024 Bill Ferguson . + + This program 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 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 this program. If not, see . +]] +--[[ + toggle_group_view - toggle only group visible in lighttable + + toggle_group_view provides a way to "separate" a group from + the lighttable display and limit the display to just the group. + Pressing the shortcut again returns to the full lighttable view. + + ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT + None + + USAGE + * place the script in your lua scripts folder + * start the script with script manager + * assign a key sequence to the shortcut + + BUGS, COMMENTS, SUGGESTIONS + Bill Ferguson + + CHANGES +]] + +local dt = require "darktable" +local du = require "lib/dtutils" +local log = require "lib/dtutils.log" + + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- C O N S T A N T S +-- - - - - - - - - - - - - - - - - - - - - - - - + +local MODULE = "toggle_group_view" +local DEFAULT_LOG_LEVEL = log.error +local TMP_DIR = dt.configuration.tmp_dir + +-- path separator +local PS = dt.configuration.running_os == "windows" and "\\" or "/" + +-- command separator +local CS = dt.configuration.running_os == "windows" and "&" or ";" + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- A P I C H E C K +-- - - - - - - - - - - - - - - - - - - - - - - - + +du.check_min_api_version("7.0.0", MODULE) -- choose the minimum version that contains the features you need + + +-- - - - - - - - - - - - - - - - - - - - - - - - - - +-- I 1 8 N +-- - - - - - - - - - - - - - - - - - - - - - - - - - + +local gettext = dt.gettext.gettext + +dt.gettext.bindtextdomain(MODULE , dt.configuration.config_dir .. "/lua/locale/") + +local function _(msgid) + return gettext(MODULE, msgid) +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 script_data = {} + +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.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.metadata = { + name = "toggle_group_view", -- name of script + purpose = _("toggle only group visible in lighttable"), -- purpose of script + author = "Bill Ferguson ", -- your name and optionally e-mail address + help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/official/toggle_group_view/" -- URL to help/documentation +} + + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- L O G L E V E L +-- - - - - - - - - - - - - - - - - - - - - - - - + +log.log_level(DEFAULT_LOG_LEVEL) + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- N A M E S P A C E +-- - - - - - - - - - - - - - - - - - - - - - - - + +local toggle_group_view = {} + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- G L O B A L V A R I A B L E S +-- - - - - - - - - - - - - - - - - - - - - - - - + +local group_active = false +local filmroll = "" +local collection_rules = {} + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- F U N C T I O N S +-- - - - - - - - - - - - - - - - - - - - - - - - + +local function add_collection_rule(rule_string) + + local rule = dt.gui.libs.collect.new_rule() + + rule.mode = "DT_LIB_COLLECT_MODE_AND" + rule.data = rule_string + rule.item = "DT_COLLECTION_PROP_FILENAME" + + table.insert(collection_rules, rule) +end + +local function show_group() + + local img = dt.gui.action_images[1] -- if you hover over an image and press a keyboard shortcut, it will get returned in dt.gui.action_images + + local collection_rule_string = "" + + local first = true + + collection_rules = {} + + local group_id = img.group_leader + + local rule = dt.gui.libs.collect.new_rule() + + rule.mode = "DT_LIB_COLLECT_MODE_AND" + rule.data = tostring(group_id.id) + rule.item = "DT_COLLECTION_PROP_GROUP_ID" + + table.insert(collection_rules, rule) + + -- dt.gui.libs.collect.filter returns the previous rule set when you install another + collection_rules = dt.gui.libs.collect.filter(collection_rules) +end + +local function reset() + dt.gui.libs.collect.filter(collection_rules) +end + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- D A R K T A B L E I N T E G R A T I O N +-- - - - - - - - - - - - - - - - - - - - - - - - + +local function destroy() + dt.gui.libs.destroy_action(MODULE, "toggle group view") + -- leave the shortcut so it doesn't need to be reassigned + -- the next time this module starts +end + +script_data.destroy = destroy + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- E V E N T S +-- - - - - - - - - - - - - - - - - - - - - - - - + +dt.gui.libs.image.register_action( + MODULE, "toggle group view", + function(event, images) + if group_active then + reset() + group_active = false + else + show_group() + group_active = true + end + end, + "toggle group view for selected image" +) + +dt.register_event( + MODULE, "shortcut", + function(event, shortcut) + if group_active then + reset() + group_active = false + else + show_group() + group_active = true + end + end, + "toggle group view for selected image" +) + +return script_data From 1762b372b199c3c5ffb8b3b0ac3078980a30ae07 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Wed, 25 Mar 2026 12:33:21 -0400 Subject: [PATCH 2/5] official/toggle_group_view - made button sensitive to group members selected --- official/toggle_group_view.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/official/toggle_group_view.lua b/official/toggle_group_view.lua index 476c2929..840fe212 100644 --- a/official/toggle_group_view.lua +++ b/official/toggle_group_view.lua @@ -159,12 +159,21 @@ local function reset() dt.gui.libs.collect.filter(collection_rules) end +local function set_button_sensitive(images) + if #images > 0 and #dt.gui.action_images[1]:get_group_members() > 1 then + dt.gui.libs.image.set_sensitive(MODULE, true) + else + dt.gui.libs.image.set_sensitive(MODULE, false) + end +end + -- - - - - - - - - - - - - - - - - - - - - - - - -- D A R K T A B L E I N T E G R A T I O N -- - - - - - - - - - - - - - - - - - - - - - - - local function destroy() dt.gui.libs.destroy_action(MODULE, "toggle group view") + dt.destroy_event(MODULE, "selection_changed") -- leave the shortcut so it doesn't need to be reassigned -- the next time this module starts end @@ -203,4 +212,15 @@ dt.register_event( "toggle group view for selected image" ) +dt.register_event(MODULE, "selection-changed", + function(event) + set_button_sensitive(dt.gui.selection()) + end +) + +dt.register_event(MODULE, "image-group-information-changed", + function(event, reason, image, other_image) + set_button_sensitive(dt.gui.selection()) + end +) return script_data From 35398c55e50e689531082d6b3654e4dea75c4f98 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Wed, 25 Mar 2026 13:07:03 -0400 Subject: [PATCH 3/5] official/toggle_group_view - fix no images selected so can't get a count of nil --- official/toggle_group_view.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/official/toggle_group_view.lua b/official/toggle_group_view.lua index 840fe212..bdb2f6a2 100644 --- a/official/toggle_group_view.lua +++ b/official/toggle_group_view.lua @@ -160,7 +160,7 @@ local function reset() end local function set_button_sensitive(images) - if #images > 0 and #dt.gui.action_images[1]:get_group_members() > 1 then + if images and #images > 0 and #dt.gui.action_images[1]:get_group_members() > 1 then dt.gui.libs.image.set_sensitive(MODULE, true) else dt.gui.libs.image.set_sensitive(MODULE, false) From 58bc3a69dff57a8149494fcf6f873b9d588837e6 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Thu, 26 Mar 2026 13:57:04 -0400 Subject: [PATCH 4/5] contrib/toggle_group_view - moved from official to contrib to handle event conflict with official/group_persistence. Moving to contrib forces toggle_group_view to load before group_persistence and thus get events that both need, first. If the order is reversed then toggle_group_view can bog down in a loop making darktable unresponsive. Fixed bad call in destroy and added check for selection-changed to make sure there are images before trying to set sensitivity. --- {official => contrib}/toggle_group_view.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) rename {official => contrib}/toggle_group_view.lua (95%) diff --git a/official/toggle_group_view.lua b/contrib/toggle_group_view.lua similarity index 95% rename from official/toggle_group_view.lua rename to contrib/toggle_group_view.lua index bdb2f6a2..09d731f9 100644 --- a/official/toggle_group_view.lua +++ b/contrib/toggle_group_view.lua @@ -172,7 +172,7 @@ end -- - - - - - - - - - - - - - - - - - - - - - - - local function destroy() - dt.gui.libs.destroy_action(MODULE, "toggle group view") + dt.gui.libs.image.destroy_action(MODULE, "toggle group view") dt.destroy_event(MODULE, "selection_changed") -- leave the shortcut so it doesn't need to be reassigned -- the next time this module starts @@ -212,15 +212,21 @@ dt.register_event( "toggle group view for selected image" ) +-- check the number of groups and ... dt.register_event(MODULE, "selection-changed", function(event) set_button_sensitive(dt.gui.selection()) end ) +-- it's a delete event just countdown instead of trying to keep track of +-- the selection and once I reach 0 do the set sensitive dt.register_event(MODULE, "image-group-information-changed", function(event, reason, image, other_image) - set_button_sensitive(dt.gui.selection()) + local images = dt.gui.selection() + if images then + set_button_sensitive(images) + end end ) return script_data From a94a0c2c90b36f9f89c72c018c15b359e1147d19 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Thu, 26 Mar 2026 22:41:28 -0400 Subject: [PATCH 5/5] contrib/toggle_group_view - updated help link --- contrib/toggle_group_view.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/toggle_group_view.lua b/contrib/toggle_group_view.lua index 09d731f9..d344f509 100644 --- a/contrib/toggle_group_view.lua +++ b/contrib/toggle_group_view.lua @@ -92,7 +92,7 @@ script_data.metadata = { name = "toggle_group_view", -- name of script purpose = _("toggle only group visible in lighttable"), -- purpose of script author = "Bill Ferguson ", -- your name and optionally e-mail address - help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/official/toggle_group_view/" -- URL to help/documentation + help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/contrib/toggle_group_view/" -- URL to help/documentation }