Skip to content

Commit e5537fd

Browse files
authored
Merge pull request #162 from BzKevin/BzKevin-CollectHelper
Add CollectHelper
2 parents 2b2a09e + 9e0490d commit e5537fd

File tree

1 file changed

+221
-0
lines changed

1 file changed

+221
-0
lines changed

contrib/CollectHelper.lua

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
--[[Collect Helper plugin for darktable
2+
3+
copyright (c) 2019 Kevin Ertel
4+
5+
darktable is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
darktable is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with darktable. If not, see <http://www.gnu.org/licenses/>.
17+
]]
18+
19+
--[[About this plugin
20+
This plugin adds the button(s) to the "Selected Images" module:
21+
1) Return to Previous Collection
22+
2) Collect on image's Folder
23+
3) Collect on image's Color Label(s)
24+
4) Collect on All (AND)
25+
26+
It also adds 3 preferences to the lua options dialog box which allow the user to activate/deactivate the 3 "Collect on" buttons.
27+
28+
Button Behavior:
29+
1) Return to Previous Collection - Will reset the collect parameters to the previously active settings
30+
2) Collect on image's Folder - Will change the collect parameters to be "Folder" with a value of the selected image's folder location
31+
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
32+
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
33+
34+
----REQUIRED SOFTWARE----
35+
NA
36+
37+
----USAGE----
38+
Install: (see here for more detail: https://github.com/darktable-org/lua-scripts )
39+
1) Copy this file in to your "lua/contrib" folder where all other scripts reside.
40+
2) Require this file in your luarc file, as with any other dt plug-in
41+
42+
Select the photo you wish to change you collection based on.
43+
In the "Selected Images" module click on "Collect on this Image"
44+
45+
----KNOWN ISSUES----
46+
]]
47+
48+
local dt = require "darktable"
49+
local gettext = dt.gettext
50+
local previous = nil
51+
local all_active = false
52+
53+
-- Tell gettext where to find the .mo file translating messages for a particular domain
54+
gettext.bindtextdomain("gimp",dt.configuration.config_dir.."/lua/locale/")
55+
56+
local function _(msgid)
57+
return gettext.dgettext("CollectHelper", msgid)
58+
end
59+
60+
-- FUNCTION --
61+
local function CheckSingleImage(selection)
62+
if #selection ~= 1 then
63+
dt.print(_("Please select a single image"))
64+
return true
65+
end
66+
return false
67+
end
68+
local function CheckHasColorLabel(selection)
69+
local ret = false
70+
for _,image in pairs(selection) do
71+
if image.red then ret = true end
72+
if image.blue then ret = true end
73+
if image.green then ret = true end
74+
if image.yellow then ret = true end
75+
if image.purple then ret = true end
76+
end
77+
return ret
78+
end
79+
local function PreviousCollection()
80+
if previous ~= nil then
81+
previous = dt.gui.libs.collect.filter(previous)
82+
end
83+
end
84+
local function CollectOnFolder(all_rules, all_active)
85+
local images = dt.gui.selection()
86+
if CheckSingleImage(images) then
87+
return
88+
end
89+
local rules = {}
90+
local rule = dt.gui.libs.collect.new_rule()
91+
rule.mode = "DT_LIB_COLLECT_MODE_AND"
92+
rule.data = images[1].path
93+
rule.item = "DT_COLLECTION_PROP_FOLDERS"
94+
table.insert(rules, rule)
95+
if all_active then
96+
for _,active_rule in pairs(rules) do
97+
table.insert(all_rules, active_rule)
98+
end
99+
return all_rules
100+
else
101+
previous = dt.gui.libs.collect.filter(rules)
102+
end
103+
end
104+
local function CollectOnColors(all_rules, all_active)
105+
local images = dt.gui.selection()
106+
if CheckSingleImage(images) then
107+
return
108+
end
109+
if not CheckHasColorLabel(images) then
110+
dt.print(_('select an image with an active color label'))
111+
return
112+
end
113+
for _,image in pairs(images) do
114+
local rules = {}
115+
if image.red then
116+
local red_rule = dt.gui.libs.collect.new_rule()
117+
red_rule.mode = "DT_LIB_COLLECT_MODE_AND"
118+
red_rule.data = "red"
119+
red_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
120+
table.insert(rules, red_rule)
121+
end
122+
if image.blue then
123+
local blue_rule = dt.gui.libs.collect.new_rule()
124+
blue_rule.mode = "DT_LIB_COLLECT_MODE_AND"
125+
blue_rule.data = "blue"
126+
blue_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
127+
table.insert(rules, blue_rule)
128+
end
129+
if image.green then
130+
local green_rule = dt.gui.libs.collect.new_rule()
131+
green_rule.mode = "DT_LIB_COLLECT_MODE_AND"
132+
green_rule.data = "green"
133+
green_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
134+
table.insert(rules, green_rule)
135+
end
136+
if image.yellow then
137+
local yellow_rule = dt.gui.libs.collect.new_rule()
138+
yellow_rule.mode = "DT_LIB_COLLECT_MODE_AND"
139+
yellow_rule.data = "yellow"
140+
yellow_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
141+
table.insert(rules, yellow_rule)
142+
end
143+
if image.purple then
144+
local purple_rule = dt.gui.libs.collect.new_rule()
145+
purple_rule.mode = "DT_LIB_COLLECT_MODE_AND"
146+
purple_rule.data = "purple"
147+
purple_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
148+
table.insert(rules, purple_rule)
149+
end
150+
if all_active then
151+
for _,active_rule in pairs(rules) do
152+
table.insert(all_rules, active_rule)
153+
end
154+
return all_rules
155+
else
156+
previous = dt.gui.libs.collect.filter(rules)
157+
end
158+
end
159+
end
160+
local function CollectOnAll_AND()
161+
local images = dt.gui.selection()
162+
if CheckSingleImage(images) then
163+
return
164+
end
165+
local rules = {}
166+
if dt.preferences.read('module_CollectHelper','folder','bool') then
167+
rules = CollectOnFolder(rules, true)
168+
end
169+
if dt.preferences.read('module_CollectHelper','colors','bool') then
170+
rules = CollectOnColors(rules, true)
171+
end
172+
previous = dt.gui.libs.collect.filter(rules)
173+
end
174+
175+
-- GUI --
176+
dt.gui.libs.image.register_action(
177+
_("collect: previous"),
178+
function() PreviousCollection() end,
179+
_("Sets the Collect parameters to be the previously active parameters")
180+
)
181+
if dt.preferences.read('module_CollectHelper','folder','bool') then
182+
dt.gui.libs.image.register_action(
183+
_("collect: folder"),
184+
function() CollectOnFolder(_ , false) end,
185+
_("Sets the Collect parameters to be the selected images's folder")
186+
)
187+
end
188+
if dt.preferences.read('module_CollectHelper','colors','bool') then
189+
dt.gui.libs.image.register_action(
190+
_("collect: color label(s)"),
191+
function() CollectOnColors(_ , false) end,
192+
_("Sets the Collect parameters to be the selected images's color label(s)")
193+
)
194+
end
195+
if dt.preferences.read('module_CollectHelper','all_and','bool') then
196+
dt.gui.libs.image.register_action(
197+
_("collect: all (AND)"),
198+
function() CollectOnAll_AND() end,
199+
_("Sets the Collect parameters based on all activated CollectHelper options")
200+
)
201+
end
202+
203+
-- PREFERENCES --
204+
dt.preferences.register("module_CollectHelper", "all_and", -- name
205+
"bool", -- type
206+
_('CollectHelper: All'), -- label
207+
_('Will create a collect parameter set that utelizes all enabled CollectHelper types (AND)'), -- tooltip
208+
true -- default
209+
)
210+
dt.preferences.register("module_CollectHelper", "colors", -- name
211+
"bool", -- type
212+
_('CollectHelper: Color Label(s)'), -- label
213+
_('Enable the button that allows you to swap to a collection based on selected image\'s COLOR LABEL(S)'), -- tooltip
214+
true -- default
215+
)
216+
dt.preferences.register("module_CollectHelper", "folder", -- name
217+
"bool", -- type
218+
_('CollectHelper: Folder'), -- label
219+
_('Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location'), -- tooltip
220+
true -- default
221+
)

0 commit comments

Comments
 (0)