From 138b23674a2b428c2440f8674af4b20890f1be97 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sun, 9 Aug 2020 00:36:43 -0400 Subject: [PATCH] Added check to ensure we are in lighttable view prior to callling darktable.register_lib. If darktable was invoked in single image (darkroom) mode, then an event handler is registered to detect the change from darkroom mode to lighttable mode so that we can then call darktable.register_lib. --- contrib/photils.lua | 53 +++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/contrib/photils.lua b/contrib/photils.lua index 1c72f4b..cc41b34 100644 --- a/contrib/photils.lua +++ b/contrib/photils.lua @@ -91,7 +91,13 @@ local PHOTILS = { per_page = 10, selected_tags = {}, in_pagination = false, - tagged_image = "" + tagged_image = "", + module_installed = false, + event_registered = false, + plugin_display_views = { + [dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}, + [dt.gui.views.darkroom] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER", 100} + }, } local GUI = { @@ -358,6 +364,21 @@ function PHOTILS.on_reset(with_view) GUI.attach_button.sensitive = false end +local function install_module() + if not PHOTILS.module_installed then + dt.register_lib(MODULE_NAME, + "photils autotagger", + true, + true, + PHOTILS.plugin_display_views, + GUI.container, + nil, + nil + ) + PHOTILS.module_installed = true + end +end + -- add a fix number of buttons for _ = 1, PHOTILS.per_page, 1 do local btn_tag = dt.new_widget("check_button") { @@ -402,10 +423,6 @@ table.insert(GUI.container, GUI.stack) GUI.stack.active = 1 -local plugin_display_views = { - [dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}, - [dt.gui.views.darkroom] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER", 100} -} -- uses photils: prefix because script settings are all together and not seperated by script @@ -417,12 +434,20 @@ dt.preferences.register(MODULE_NAME, true) dt.register_event("mouse-over-image-changed",PHOTILS.image_changed) -dt.register_lib(MODULE_NAME, - "photils autotagger", - true, - true, - plugin_display_views, - GUI.container, - nil, - nil -) + +if dt.gui.current_view().name == "lighttable" then + install_module() +else + if not PHOTILS.event_registered then + dt.register_event( + "view-changed", + function(event, old_view, new_view) + if new_view.name == "lighttable" and old_view.name == "darkroom" then + install_module() + end + end + ) + PHOTILS.event_registered = true + end +end +