Merge branch 'master' into script_manager_new_ui

This commit is contained in:
wpferguson
2024-06-07 19:31:25 -04:00
committed by GitHub
77 changed files with 4036 additions and 2134 deletions

View File

@@ -31,13 +31,29 @@
local dt = require "darktable"
local du = require "lib/dtutils"
local df = require "lib/dtutils.file"
local dtsys = require "lib/dtutils.system"
du.check_min_api_version("7.0.0", "executable_manager")
local gettext = dt.gettext.gettext
dt.gettext.bindtextdomain("executable_manager", dt.configuration.config_dir .."/lua/locale/")
local function _(msg)
return gettext(msg)
end
-- return data structure for script_manager
local script_data = {}
script_data.metadata = {
name = "executable_manager",
purpose = _("manage the list of external executables used by the lua scripts"),
author = "Bill Ferguson <wpferguson@gmail.com>",
help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/tools/executable_manager"
}
script_data.destroy = nil -- function to destory the script
script_data.destroy_method = nil -- set to hide for libs since we can't destroy them commpletely yet
script_data.restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again
@@ -45,10 +61,6 @@ script_data.show = nil -- only required for libs since the destroy_method only h
local PS = dt.configuration.running_os == "windows" and "\\" or "/"
local gettext = dt.gettext
gettext.bindtextdomain("executable_manager",dt.configuration.config_dir.."/lua/locale/")
local exec_man = {} -- our own namespace
exec_man.module_installed = false
exec_man.event_registered = false
@@ -57,10 +69,6 @@ exec_man.event_registered = false
-- F U N C T I O N S
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
local function _(msg)
return gettext.dgettext("executable_manager", msg)
end
local function grep(file, pattern)
local result = {}
@@ -68,7 +76,7 @@ local function grep(file, pattern)
if dt.configuration.running_os == "windows" then
-- use find to get the matches
local command = "\\windows\\system32\\find.exe " .. "\"" .. pattern .. "\"" .. " " .. file
local f = io.popen(command)
local f = dtsys.io_popen(command)
local output = f:read("all")
f:close()
-- strip out the first line
@@ -77,7 +85,7 @@ local function grep(file, pattern)
else
-- use grep and just return the answers
local command = "grep " .. pattern .. " " .. file
local f = io.popen(command)
local f = dtsys.io_popen(command)
local output = f:read("all")
f:close()
result = du.split(output, "\n")
@@ -100,13 +108,19 @@ local function update_combobox_choices(combobox, choice_table, selected)
end
local function install_module()
local panel = "DT_UI_CONTAINER_PANEL_LEFT_BOTTOM"
local panel_pos = 600
if dt.configuration.running_os == "windows" then
panel = "DT_UI_CONTAINER_PANEL_LEFT_CENTER"
panel_pos = 100
end
if not exec_man.module_installed then
dt.register_lib(
"executable_manager", -- Module name
"executable manager", -- Visible name
true, -- expandable
false, -- resetable
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_LEFT_BOTTOM", 600}}, -- containers
{[dt.gui.views.lighttable] = {panel, panel_pos}}, -- containers
dt.new_widget("box") -- widget
{
orientation = "vertical",
@@ -142,7 +156,7 @@ local matches = grep(DARKTABLERC, "executable_paths")
-- check if we have something to manage and exit if not
if #matches == 0 then
dt.print(_("No executable paths found, exiting..."))
dt.print(_("no executable paths found, exiting..."))
return
end
@@ -167,7 +181,7 @@ for i,exec in ipairs(exec_table) do
editable = false
}
executable_path_widgets[exec] = dt.new_widget("file_chooser_button"){
title = _("select ") .. exec .. _(" executable"),
title = _(string.format("select %s executable", exec)),
value = df.get_executable_path_preference(exec),
is_directory = false,
changed_callback = function(self)
@@ -210,7 +224,7 @@ for i,exec in ipairs(exec_table) do
dt.new_widget("section_label"){label = _("reset")},
dt.new_widget("button"){
label = _("clear"),
tooltip = _("Clear path for ") .. exec,
tooltip = string.format(_("clear path for %s"), exec),
clicked_callback = function()
df.set_executable_path_preference(exec, "")
executable_path_widgets[exec].value = ""

View File

@@ -1,108 +0,0 @@
--[[
gen_18n_mo.lua - generate .mo files from .po files and put them in the correct place
Copyright (C) 2016,2018 Bill Ferguson <wpferguson@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
]]
--[[
gen_i18n_mo - generate translation files from the source and place them in the appropriate locale directory
gen_i18n_mo finds all the .po files scattered throughout the script tree, compiles them into
.mo files and places them in the correct locale directory for use by the gettext tools.
]]
local dt = require "darktable"
local du = require "lib/dtutils"
local df = require "lib/dtutils.file"
local log = require "lib/dtutils.log"
local dtsys = require "lib/dtutils.system"
du.check_min_api_version("5.0.0", "gen_I18n_mo")
local function destroy()
-- nothing to destroy
end
-- figure out the path separator
local PS = dt.configuration.running_os == "windows" and "\\" or "/"
local LUA_DIR = dt.configuration.config_dir .. PS .. "lua" .. PS
local LOCALE_DIR = dt.configuration.config_dir .. PS .. "lua" .. PS .. "locale" .. PS
-- check if we have msgfmt
local msgfmt_executable = df.check_if_bin_exists("msgfmt")
if msgfmt_executable then
-- find the .po files
local find_cmd = "find -L " .. LUA_DIR .. " -name \\*.po -print"
if dt.configuration.running_os == "windows" then
find_cmd = "dir /b/s " .. LUA_DIR .. "\\*.po"
end
local output = io.popen(find_cmd)
-- for each .po file....
for line in output:lines() do
local fname = df.get_filename(line)
-- get the language used... this depends on the file being named using
-- the convention /..../lang/LC_MESSAGES/file.po where lang is de_DE, fr_FR, etc.
local path_parts = du.split(line, PS)
local lang = path_parts[#path_parts - 2]
-- ensure there is a destination directory for them
local mkdir_cmd = "mkdir -p "
if dt.configuration.running_os == "windows" then
mkdir_cmd = "mkdir "
end
if not df.check_if_file_exists(LOCALE_DIR .. lang .. PS .. "LC_MESSAGES") then
log.msg(log.info, "Creating locale", lang)
os.execute(mkdir_cmd .. LOCALE_DIR .. lang .. PS .. "LC_MESSAGES")
end
-- generate the mo file
fname = string.gsub(fname, ".po$", ".mo")
log.msg(log.info, "Compiling translation to", fname)
local result = os.execute(msgfmt_executable .. " -o " .. LOCALE_DIR .. lang .. PS .. "LC_MESSAGES" .. PS .. fname .. " " .. line)
end
else
log.msg(log.screen, "ERROR: msgfmt executable not found. Please install or specifiy location in preferences.")
end
dt.preferences.register("executable_paths", "msgfmt", -- name
"file", -- type
'gen_i18n_mo: msgfmt location', -- label
'Install location of msgfmt. Requires restart to take effect.', -- tooltip
"msgfmt", -- default
dt.new_widget("file_chooser_button"){
title = "Select msgfmt[.exe] file",
value = "",
is_directory = false,
}
)
local script_data = {}
script_data.destroy = destroy
return script_data

View File

@@ -7,11 +7,20 @@
local dt = require "darktable"
local du = require "lib/dtutils"
local df = require "lib/dtutils.file"
local dtsys = require "lib/dtutils.system"
local log = require "lib/dtutils.log"
local libname = nil
du.check_min_api_version("3.0.0", "get_lib_manpages")
local gettext = dt.gettext.gettext
dt.gettext.bindtextdomain("get_lib_manpages", dt.configuration.config_dir .."/lua/locale/")
local function _(msg)
return gettext(msg)
end
local function destroy()
-- nothing to destroy
end
@@ -37,7 +46,7 @@ local function output_man(d)
mf:close()
if df.check_if_bin_exists("groff") then
if df.check_if_bin_exists("ps2pdf") then
os.execute("groff -man " .. fname .. " | ps2pdf - " .. fname .. ".pdf")
dtsys.os_execute("groff -man " .. fname .. " | ps2pdf - " .. fname .. ".pdf")
else
log.msg(log.error, "Missing ps2pdf. Can't generate pdf man pages.")
end
@@ -51,7 +60,7 @@ end
-- find the libraries
local output = io.popen("cd "..dt.configuration.config_dir.."/lua/lib ;find . -name \\*.lua -print | sort")
local output = dtsys.io_popen("cd "..dt.configuration.config_dir.."/lua/lib ;find . -name \\*.lua -print | sort")
-- loop through the libraries
@@ -79,6 +88,14 @@ for line in output:lines() do
end
local script_data = {}
script_data.metadata = {
name = "get_lib_manpages",
purpose = _("output the internal library documentation as man pages"),
author = "Bill Ferguson <wpferguson@gmail.com>",
help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/tools/get_lib_manpages"
}
script_data.destroy = destroy
return script_data

View File

@@ -6,9 +6,18 @@
local dt = require "darktable"
local du = require "lib/dtutils"
local dtsys = require "lib/dtutils.system"
du.check_min_api_version("3.0.0", "get_libdoc")
local gettext = dt.gettext.gettext
dt.gettext.bindtextdomain("get_libdoc", dt.configuration.config_dir .."/lua/locale/")
local function _(msg)
return gettext(msg)
end
local function destroy()
-- nothing to destroy
end
@@ -28,7 +37,7 @@ end
-- find the libraries
local output = io.popen("cd "..dt.configuration.config_dir.."/lua/lib ;find . -name \\*.lua -print | sort")
local output = dtsys.io_popen("cd "..dt.configuration.config_dir.."/lua/lib ;find . -name \\*.lua -print | sort")
-- loop through the libraries
@@ -53,6 +62,14 @@ for line in output:lines() do
end
local script_data = {}
script_data.metadata = {
name = "get_libdoc",
purpose = _("retrieve and print the documentation to the console"),
author = "Bill Ferguson <wpferguson@gmail.com>",
help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/tools/get_libdoc"
}
script_data.destroy = destroy
return script_data

View File

@@ -56,14 +56,16 @@ local dtsys = require "lib/dtutils.system"
local log = require "lib/dtutils.log"
local debug = require "darktable.debug"
local gettext = dt.gettext
-- set up translation
local gettext = dt.gettext.gettext
-- Tell gettext where to find the .mo file translating messages for a particular domain
dt.gettext.bindtextdomain("script_manager", dt.configuration.config_dir .. "/lua/locale/")
local function _(msgid)
return gettext.dgettext("script_manager", msgid)
return gettext(msgid)
end
-- api check
@@ -459,7 +461,9 @@ local function get_script_doc(script)
-- assume that the second block comment is the documentation
description = string.match(content, "%-%-%[%[.-%]%].-%-%-%[%[(.-)%]%]")
else
log.msg(log.error, "can't read from " .. script)
end
if description then
restore_log_level(old_log_level)
@@ -489,7 +493,9 @@ local function activate(script)
if status then
pref_write(script.script_name, "bool", true)
log.msg(log.screen, _(string.format("loaded %s", script.script_name)))
script.running = true
if err ~= true then
@@ -503,10 +509,10 @@ local function activate(script)
end
else
log.msg(log.screen, _(string.format("%s failed to load", script.script_name)))
log.msg(log.error, "error loading " .. script.script_name)
log.msg(log.error, "error message: " .. err)
end
else -- script is a lib and loaded but hidden and the user wants to reload
script.data.restart()
@@ -549,13 +555,16 @@ local function deactivate(script)
end
log.msg(log.info, "turned off " .. script.script_name)
log.msg(log.screen, _(string.format("%s stopped", script.name)))
else
script.running = false
log.msg(log.info, "setting " .. script.script_name .. " to not start")
log.msg(log.screen, _(string.format("%s will not start when darktable is restarted", script.name)))
end
restore_log_level(old_log_level)
@@ -652,6 +661,35 @@ local function ensure_lib_in_search_path(line)
restore_log_level(old_log_level)
end
local function ensure_lib_in_search_path(line)
local old_log_level = set_log_level(sm.log_level)
set_log_level(log.debug)
log.msg(log.debug, "line is " .. line)
if string.match(line, ds.sanitize_lua(dt.configuration.config_dir .. PS .. "lua" .. PS .. "lib")) then
log.msg(log.debug, line .. " is already in search path, returning...")
return
end
local pattern = dt.configuration.running_os == "windows" and "(.+)\\lib\\.+lua" or "(.+)/lib/.+lua"
local path = string.match(line, pattern)
log.msg(log.debug, "extracted path is " .. path)
log.msg(log.debug, "package.path is " .. package.path)
if not string.match(package.path, ds.sanitize_lua(path)) then
log.msg(log.debug, "path isn't in package.path, adding...")
package.path = package.path .. ";" .. path .. "/?.lua"
log.msg(log.debug, "new package.path is " .. package.path)
end
restore_log_level(old_log_level)
end
local function scan_scripts(script_dir)
local old_log_level = set_log_level(sm.log_level)
@@ -695,7 +733,9 @@ local function update_scripts()
local git = sm.executables.git
if not git then
log.msg(log.screen, _("ERROR: git not found. Install or specify the location of the git executable."))
return
end
@@ -1404,7 +1444,6 @@ local page_back = "<"
local page_forward = ">"
sm.widgets.page_status = dt.new_widget("label"){label = _("page:")}
sm.widgets.page_back = dt.new_widget("button"){
label = page_back,
clicked_callback = function(this)
@@ -1432,6 +1471,7 @@ sm.widgets.page_control = dt.new_widget("box"){
sm.widgets.scripts = dt.new_widget("box"){
orientation = vertical,
dt.new_widget("section_label"){label = _(" ")},
dt.new_widget("label"){label = " "},
dt.new_widget("label"){label = _("scripts")},