Skip to content

Commit 771e03c

Browse files
authored
Merge pull request darktable-org#279 from wpferguson/278_fix_register_lib_hang
278 fix register lib hang
2 parents 7d9b8db + 912ae93 commit 771e03c

19 files changed

+767
-271
lines changed

contrib/AutoGrouper.lua

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ local function _(msgid)
4545
return gettext.dgettext("AutoGrouper", msgid)
4646
end
4747

48+
local Ag = {}
49+
Ag.module_installed = false
50+
Ag.event_registered = false
51+
52+
local GUI = {
53+
gap = {},
54+
selected = {},
55+
collection = {}
56+
}
57+
58+
4859
local function InRange(test, low, high) --tests if test value is within range of low and high (inclusive)
4960
if test >= low and test <= high then
5061
return true
@@ -111,12 +122,26 @@ local function main(on_collection)
111122
end
112123
end
113124

125+
local function install_module()
126+
if not Ag.module_installed then
127+
dt.register_lib(
128+
'AutoGroup_Lib', -- Module name
129+
_('auto group'), -- name
130+
true, -- expandable
131+
true, -- resetable
132+
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 99}}, -- containers
133+
dt.new_widget("box"){
134+
orientation = "vertical",
135+
GUI.gap,
136+
GUI.selected,
137+
GUI.collection
138+
}
139+
)
140+
Ag.module_installed = true
141+
end
142+
end
143+
114144
-- GUI --
115-
GUI = {
116-
gap = {},
117-
selected = {},
118-
collection = {}
119-
}
120145
temp = dt.preferences.read(MOD, 'active_gap', 'integer')
121146
if not InRange(temp, 1, 86400) then temp = 3 end
122147
GUI.gap = dt.new_widget('slider'){
@@ -143,16 +168,20 @@ GUI.collection = dt.new_widget("button"){
143168
tooltip =_('auto group the entire collection'),
144169
clicked_callback = function() main(true) end
145170
}
146-
dt.register_lib(
147-
'AutoGroup_Lib', -- Module name
148-
_('auto group'), -- name
149-
true, -- expandable
150-
true, -- resetable
151-
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 99}}, -- containers
152-
dt.new_widget("box"){
153-
orientation = "vertical",
154-
GUI.gap,
155-
GUI.selected,
156-
GUI.collection
157-
}
158-
)
171+
172+
if dt.gui.current_view().name == "lighttable" then
173+
install_module()
174+
else
175+
if not Ag.event_registered then
176+
dt.register_event(
177+
"view-changed",
178+
function(event, old_view, new_view)
179+
if new_view.name == "lighttable" and old_view.name == "darkroom" then
180+
install_module()
181+
end
182+
end
183+
)
184+
Ag.event_registered = true
185+
end
186+
end
187+

contrib/HDRMerge.lua

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ local GUI = { --GUI Elements Table
9494
}
9595
}
9696

97+
HDRM.module_installed = false
98+
HDRM.event_registered = false
99+
100+
97101
--Detect User Styles--
98102
local styles = dt.styles
99103
local styles_count = 1 -- 'none' = 1
@@ -264,6 +268,23 @@ local function main()
264268

265269
end
266270

