From 9900f46be4d8327b2666d93b3f839e24c458fe7e Mon Sep 17 00:00:00 2001 From: Tobias Scheck Date: Mon, 15 Mar 2021 11:36:37 +0100 Subject: [PATCH 1/2] add option to apply selected tags from a single image to multiple images (close #3); add setting parameter to enable/disable the export of an image before tag suggestion (close #5) --- contrib/photils.lua | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/contrib/photils.lua b/contrib/photils.lua index 69829be..32931e7 100644 --- a/contrib/photils.lua +++ b/contrib/photils.lua @@ -143,7 +143,7 @@ local GUI = { attach_button = dt.new_widget("button") { label = "", sensitive = false, - clicked_callback = function() PHOTILS.attach_tags() end + clicked_callback = function(self) PHOTILS.attach_tags() end }, confidence_slider = dt.new_widget("slider") { step = 1, @@ -226,16 +226,25 @@ function PHOTILS.paginate() end function PHOTILS.attach_tags() - local image = dt.gui.selection()[1] - for tag, _ in pairs(PHOTILS.selected_tags) do - local dt_tag = dt.tags.create(tag) - dt.tags.attach(dt_tag, image) + local num_selected = #dt.gui.selection() + local job = dt.gui.create_job(_("Apply tag to image"), true) + + for i = 1, num_selected, 1 do + local image = dt.gui.selection()[i] + for tag, _ in pairs(PHOTILS.selected_tags) do + local dt_tag = dt.tags.create(tag) + dt.tags.attach(dt_tag, image) + end + + job.percent = i / num_selected + dt.print(_("Tags successfully attached to image")) end - dt.print(_("Tags successfully attached to image")) + job.valid = false end function PHOTILS.get_tags(image, with_export) + local tmp_file = df.create_tmp_file() local in_arg = df.sanitize_filename(tostring(image)) local out_arg = df.sanitize_filename(tmp_file) @@ -305,7 +314,8 @@ function PHOTILS.on_tags_clicked() dt.control.sleep(2000) end - if not PHOTILS.get_tags(images[1], true) then + with_export = dt.preferences.read(MODULE_NAME, "export_image_before_for_tags", "bool") + if not PHOTILS.get_tags(images[1], with_export) then local msg = string.format(_("%s failed, see terminal output for details"), MODULE_NAME) GUI.warning_label.label = msg GUI.stack.active = GUI.error_view @@ -435,6 +445,15 @@ dt.preferences.register(MODULE_NAME, _("if enabled, the confidence value for each tag is displayed"), true) +dt.preferences.register(MODULE_NAME, + "export_image_before_for_tags", + "bool", + _("photils: use exported image for tag request"), + _("If enabled, the image passed to photils for tag suggestion is based on the exported, already edited image. " .. + "Otherwise, the embedded thumbnail of the RAW file will be used for tag suggestion." .. + "The embedded thumbnail could speedup the tag suggestion but can fail if the RAW file is not supported."), + true) + dt.register_event("photils", "mouse-over-image-changed", PHOTILS.image_changed) From 1d10d5234fb2e33cc7322556ce30436c9a7411b3 Mon Sep 17 00:00:00 2001 From: Tobias Scheck Date: Mon, 15 Mar 2021 11:41:52 +0100 Subject: [PATCH 2/2] refactore print method --- contrib/photils.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/photils.lua b/contrib/photils.lua index 32931e7..e3e0e4b 100644 --- a/contrib/photils.lua +++ b/contrib/photils.lua @@ -237,9 +237,9 @@ function PHOTILS.attach_tags() end job.percent = i / num_selected - dt.print(_("Tags successfully attached to image")) end + dt.print(_("Tags successfully attached to image")) job.valid = false end