Files
dtlua/open_ooc.lua
Florian Tham bc308b4845 open_ooc
2025-04-10 11:25:20 +02:00

146 lines
4.1 KiB
Lua

--[[
ext_proc.lua - export and process with an arbitrary binary
Copyright (C) 2025 Florian Tham <fgtham@gmail.com>.
Heavily based on gimp.lua and thus is
Copyright (c) 2016 Bill Ferguson
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/>.
]]
--[[
open_ooc - open associated out-of-camera jpeg for selected raw files
This script opens jpeg files for selected raw files. This helps when ignoring
jpegs on import, but you want to view the jpeg nontheless.
USAGE
* require this script from your main lua file
* select an image or images
* in the "selected images" section, press "open ooc jpeg"
BUGS, COMMENTS, SUGGESTIONS
* Send to Florian Tham, fgtham@gmail.com
]]
local dt = require "darktable"
local du = require "lib/dtutils"
local df = require "lib/dtutils.file"
local dtsys = require "lib/dtutils.system"
local ooc_widget = nil
local wg = {}
local MODULE = "open_ooc"
du.check_min_api_version("7.0.0", MODULE)
-- from https://github.com/ChristianBirzer/darktable_extra_scripts/blob/main/HeliconFocus.lua
-- find locale directory:
local os_path_seperator = "/"
local scriptfile = debug.getinfo( 1, "S" )
local localedir = dt.configuration.config_dir..'/lua/locale/'
if scriptfile ~= nil and scriptfile.source ~= nil then
local path = scriptfile.source:match( "[^@].*[/\\]" )
localedir = path..os_path_seperator..'locale'
end
dt.print_log( "localedir: "..localedir )
local gettext = dt.gettext
gettext.bindtextdomain(MODULE, localedir)
local function _(msgid)
return gettext.dgettext(MODULE, msgid)
end
-- return data structure for script_manager
local script_data = {}
script_data.metadata = {
name = _("open ooc jpeg"),
purpose = _("open associated ooc jpegs for selected raw files"),
author = "Florian Tham <fgtham@gmail.com>",
help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/contrib/open_ooc"
}
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, 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
script_data.show = nil -- only required for libs since the destroy_method only hides them
local viewer = {}
viewer.executable = "sxiv"
viewer.args = ""
local function open_ooc() --finalize
local selected_images = dt.gui.selection()
local file_list = ""
if #selected_images == 0 then
dt.print(_("please select an image"))
return
end
for _, image in pairs(selected_images) do
if df.get_filetype(image.filename) == "CR3" then
current_image = image.path .. os_path_seperator .. image.filename
current_image = string.gsub(current_image, ".CR3", ".JPG")
if df.check_if_file_exists(current_image) then
file_list = file_list .. current_image .. " "
end
end
end
if file_list == "" then
dt.print(_("selection empty, or no jpeg available"))
return
end
cmd = viewer.executable .. " " .. viewer.args .. " " .. file_list
dt.print_log("open_ooc: " .. cmd)
dtsys.external_command(cmd)
end
local function destroy()
dt.gui.libs.image.destroy_actin(MODULE)
dt.destroy_event(MODULE, "shortcut")
end
-- Register
dt.gui.libs.image.register_action(
MODULE, _("open jpeg"),
function() open_ooc() end,
_("open associated ooc jpegs for the selected raw files")
)
dt.register_event(
MODULE,
"shortcut",
function(event, shortcut) open_ooc() end,
MODULE
)
--
script_data.destroy = destroy
return script_data