From 4d6dfea3a5e977264c914bdb3ccde983fc4073a9 Mon Sep 17 00:00:00 2001 From: BzKevin <36381472+BzKevin@users.noreply.github.com> Date: Wed, 13 Feb 2019 12:23:34 -0500 Subject: [PATCH 1/4] Add CollectHelper --- contrib/CollectHelper.lua | 199 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 contrib/CollectHelper.lua diff --git a/contrib/CollectHelper.lua b/contrib/CollectHelper.lua new file mode 100644 index 0000000..37e9a8e --- /dev/null +++ b/contrib/CollectHelper.lua @@ -0,0 +1,199 @@ +--[[Collect Helper plugin for darktable + + copyright (c) 2019 Kevin Ertel + + 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 . +]] + +--[[About this plugin +This plugin adds the button(s) to the "Selected Images" module: +1) Return to Previous Collection +2) Collect on image's Folder +3) Collect on image's Color Label(s) +4) Collect on All (AND) + +It also adds 3 preferences to the lua options dialog box which allow the user to activate/deactivate the 3 "Collect on" buttons. + +Button Behavior: +1) Return to Previous Collection - Will reset the collect parameters to the previously active settings +2) Collect on image's Folder - Will change the collect parameters to be "Folder" with a value of the selected image's folder location +3) Collect on image's Color Label(s) - Will change the collect parameter to be "Color" with a value of the selected images color labels, will apply multiple parameters with AND logic if multiple exist +4) Collect on All (AND) - Will collect on all parameters activated by the preferences dialog, as such this button is redundant if you only have one of the two other options enabled + +----REQUIRED SOFTWARE---- +NA + +----USAGE---- +Install: (see here for more detail: https://github.com/darktable-org/lua-scripts ) + 1) Copy this file in to your "lua/contrib" folder where all other scripts reside. + 2) Require this file in your luarc file, as with any other dt plug-in + +Select the photo you wish to change you collection based on. +In the "Selected Images" module click on "Collect on this Image" + +----KNOWN ISSUES---- +]] + +local dt = require "darktable" +previous = nil +all_active = false + +-- FUNCTION -- +local function CheckSingleImage(selection) + if #selection ~= 1 then + dt.print("Please select a single image") + return 1 + end + return 0 +end +local function PreviousCollection() + if previous ~= nil then + previous = dt.gui.libs.collect.filter(previous) + end +end +local function CollectOnFolder() + local images = dt.gui.selection() + if CheckSingleImage(images) == 1 then + return + end + rules = {} + all_rules = {} + rule = dt.gui.libs.collect.new_rule() + rule.mode = "DT_LIB_COLLECT_MODE_AND" + rule.data = images[1].path + rule.item = "DT_COLLECTION_PROP_FOLDERS" + table.insert(rules, rule) + if all_active then + for _,active_rule in pairs(rules) do + table.insert(all_rules, active_rule) + end + else + previous = dt.gui.libs.collect.filter(rules) + end +end +local function CollectOnColors() + local images = dt.gui.selection() + if CheckSingleImage(images) == 1 then + return + end + for _,image in pairs(images) do + rules = {} + if image.red then + red_rule = dt.gui.libs.collect.new_rule() + red_rule.mode = "DT_LIB_COLLECT_MODE_AND" + red_rule.data = "red" + red_rule.item = "DT_COLLECTION_PROP_COLORLABEL" + table.insert(rules, red_rule) + end + if image.blue then + blue_rule = dt.gui.libs.collect.new_rule() + blue_rule.mode = "DT_LIB_COLLECT_MODE_AND" + blue_rule.data = "blue" + blue_rule.item = "DT_COLLECTION_PROP_COLORLABEL" + table.insert(rules, blue_rule) + end + if image.green then + green_rule = dt.gui.libs.collect.new_rule() + green_rule.mode = "DT_LIB_COLLECT_MODE_AND" + green_rule.data = "green" + green_rule.item = "DT_COLLECTION_PROP_COLORLABEL" + table.insert(rules, green_rule) + end + if image.yellow then + yellow_rule = dt.gui.libs.collect.new_rule() + yellow_rule.mode = "DT_LIB_COLLECT_MODE_AND" + yellow_rule.data = "yellow" + yellow_rule.item = "DT_COLLECTION_PROP_COLORLABEL" + table.insert(rules, yellow_rule) + end + if image.purple then + purple_rule = dt.gui.libs.collect.new_rule() + purple_rule.mode = "DT_LIB_COLLECT_MODE_AND" + purple_rule.data = "purple" + purple_rule.item = "DT_COLLECTION_PROP_COLORLABEL" + table.insert(rules, purple_rule) + end + if all_active then + for _,active_rule in pairs(rules) do + table.insert(all_rules, active_rule) + end + else + previous = dt.gui.libs.collect.filter(rules) + end + end +end +local function CollectOnAll_AND() + local images = dt.gui.selection() + if CheckSingleImage(images) == 1 then + return + end + all_rules = {} + all_active = true + if dt.preferences.read('module_CollectHelper','folder','bool') then + CollectOnFolder() + end + if dt.preferences.read('module_CollectHelper','colors','bool') then + CollectOnColors() + end + all_active = false + previous = dt.gui.libs.collect.filter(all_rules) +end + +-- GUI -- +dt.gui.libs.image.register_action( + "Return to Previous Collection", + function() PreviousCollection() end, + "Sets the Collect parameters to be the previously active parameters" +) +if dt.preferences.read('module_CollectHelper','folder','bool') then + dt.gui.libs.image.register_action( + "Collect on image's Folder", + function() CollectOnFolder() end, + "Sets the Collect parameters to be the selected images's folder" + ) +end +if dt.preferences.read('module_CollectHelper','colors','bool') then + dt.gui.libs.image.register_action( + "Collect on image's Color Label(s)", + function() CollectOnColors() end, + "Sets the Collect parameters to be the selected images's color label(s)" + ) +end +if dt.preferences.read('module_CollectHelper','all_and','bool') then + dt.gui.libs.image.register_action( + "Collect on All (AND)", + function() CollectOnAll_AND() end, + "Sets the Collect parameters based on all activated CollectHelper options" + ) +end + +-- PREFERENCES -- +dt.preferences.register("module_CollectHelper", "all_and", -- name + "bool", -- type + 'CollectHelper: All', -- label + 'Will create a collect parameter set that utelizes all enabled CollectHelper types (AND)', -- tooltip + true -- default +) +dt.preferences.register("module_CollectHelper", "colors", -- name + "bool", -- type + 'CollectHelper: Color Label(s)', -- label + 'Enable the button that allows you to swap to a collection based on selected image\'s COLOR LABEL(S)', -- tooltip + true -- default +) +dt.preferences.register("module_CollectHelper", "folder", -- name + "bool", -- type + 'CollectHelper: Folder', -- label + 'Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location', -- tooltip + true -- default +) \ No newline at end of file From ff0352cfe644c568e720f876b2f758049007edd5 Mon Sep 17 00:00:00 2001 From: BzKevin <36381472+BzKevin@users.noreply.github.com> Date: Wed, 13 Feb 2019 13:42:54 -0500 Subject: [PATCH 2/4] Updated version of Collect Helper Reworded the button text to better match with the rest of darktable's buttons --- contrib/CollectHelper.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/CollectHelper.lua b/contrib/CollectHelper.lua index 37e9a8e..fabe4c9 100644 --- a/contrib/CollectHelper.lua +++ b/contrib/CollectHelper.lua @@ -152,27 +152,27 @@ end -- GUI -- dt.gui.libs.image.register_action( - "Return to Previous Collection", + "collect: previous", function() PreviousCollection() end, "Sets the Collect parameters to be the previously active parameters" ) if dt.preferences.read('module_CollectHelper','folder','bool') then dt.gui.libs.image.register_action( - "Collect on image's Folder", + "collect: folder", function() CollectOnFolder() end, "Sets the Collect parameters to be the selected images's folder" ) end if dt.preferences.read('module_CollectHelper','colors','bool') then dt.gui.libs.image.register_action( - "Collect on image's Color Label(s)", + "collect: color label(s)", function() CollectOnColors() end, "Sets the Collect parameters to be the selected images's color label(s)" ) end if dt.preferences.read('module_CollectHelper','all_and','bool') then dt.gui.libs.image.register_action( - "Collect on All (AND)", + "collect: all (AND)", function() CollectOnAll_AND() end, "Sets the Collect parameters based on all activated CollectHelper options" ) From b682284a2a8433ec856a52601b26d8b945df9778 Mon Sep 17 00:00:00 2001 From: BzKevin <36381472+BzKevin@users.noreply.github.com> Date: Fri, 15 Feb 2019 14:08:04 -0500 Subject: [PATCH 3/4] Update with 'local' variable designation Updated variable definitions with 'local' designation. Doing so slightly broke the script so I modified the function calls a tad to pass variables in and out as needed for "CollectOnAll" function to work. --- contrib/CollectHelper.lua | 53 +++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/contrib/CollectHelper.lua b/contrib/CollectHelper.lua index fabe4c9..3684686 100644 --- a/contrib/CollectHelper.lua +++ b/contrib/CollectHelper.lua @@ -46,30 +46,29 @@ In the "Selected Images" module click on "Collect on this Image" ]] local dt = require "darktable" -previous = nil -all_active = false +local previous = nil +local all_active = false -- FUNCTION -- local function CheckSingleImage(selection) if #selection ~= 1 then dt.print("Please select a single image") - return 1 + return true end - return 0 + return false end local function PreviousCollection() if previous ~= nil then previous = dt.gui.libs.collect.filter(previous) end end -local function CollectOnFolder() +local function CollectOnFolder(all_rules, all_active) local images = dt.gui.selection() - if CheckSingleImage(images) == 1 then + if CheckSingleImage(images) then return end - rules = {} - all_rules = {} - rule = dt.gui.libs.collect.new_rule() + local rules = {} + local rule = dt.gui.libs.collect.new_rule() rule.mode = "DT_LIB_COLLECT_MODE_AND" rule.data = images[1].path rule.item = "DT_COLLECTION_PROP_FOLDERS" @@ -78,47 +77,48 @@ local function CollectOnFolder() for _,active_rule in pairs(rules) do table.insert(all_rules, active_rule) end + return all_rules else previous = dt.gui.libs.collect.filter(rules) end end -local function CollectOnColors() +local function CollectOnColors(all_rules, all_active) local images = dt.gui.selection() - if CheckSingleImage(images) == 1 then + if CheckSingleImage(images) then return end for _,image in pairs(images) do - rules = {} + local rules = {} if image.red then - red_rule = dt.gui.libs.collect.new_rule() + local red_rule = dt.gui.libs.collect.new_rule() red_rule.mode = "DT_LIB_COLLECT_MODE_AND" red_rule.data = "red" red_rule.item = "DT_COLLECTION_PROP_COLORLABEL" table.insert(rules, red_rule) end if image.blue then - blue_rule = dt.gui.libs.collect.new_rule() + local blue_rule = dt.gui.libs.collect.new_rule() blue_rule.mode = "DT_LIB_COLLECT_MODE_AND" blue_rule.data = "blue" blue_rule.item = "DT_COLLECTION_PROP_COLORLABEL" table.insert(rules, blue_rule) end if image.green then - green_rule = dt.gui.libs.collect.new_rule() + local green_rule = dt.gui.libs.collect.new_rule() green_rule.mode = "DT_LIB_COLLECT_MODE_AND" green_rule.data = "green" green_rule.item = "DT_COLLECTION_PROP_COLORLABEL" table.insert(rules, green_rule) end if image.yellow then - yellow_rule = dt.gui.libs.collect.new_rule() + local yellow_rule = dt.gui.libs.collect.new_rule() yellow_rule.mode = "DT_LIB_COLLECT_MODE_AND" yellow_rule.data = "yellow" yellow_rule.item = "DT_COLLECTION_PROP_COLORLABEL" table.insert(rules, yellow_rule) end if image.purple then - purple_rule = dt.gui.libs.collect.new_rule() + local purple_rule = dt.gui.libs.collect.new_rule() purple_rule.mode = "DT_LIB_COLLECT_MODE_AND" purple_rule.data = "purple" purple_rule.item = "DT_COLLECTION_PROP_COLORLABEL" @@ -128,6 +128,7 @@ local function CollectOnColors() for _,active_rule in pairs(rules) do table.insert(all_rules, active_rule) end + return all_rules else previous = dt.gui.libs.collect.filter(rules) end @@ -135,19 +136,17 @@ local function CollectOnColors() end local function CollectOnAll_AND() local images = dt.gui.selection() - if CheckSingleImage(images) == 1 then + if CheckSingleImage(images) then return end - all_rules = {} - all_active = true + local rules = {} if dt.preferences.read('module_CollectHelper','folder','bool') then - CollectOnFolder() + rules = CollectOnFolder(rules, true) end if dt.preferences.read('module_CollectHelper','colors','bool') then - CollectOnColors() + rules = CollectOnColors(rules, true) end - all_active = false - previous = dt.gui.libs.collect.filter(all_rules) + previous = dt.gui.libs.collect.filter(rules) end -- GUI -- @@ -159,14 +158,14 @@ dt.gui.libs.image.register_action( if dt.preferences.read('module_CollectHelper','folder','bool') then dt.gui.libs.image.register_action( "collect: folder", - function() CollectOnFolder() end, + function() CollectOnFolder(_ , false) end, "Sets the Collect parameters to be the selected images's folder" ) end if dt.preferences.read('module_CollectHelper','colors','bool') then dt.gui.libs.image.register_action( "collect: color label(s)", - function() CollectOnColors() end, + function() CollectOnColors(_ , false) end, "Sets the Collect parameters to be the selected images's color label(s)" ) end @@ -196,4 +195,4 @@ dt.preferences.register("module_CollectHelper", "folder", -- name 'CollectHelper: Folder', -- label 'Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location', -- tooltip true -- default -) \ No newline at end of file +) From 9e0490d37158118858251dedaa10e2e7aef6578e Mon Sep 17 00:00:00 2001 From: BzKevin <36381472+BzKevin@users.noreply.github.com> Date: Tue, 26 Feb 2019 14:30:11 -0500 Subject: [PATCH 4/4] Add gettext, check for color label Add translate-ability. Also adds a check that the selected image has an active color label and displays a message if it does not --- contrib/CollectHelper.lua | 53 ++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/contrib/CollectHelper.lua b/contrib/CollectHelper.lua index 3684686..bd58ce7 100644 --- a/contrib/CollectHelper.lua +++ b/contrib/CollectHelper.lua @@ -46,17 +46,36 @@ In the "Selected Images" module click on "Collect on this Image" ]] local dt = require "darktable" +local gettext = dt.gettext local previous = nil local all_active = false +-- Tell gettext where to find the .mo file translating messages for a particular domain +gettext.bindtextdomain("gimp",dt.configuration.config_dir.."/lua/locale/") + +local function _(msgid) + return gettext.dgettext("CollectHelper", msgid) +end + -- FUNCTION -- local function CheckSingleImage(selection) if #selection ~= 1 then - dt.print("Please select a single image") + dt.print(_("Please select a single image")) return true end return false end +local function CheckHasColorLabel(selection) + local ret = false + for _,image in pairs(selection) do + if image.red then ret = true end + if image.blue then ret = true end + if image.green then ret = true end + if image.yellow then ret = true end + if image.purple then ret = true end + end + return ret +end local function PreviousCollection() if previous ~= nil then previous = dt.gui.libs.collect.filter(previous) @@ -87,6 +106,10 @@ local function CollectOnColors(all_rules, all_active) if CheckSingleImage(images) then return end + if not CheckHasColorLabel(images) then + dt.print(_('select an image with an active color label')) + return + end for _,image in pairs(images) do local rules = {} if image.red then @@ -151,48 +174,48 @@ end -- GUI -- dt.gui.libs.image.register_action( - "collect: previous", + _("collect: previous"), function() PreviousCollection() end, - "Sets the Collect parameters to be the previously active parameters" + _("Sets the Collect parameters to be the previously active parameters") ) if dt.preferences.read('module_CollectHelper','folder','bool') then dt.gui.libs.image.register_action( - "collect: folder", + _("collect: folder"), function() CollectOnFolder(_ , false) end, - "Sets the Collect parameters to be the selected images's folder" + _("Sets the Collect parameters to be the selected images's folder") ) end if dt.preferences.read('module_CollectHelper','colors','bool') then dt.gui.libs.image.register_action( - "collect: color label(s)", + _("collect: color label(s)"), function() CollectOnColors(_ , false) end, - "Sets the Collect parameters to be the selected images's color label(s)" + _("Sets the Collect parameters to be the selected images's color label(s)") ) end if dt.preferences.read('module_CollectHelper','all_and','bool') then dt.gui.libs.image.register_action( - "collect: all (AND)", + _("collect: all (AND)"), function() CollectOnAll_AND() end, - "Sets the Collect parameters based on all activated CollectHelper options" + _("Sets the Collect parameters based on all activated CollectHelper options") ) end -- PREFERENCES -- dt.preferences.register("module_CollectHelper", "all_and", -- name "bool", -- type - 'CollectHelper: All', -- label - 'Will create a collect parameter set that utelizes all enabled CollectHelper types (AND)', -- tooltip + _('CollectHelper: All'), -- label + _('Will create a collect parameter set that utelizes all enabled CollectHelper types (AND)'), -- tooltip true -- default ) dt.preferences.register("module_CollectHelper", "colors", -- name "bool", -- type - 'CollectHelper: Color Label(s)', -- label - 'Enable the button that allows you to swap to a collection based on selected image\'s COLOR LABEL(S)', -- tooltip + _('CollectHelper: Color Label(s)'), -- label + _('Enable the button that allows you to swap to a collection based on selected image\'s COLOR LABEL(S)'), -- tooltip true -- default ) dt.preferences.register("module_CollectHelper", "folder", -- name "bool", -- type - 'CollectHelper: Folder', -- label - 'Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location', -- tooltip + _('CollectHelper: Folder'), -- label + _('Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location'), -- tooltip true -- default )