added darkroom mode
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
DESCRIPTION
|
||||
ext_editor.lua - edit images with external editors - for Windows only at the moment
|
||||
|
||||
This script provides helpers to edit image files with programs extenal to darktable.
|
||||
This script provides helpers to edit image files with programs external to darktable.
|
||||
It adds:
|
||||
- a new target storage "collection". Image exported will be reimported to collection for
|
||||
further edit with external programs
|
||||
@@ -24,20 +24,40 @@
|
||||
* the exported image will be imported into collection and grouped with the original image
|
||||
|
||||
* select an image for editing with en external program
|
||||
* in lighttable / external editors, select program and press "edit with external program"
|
||||
* edit the image with the external editor, overwite the file, quit the external program
|
||||
* lighttable will be updated
|
||||
* in lighttable / external editors, select program and press "edit"
|
||||
* edit the image with the external editor, overwite the file, quit the external program
|
||||
* the selected image will be updated
|
||||
or
|
||||
* in lighttable / external editors, select program and press "edit a copy"
|
||||
* edit the image with the external editor, overwite the file, quit the external program
|
||||
* a copy of the selected image will be created and updated
|
||||
or
|
||||
* in lighttable select target storage "collection"
|
||||
* enter in darkroom
|
||||
* to create an export or a copy press CRTL+E
|
||||
* use the shortcut to edit the current image with the corresponding external editor
|
||||
* overwite the file, quit the external program
|
||||
* the darkroom view will be updated
|
||||
|
||||
* warning: mouseover on lighttable / filmstrip will prevail on current image
|
||||
* this is the default DT behavior, not a bug of this script
|
||||
|
||||
CAVEATS
|
||||
* currently developed and tested only for Windows
|
||||
* button are not equal in size and centered
|
||||
|
||||
|
||||
TODO
|
||||
* localization
|
||||
* check min API version
|
||||
* support other OS
|
||||
* buttons are not equal in size and centered
|
||||
|
||||
BUGS, COMMENTS, SUGGESTIONS
|
||||
* send to Marco Carrarini, marco.carrarini@gmail.com
|
||||
|
||||
CHANGES
|
||||
* 20191220 - initial version, PR done
|
||||
* 20191221 - reworked, cleaned, added "copy and edit"
|
||||
* 20191222 - added darkroom mode
|
||||
|
||||
]]
|
||||
|
||||
@@ -83,24 +103,6 @@ if not (dt.preferences.read("ext_editor","initialized", "bool")) then
|
||||
local lastchoice = dt.preferences.read("ext_editor","lastchoice", "integer")
|
||||
|
||||
|
||||
-- combobox
|
||||
local combobox = dt.new_widget("combobox")
|
||||
{
|
||||
label = "choose program",
|
||||
tooltip = "select the external editor from the list",
|
||||
value = lastchoice, -- remember status,
|
||||
program_names[1],
|
||||
program_names[2],
|
||||
program_names[3],
|
||||
program_names[4],
|
||||
program_names[5],
|
||||
program_names[6],
|
||||
program_names[7],
|
||||
program_names[8],
|
||||
program_names[9]
|
||||
}
|
||||
|
||||
|
||||
-- group image with leader image
|
||||
local function group_if_not_member(img, new_img)
|
||||
local image_table = img:get_group_members()
|
||||
@@ -119,15 +121,13 @@ local function group_if_not_member(img, new_img)
|
||||
-- shows export progress
|
||||
local function show_status(storage, image, format, filename,
|
||||
number, total, high_quality, extra_data)
|
||||
dt.print(string.format(_("Export Image %i/%i"), number, total))
|
||||
dt.print(string.format("Exporting Image %i/%i ...", number, total))
|
||||
end
|
||||
|
||||
|
||||
-- callback for button "edit"
|
||||
local function OpenWith(choice)
|
||||
|
||||
local images = dt.gui.selection()
|
||||
|
||||
local function OpenWith(images, choice)
|
||||
|
||||
if #images == 1 then
|
||||
for _, image in pairs(images) do
|
||||
|
||||
@@ -139,11 +139,29 @@ local function OpenWith(choice)
|
||||
dt.print("Launching "..program_names[choice].."...")
|
||||
dtsys.external_command(run_cmd)
|
||||
|
||||
-- refresh image cache
|
||||
image:drop_cache()
|
||||
-- refresh the image view
|
||||
-- note that only image:drop_cache() is not enough to refresh view in darkroom mode
|
||||
-- therefore image must be deleted and reimported to force refresh
|
||||
|
||||
local image_leader = image.group_leader
|
||||
image:delete ()
|
||||
local new_image = dt.database.import(name)
|
||||
new_image:group_with(image_leader)
|
||||
|
||||
-- copy tags from image leader
|
||||
for _,tag in pairs(dt.tags.get_tags(image_leader)) do
|
||||
if not (string.sub(tag.name,1,9) == "darktable") then
|
||||
dt.tags.attach(tag, new_image)
|
||||
end
|
||||
end
|
||||
|
||||
-- remember the last editor used
|
||||
dt.preferences.write("ext_editor","lastchoice", "integer", choice)
|
||||
|
||||
-- refresh darkroom view
|
||||
if dt.gui.current_view () == dt.gui.views.darkroom then
|
||||
dt.gui.views.darkroom.display_image(new_image)
|
||||
end
|
||||
end
|
||||
else
|
||||
dt.print('please select one image')
|
||||
@@ -153,9 +171,7 @@ local function OpenWith(choice)
|
||||
|
||||
|
||||
-- callback for button "copy and edit"
|
||||
local function CopyAndOpenWith(choice)
|
||||
|
||||
local images = dt.gui.selection()
|
||||
local function CopyAndOpenWith(images, choice)
|
||||
|
||||
if #images == 1 then
|
||||
for _,image in pairs(images) do
|
||||
@@ -206,37 +222,11 @@ local function CopyAndOpenWith(choice)
|
||||
end
|
||||
|
||||
|
||||
-- button edit
|
||||
local button1 = dt.new_widget("button")
|
||||
{
|
||||
label = "edit",
|
||||
tooltip = "open the selected image in external editor",
|
||||
dt_lua_align_t = center,
|
||||
clicked_callback = function (_)
|
||||
local choice = combobox.selected
|
||||
OpenWith(choice)
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
-- button copy and edit
|
||||
local button2 = dt.new_widget("button")
|
||||
{
|
||||
label = "edit a copy",
|
||||
tooltip = "create a copy of the selected image and open it in external editor",
|
||||
clicked_callback = function (_)
|
||||
local choice = combobox.selected
|
||||
CopyAndOpenWith(choice)
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
-- box for the two buttons
|
||||
local box1 = dt.new_widget ("box") {
|
||||
orientation = "horizontal",
|
||||
button1,
|
||||
button2
|
||||
}
|
||||
-- callback function for shortcuts
|
||||
local function program_shortcut(event, shortcut)
|
||||
local choice = tonumber(string.sub(shortcut, -1))
|
||||
OpenWith(dt.gui.action_images, choice)
|
||||
end
|
||||
|
||||
|
||||
-- export images and reimport in collection
|
||||
@@ -260,31 +250,63 @@ local function export2collection(storage, image_table, extra_data)
|
||||
local result = df.file_move(temp_name, new_name)
|
||||
|
||||
if result then
|
||||
|
||||
-- import in database and group
|
||||
local new_image = dt.database.import(new_name)
|
||||
group_if_not_member(image, new_image)
|
||||
|
||||
-- copy image tags
|
||||
for _,tag in pairs(dt.tags.get_tags(image)) do
|
||||
if not (string.sub(tag.name,1,9) == "darktable") then
|
||||
dt.tags.attach(tag, new_image)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- callback function for shortcuts
|
||||
local function program_shortcut(event, shortcut)
|
||||
local choice = tonumber(string.sub(shortcut, -1))
|
||||
OpenWith(choice)
|
||||
end
|
||||
-- combobox
|
||||
local combobox = dt.new_widget("combobox")
|
||||
{
|
||||
label = "choose program",
|
||||
tooltip = "select the external editor from the list",
|
||||
value = lastchoice, -- remember status,
|
||||
program_names[1],
|
||||
program_names[2],
|
||||
program_names[3],
|
||||
program_names[4],
|
||||
program_names[5],
|
||||
program_names[6],
|
||||
program_names[7],
|
||||
program_names[8],
|
||||
program_names[9]
|
||||
}
|
||||
|
||||
|
||||
-- register new storage
|
||||
dt.register_storage("exp2coll", "collection", show_status, export2collection)
|
||||
-- button edit
|
||||
local button1 = dt.new_widget("button")
|
||||
{
|
||||
label = " edit ",
|
||||
tooltip = "open the selected image in external editor",
|
||||
dt_lua_align_t = center,
|
||||
clicked_callback = function (_)
|
||||
local choice = combobox.selected
|
||||
OpenWith(dt.gui.action_images, choice)
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
-- button edit a copy
|
||||
local button2 = dt.new_widget("button")
|
||||
{
|
||||
label = " edit a copy ",
|
||||
tooltip = "create a copy of the selected image and open it in external editor",
|
||||
clicked_callback = function (_)
|
||||
local choice = combobox.selected
|
||||
CopyAndOpenWith(dt.gui.action_images, choice)
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
-- box for the two buttons
|
||||
local box1 = dt.new_widget ("box") {
|
||||
orientation = "horizontal",
|
||||
button1,
|
||||
button2
|
||||
}
|
||||
|
||||
|
||||
-- register new lighttable module
|
||||
@@ -305,7 +327,11 @@ dt.register_lib(
|
||||
)
|
||||
|
||||
|
||||
-- register new preferences
|
||||
-- register new storage
|
||||
dt.register_storage("exp2coll", "collection", show_status, export2collection)
|
||||
|
||||
|
||||
-- register the new preferences
|
||||
dt.preferences.register("ext_editor","program_path_9", "string","path to external editor 9", "path to external editor","")
|
||||
dt.preferences.register("ext_editor","program_name_9", "string","name of external editor 9", "name of external editor","")
|
||||
|
||||
@@ -334,7 +360,7 @@ dt.preferences.register("ext_editor","program_path_1", "string","path to externa
|
||||
dt.preferences.register("ext_editor","program_name_1", "string","name of external editor 1", "name of external editor","")
|
||||
|
||||
|
||||
-- register new shortcuts
|
||||
-- register the new shortcuts
|
||||
dt.register_event("shortcut", program_shortcut, "edit with program 1")
|
||||
dt.register_event("shortcut", program_shortcut, "edit with program 2")
|
||||
dt.register_event("shortcut", program_shortcut, "edit with program 3")
|
||||
@@ -345,5 +371,7 @@ dt.register_event("shortcut", program_shortcut, "edit with program 7")
|
||||
dt.register_event("shortcut", program_shortcut, "edit with program 8")
|
||||
dt.register_event("shortcut", program_shortcut, "edit with program 9")
|
||||
|
||||
-- end of script
|
||||
|
||||
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua
|
||||
-- kate: hl Lua;
|
||||
|
||||
Reference in New Issue
Block a user