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
+ local log = require " lib/dtutils.log"
41
+
42
+ -- - - - - - - - - - - - - - - - - - - - - - - -
43
+ -- C O N S T A N T S
44
+ -- - - - - - - - - - - - - - - - - - - - - - - -
45
+
46
+ local MODULE <const> = " auto_snapshot"
47
+ local DEFAULT_LOG_LEVEL <const> = log .error
48
+
49
+ -- - - - - - - - - - - - - - - - - - - - - - - -
50
+ -- A P I C H E C K
51
+ -- - - - - - - - - - - - - - - - - - - - - - - -
52
+
53
+ du .check_min_api_version (" 7.0.0" , MODULE ) -- choose the minimum version that contains the features you need
54
+
55
+
56
+ -- - - - - - - - - - - - - - - - - - - - - - - - - -
57
+ -- I 1 8 N
58
+ -- - - - - - - - - - - - - - - - - - - - - - - - - -
59
+
60
+ local gettext = dt .gettext .gettext
61
+
62
+ dt .gettext .bindtextdomain (MODULE , dt .configuration .config_dir .. " /lua/locale/" )
63
+
64
+ local function _ (msgid )
65
+ return gettext (MODULE , msgid )
66
+ end
67
+
68
+
69
+ -- - - - - - - - - - - - - - - - - - - - - - - - - -
70
+ -- S C R I P T M A N A G E R I N T E G R A T I O N
71
+ -- - - - - - - - - - - - - - - - - - - - - - - - - -
72
+
73
+ local script_data = {}
74
+
75
+ script_data .destroy = nil -- function to destory the script
76
+ script_data .destroy_method = nil -- set to hide for libs since we can't destroy them commpletely yet
77
+ script_data .restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again
78
+ script_data .show = nil -- only required for libs since the destroy_method only hides them
79
+
80
+ script_data .metadata = {
81
+ name = " auto_snapshot" , -- name of script
82
+ purpose = _ (" automatically take a snapshot when an image is loaded in darkroom" ), -- purpose of script
83
+ author = " Bill Ferguson <wpferguson.com>" , -- your name and optionally e-mail address
84
+ help = " " -- URL to help/documentation
85
+ }
86
+
87
+
88
+ -- - - - - - - - - - - - - - - - - - - - - - - -
89
+ -- L O G L E V E L
90
+ -- - - - - - - - - - - - - - - - - - - - - - - -
91
+
92
+ log .log_level (DEFAULT_LOG_LEVEL )
93
+
94
+ -- - - - - - - - - - - - - - - - - - - - - - - -
95
+ -- N A M E S P A C E
96
+ -- - - - - - - - - - - - - - - - - - - - - - - -
97
+
98
+ local auto_snapshot = {}
99
+
100
+ -- - - - - - - - - - - - - - - - - - - - - - - -
101
+ -- P R E F E R E N C E S
102
+ -- - - - - - - - - - - - - - - - - - - - - - - -
103
+
104
+ dt .preferences .register (MODULE , " always_create_snapshot" , " bool" , " always automatically create_snapshot" ,
105
+ " auto_snapshot - create a snapshot even if the image is altered" , false )
106
+
107
+ -- - - - - - - - - - - - - - - - - - - - - - - -
108
+ -- D A R K T A B L E I N T E G R A T I O N
109
+ -- - - - - - - - - - - - - - - - - - - - - - - -
110
+
111
+ local function destroy ()
112
+ dt .destroy_event (MODULE , " darkroom-image-loaded" )
113
+ end
114
+
115
+ script_data .destroy = destroy
116
+
117
+ -- - - - - - - - - - - - - - - - - - - - - - - -
118
+ -- E V E N T S
119
+ -- - - - - - - - - - - - - - - - - - - - - - - -
120
+
121
+ dt .register_event (MODULE , " darkroom-image-loaded" ,
122
+ function (event , clean , image )
123
+ local always = dt .preferences .read (MODULE , " always_create_snapshot" , " bool" )
124
+ if clean and always then
125
+ dt .gui .libs .snapshots .take_snapshot ()
126
+ elseif clean and not image .is_altered then
127
+ dt .gui .libs .snapshots .take_snapshot ()
128
+ end
129
+
130
+ end
131
+ )
132
+
133
+
134
+ return script_data
0 commit comments