Skip to content

Commit 7810791

Browse files
authored
Merge pull request darktable-org#330 from scheckmedia/master
photils plugin
2 parents 0d2c4df + 1d10d52 commit 7810791

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

contrib/photils.lua

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ local GUI = {
143143
attach_button = dt.new_widget("button") {
144144
label = "",
145145
sensitive = false,
146-
clicked_callback = function() PHOTILS.attach_tags() end
146+
clicked_callback = function(self) PHOTILS.attach_tags() end
147147
},
148148
confidence_slider = dt.new_widget("slider") {
149149
step = 1,
@@ -226,16 +226,25 @@ function PHOTILS.paginate()
226226
end
227227

228228
function PHOTILS.attach_tags()
229-
local image = dt.gui.selection()[1]
230-
for tag, _ in pairs(PHOTILS.selected_tags) do
231-
local dt_tag = dt.tags.create(tag)
232-
dt.tags.attach(dt_tag, image)
229+
local num_selected = #dt.gui.selection()
230+
local job = dt.gui.create_job(_("Apply tag to image"), true)
231+
232+
for i = 1, num_selected, 1 do
233+
local image = dt.gui.selection()[i]
234+
for tag, _ in pairs(PHOTILS.selected_tags) do
235+
local dt_tag = dt.tags.create(tag)
236+
dt.tags.attach(dt_tag, image)
237+
end
238+
239+
job.percent = i / num_selected
233240
end
234241

235242
dt.print(_("Tags successfully attached to image"))
243+
job.valid = false
236244
end
237245

238246
function PHOTILS.get_tags(image, with_export)
247+
239248
local tmp_file = df.create_tmp_file()
240249
local in_arg = df.sanitize_filename(tostring(image))
241250
local out_arg = df.sanitize_filename(tmp_file)
@@ -305,7 +314,8 @@ function PHOTILS.on_tags_clicked()
305314
dt.control.sleep(2000)
306315
end
307316

308-
if not PHOTILS.get_tags(images[1], true) then
317+
with_export = dt.preferences.read(MODULE_NAME, "export_image_before_for_tags", "bool")
318+
if not PHOTILS.get_tags(images[1], with_export) then
309319
local msg = string.format(_("%s failed, see terminal output for details"), MODULE_NAME)
310320
GUI.warning_label.label = msg
311321
GUI.stack.active = GUI.error_view
@@ -435,6 +445,15 @@ dt.preferences.register(MODULE_NAME,
435445
_("if enabled, the confidence value for each tag is displayed"),
436446
true)
437447

448+
dt.preferences.register(MODULE_NAME,
449+
"export_image_before_for_tags",
450+
"bool",
451+
_("photils: use exported image for tag request"),
452+
_("If enabled, the image passed to photils for tag suggestion is based on the exported, already edited image. " ..
453+
"Otherwise, the embedded thumbnail of the RAW file will be used for tag suggestion." ..
454+
"The embedded thumbnail could speedup the tag suggestion but can fail if the RAW file is not supported."),
455+
true)
456+
438457
dt.register_event("photils", "mouse-over-image-changed",
439458
PHOTILS.image_changed)
440459

0 commit comments

Comments
 (0)