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.

This commit is contained in:
Bill Ferguson
2020-08-08 23:21:54 -04:00
parent cc4f1d7251
commit d05536bed4

View File

@@ -45,6 +45,17 @@ local function _(msgid)
return gettext.dgettext("AutoGrouper", msgid) return gettext.dgettext("AutoGrouper", msgid)
end end
local Ag = {}
Ag.module_installed = false
Ag.event_registered = false
local GUI = {
gap = {},
selected = {},
collection = {}
}
local function InRange(test, low, high) --tests if test value is within range of low and high (inclusive) local function InRange(test, low, high) --tests if test value is within range of low and high (inclusive)
if test >= low and test <= high then if test >= low and test <= high then
return true return true
@@ -111,12 +122,26 @@ local function main(on_collection)
end end
end end
local function install_module()
if not Ag.module_installed then
dt.register_lib(
'AutoGroup_Lib', -- Module name
_('auto group'), -- name
true, -- expandable
true, -- resetable
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 99}}, -- containers
dt.new_widget("box"){
orientation = "vertical",
GUI.gap,
GUI.selected,
GUI.collection
}
)
Ag.module_installed = true
end
end
-- GUI -- -- GUI --
GUI = {
gap = {},
selected = {},
collection = {}
}
temp = dt.preferences.read(MOD, 'active_gap', 'integer') temp = dt.preferences.read(MOD, 'active_gap', 'integer')
if not InRange(temp, 1, 86400) then temp = 3 end if not InRange(temp, 1, 86400) then temp = 3 end
GUI.gap = dt.new_widget('slider'){ GUI.gap = dt.new_widget('slider'){
@@ -143,16 +168,20 @@ GUI.collection = dt.new_widget("button"){
tooltip =_('auto group the entire collection'), tooltip =_('auto group the entire collection'),
clicked_callback = function() main(true) end clicked_callback = function() main(true) end
} }
dt.register_lib(
'AutoGroup_Lib', -- Module name if dt.gui.current_view().name == "lighttable" then
_('auto group'), -- name install_module()
true, -- expandable else
true, -- resetable if not Ag.event_registered then
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 99}}, -- containers dt.register_event(
dt.new_widget("box"){ "view-changed",
orientation = "vertical", function(event, old_view, new_view)
GUI.gap, if new_view.name == "lighttable" and old_view.name == "darkroom" then
GUI.selected, install_module()
GUI.collection end
} end
) )
Ag.event_registered = true
end
end