-
Notifications
You must be signed in to change notification settings - Fork 129
Add CollectHelper #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wpferguson
merged 4 commits into
darktable-org:master
from
BzKevin:BzKevin-CollectHelper
Feb 26, 2019
Merged
Add CollectHelper #162
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
--[[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 <http://www.gnu.org/licenses/>. | ||
]] | ||
|
||
--[[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" | ||
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")) | ||
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) | ||
end | ||
end | ||
local function CollectOnFolder(all_rules, all_active) | ||
local images = dt.gui.selection() | ||
if CheckSingleImage(images) then | ||
return | ||
end | ||
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" | ||
table.insert(rules, rule) | ||
if all_active then | ||
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(all_rules, all_active) | ||
local images = dt.gui.selection() | ||
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 | ||
BzKevin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
local rules = {} | ||
if image.red then | ||
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 | ||
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 | ||
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 | ||
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 | ||
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" | ||
table.insert(rules, purple_rule) | ||
end | ||
if all_active then | ||
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 | ||
end | ||
local function CollectOnAll_AND() | ||
local images = dt.gui.selection() | ||
if CheckSingleImage(images) then | ||
return | ||
end | ||
local rules = {} | ||
if dt.preferences.read('module_CollectHelper','folder','bool') then | ||
rules = CollectOnFolder(rules, true) | ||
end | ||
if dt.preferences.read('module_CollectHelper','colors','bool') then | ||
rules = CollectOnColors(rules, true) | ||
end | ||
previous = dt.gui.libs.collect.filter(rules) | ||
end | ||
|
||
-- GUI -- | ||
dt.gui.libs.image.register_action( | ||
_("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: folder"), | ||
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(_ , false) 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: 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 | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.