Skip to content

Instantly share code, notes, and snippets.

@rds13
Created February 20, 2023 20:33
Show Gist options
  • Save rds13/15675bd692133017d88cb18479abe40d to your computer and use it in GitHub Desktop.
Save rds13/15675bd692133017d88cb18479abe40d to your computer and use it in GitHub Desktop.
--[[
This file is part of darktable,
Copyright 2023 by Romuald du Song.
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/>.
]]
--[[
darktable dummy export script
ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT
WARNING
This script is only tested with Apple macOS
USAGE
* require this script from your main Lua file
LICENSE
GPLv2
]]
local dt = require "darktable"
local du = require "lib/dtutils"
local df = require "lib/dtutils.file"
local ds = require "lib/dtutils.string"
local dsys = require "lib/dtutils.system"
local log = require "lib/dtutils.log"
local PS = dt.configuration.running_os == "windows" and "\\" or "/"
local MODULE_NAME = "dummy"
du.check_min_api_version("7.0.0", MODULE_NAME)
-- return data structure for script_manager
local script_data = {}
script_data.destroy = nil -- function to destroy the script
script_data.destroy_method = nil -- set to hide for libs since we can't destroy them completely yet, otherwise leave as nil
script_data.restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again
-- namespace
local wa = {}
local function get_script_path()
if not wa.source_path then
local source = debug.getinfo(1).source
source = string.match(source, "@.-(.*)$")
local source_path = df.get_path(source)
if (string.sub(source_path,1,2) == ".") then
source_path = dt.configuration.config_dir..PS..string.sub(source_path, 2)
end
wa.source_path = source_path
end
log.msg(log.debug, "Current source path is " .. wa.source_path)
return wa.source_path
end
-- debug level
log.log_level(log.debug)
-- Tell gettext where to find the .mo file translating messages for a particular domain
local gettext = dt.gettext
local gettext_path = get_script_path().."locale"..PS
log.msg(log.debug, "Configuring translation with path "..gettext_path)
gettext.bindtextdomain(MODULE_NAME, gettext_path)
local function _(msgid)
return gettext.dgettext(MODULE_NAME, msgid)
end
local function show_status(storage, image, format, filename, number, total, high_quality, extra_data)
dt.print(string.format(_("Dummy : export image %i/%i"), number, total))
end
local function launch_dummy(storage, image_table, extra_data)
for image, exported_image in pairs(image_table) do
local filename = image.path..PS..image.filename
log.msg(log.debug, "Image at "..filename.." aspect_ratio:"..tostring(image.aspect_ratio))
end
end
local function destroy()
dt.destroy_storage(MODULE_NAME)
end
-- Widgets
wa.lbl_hdr = dt.new_widget('section_label') {
label = _('Dummy options')
}
wa.storage_widget = dt.new_widget("box") {
orientation = "vertical",
wa.lbl_hdr
}
-- Register
dt.register_storage(MODULE_NAME, _("Dummy"), show_status, launch_dummy, nil, nil, wa.storage_widget)
script_data.destroy = destroy
return script_data
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua
-- kate: hl Lua;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment