Skip to content

Commit 7a3a9ba

Browse files
authored
Removed preferences for exe
The GUI is now made of a stack which has two boxes in it. One box contains all the normal GUI elements, the other contains a file chooser button and a normal button to call an update routine. This box is only displayed if an issue is found. I decided to track the install status via a preference boolean, rather than calling df_check_if_bin_exists at startup every time. I do this because on my windows PC I was starting to get slow startups with too many scripts installed and many many flashing CMD windows at startup as well, which was a nuisance.
1 parent 5d3910d commit 7a3a9ba

File tree

1 file changed

+61
-17
lines changed

1 file changed

+61
-17
lines changed

contrib/HDRMerge.lua

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ local mod = 'module_HDRMerge'
5151
local os_path_seperator = '/'
5252
if dt.configuration.running_os == 'windows' then os_path_seperator = '\\' end
5353

54-
dt.preferences.register("executable_paths", "HDRMerge", -- name
55-
"file", -- type
56-
'HDRMerge: binary location', -- label
57-
'Install location of HDRMerge. Requires restart to take effect.', -- tooltip
58-
"HDRMerge" -- default
59-
)
6054
local temp
6155
local HDRM = { --HDRMerge Program Table
6256
name = 'HDRMerge',
@@ -84,7 +78,12 @@ local GUI = { --GUI Elements Table
8478
copy_tags ={},
8579
add_tags ={}
8680
},
87-
run = {}
81+
run = {},
82+
stack = {},
83+
options = {},
84+
exes = {},
85+
exe_chooser = {},
86+
exe_update = {},
8887
}
8988

9089
--Detect User Styles--
@@ -138,12 +137,29 @@ local function PreCall(prog_tbl) --looks to see if this is the first call, if so
138137
prog.bin = df.check_if_bin_exists(prog.name)
139138
if not prog.bin then
140139
prog.install_error = true
140+
dt.preferences.write(mod, 'bin_exists', 'bool', false)
141141
else
142142
prog.bin = CleanSpaces(prog.bin)
143143
end
144144
prog.first_run = false
145145
end
146146
end
147+
if not dt.preferences.read(mod, 'bin_exists', 'bool') then GUI.stack.active = 2 end
148+
end
149+
150+
local function ExeUpdate(prog_tbl)
151+
dt.preferences.write(mod, 'bin_exists', 'bool', true)
152+
for _,prog in pairs(prog_tbl) do
153+
prog.bin = df.check_if_bin_exists(prog.name)
154+
if not prog.bin then
155+
prog.install_error = true
156+
dt.preferences.write(mod, 'bin_exists', 'bool', false)
157+
else
158+
prog.bin = CleanSpaces(prog.bin)
159+
end
160+
prog.first_run = false
161+
end
162+
if dt.preferences.read(mod, 'bin_exists', 'bool') then GUI.stack.active = 1 end
147163
end
148164

149165
local function UpdateActivePreference() --sliders & entry boxes do not have a click/changed callback, so their values must be saved to the active preference
@@ -340,6 +356,43 @@ GUI.run = dt.new_widget("button"){
340356
tooltip ='run HDRMerge with the above specified settings',
341357
clicked_callback = function() main() end
342358
}
359+
GUI.exe_chooser = dt.new_widget('file_chooser_button'){
360+
title = "Select HDRmerge executable",
361+
value = df.get_executable_path_preference(HDRM.name),
362+
is_directory = false
363+
}
364+
GUI.exe_update = dt.new_widget('button'){
365+
label = 'update',
366+
tooltip ='update the binary path with current value',
367+
clicked_callback = function() ExeUpdate({HDRM}) end
368+
}
369+
GUI.options = dt.new_widget('box'){
370+
orientation = 'vertical',
371+
lbl_hdr,
372+
GUI.HDR.bps,
373+
GUI.HDR.size,
374+
GUI.HDR.batch,
375+
GUI.HDR.gap,
376+
lbl_import,
377+
GUI.Target.style,
378+
GUI.Target.copy_tags,
379+
GUI.Target.add_tags,
380+
GUI.run
381+
}
382+
GUI.exes = dt.new_widget('box'){
383+
orientation = 'vertical',
384+
GUI.exe_chooser,
385+
GUI.exe_update
386+
}
387+
GUI.stack = dt.new_widget('stack'){
388+
active = 1,
389+
GUI.options,
390+
GUI.exes
391+
}
392+
if not dt.preferences.read(mod, 'bin_exists', 'bool') then
393+
GUI.stack.active = 2
394+
end
395+
343396
dt.register_lib( -- register HDRMerge module
344397
"HDRMerge_Lib", -- Module name
345398
"HDRMerge", -- name
@@ -348,15 +401,6 @@ dt.register_lib( -- register HDRMerge module
348401
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 99}}, -- containers
349402
dt.new_widget("box"){
350403
orientation = "vertical",
351-
lbl_hdr,
352-
GUI.HDR.bps,
353-
GUI.HDR.size,
354-
GUI.HDR.batch,
355-
GUI.HDR.gap,
356-
lbl_import,
357-
GUI.Target.style,
358-
GUI.Target.copy_tags,
359-
GUI.Target.add_tags,
360-
GUI.run
404+
GUI.stack
361405
}
362406
)

0 commit comments

Comments
 (0)