Merge pull request #330 from scheckmedia/master

photils plugin
This commit is contained in:
supertobi
2021-03-15 13:36:04 +01:00
committed by GitHub

View File

@@ -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
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)