From 33b99a97e4af3d6ae13b43f420c6d9a1d75a1702 Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 16 Apr 2020 17:51:09 -0700 Subject: [PATCH 01/13] initial module minus style picker --- contrib/exportLUT.lua | 131 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 contrib/exportLUT.lua diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua new file mode 100644 index 0000000..c2688ed --- /dev/null +++ b/contrib/exportLUT.lua @@ -0,0 +1,131 @@ +--[[ + This file is part of darktable, + copyright (c) 2016 Tobias Jakobs + + darktable 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. + + darktable 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 darktable. If not, see . +]] +--[[ + +USAGE +* require this script from your main lua file + To do this add this line to the file .config/darktable/luarc: +require "moduleExample" + +* it creates a new example lighttable module + +More informations about building user interface elements: +https://www.darktable.org/usermanual/ch09.html.php#lua_gui_example +And about new_widget here: +https://www.darktable.org/lua-api/index.html.php#darktable_new_widget +]] + +local dt = require "darktable" +local du = require "lib/dtutils" + +du.check_min_api_version("3.0.0", "moduleExample") + +-- add a new lib + +local combobox = dt.new_widget("combobox"){label = "on conflict", value = 1, "skip", "overwrite"} + +--https://www.darktable.org/lua-api/ar01s02s54.html.php + +local file_chooser_button = dt.new_widget("file_chooser_button") +{ + title = "Identity_file_chooser", -- The title of the window when choosing a file + value = "", -- The currently selected file + is_directory = false -- True if the file chooser button only allows directories to be selecte +} + +local export_chooser_button = dt.new_widget("file_chooser_button") +{ + title = "Export_location_chooser", -- The title of the window when choosing a file + value = "", -- The currently selected file + is_directory = true -- True if the file chooser button only allows directories to be selecte +} + +local identity_label = dt.new_widget("label"){ + label = "choose the identity haldclut file" +} + +local output_label = dt.new_widget("label"){ + label = "choose the output location" +} + +local separator = dt.new_widget("separator"){} + +if (dt.configuration.api_version_major >= 6) then + local section_label = dt.new_widget("section_label") + { + label = "MySectionLabel" + } + + dt.register_lib( + "export haldclut", -- Module name + "export haldclut", -- name + true, -- expandable + false, -- resetable + {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, -- containers + identity_label, + file_chooser_button, + output_label, + export_chooser_button, + combobox, + separator, + dt.new_widget("box") -- widget + { + orientation = "vertical", + dt.new_widget("button") + { + label = "export", + clicked_callback = function (_) + dt.print("Button clicked") + end + }, + section_label + }, + nil,-- view_enter + nil -- view_leave + ) +else + dt.register_lib( + "export haldclut", -- Module name + "export haldclut", -- name + true, -- expandable + false, -- resetable + {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, -- containers + dt.new_widget("box") -- widget + { + orientation = "vertical", + identity_label, + file_chooser_button, + output_label, + export_chooser_button, + combobox, + separator, + dt.new_widget("button") + { + label = "export", + clicked_callback = function (_) + dt.print("Button clicked") + end + } + }, + nil,-- view_enter + nil -- view_leave + ) +end + +-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua +-- kate: hl Lua; From 792e782e8c101f7a333b583674feb4aaa81e8b37 Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 16 Apr 2020 22:27:57 -0700 Subject: [PATCH 02/13] basic frontend --- contrib/exportLUT.lua | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua index c2688ed..adb0534 100644 --- a/contrib/exportLUT.lua +++ b/contrib/exportLUT.lua @@ -33,7 +33,7 @@ https://www.darktable.org/lua-api/index.html.php#darktable_new_widget local dt = require "darktable" local du = require "lib/dtutils" -du.check_min_api_version("3.0.0", "moduleExample") +du.check_min_api_version("3.0.0", "exportLUT") -- add a new lib @@ -63,7 +63,27 @@ local output_label = dt.new_widget("label"){ label = "choose the output location" } -local separator = dt.new_widget("separator"){} +local separator = dt.new_widget("separator"){ + +} + +local function create_lut(style, haldclut) + haldclut.reset + dt.styles.apply(style, haldclut) +end + +local function export_lut(haldclut) + +end + +local function export_luts() + identity = dt.database.import(file_chooser_button) + for style_num, style in ipairs(dt.styles) do + identity = create_lut(style, identity) + export_lut(identity) + dt.print(style.name) + end +end if (dt.configuration.api_version_major >= 6) then local section_label = dt.new_widget("section_label") @@ -117,9 +137,7 @@ else dt.new_widget("button") { label = "export", - clicked_callback = function (_) - dt.print("Button clicked") - end + clicked_callback = export_luts } }, nil,-- view_enter From fe97e2965484384122bbdd8931918ff432b27d63 Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 16 Apr 2020 22:59:33 -0700 Subject: [PATCH 03/13] Working? version --- contrib/exportLUT.lua | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua index adb0534..35981ab 100644 --- a/contrib/exportLUT.lua +++ b/contrib/exportLUT.lua @@ -35,12 +35,12 @@ local du = require "lib/dtutils" du.check_min_api_version("3.0.0", "exportLUT") --- add a new lib +-- Thanks Kevin Ertel for this trick +local os_path_seperator = '/' +if dt.configuration.running_os == 'windows' then os_path_seperator = '\\' end local combobox = dt.new_widget("combobox"){label = "on conflict", value = 1, "skip", "overwrite"} ---https://www.darktable.org/lua-api/ar01s02s54.html.php - local file_chooser_button = dt.new_widget("file_chooser_button") { title = "Identity_file_chooser", -- The title of the window when choosing a file @@ -64,24 +64,20 @@ local output_label = dt.new_widget("label"){ } local separator = dt.new_widget("separator"){ - } -local function create_lut(style, haldclut) - haldclut.reset - dt.styles.apply(style, haldclut) -end - -local function export_lut(haldclut) - -end - local function export_luts() - identity = dt.database.import(file_chooser_button) + identity = dt.database.import(file_chooser_button.value) for style_num, style in ipairs(dt.styles) do - identity = create_lut(style, identity) - export_lut(identity) - dt.print(style.name) + + identity:reset() + dt.styles.apply(style, identity) + + io_lut = dt.new_format("png") + dt.print(export_chooser_button.value .. os_path_seperator .. style.name) + io_lut:write_image(identity, export_chooser_button.value .. os_path_seperator .. style.name) + + dt.print(export_chooser_button.value .. os_path_seperator .. style.name) end end From 28b9073010eb5cf26281a18ed057d10467ab0994 Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 16 Apr 2020 23:42:51 -0700 Subject: [PATCH 04/13] Code and UI cleanup --- contrib/exportLUT.lua | 111 ++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 70 deletions(-) diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua index 35981ab..ab63fce 100644 --- a/contrib/exportLUT.lua +++ b/contrib/exportLUT.lua @@ -1,6 +1,6 @@ --[[ This file is part of darktable, - copyright (c) 2016 Tobias Jakobs + copyright (c) 2020 Noah Clarke darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,18 +16,14 @@ along with darktable. If not, see . ]] --[[ +Add the following line to .config/darktable/luarc to enable this lightable module: + require "exportLut" -USAGE -* require this script from your main lua file - To do this add this line to the file .config/darktable/luarc: -require "moduleExample" +Given a haldCLUT identity file this script generates haldCLUTS from all the user's +styles and exports them to a location of their choosing. -* it creates a new example lighttable module - -More informations about building user interface elements: -https://www.darktable.org/usermanual/ch09.html.php#lua_gui_example -And about new_widget here: -https://www.darktable.org/lua-api/index.html.php#darktable_new_widget +Warning: during export if a naming collision occurs the older file is automatically +overwritten silently. ]] local dt = require "darktable" @@ -35,24 +31,20 @@ local du = require "lib/dtutils" du.check_min_api_version("3.0.0", "exportLUT") --- Thanks Kevin Ertel for this trick +-- Thanks Kevin Ertel for this bit local os_path_seperator = '/' if dt.configuration.running_os == 'windows' then os_path_seperator = '\\' end -local combobox = dt.new_widget("combobox"){label = "on conflict", value = 1, "skip", "overwrite"} - -local file_chooser_button = dt.new_widget("file_chooser_button") -{ - title = "Identity_file_chooser", -- The title of the window when choosing a file - value = "", -- The currently selected file - is_directory = false -- True if the file chooser button only allows directories to be selecte +local file_chooser_button = dt.new_widget("file_chooser_button"){ + title = "Identity_file_chooser", + value = "", + is_directory = false } -local export_chooser_button = dt.new_widget("file_chooser_button") -{ - title = "Export_location_chooser", -- The title of the window when choosing a file - value = "", -- The currently selected file - is_directory = true -- True if the file chooser button only allows directories to be selecte +local export_chooser_button = dt.new_widget("file_chooser_button"){ + title = "Export_location_chooser", + value = "", + is_directory = true } local identity_label = dt.new_widget("label"){ @@ -63,7 +55,9 @@ local output_label = dt.new_widget("label"){ label = "choose the output location" } -local separator = dt.new_widget("separator"){ +local export_button = dt.new_widget("button"){ + label = "export", + clicked_callback = export_luts } local function export_luts() @@ -74,72 +68,49 @@ local function export_luts() dt.styles.apply(style, identity) io_lut = dt.new_format("png") - dt.print(export_chooser_button.value .. os_path_seperator .. style.name) - io_lut:write_image(identity, export_chooser_button.value .. os_path_seperator .. style.name) - - dt.print(export_chooser_button.value .. os_path_seperator .. style.name) + dt.print("Exporting: " .. export_chooser_button.value .. os_path_seperator .. style.name .. ".png") + io_lut:write_image(identity, export_chooser_button.value .. os_path_seperator .. style.name .. ".png") end + identity:reset() end if (dt.configuration.api_version_major >= 6) then - local section_label = dt.new_widget("section_label") - { - label = "MySectionLabel" - } dt.register_lib( - "export haldclut", -- Module name - "export haldclut", -- name - true, -- expandable - false, -- resetable - {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, -- containers + "export haldclut", + "export haldclut", + true, + false, + {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, identity_label, file_chooser_button, output_label, export_chooser_button, - combobox, - separator, - dt.new_widget("box") -- widget + dt.new_widget("box") { orientation = "vertical", - dt.new_widget("button") - { - label = "export", - clicked_callback = function (_) - dt.print("Button clicked") - end - }, - section_label + export_button }, - nil,-- view_enter - nil -- view_leave + nil, + nil ) else dt.register_lib( - "export haldclut", -- Module name - "export haldclut", -- name - true, -- expandable - false, -- resetable - {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, -- containers - dt.new_widget("box") -- widget + "export haldclut", + "export haldclut", + true, + false, + {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, + dt.new_widget("box") { orientation = "vertical", identity_label, file_chooser_button, output_label, export_chooser_button, - combobox, - separator, - dt.new_widget("button") - { - label = "export", - clicked_callback = export_luts - } + export_button }, - nil,-- view_enter - nil -- view_leave + nil, + nil ) -end - --- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua --- kate: hl Lua; +end \ No newline at end of file From 286ef7766302819b90b6d892afe462d110cefbf3 Mon Sep 17 00:00:00 2001 From: Noah Date: Sun, 19 Apr 2020 00:36:47 -0700 Subject: [PATCH 05/13] Some error checking and warnings --- contrib/exportLUT.lua | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua index ab63fce..65a4f57 100644 --- a/contrib/exportLUT.lua +++ b/contrib/exportLUT.lua @@ -55,25 +55,33 @@ local output_label = dt.new_widget("label"){ label = "choose the output location" } -local export_button = dt.new_widget("button"){ - label = "export", - clicked_callback = export_luts +local warning_label = dt.new_widget("label"){ + label = "WARNING: files may be silently overwritten" } local function export_luts() identity = dt.database.import(file_chooser_button.value) - for style_num, style in ipairs(dt.styles) do - + if(type(identity) ~= "userdata") then + dt.print("Invalid identity lut file") + else + for style_num, style in ipairs(dt.styles) do + + identity:reset() + dt.styles.apply(style, identity) + + io_lut = dt.new_format("png") + dt.print("Exporting: " .. export_chooser_button.value .. os_path_seperator .. style.name .. ".png") + io_lut:write_image(identity, export_chooser_button.value .. os_path_seperator .. style.name .. ".png") + end identity:reset() - dt.styles.apply(style, identity) - - io_lut = dt.new_format("png") - dt.print("Exporting: " .. export_chooser_button.value .. os_path_seperator .. style.name .. ".png") - io_lut:write_image(identity, export_chooser_button.value .. os_path_seperator .. style.name .. ".png") end - identity:reset() end +local export_button = dt.new_widget("button"){ + label = "export", + clicked_callback = export_luts +} + if (dt.configuration.api_version_major >= 6) then dt.register_lib( @@ -86,6 +94,7 @@ if (dt.configuration.api_version_major >= 6) then file_chooser_button, output_label, export_chooser_button, + warning_label, dt.new_widget("box") { orientation = "vertical", @@ -108,6 +117,7 @@ else file_chooser_button, output_label, export_chooser_button, + warning_label, export_button }, nil, From 01184bee721d217dc1d1e29d60e7e40bded6756f Mon Sep 17 00:00:00 2001 From: Noah Date: Mon, 4 May 2020 23:58:52 -0700 Subject: [PATCH 06/13] Updated API version check and forced PNG to 16 bits --- contrib/exportLUT.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua index 65a4f57..e2f599e 100644 --- a/contrib/exportLUT.lua +++ b/contrib/exportLUT.lua @@ -29,7 +29,7 @@ overwritten silently. local dt = require "darktable" local du = require "lib/dtutils" -du.check_min_api_version("3.0.0", "exportLUT") +du.check_min_api_version("5.0.0", "exportLUT") -- Thanks Kevin Ertel for this bit local os_path_seperator = '/' @@ -70,8 +70,9 @@ local function export_luts() dt.styles.apply(style, identity) io_lut = dt.new_format("png") - dt.print("Exporting: " .. export_chooser_button.value .. os_path_seperator .. style.name .. ".png") + io_lut.bpp = 16 io_lut:write_image(identity, export_chooser_button.value .. os_path_seperator .. style.name .. ".png") + dt.print("Exported: " .. export_chooser_button.value .. os_path_seperator .. style.name .. ".png") end identity:reset() end From 5709cfebd4b6f1304732b509e0905c23e48d944d Mon Sep 17 00:00:00 2001 From: Noah Date: Tue, 5 May 2020 00:02:47 -0700 Subject: [PATCH 07/13] Remove unneeded API check --- contrib/exportLUT.lua | 51 ++++++++++++------------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua index e2f599e..da187f1 100644 --- a/contrib/exportLUT.lua +++ b/contrib/exportLUT.lua @@ -83,45 +83,22 @@ local export_button = dt.new_widget("button"){ clicked_callback = export_luts } -if (dt.configuration.api_version_major >= 6) then - - dt.register_lib( - "export haldclut", - "export haldclut", - true, - false, - {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, +dt.register_lib( + "export haldclut", + "export haldclut", + true, + false, + {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, + dt.new_widget("box") + { + orientation = "vertical", identity_label, file_chooser_button, output_label, export_chooser_button, warning_label, - dt.new_widget("box") - { - orientation = "vertical", - export_button - }, - nil, - nil - ) -else - dt.register_lib( - "export haldclut", - "export haldclut", - true, - false, - {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, - dt.new_widget("box") - { - orientation = "vertical", - identity_label, - file_chooser_button, - output_label, - export_chooser_button, - warning_label, - export_button - }, - nil, - nil - ) -end \ No newline at end of file + export_button + }, + nil, + nil +) \ No newline at end of file From 4455347930947099fa2f67a9eb86d05ed5d08cf3 Mon Sep 17 00:00:00 2001 From: Noah Date: Wed, 6 May 2020 01:14:34 -0700 Subject: [PATCH 08/13] Exporting luts now creates a job --- contrib/exportLUT.lua | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua index da187f1..eaacf44 100644 --- a/contrib/exportLUT.lua +++ b/contrib/exportLUT.lua @@ -59,21 +59,38 @@ local warning_label = dt.new_widget("label"){ label = "WARNING: files may be silently overwritten" } +local function end_job(job) + job.valid = false +end + local function export_luts() - identity = dt.database.import(file_chooser_button.value) + local identity = dt.database.import(file_chooser_button.value) if(type(identity) ~= "userdata") then dt.print("Invalid identity lut file") else + local job = dt.gui.create_job('Exporting styles as haldCLUTs', true, end_job) + + local size = 1 + + for style_num, style in ipairs(dt.styles) do + size = size + 1 + end + + local count = 0 for style_num, style in ipairs(dt.styles) do identity:reset() dt.styles.apply(style, identity) - io_lut = dt.new_format("png") + local io_lut = dt.new_format("png") io_lut.bpp = 16 io_lut:write_image(identity, export_chooser_button.value .. os_path_seperator .. style.name .. ".png") + count = count + 1 + job.percent = count / size dt.print("Exported: " .. export_chooser_button.value .. os_path_seperator .. style.name .. ".png") end + dt.print("Done exporting haldCLUTs") + job.valid = false identity:reset() end end From aef7363beee9a8f88fa4983c401b347ea395175e Mon Sep 17 00:00:00 2001 From: Noah Date: Wed, 6 May 2020 13:19:12 -0700 Subject: [PATCH 09/13] make 8bit not 16bit luts (extra depth uneeded) --- contrib/exportLUT.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua index eaacf44..25741bc 100644 --- a/contrib/exportLUT.lua +++ b/contrib/exportLUT.lua @@ -83,7 +83,7 @@ local function export_luts() dt.styles.apply(style, identity) local io_lut = dt.new_format("png") - io_lut.bpp = 16 + io_lut.bpp = 8 io_lut:write_image(identity, export_chooser_button.value .. os_path_seperator .. style.name .. ".png") count = count + 1 job.percent = count / size From 23131a301bcd2770e44b3e60c217a7b77805d229 Mon Sep 17 00:00:00 2001 From: Noah Clarke Date: Thu, 7 May 2020 12:15:31 -0700 Subject: [PATCH 10/13] Fix include path --- contrib/exportLUT.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua index 25741bc..6d29647 100644 --- a/contrib/exportLUT.lua +++ b/contrib/exportLUT.lua @@ -17,7 +17,7 @@ ]] --[[ Add the following line to .config/darktable/luarc to enable this lightable module: - require "exportLut" + require "contrib/exportLut" Given a haldCLUT identity file this script generates haldCLUTS from all the user's styles and exports them to a location of their choosing. @@ -118,4 +118,4 @@ dt.register_lib( }, nil, nil -) \ No newline at end of file +) From 71e72b688f74c217462373d966b2251138c36426 Mon Sep 17 00:00:00 2001 From: Noah Date: Tue, 16 Jun 2020 01:50:59 -0700 Subject: [PATCH 11/13] Exported luts now have folder hierarchy --- contrib/exportLUT.lua | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua index 6d29647..dd452aa 100644 --- a/contrib/exportLUT.lua +++ b/contrib/exportLUT.lua @@ -28,12 +28,16 @@ overwritten silently. local dt = require "darktable" local du = require "lib/dtutils" +local df = require("lib/dtutils.file") +local ds = require("lib/dtutils.system") du.check_min_api_version("5.0.0", "exportLUT") -- Thanks Kevin Ertel for this bit local os_path_seperator = '/' if dt.configuration.running_os == 'windows' then os_path_seperator = '\\' end +local mkdir_command = 'mkdir -p ' +if dt.configuration.running_os == 'windows' then mkdir_command = 'mkdir ' end local file_chooser_button = dt.new_widget("file_chooser_button"){ title = "Identity_file_chooser", @@ -63,6 +67,18 @@ local function end_job(job) job.valid = false end +local function output_path(style_name, job) + local output_location = export_chooser_button.value .. os_path_seperator .. style_name .. ".png" + output_location = string.gsub(output_location, "|", os_path_seperator) + local output_dir = string.reverse(output_location) + output_dir = string.gsub(output_dir, ".-" .. os_path_seperator, os_path_seperator, 1) + output_dir = string.reverse(output_dir) + if(output_dir ~= "") then + df.mkdir(df.sanitize_filename(output_dir)) + end + return output_location +end + local function export_luts() local identity = dt.database.import(file_chooser_button.value) if(type(identity) ~= "userdata") then @@ -81,13 +97,13 @@ local function export_luts() identity:reset() dt.styles.apply(style, identity) - local io_lut = dt.new_format("png") io_lut.bpp = 8 - io_lut:write_image(identity, export_chooser_button.value .. os_path_seperator .. style.name .. ".png") + + io_lut:write_image(identity, output_path(style.name, job)) count = count + 1 job.percent = count / size - dt.print("Exported: " .. export_chooser_button.value .. os_path_seperator .. style.name .. ".png") + dt.print("Exported: " .. output_path(style.name, job)) end dt.print("Done exporting haldCLUTs") job.valid = false From 802c17d5905dafc1bf30223a9e0f08db8931ccd7 Mon Sep 17 00:00:00 2001 From: Noah Date: Tue, 16 Jun 2020 01:59:43 -0700 Subject: [PATCH 12/13] Added translated text --- contrib/exportLUT.lua | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua index dd452aa..5d85bdc 100644 --- a/contrib/exportLUT.lua +++ b/contrib/exportLUT.lua @@ -31,6 +31,8 @@ local du = require "lib/dtutils" local df = require("lib/dtutils.file") local ds = require("lib/dtutils.system") +local gettext = dt.gettext + du.check_min_api_version("5.0.0", "exportLUT") -- Thanks Kevin Ertel for this bit @@ -40,27 +42,27 @@ local mkdir_command = 'mkdir -p ' if dt.configuration.running_os == 'windows' then mkdir_command = 'mkdir ' end local file_chooser_button = dt.new_widget("file_chooser_button"){ - title = "Identity_file_chooser", + title = gettext.gettext("Identity_file_chooser"), value = "", is_directory = false } local export_chooser_button = dt.new_widget("file_chooser_button"){ - title = "Export_location_chooser", + title = gettext.gettext("Export_location_chooser"), value = "", is_directory = true } local identity_label = dt.new_widget("label"){ - label = "choose the identity haldclut file" + label = gettext.gettext("choose the identity haldclut file") } local output_label = dt.new_widget("label"){ - label = "choose the output location" + label = gettext.gettext("choose the output location") } local warning_label = dt.new_widget("label"){ - label = "WARNING: files may be silently overwritten" + label = gettext.gettext("WARNING: files may be silently overwritten") } local function end_job(job) @@ -82,9 +84,9 @@ end local function export_luts() local identity = dt.database.import(file_chooser_button.value) if(type(identity) ~= "userdata") then - dt.print("Invalid identity lut file") + dt.print(gettext.gettext("Invalid identity lut file")) else - local job = dt.gui.create_job('Exporting styles as haldCLUTs', true, end_job) + local job = dt.gui.create_job(gettext.gettext('Exporting styles as haldCLUTs'), true, end_job) local size = 1 @@ -103,22 +105,22 @@ local function export_luts() io_lut:write_image(identity, output_path(style.name, job)) count = count + 1 job.percent = count / size - dt.print("Exported: " .. output_path(style.name, job)) + dt.print(gettext.gettext("Exported: ") .. output_path(style.name, job)) end - dt.print("Done exporting haldCLUTs") + dt.print(gettext.gettext("Done exporting haldCLUTs")) job.valid = false identity:reset() end end local export_button = dt.new_widget("button"){ - label = "export", + label = gettext.gettext("export"), clicked_callback = export_luts } dt.register_lib( - "export haldclut", - "export haldclut", + gettext.gettext("export haldclut"), + gettext.gettext("export haldclut"), true, false, {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, From 593917db9a50426fd77b0752dddf65d73f4914eb Mon Sep 17 00:00:00 2001 From: Noah Date: Sat, 4 Jul 2020 23:20:30 -0700 Subject: [PATCH 13/13] Fix gettext implementation --- contrib/exportLUT.lua | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua index 5d85bdc..aa76b0d 100644 --- a/contrib/exportLUT.lua +++ b/contrib/exportLUT.lua @@ -33,6 +33,12 @@ local ds = require("lib/dtutils.system") local gettext = dt.gettext +gettext.bindtextdomain("exportLUT",dt.configuration.config_dir.."/lua/locale/") + +local function _(msgid) + return gettext.dgettext("exportLUT", msgid) +end + du.check_min_api_version("5.0.0", "exportLUT") -- Thanks Kevin Ertel for this bit @@ -42,27 +48,27 @@ local mkdir_command = 'mkdir -p ' if dt.configuration.running_os == 'windows' then mkdir_command = 'mkdir ' end local file_chooser_button = dt.new_widget("file_chooser_button"){ - title = gettext.gettext("Identity_file_chooser"), + title = _("Identity_file_chooser"), value = "", is_directory = false } local export_chooser_button = dt.new_widget("file_chooser_button"){ - title = gettext.gettext("Export_location_chooser"), + title = _("Export_location_chooser"), value = "", is_directory = true } local identity_label = dt.new_widget("label"){ - label = gettext.gettext("choose the identity haldclut file") + label = _("choose the identity haldclut file") } local output_label = dt.new_widget("label"){ - label = gettext.gettext("choose the output location") + label = _("choose the output location") } local warning_label = dt.new_widget("label"){ - label = gettext.gettext("WARNING: files may be silently overwritten") + label = _("WARNING: files may be silently overwritten") } local function end_job(job) @@ -84,9 +90,9 @@ end local function export_luts() local identity = dt.database.import(file_chooser_button.value) if(type(identity) ~= "userdata") then - dt.print(gettext.gettext("Invalid identity lut file")) + dt.print(_("Invalid identity lut file")) else - local job = dt.gui.create_job(gettext.gettext('Exporting styles as haldCLUTs'), true, end_job) + local job = dt.gui.create_job(_('Exporting styles as haldCLUTs'), true, end_job) local size = 1 @@ -105,22 +111,22 @@ local function export_luts() io_lut:write_image(identity, output_path(style.name, job)) count = count + 1 job.percent = count / size - dt.print(gettext.gettext("Exported: ") .. output_path(style.name, job)) + dt.print(_("Exported: ") .. output_path(style.name, job)) end - dt.print(gettext.gettext("Done exporting haldCLUTs")) + dt.print(_("Done exporting haldCLUTs")) job.valid = false identity:reset() end end local export_button = dt.new_widget("button"){ - label = gettext.gettext("export"), + label = _("export"), clicked_callback = export_luts } dt.register_lib( - gettext.gettext("export haldclut"), - gettext.gettext("export haldclut"), + _("export haldclut"), + _("export haldclut"), true, false, {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}},