Skip to content

Commit 752e27d

Browse files
committed
Added detached mode to Edit with GIMP so that GIMP can keep running and accepting new images
1 parent 33523fb commit 752e27d

File tree

2 files changed

+57
-30
lines changed

2 files changed

+57
-30
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## Changes from most recent to oldest
22

3+
** 25 Feb 2021 - wpferguson - added detached mode to contrib/gimp.lua**
4+
5+
* Added run_detached checkbox to the exporter GUI. Selecting run_detached
6+
let's GIMP keep running and accepting additional images. It does not return
7+
the edited images to darktable.
8+
39
**24 Feb 2021 - Mark64 - make ext_editor lib visible in darkroom view**
410

511
**17 Feb 2021 - wpferguson - API 6.2.3 register_action changes**

contrib/gimp.lua

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
* require this script from your main lua file
4242
* select an image or images for editing with GIMP
4343
* in the export dialog select "Edit with GIMP" and select the format and bit depth for the
44-
exported image
44+
exported image. Check the "run_detached" button to run GIMP in detached mode. Images
45+
will not be returned to darktable in this mode, but additional images can be sent to
46+
GIMP without stopping it.
4547
* Press "export"
4648
* Edit the image with GIMP then save the changes with File->Overwrite....
4749
* Exit GIMP
@@ -103,6 +105,8 @@ end
103105

104106
local function gimp_edit(storage, image_table, extra_data) --finalize
105107

108+
local run_detached = dt.preferences.read("gimp", "run_detached", "bool")
109+
106110
local gimp_executable = df.check_if_bin_exists("gimp")
107111

108112
if not gimp_executable then
@@ -111,7 +115,11 @@ local function gimp_edit(storage, image_table, extra_data) --finalize
111115
end
112116

113117
if dt.configuration.running_os == "macos" then
114-
gimp_executable = "open -W -a " .. gimp_executable
118+
if run_detached then
119+
gimp_executable = "open -a " .. gimp_executable
120+
else
121+
gimp_executable = "open -W -a " .. gimp_executable
122+
end
115123
end
116124

117125
-- list of exported images
@@ -130,54 +138,67 @@ local function gimp_edit(storage, image_table, extra_data) --finalize
130138
local gimpStartCommand
131139
gimpStartCommand = gimp_executable .. " " .. img_list
132140

141+
if run_detached then
142+
if dt.configuration.running_os == "windows" then
143+
gimpStartCommand = "start /b \"\" " .. gimpStartCommand
144+
else
145+
gimpStartCommand = gimpStartCommand .. " &"
146+
end
147+
end
148+
133149
dt.print_log(gimpStartCommand)
134150

135151
dtsys.external_command(gimpStartCommand)
136152

137-
-- for each of the image, exported image pairs
138-
-- move the exported image into the directory with the original
139-
-- then import the image into the database which will group it with the original
140-
-- and then copy over any tags other than darktable tags
153+
if not run_detached then
154+
155+
-- for each of the image, exported image pairs
156+
-- move the exported image into the directory with the original
157+
-- then import the image into the database which will group it with the original
158+
-- and then copy over any tags other than darktable tags
141159

142-
for image,exported_image in pairs(image_table) do
160+
for image,exported_image in pairs(image_table) do
143161

144-
local myimage_name = image.path .. "/" .. df.get_filename(exported_image)
162+
local myimage_name = image.path .. "/" .. df.get_filename(exported_image)
145163

146-
while df.check_if_file_exists(myimage_name) do
147-
myimage_name = df.filename_increment(myimage_name)
148-
-- limit to 99 more exports of the original export
149-
if string.match(df.get_basename(myimage_name), "_(d-)$") == "99" then
150-
break
164+
while df.check_if_file_exists(myimage_name) do
165+
myimage_name = df.filename_increment(myimage_name)
166+
-- limit to 99 more exports of the original export
167+
if string.match(df.get_basename(myimage_name), "_(d-)$") == "99" then
168+
break
169+
end
151170
end
152-
end
153171

154-
dt.print_log("moving " .. exported_image .. " to " .. myimage_name)
155-
local result = df.file_move(exported_image, myimage_name)
172+
dt.print_log("moving " .. exported_image .. " to " .. myimage_name)
173+
local result = df.file_move(exported_image, myimage_name)
156174

157-
if result then
158-
dt.print_log("importing file")
159-
local myimage = dt.database.import(myimage_name)
175+
if result then
176+
dt.print_log("importing file")
177+
local myimage = dt.database.import(myimage_name)
160178

161-
group_if_not_member(image, myimage)
179+
group_if_not_member(image, myimage)
162180

163-
for _,tag in pairs(dt.tags.get_tags(image)) do
164-
if not (string.sub(tag.name,1,9) == "darktable") then
165-
dt.print_log("attaching tag")
166-
dt.tags.attach(tag,myimage)
181+
for _,tag in pairs(dt.tags.get_tags(image)) do
182+
if not (string.sub(tag.name,1,9) == "darktable") then
183+
dt.print_log("attaching tag")
184+
dt.tags.attach(tag,myimage)
185+
end
167186
end
168187
end
169188
end
170189
end
171-
172190
end
173191

174192
-- Register
175193

176-
local executables = {"gimp"}
177-
178-
if dt.configuration.running_os ~= "linux" then
179-
gimp_widget = df.executable_path_widget(executables)
180-
end
194+
gimp_widget = dt.new_widget("check_button"){
195+
label = _("run detached"),
196+
tooltip = _("don't import resulting image back into darktable"),
197+
value = dt.preferences.read("gimp", "run_detached", "bool"),
198+
clicked_callback = function(this)
199+
dt.preferences.write("gimp", "run_detached", "bool", this.value)
200+
end
201+
}
181202

182203
dt.register_storage("module_gimp", _("Edit with GIMP"), show_status, gimp_edit, nil, nil, gimp_widget)
183204

0 commit comments

Comments
 (0)