Skip to content

Commit 8004b96

Browse files
authored
Merge branch 'master' into BzKevin-enfuseAdvanced-refactor
2 parents f82ae6c + 7cc58d9 commit 8004b96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1839
-355
lines changed

contrib/AutoGrouper.lua

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
--[[AutoGrouper 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 module "Auto Group" to darktable's lighttable view
21+
22+
----REQUIRED SOFTWARE----
23+
None
24+
25+
----USAGE----
26+
Install: (see here for more detail: https://github.com/darktable-org/lua-scripts )
27+
1) Copy this file in to your "lua/contrib" folder where all other scripts reside.
28+
2) Require this file in your luarc file, as with any other dt plug-in
29+
30+
Set a gap amount in second which will be used to determine when images should no
31+
longer be added to a group. If an image is more then the specified amount of time
32+
from the last image in the group it will not be added. Images without timestamps
33+
in exif data will be ignored.
34+
35+
There are two buttons. One allows the grouping to be performed only on the currently
36+
selected images, the other button performs grouping on the entire active collection
37+
]]
38+
39+
local dt = require "darktable"
40+
local MOD = 'autogrouper'
41+
local gettext = dt.gettext
42+
-- Tell gettext where to find the .mo file translating messages for a particular domain
43+
gettext.bindtextdomain("AutoGrouper",dt.configuration.config_dir.."/lua/locale/")
44+
local function _(msgid)
45+
return gettext.dgettext("AutoGrouper", msgid)
46+
end
47+
48+
local function InRange(test, low, high) --tests if test value is within range of low and high (inclusive)
49+
if test >= low and test <= high then
50+
return true
51+
else
52+
return false
53+
end
54+
end
55+
56+
local function CompTime(first, second) --compares the timestamps and returns true if first was taken before second
57+
first_time = first.exif_datetime_taken
58+
if string.match(first_time, '[0-9]') == nil then first_time = '9999:99:99 99:99:99' end
59+
first_time = tonumber(string.gsub(first_time, '[^0-9]*',''))
60+
second_time = second.exif_datetime_taken
61+
if string.match(second_time, '[0-9]') == nil then second_time = '9999:99:99 99:99:99' end
62+
second_time = tonumber(string.gsub(second_time, '[^0-9]*',''))
63+
return first_time < second_time
64+
end
65+
66+
local function SeperateTime(str) --seperates the timestamp into individual components for used with OS.time operations
67+
local cleaned = string.gsub(str, '[^%d]',':')
68+
cleaned = string.gsub(cleaned, '::*',':') --YYYY:MM:DD:hh:mm:ss
69+
local year = string.sub(cleaned,1,4)
70+
local month = string.sub(cleaned,6,7)
71+
local day = string.sub(cleaned,9,10)
72+
local hour = string.sub(cleaned,12,13)
73+
local min = string.sub(cleaned,15,16)
74+
local sec = string.sub(cleaned,18,19)
75+
return {year = year, month = month, day = day, hour = hour, min = min, sec = sec}
76+
end
77+
78+
local function GetTimeDiff(curr_image, prev_image) --returns the time difference (in sec.) from current image and the previous image
79+
local curr_time = SeperateTime(curr_image.exif_datetime_taken)
80+
local prev_time = SeperateTime(prev_image.exif_datetime_taken)
81+
return os.time(curr_time)-os.time(prev_time)
82+
end
83+
84+
local function main(on_collection)
85+
local images = {}
86+
if on_collection then
87+
local col_images = dt.collection
88+
for i,image in ipairs(col_images) do --copy images to a standard table, table.sort barfs on type dt_lua_singleton_image_collection
89+
table.insert(images,i,image)
90+
end
91+
else
92+
images = dt.gui.selection()
93+
end
94+
dt.preferences.write(MOD, 'active_gap', 'integer', GUI.gap.value)
95+
if #images < 2 then
96+
dt.print('please select at least 2 images')
97+
return
98+
end
99+
table.sort(images, function(first, second) return CompTime(first,second) end) --sort images by timestamp
100+
101+
for i, image in ipairs(images) do
102+
if i == 1 then
103+
prev_image = image
104+
elseif string.match(image.exif_datetime_taken, '[%d]') ~= nil then --make sure current image has a timestamp, if so check if it is within the user specified gap value and add to group
105+
local curr_image = image
106+
if GetTimeDiff(curr_image, prev_image) <= GUI.gap.value then
107+
images[i]:group_with(images[i-1])
108+
end
109+
prev_image = curr_image
110+
end
111+
end
112+
end
113+
114+
-- GUI --
115+
GUI = {
116+
gap = {},
117+
selected = {},
118+
collection = {}
119+
}
120+
temp = dt.preferences.read(MOD, 'active_gap', 'integer')
121+
if not InRange(temp, 1, 86400) then temp = 3 end
122+
GUI.gap = dt.new_widget('slider'){
123+
label = _('group gap [sec.]'),
124+
tooltip = _('minimum gap, in seconds, between groups'),
125+
soft_min = 1,
126+
soft_max = 60,
127+
hard_min = 1,
128+
hard_max = 86400,
129+
step = 1,
130+
digits = 0,
131+
value = temp,
132+
reset_callback = function(self)
133+
self.value = 3
134+
end
135+
}
136+
GUI.selected = dt.new_widget("button"){
137+
label = _('auto group: selected'),
138+
tooltip =_('auto group selected images'),
139+
clicked_callback = function() main(false) end
140+
}
141+
GUI.collection = dt.new_widget("button"){
142+
label = _('auto group: collection'),
143+
tooltip =_('auto group the entire collection'),
144+
clicked_callback = function() main(true) end
145+
}
146+
dt.register_lib(
147+
'AutoGroup_Lib', -- Module name
148+
_('auto group'), -- name
149+
true, -- expandable
150+
true, -- resetable
151+
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 99}}, -- containers
152+
dt.new_widget("box"){
153+
orientation = "vertical",
154+
GUI.gap,
155+
GUI.selected,
156+
GUI.collection
157+
}
158+
)

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("CollectHelper",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)