271+
local function install_module()
272+
if not HDRM.module_installed then
273+
dt.register_lib( -- register HDRMerge module
274+
'HDRMerge_Lib', -- Module name
275+
_('HDRMerge'), -- name
276+
true, -- expandable
277+
true, -- resetable
278+
{[dt.gui.views.lighttable] = {'DT_UI_CONTAINER_PANEL_RIGHT_CENTER', 99}}, -- containers
279+
dt.new_widget('box'){
280+
orientation = 'vertical',
281+
GUI.stack
282+
}
283+
)
284+
HDRM.module_installed = true
285+
end
286+
end
287+
267288
-- GUI Elements --
268289
local lbl_hdr = dt.new_widget('section_label'){
269290
label = _('HDRMerge options')
@@ -411,14 +432,18 @@ else
411432
GUI.stack.active = 2
412433
end
413434

414-
dt.register_lib( -- register HDRMerge module
415-
'HDRMerge_Lib', -- Module name
416-
_('HDRMerge'), -- name
417-
true, -- expandable
418-
true, -- resetable
419-
{[dt.gui.views.lighttable] = {'DT_UI_CONTAINER_PANEL_RIGHT_CENTER', 99}}, -- containers
420-
dt.new_widget('box'){
421-
orientation = 'vertical',
422-
GUI.stack
423-
}
424-
)
435+
if dt.gui.current_view().name == "lighttable" then
436+
install_module()
437+
else
438+
if not HDRM.event_registered then
439+
dt.register_event(
440+
"view-changed",
441+
function(event, old_view, new_view)
442+
if new_view.name == "lighttable" and old_view.name == "darkroom" then
443+
install_module()
444+
end
445+
end
446+
)
447+
HDRM.event_registered = true
448+
end
449+
end

contrib/LabelsToTags.lua

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ du.check_min_api_version("3.0.0", "LabelsToTags")
5555
-- Lua 5.3 no longer has "unpack" but "table.unpack"
5656
unpack = unpack or table.unpack
5757

58+
local ltt = {}
59+
ltt.module_installed = false
60+
ltt.event_registered = false
61+
5862
local LIB_ID = "LabelsToTags"
5963

6064
-- Helper functions: BEGIN
@@ -184,7 +188,7 @@ local function doTagging(selfC)
184188
job.valid = false
185189
end
186190

187-
local my_widget = darktable.new_widget("box") {
191+
ltt.my_widget = darktable.new_widget("box") {
188192
orientation = "vertical",
189193
mappingComboBox,
190194
darktable.new_widget("button") {
@@ -217,6 +221,15 @@ darktable.register_tag_mapping = function(name, mapping)
217221
mappingComboBox.reset_callback(mappingComboBox)
218222
end
219223

224+
local function install_module()
225+
if not ltt.module_installed then
226+
darktable.register_lib(LIB_ID,"labels to tags",true,true,{
227+
[darktable.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER",20},
228+
},ltt.my_widget,nil,nil)
229+
ltt.module_installed = true
230+
end
231+
end
232+
220233
--[[
221234
darktable.register_tag_mapping("Example",
222235
{ ["+----*"] = { "Red", "Only red" },
@@ -229,6 +242,19 @@ darktable.register_tag_mapping("Example",
229242
["*****R"] = { "Rejected" } })
230243
]]
231244

232-
darktable.register_lib(LIB_ID,"labels to tags",true,true,{
233-
[darktable.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER",20},
234-
},my_widget,nil,nil)
245+
if darktable.gui.current_view().name == "lighttable" then
246+
install_module()
247+
else
248+
if not ltt.event_registered then
249+
darktable.register_event(
250+
"view-changed",
251+
function(event, old_view, new_view)
252+
if new_view.name == "lighttable" and old_view.name == "darkroom" then
253+
install_module()
254+
end
255+
end
256+
)
257+
ltt.event_registered = true
258+
end
259+
end
260+

contrib/copy_attach_detach_tags.lua

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ local function _(msgid)
5151
return gettext.dgettext("copy_attach_detach_tags", msgid)
5252
end
5353

54+
local cadt = {}
55+
cadt.module_installed = false
56+
cadt.event_registered = false
57+
cadt.widget_table = {}
58+
5459

5560
local image_tags = {}
5661

@@ -156,6 +161,26 @@ local function replace_tags()
156161
dt.print(_('Tags replaced'))
157162
end
158163

164+
local function install_module()
165+
if not cadt.module_installed then
166+
dt.register_lib("tagging_addon","Tagging addon",true,true,{
167+
[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER",500}
168+
},
169+
dt.new_widget("box") {
170+
-- orientation = "vertical",
171+
reset_callback = function()
172+
taglist_label.label = ""
173+
image_tags = {}
174+
end,
175+
table.unpack(cadt.widget_table),
176+
},
177+
nil,
178+
nil
179+
)
180+
cadt.module_installed = true
181+
end
182+
end
183+
159184
-- create modul Tagging addons
160185
taglist_label.reset_callback = mcopy_tags
161186

@@ -190,31 +215,31 @@ local box2 = dt.new_widget("box"){
190215
local sep = dt.new_widget("separator"){}
191216

192217
-- pack elements into widget table for a nicer layout
193-
local widget_table = {}
194218

195-
widget_table[1] = box1
196-
widget_table[#widget_table+1] = box2
219+
cadt.widget_table[1] = box1
220+
cadt.widget_table[#cadt.widget_table+1] = box2
197221

198-
widget_table[#widget_table+1] = sep
199-
widget_table[#widget_table+1] = taglabel
200-
widget_table[#widget_table+1] = taglist_label
222+
cadt.widget_table[#cadt.widget_table+1] = sep
223+
cadt.widget_table[#cadt.widget_table+1] = taglabel
224+
cadt.widget_table[#cadt.widget_table+1] = taglist_label
201225

202226

203227
-- create modul
204-
dt.register_lib("tagging_addon","Tagging addon",true,true,{
205-
[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER",500}
206-
},
207-
dt.new_widget("box") {
208-
-- orientation = "vertical",
209-
reset_callback = function()
210-
taglist_label.label = ""
211-
image_tags = {}
212-
end,
213-
table.unpack(widget_table),
214-
},
215-
nil,
216-
nil
217-
)
228+
if dt.gui.current_view().name == "lighttable" then
229+
install_module()
230+
else
231+
if not cadt.event_registered then
232+
dt.register_event(
233+
"view-changed",
234+
function(event, old_view, new_view)
235+
if new_view.name == "lighttable" and old_view.name == "darkroom" then
236+
install_module()
237+
end
238+
end
239+
)
240+
cadt.event_registered = true
241+
end
242+
end
218243

219244

220245
-- shortcut for copy

contrib/exportLUT.lua

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ end
4141

4242
du.check_min_api_version("5.0.0", "exportLUT")
4343

44+
local eL = {}
45+
eL.module_installed = false
46+
eL.event_registered = false
47+
eL.widgets = {}
48+
4449
-- Thanks Kevin Ertel for this bit
4550
local os_path_seperator = '/'
4651
if dt.configuration.running_os == 'windows' then os_path_seperator = '\\' end
@@ -119,27 +124,51 @@ local function export_luts()
119124
end
120125
end
121126

127+
local function install_module()
128+
if not eL.module_installed then
129+
dt.register_lib(
130+
_("export haldclut"),
131+
_("export haldclut"),
132+
true,
133+
false,
134+
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}},
135+
dt.new_widget("box")
136+
{
137+
orientation = "vertical",
138+
table.unpack(eL.widgets),
139+
},
140+
nil,
141+
nil
142+
)
143+
eL.module_installed = true
144+
end
145+
end
146+
122147
local export_button = dt.new_widget("button"){
123148
label = _("export"),
124149
clicked_callback = export_luts
125150
}
126151

127-
dt.register_lib(
128-
_("export haldclut"),
129-
_("export haldclut"),
130-
true,
131-
false,
132-
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}},
133-
dt.new_widget("box")
134-
{
135-
orientation = "vertical",
136-
identity_label,
137-
file_chooser_button,
138-
output_label,
139-
export_chooser_button,
140-
warning_label,
141-
export_button
142-
},
143-
nil,
144-
nil
145-
)
152+
table.insert(eL.widgets, identity_label)
153+
table.insert(eL.widgets, file_chooser_button)
154+
table.insert(eL.widgets, output_label)
155+
table.insert(eL.widgets, export_chooser_button)
156+
table.insert(eL.widgets, warning_label)
157+
table.insert(eL.widgets, export_button)
158+
159+
if dt.gui.current_view().name == "lighttable" then
160+
install_module()
161+
else
162+
if not eL.event_registered then
163+
dt.register_event(
164+
"view-changed",
165+
function(event, old_view, new_view)
166+
if new_view.name == "lighttable" and old_view.name == "darkroom" then
167+
install_module()
168+
end
169+
end
170+
)
171+
eL.event_registered = true
172+
end
173+
end
174+

0 commit comments

Comments
 (0)