Add reset callback to face recognition widget and show the default values in the GUI.

This commit is contained in:
Piter Dias
2020-01-27 17:44:49 -03:00
parent 4708110804
commit e96b78b175

View File

@@ -69,16 +69,9 @@ end
-- preferences
if not dt.preferences.read(MODULE, "initialized", "bool") then
dt.preferences.write(MODULE, "unknown_tag", "string", "unknown_person")
dt.preferences.write(MODULE, "ignore_tags", "string", "")
dt.preferences.write(MODULE, "tolerance", "float", 0.6)
dt.preferences.write(MODULE, "num_cores", "integer", 0)
dt.preferences.write(MODULE, "known_image_path", "directory", dt.configuration.config_dir .. "/face_recognition")
dt.preferences.write(MODULE, "export_format", "integer", 1)
dt.preferences.write(MODULE, "max_width", "integer", 1000)
dt.preferences.write(MODULE, "max_height", "integer", 1000)
reset_preferences()
save_preferences()
dt.preferences.write(MODULE, "initialized", "bool", true)
dt.preferences.write(MODULE, "no_persons_found_tag", "string", "no_persons_found")
end
local function build_image_table(images)
@@ -155,14 +148,29 @@ end
local function save_preferences()
dt.preferences.write(MODULE, "unknown_tag", "string", fc.unknown_tag.text)
dt.preferences.write(MODULE, "ignore_tags", "string", fc.ignore_tags.text)
dt.preferences.write(MODULE, "max_width", "integer", tonumber(fc.width.text))
dt.preferences.write(MODULE, "max_height", "integer", tonumber(fc.height.text))
dt.preferences.write(MODULE, "num_cores", "integer", fc.num_cores.value)
dt.preferences.write(MODULE, "no_persons_found_tag", "string", fc.no_persons_found_tag.text)
dt.preferences.write(MODULE, "ignore_tags", "string", fc.ignore_tags.text)
dt.preferences.write(MODULE, "known_image_path", "directory", fc.known_image_path.value)
local val = fc.tolerance.value
val = string.gsub(tostring(val), ",", ".")
dt.preferences.write(MODULE, "tolerance", "float", tonumber(val))
dt.preferences.write(MODULE, "num_cores", "integer", fc.num_cores.value)
dt.preferences.write(MODULE, "export_format", "integer", fc.export_format.selected)
dt.preferences.write(MODULE, "max_width", "integer", tonumber(fc.width.text))
dt.preferences.write(MODULE, "max_height", "integer", tonumber(fc.height.text))
end
local function reset_preferences()
fc.unknown_tag.text = "unknown_person"
fc.no_persons_found_tag.text = "no_persons_found"
fc.ignore_tags.text = ""
fc.known_image_path.value = dt.configuration.config_dir .. "/face_recognition"
fc.tolerance.value = 0.6
fc.num_cores.value = -1
fc.export_format.selected = 1
fc.width.text = 1000
fc.height.text = 1000
save_preferences()
end
-- Check if image has ignored tag attached
@@ -432,7 +440,10 @@ table.insert(widgets, fc.execute)
fc.widget = dt.new_widget("box"){
orientation = vertical,
table.unpack(widgets)
reset_callback = function(this)
reset_preferences()
end,
table.unpack(widgets),
}
--fc.tolerance.value = dt.preferences.read(MODULE, "tolerance", "float")
@@ -444,7 +455,7 @@ dt.register_lib(
"face_recognition", -- Module name
_("face recognition"), -- Visible name
true, -- expandable
false, -- resetable
true, -- resetable
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 300}}, -- containers
fc.widget,
nil,-- view_enter