From fe942100a40691d3b2250b5125b9984e3231dca5 Mon Sep 17 00:00:00 2001 From: Andy Chien Date: Fri, 23 Feb 2018 10:07:45 -0800 Subject: [PATCH 1/3] hugin plugin improvements * added preference requiring user to specify the paths for hugin, hugin_executor and pto_gen needed for this plguin * added preference to allow user to choose to launch hugin in GUI mode * minor fix to the way files are handled; due to some versions of hugin_executor not writing out to the path specified in --prefix, assume we are working in the tmp directory and then move the file afterwards --- contrib/hugin.lua | 105 +++++++++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 39 deletions(-) diff --git a/contrib/hugin.lua b/contrib/hugin.lua index 9008b15..477e506 100644 --- a/contrib/hugin.lua +++ b/contrib/hugin.lua @@ -28,7 +28,9 @@ ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT * hugin USAGE -* require this file from your main luarc config file. +* require this file from your main luarc config file +* set the hugin tool paths in preferences +* if hugin gui mode is used, save the final result in the tmp directory with the first file name and _pano as suffix for the image to be automatically imported to DT afterwards This plugin will add a new storage option and calls hugin after export. ]] @@ -37,6 +39,7 @@ local dt = require "darktable" local df = require "lib/dtutils.file" require "official/yield" local gettext = dt.gettext +local namespace = 'module_hugin' -- works with darktable API version from 2.0.0 to 5.0.0 dt.configuration.check_version(...,{2,0,0},{3,0,0},{4,0,0},{5,0,0}) @@ -45,28 +48,33 @@ dt.configuration.check_version(...,{2,0,0},{3,0,0},{4,0,0},{5,0,0}) gettext.bindtextdomain("hugin",dt.configuration.config_dir.."/lua/locale/") local function _(msgid) - return gettext.dgettext("hugin", msgid) + return gettext.dgettext("hugin", msgid) end local function show_status(storage, image, format, filename, number, total, high_quality, extra_data) - dt.print("Export to Hugin "..tostring(number).."/"..tostring(total)) + dt.print("exporting to Hugin: "..tostring(number).."/"..tostring(total)) end local function create_panorama(storage, image_table, extra_data) --finalize - if not df.check_if_bin_exists("hugin") then - dt.print_error(_("hugin not found")) - return - end - -- Since Hugin 2015.0.0 hugin provides a command line tool to start the assistant -- http://wiki.panotools.org/Hugin_executor -- We need pto_gen to create pto file for hugin_executor -- http://hugin.sourceforge.net/docs/manual/Pto_gen.html - local hugin_executor = false - if (df.check_if_bin_exists("hugin_executor") and df.check_if_bin_exists("pto_gen")) then - hugin_executor = true + local hugin = '"'..dt.preferences.read(namespace, "hugin", "file")..'"' + local hugin_executor = '"'..dt.preferences.read(namespace, "hugin_executor", "file")..'"' + local pto_gen = '"'..dt.preferences.read(namespace, "pto_gen", "file")..'"' + local user_prefer_gui = dt.preferences.read(namespace, "hugin_prefer_gui", "bool") + + local cmd_line_available = false + if df.check_if_bin_exists(hugin_executor) and df.check_if_bin_exists(pto_gen) then + cmd_line_available = true + end + + local gui_available = false + if df.check_if_bin_exists(hugin) then + gui_available = true end -- list of exported images @@ -76,58 +84,77 @@ local function create_panorama(storage, image_table, extra_data) --finalize -- reset and create image list img_list = "" for k,v in pairs(image_table) do - img_list = img_list ..v.. " " - table.insert(img_set, k) + img_list = img_list..v..' ' + table.insert(img_set, k) end - -- use first file as basename + -- use first file as basename for output file table.sort(img_set, function(a,b) return a.filename Date: Mon, 5 Mar 2018 09:31:34 -0800 Subject: [PATCH 2/3] * updated to work with new dtutils_file * added checkbox to allow user to launch hugin in gui mode * changed the logic so hugin will write temp files to tmp directory and then move the final result to the directory of original source files. this improves speed when original source files are on network mapped drive * added some additional error messages --- contrib/hugin.lua | 72 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/contrib/hugin.lua b/contrib/hugin.lua index 477e506..df36796 100644 --- a/contrib/hugin.lua +++ b/contrib/hugin.lua @@ -29,7 +29,7 @@ ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT USAGE * require this file from your main luarc config file -* set the hugin tool paths in preferences +* set the hugin tool paths (on some platforms) * if hugin gui mode is used, save the final result in the tmp directory with the first file name and _pano as suffix for the image to be automatically imported to DT afterwards This plugin will add a new storage option and calls hugin after export. @@ -39,7 +39,13 @@ local dt = require "darktable" local df = require "lib/dtutils.file" require "official/yield" local gettext = dt.gettext + local namespace = 'module_hugin' +local user_pref_str = 'prefer_gui' +local user_prefer_gui = dt.preferences.read(namespace, user_pref_str, "bool") +local hugin_widget = nil +local exec_widget = nil +local executable_table = {"hugin", "hugin_executor", "pto_gen"} -- works with darktable API version from 2.0.0 to 5.0.0 dt.configuration.check_version(...,{2,0,0},{3,0,0},{4,0,0},{5,0,0}) @@ -51,9 +57,14 @@ local function _(msgid) return gettext.dgettext("hugin", msgid) end +local function user_preference_changed(widget) + user_prefer_gui = widget.value + dt.preferences.write(namespace, user_pref_str, "bool", user_prefer_gui) +end + local function show_status(storage, image, format, filename, number, total, high_quality, extra_data) - dt.print("exporting to Hugin: "..tostring(number).."/"..tostring(total)) + dt.print("exporting to hugin: "..tostring(number).."/"..tostring(total)) end local function create_panorama(storage, image_table, extra_data) --finalize @@ -62,19 +73,21 @@ local function create_panorama(storage, image_table, extra_data) --finalize -- We need pto_gen to create pto file for hugin_executor -- http://hugin.sourceforge.net/docs/manual/Pto_gen.html - local hugin = '"'..dt.preferences.read(namespace, "hugin", "file")..'"' - local hugin_executor = '"'..dt.preferences.read(namespace, "hugin_executor", "file")..'"' - local pto_gen = '"'..dt.preferences.read(namespace, "pto_gen", "file")..'"' - local user_prefer_gui = dt.preferences.read(namespace, "hugin_prefer_gui", "bool") - - local cmd_line_available = false - if df.check_if_bin_exists(hugin_executor) and df.check_if_bin_exists(pto_gen) then - cmd_line_available = true - end + local hugin = df.check_if_bin_exists("hugin") + local hugin_executor = df.check_if_bin_exists("hugin_executor") + local pto_gen = df.check_if_bin_exists("pto_gen") local gui_available = false - if df.check_if_bin_exists(hugin) then + if hugin then gui_available = true + else + dt.print(_("hugin is not found, did you set the path?")) + return + end + + local cmd_line_available = false + if hugin_executor and pto_gen then + cmd_line_available = true end -- list of exported images @@ -95,6 +108,11 @@ local function create_panorama(storage, image_table, extra_data) --finalize first_file = k break end + if first_file == nil then + dt.print("no file selected") + return + end + local pto_path = dt.configuration.tmp_dir..'/project.pto' local filepath = df.split_filepath(first_file.filename) local tmp_filename = filepath['basename'].."_pano.tif" @@ -124,16 +142,16 @@ local function create_panorama(storage, image_table, extra_data) --finalize if (user_prefer_gui) then dt.print(_("launching hugin")) else - dt.print(_("unable to find command line tools, launching hugin") + dt.print(_("unable to find command line tools, launching hugin")) end huginStartCommand = hugin..' '..img_list else - dt.print(_("hugin isn't available, please set the paths in preferences.")) + dt.print(_("hugin isn't available.")) end if not (huginStartCommand==nil) then if not dt.control.execute(huginStartCommand) then - dt.print(_("command hugin failed ...")) + dt.print(_("hugin failed ...")) else if df.check_if_file_exists(src_path) then df.file_move(src_path, dst_path) @@ -150,11 +168,23 @@ local function create_panorama(storage, image_table, extra_data) --finalize end -- Register -dt.register_storage(namespace, _("hugin panorama"), show_status, create_panorama) -dt.preferences.register(namespace, "pto_gen", "file", _("pto_gen location"), "choose the pto_gen executable.", "/usr/bin/pto_gen") -dt.preferences.register(namespace, "hugin_executor", "file", _("hugin_executor location"), "choose the hugin_executor executable.", "/usr/bin/hugin_executor") -dt.preferences.register(namespace, "hugin", "file", _("hugin location"), "choose the hugin executable", "/usr/bin/hugin") -dt.preferences.register(namespace, "hugin_prefer_gui", "bool", _("prefer hugin gui over command line"), "always launches hugin gui instead of automated from command line.", false) +if dt.configuration.running_os ~= "linux" then + exec_widget = df.executable_path_widget(executable_table) +end + +hugin_widget = dt.new_widget("box") { + orientation = "vertical", + dt.new_widget("check_button") + { + label = _(" launch hugin gui"), + value = user_prefer_gui, + tooltip = _('launch hugin in gui mode'), + clicked_callback = user_preference_changed + }, + exec_widget +} + +dt.register_storage(namespace, _("hugin panorama"), show_status, create_panorama, nil, nil, hugin_widget) -- --- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua +-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua \ No newline at end of file From 44081b772f2a69879d4b966b8b4106b2dc9c7e76 Mon Sep 17 00:00:00 2001 From: Andy Chien Date: Mon, 19 Mar 2018 06:51:30 -0700 Subject: [PATCH 3/3] fixed version requirement due to updates to darktable.configuration.running_os --- contrib/hugin.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/hugin.lua b/contrib/hugin.lua index df36796..c8106eb 100644 --- a/contrib/hugin.lua +++ b/contrib/hugin.lua @@ -48,7 +48,7 @@ local exec_widget = nil local executable_table = {"hugin", "hugin_executor", "pto_gen"} -- works with darktable API version from 2.0.0 to 5.0.0 -dt.configuration.check_version(...,{2,0,0},{3,0,0},{4,0,0},{5,0,0}) +dt.configuration.check_version(...,{5,0,0}) -- Tell gettext where to find the .mo file translating messages for a particular domain gettext.bindtextdomain("hugin",dt.configuration.config_dir.."/lua/locale/")