Skip to content

Commit 3bb4e9c

Browse files
committed
contrib/auto_snapshot - take a snapshot automatically when opening an image in darkroom
1 parent 5727b2d commit 3bb4e9c

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

contrib/auto_snapshot.lua

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
--[[
2+
3+
auto_snapshot.lua - automatically take a snapshot when an image is loaded in darkroom
4+
5+
Copyright (C) 2024 Bill Ferguson <wpferguson.com>.
6+
7+
This program is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation; either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
]]
20+
--[[
21+
auto_snapshot -
22+
23+
automatically take a snapshot when an image is loaded in darkroom
24+
25+
ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT
26+
None
27+
28+
USAGE
29+
* start the script from script_manager
30+
* open an image in darkroom
31+
32+
BUGS, COMMENTS, SUGGESTIONS
33+
Bill Ferguson <wpferguson.com>
34+
35+
CHANGES
36+
]]
37+
38+
local dt = require "darktable"
39+
local du = require "lib/dtutils"
40+
41+
-- - - - - - - - - - - - - - - - - - - - - - - -
42+
-- C O N S T A N T S
43+
-- - - - - - - - - - - - - - - - - - - - - - - -
44+
45+
local MODULE <const> = "auto_snapshot"
46+
local DEFAULT_LOG_LEVEL <const> = log.error
47+
48+
-- - - - - - - - - - - - - - - - - - - - - - - -
49+
-- A P I C H E C K
50+
-- - - - - - - - - - - - - - - - - - - - - - - -
51+
52+
du.check_min_api_version("7.0.0", MODULE) -- choose the minimum version that contains the features you need
53+
54+
55+
-- - - - - - - - - - - - - - - - - - - - - - - - - -
56+
-- I 1 8 N
57+
-- - - - - - - - - - - - - - - - - - - - - - - - - -
58+
59+
local gettext = dt.gettext.gettext
60+
61+
dt.gettext.bindtextdomain(MODULE , dt.configuration.config_dir .. "/lua/locale/")
62+
63+
local function _(msgid)
64+
return gettext(MODULE, msgid)
65+
end
66+
67+
68+
-- - - - - - - - - - - - - - - - - - - - - - - - - -
69+
-- S C R I P T M A N A G E R I N T E G R A T I O N
70+
-- - - - - - - - - - - - - - - - - - - - - - - - - -
71+
72+
local script_data = {}
73+
74+
script_data.destroy = nil -- function to destory the script
75+
script_data.destroy_method = nil -- set to hide for libs since we can't destroy them commpletely yet
76+
script_data.restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again
77+
script_data.show = nil -- only required for libs since the destroy_method only hides them
78+
79+
script_data.metadata = {
80+
name = "auto_snapshot", -- name of script
81+
purpose = _("automatically take a snapshot when an image is loaded in darkroom"), -- purpose of script
82+
author = "Bill Ferguson <wpferguson.com>", -- your name and optionally e-mail address
83+
help = "" -- URL to help/documentation
84+
}
85+
86+
87+
-- - - - - - - - - - - - - - - - - - - - - - - -
88+
-- L O G L E V E L
89+
-- - - - - - - - - - - - - - - - - - - - - - - -
90+
91+
log.log_level(DEFAULT_LOG_LEVEL)
92+
93+
-- - - - - - - - - - - - - - - - - - - - - - - -
94+
-- N A M E S P A C E
95+
-- - - - - - - - - - - - - - - - - - - - - - - -
96+
97+
local auto_snapshot = {}
98+
99+
-- - - - - - - - - - - - - - - - - - - - - - - -
100+
-- D A R K T A B L E I N T E G R A T I O N
101+
-- - - - - - - - - - - - - - - - - - - - - - - -
102+
103+
local function destroy()
104+
dt.destroy_event(MODULE, "darkroom-image-loaded")
105+
end
106+
107+
script_data.destroy = destroy
108+
109+
-- - - - - - - - - - - - - - - - - - - - - - - -
110+
-- E V E N T S
111+
-- - - - - - - - - - - - - - - - - - - - - - - -
112+
113+
dt.register_event(MODULE, "darkroom-image-loaded",
114+
function(event, clean, image)
115+
if clean then
116+
dt.gui.libs.snapshots.take_snapshot()
117+
end
118+
119+
end
120+
)
121+
122+
123+
return script_data

0 commit comments

Comments
 (0)