-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZereneStacker.lua
executable file
·735 lines (610 loc) · 27.9 KB
/
ZereneStacker.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
--[[
ZereneStacker.lua - stack images with Zerene Stacker
Copyright (C) 2024 Fiona Boston <[email protected]>.
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/>.
================================================================
ZereneStacker
This script will add a new panel to integrate Zerene Stacker stacking software into darktable
to be able to pass or export a bunch of images to Zerene Stacker, reimport the result(s) and
optionally group the images and optionally copy and add tags to the imported image(s)
ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT
you must have Zerene Stacker (commercial software) installed on your system.
PRIOR TO FIRST RUN
Create an empty folder to be used as the Stacker Staging Folder.
This folder will be used to store exported images prior to stacking and the output from Zerene Stacker prior to importing to DT.
It will also hold the ZereneBatch.xml batch script file.
All images should be removed from this folder once this script completes.
WHen Zerene is run using the Batch API (as this script does) it uses a batch script file to tell Zerene Stacker what to do.
More details can be found here https://zerenesystems.com/cms/stacker/docs/batchapi
This lua script assumes that the batch script file is named ZereneBatch.xml and is located in the Stacker Staging Folder.
A sample batch script is included on the web page above which performs simple stacking tasks suitable for this script. Copy this XML
into a new file and save as ZereneBatch.xml in the Staging Folder. This should be the only file in the folder (the script may not run if other
files are present). Details of how to make more sophisticated batch scipts are on the Zerene web site, and the Zerene Stacker application
can be used to create very complex scripts that can be used instead of the above.
USAGE
* Complete the details in darktable global options -> Lua Options:
* Set the following parameters in Lua options:
* Stacker Staging Folder - folder created in above step
* Zerene Licence Folder - folder where LicenceKey.txt is stored
(try /Users/myusername/Library/Preferences/ZereneStacker on a Mac
c:\Program Files\ZereneStacker on Windows
/home/myusername/.ZereneStacker on Linux)
* Zerene Stacker Java Folder = folder where ZereneStacker.jar file is held
(try /Applications/ZereneStacker.app/Contents/Resources/Java on a Mac
c:\Program Files\ZereneStacker on Windows
top level directory of Zerene installation location on linux)
* Select two or more images
* Expand the zerene stacker panel
* * 'group': If checked, the selected source images and the imported results are grouped together and the first result image
is set as group leader
* 'copy tags': If checked, all tags from all source images are copied to the resulting image
* 'new tags': Enter a comma seperated list of tags that shall be added to the resulting image on import.
* 'stack with Zerene Stacker': Press this button to start export of tifs and then start Zerene Stacker application
*
* The selected images will be exported to .tif files in the Stacler Staging Folder
* Zerene will launch and process the images per the ZereneBatch.xml script
* Once the batch processing is complete a dialog will pop - click OK to acknowledge.
* Zerene Stacker will stay open to allow retouching - ensure the output files(s) are resaved if changes are made
* Close Zerene Stacker after saving to start the import of the resulting image(s).
*
*** NOTE - The script may fail if the default output filenames are altered. ***
*
* The stacked images will be moved to folder of the first input files and imported to Darktable
* More than one image (e.g. different stacking settings) can be saved and all of them will be imported after closing zerene stacker
This script was tested on the following platforms:
- darktable 4.8.1 and above on:
- macOS on Apple Silcon
- Windows 11 ARM running in a VM on Apple Silicon
- Linux - Ubuntu LXQt 24.01.1 LTS running on amd64
BUGS, COMMENTS, SUGGESTIONS
* Send to Fiona Boston, [email protected]
]]
-- *************************************************
-- Setup and Initialisation
-- *************************************************
local dt = require 'darktable'
local du = require "lib/dtutils"
local df = require 'lib/dtutils.file'
local dsys = require 'lib/dtutils.system'
-- lua libraries installed via luarocks https://github.com/luarocks/luarocks/wiki
-- luafilesystem - https://lunarmodules.github.io/luafilesystem/index.html - file system functions
-- additional validation and output checking is activated if lfs is present
local lfs_loaded,lfs = pcall(require,'lfs')
if lfs_loaded == false then
dt.print_log("No lfs module")
else
dt.print_log("lfs module found")
end
-- luaexpat - https://lunarmodules.github.io/luaexpat/index.html - XML Expat parsing
-- not currently used but future enhancement around chcking ZereneBatch.xml may require it
local xml_loaded,lxp = pcall(require,'lxp')
if xml_loaded == true then
dt.print_log("lxp module found")
else
dt.print_log("No lxp module")
end
du.check_min_api_version("7.0.0", "ZereneStacker")
-- return data structure for script_manager
local script_data = {}
script_data.metadata = {
name = "ZereneStacker",
purpose = "Create focus stack using Zerene Stacker",
author = "Fiona Boston <[email protected]>",
help = "https://github.com/fjb2020/darktable-scripts"
}
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
local temp
local GUI = { --GUI Elements Table
optionwidgets = {
label_import_options = {},
group = {},
copy_metadata = {},
copy_tags = {},
add_tags_box = {},
add_tags_label = {},
add_tags = {},
},
options = {},
run = {},
}
local mod = 'module_ZereneStacker'
-- options for different OS
local os_path_seperator = '/'
local os_quote = "'"
if dt.configuration.running_os == 'windows' then
os_path_seperator = '\\'
os_quote = '"'
end
-- find locale directory:
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
-- Tell gettext where to find the .mo file translating messages for a particular domain
local gettext = dt.gettext
gettext.bindtextdomain( 'ZereneStacker', localedir )
-- declare a local namespace and a couple of variables we'll need to install the module
local mE = {}
mE.event_registered = false -- keep track of whether we've added an event callback or not
mE.module_installed = false -- keep track of whether the module is module_installed
-- *************************************************
-- utility functions
-- *************************************************
local function _(msgid)
return gettext.dgettext( 'ZereneStacker', msgid )
end
-- *************************
local function export_image( image, exportfilename)
-- export the given single image to tiff (16 bit)
local curr_image = image.path..os_path_seperator..image.filename
dt.print_log( "exporting " .. curr_image .. ' to ' .. exportfilename)
local exporter = dt.new_format("tiff")
exporter.bpp = 16
exporter:write_image(image, exportfilename)
dt.print_log( "exported file: "..exportfilename )
end
-- *************************
local function copy_tags( all_tags, image )
-- add tags on image to all_tags table
local image_tags = dt.tags.get_tags( image )
for _,tag in pairs( image_tags ) do
if string.match( tag.name, 'darktable|' ) == nil then
dt.print_log( "image: "..image.filename .. " tag: "..tag.name )
all_tags[ #all_tags + 1 ] = tag
end
end
dt.print_log( "#all_tags: ".. #all_tags )
end
-- *************************
local function insert_tags( image, tags )
for _,tag in pairs( tags ) do
dt.tags.attach(tag, image )
dt.print_log( 'image: '..image.filename..' adding tag ', tag.name )
end
end
-- *************************
--removes spaces from the front and back of passed in text
local function clean_spaces(text)
text = string.gsub(text,'^%s*','')
text = string.gsub(text,'%s*$','')
return text
end
-- *************************
local function add_additional_tags( image )
local set_tag = GUI.optionwidgets.add_tags.text
if set_tag ~= nil then -- add additional user-specified tags
for tag in string.gmatch(set_tag, '[^,]+') do
tag = clean_spaces(tag)
tag = dt.tags.create(tag)
dt.tags.attach(tag, image)
end
end
end
-- *************************
local function save_preferences()
dt.preferences.write( mod, 'group', 'bool', GUI.optionwidgets.group.value )
dt.preferences.write( mod, 'copy_metadata', 'bool', GUI.optionwidgets.copy_metadata.value )
dt.preferences.write( mod, 'copy_tags', 'bool', GUI.optionwidgets.copy_tags.value )
dt.preferences.write( mod, 'add_tags', 'string', GUI.optionwidgets.add_tags.text )
end
-- *************************
local function load_preferences()
GUI.optionwidgets.group.value = dt.preferences.read( mod, 'group', 'bool' )
GUI.optionwidgets.copy_metadata.value = dt.preferences.read( mod, 'copy_metadata', 'bool' )
GUI.optionwidgets.copy_tags.value = dt.preferences.read( mod, 'copy_tags', 'bool' )
GUI.optionwidgets.add_tags.text = dt.preferences.read( mod, 'add_tags', 'string')
end
-- *************************
-- stop running job
local function stop_job( job )
if job.valid then
job.valid = false
end
end
-- **************************
local function build_zerene_commandline(zerene_staging_fldr)
local zerene_commandline = ''
local zerene_java_folder = df.sanitize_filename( dt.preferences.read( mod, "ZereneJavaFolder", "string" ) )
-- remove single quotes from folder name
zerene_java_folder = string.gsub(zerene_java_folder,"'","")
local zerene_licfldr = df.sanitize_filename(dt.preferences.read( mod, "ZereneLicFolder", "string" ) )
-- remove single quotes from folder name
local zerene_licfolder = string.gsub(zerene_licfldr,"'","")
-- Build full commandline based on info here https://zerenesystems.com/cms/stacker/docs/batchapi
if dt.configuration.running_os == 'macos' then
zerene_commandline = '"' .. zerene_java_folder .. os_path_seperator .. 'jre' .. os_path_seperator .. 'bin' .. os_path_seperator .. 'java"' -- java runtime packaged with zerene
.. ' -Dlaunchcmddir=' .. '"' .. zerene_licfolder .. '"' -- directory that holds the Zerene Stacker license key
.. ' -Xdock:name="ZereneStacker" -Xdock:icon="' .. zerene_java_folder .. '/../ZereneEurydice.icns"' .. ' -Dapple.laf.useScreenMenuBar=true' -- Settings to integrate in to apple dock etc
.. ' -classpath "' .. zerene_java_folder.. os_path_seperator .. 'ZereneStacker.jar:' -- tell the JRE where to find the Zerene Stacker application and libraries
.. zerene_java_folder .. os_path_seperator .. 'jai_codec.jar:'
.. zerene_java_folder .. os_path_seperator .. 'jdom.jar:'
.. zerene_java_folder .. os_path_seperator .. 'jai_core.jar:'
.. zerene_java_folder .. os_path_seperator .. 'metadata-extractor-2.4.0-beta-1.jar:'
.. zerene_java_folder .. os_path_seperator .. 'jai_imageio.jar:'
.. zerene_java_folder .. os_path_seperator .. 'jdk10hooks.jar"'
end
if dt.configuration.running_os == 'windows' then
zerene_java_folder = zerene_java_folder:gsub('"','') -- remove enclosing quotes
zerene_commandline = '"' .. zerene_java_folder .. os_path_seperator .. 'jre' .. os_path_seperator .. 'bin' .. os_path_seperator .. 'javaw.exe"' -- java runtime packaged with zerene
.. ' -Dlaunchcmddir=' .. '"' .. zerene_licfolder .. '"' -- directory that holds the Zerene Stacker license key
.. ' -DjavaBits=64bitJava'
.. ' -classpath "' .. zerene_java_folder.. os_path_seperator .. 'ZereneStacker.jar;' -- tell the JRE where to find the Zerene Stacker application and libraries
.. zerene_java_folder .. os_path_seperator .. 'JREextensions' .. os_path_seperator .. '*"'
end
if dt.configuration.running_os == 'linux' then
zerene_commandline = '"' .. zerene_java_folder .. os_path_seperator .. 'jre' .. os_path_seperator .. 'bin' .. os_path_seperator .. 'java"' -- java runtime packaged with zerene
.. ' -DjavaBits=64bitJava'
.. ' -Dlaunchcmddir=' .. '"' .. zerene_licfolder .. '"' -- directory that holds the Zerene Stacker license key
.. ' -classpath "' .. zerene_java_folder.. os_path_seperator .. 'ZereneStacker.jar:' -- tell the JRE where to find the Zerene Stacker application and libraries
.. zerene_java_folder .. os_path_seperator .. '/JREextensions/*"'
end
-- options to modify how zerene runs
zerene_commandline = zerene_commandline .. ' com.zerenesystems.stacker.gui.MainFrame'
.. ' -noSplashScreen' -- disable splash screen
.. ' -leaveLastBatchProjectOpen' -- leave project open for re-touching etc
-- Add staging folder
zerene_commandline = zerene_commandline .. ' ' .. os_quote .. zerene_staging_fldr .. os_quote
return zerene_commandline
end
-- *************************************************
-- main function to run Zerene Stacker
-- *************************************************
local function start_stacking()
dt.print_log( "starting stacking..." )
save_preferences()
local images = dt.gui.selection() --get selected images
-- create a new progress_bar displayed in darktable.gui.libs.backgroundjobs
local jobdesc = _"exporting " .. #images .. " images to Zerene Stacker..."
dt.print_log ('jobdesc is ' .. jobdesc)
local job = dt.gui.create_job( jobdesc, true, stop_job )
if #images < 2 then --ensure enough images selected
dt.print(_('not enough images selected, select at least 2 images to stack'))
stop_job(job)
return
end
local firstimagepath = '' -- this will be path that stacked images get moved to prior to import
local firstimagebase = '' -- basename of first image for naming of output files
local meta_data = { -- storage for metadata to apply to stacked images
title = '',
description = '',
creator = '',
rights = '',
}
local source_img_table = {} -- table of source images
local exported_images_table = {} -- table of exported images
local all_tags = {} -- table of all tags from source images
local images_to_group = {} -- table of images to be grouped with first images
local img_count = #images -- number of source images
local ZereneBatchFound = false
local stagingfolder = df.sanitize_filename( dt.preferences.read( mod, "StackerStagingFolder", "string" ) )
-- remove single & double quotes from folder name
stagingfolder = string.gsub(stagingfolder,"'","")
stagingfolder = string.gsub(stagingfolder,'"','')
-- check staging folder is empty other than ZereneBatch.xml - depends on lfsfilesystem which may not be available
if lfs_loaded then
local staging_clear = true
for this_file in lfs.dir(stagingfolder) do
if this_file ~= "." and this_file ~= ".." then
dt.print_log(' Found '.. this_file)
if this_file == 'ZereneBatch.xml' then
ZereneBatchFound = true
else
if string.sub(this_file,1,1) ~= '.' then -- hidden files are ok as Zerene ignores them
staging_clear=false
break
end
end
end
end
if not (staging_clear) then
dt.print_log(stagingfolder .. " not empty")
dt.print(_("Please ensure the folder " .. stagingfolder .. " contains only ZereneBatch.xml"))
stop_job(job)
return
end
if not(ZereneBatchFound) then
dt.print_log("ZereneBatch.xml not found")
dt.print(_("ZereneBatch.xml not found in " .. stagingfolder ))
stop_job(job)
return
end
end
-- create tif export of source imaage in staging folder
for i,image in pairs(images) do
local export_file_name = stagingfolder..os_path_seperator..image.filename..".tif"
export_image( image, export_file_name)
-- store tags for all exported images
copy_tags( all_tags, image )
-- store exported image name
table.insert(exported_images_table,export_file_name)
-- store source image for later grouping, tagging etc
source_img_table[ #source_img_table+1] = image
if i == 1 then
-- get path of first source image - stacked files will be moved to this folder prior to import to DT
dt.print_log( 'image.path= '..image.path )
dt.print_log( 'sanitized = '..df.sanitize_filename( image.path ) )
firstimagepath = df.sanitize_filename( image.path )
firstimagepath = string.gsub(firstimagepath,"'","")
firstimagepath = string.gsub(firstimagepath,'"','')
firstimagebase= df.get_basename(image.filename)
meta_data.title = image.title
meta_data.description = image.description
meta_data.creator = image.creator
meta_data.rights = image.rights
else
-- remember image to group later:
images_to_group[ #images_to_group + 1 ] = image
end
if dt.control.ending or not job.valid then
dt.print_log( _"exporting images canceled!")
return
end
-- update progress_bar
job.percent = i / #images
-- sleep for a short moment to give stop_job callback function a chance to run
dt.control.sleep(10)
end
-- stop job and remove progress_bar from ui, but only if not alreay canceled
stop_job(job)
-- get os dependent command line to run Zerene Stacker
local zerene_commandline = build_zerene_commandline(stagingfolder)
-- run Zerene Stacker
job = dt.gui.create_job( _"Running Zerene Stacker...", true, stop_job )
dt.print_log( 'commandline: '..zerene_commandline )
local zerene_start_time = os.date("*t",os.time())
dt.print_log("Zerene Started " .. zerene_start_time.hour ..":" .. zerene_start_time.min .. ":" .. zerene_start_time.sec)
local resp
if dt.configuration.running_os == 'windows' then
resp = dsys.windows_command( zerene_commandline)
else
resp = dsys.external_command( zerene_commandline )
end
dt.print_log( 'zerene returned '..tostring( resp ) )
if resp ~= 0 then
dt.print( _'could not start ZereneStacker application' )
end
local zerene_end_time = os.date("*t",os.time())
dt.print_log("Zerene Finished " .. zerene_end_time.hour ..":" .. zerene_end_time.min .. ":" .. zerene_end_time.sec)
stop_job(job)
-- delete exported tif files
for i,exp_file_name in pairs(exported_images_table) do
if (os.remove(exp_file_name)) then
dt.print_log("Removed " .. exp_file_name)
else
dt.print_log("Failed to renove " .. exp_file_name)
end
end
local stackedimages = {} -- table of images to be moved/imported
if lfs_loaded then
-- use lfs to find all tif images in staging folder - even if default output filenames are changed in ZereneStacker
for this_file in lfs.dir(stagingfolder) do
if this_file ~= "." and this_file ~= ".." then
dt.print_log('Found '.. this_file)
if string.sub(this_file,1,1) ~= '.' then -- ignore hidden files
local file_type = df.get_filetype(this_file)
if file_type == 'tif' then
table.insert(stackedimages,this_file)
end
end
end
end
else
-- no lfs - look for specific filenames - will fail to find immages not using default output filename "ZS-OutputImage ZS {method}.tif"
local zs_base = "ZS-OutputImage"
local zs_extensions={".tif", " ZS PMax.tif"," ZS DMap.tif"," ZS retouched.tif"}
-- now look for the full names including extensions
for jj = 1, 4 do
local this_zs_image = zs_base .. zs_extensions[jj]
-- does this file exist?
dt.print_log("Checking for " .. this_zs_image)
if df.check_if_file_exists(stagingfolder .. os_path_seperator .. this_zs_image) then
table.insert(stackedimages,this_zs_image)
end
end
end
-- process all images in stackedimages table
for _,this_file in pairs(stackedimages) do
-- rename stacked image to reflect source images
local full_filename = stagingfolder .. os_path_seperator .. this_file
local new_filename = stagingfolder ..os_path_seperator .. firstimagebase .. '-' .. img_count .. '-ZS.' .. df.get_filetype(this_file)
dt.print_log('Renaming ' .. full_filename .. ' to ' .. new_filename)
if not df.file_move(full_filename,new_filename) then
dt.print_log("Unable to rename " .. full_filename .. " to " .. new_filename .. " please check manually")
break
end
this_file = df.get_filename(new_filename)
full_filename = new_filename
-- now move renamed file from staging folder and import to DT
-- use df.create_unique_file in case stacked filename already exists in source folder
local target_filename = df.create_unique_filename( firstimagepath .. os_path_seperator .. this_file)
dt.print_log('Source is ' .. this_file .. ' target is ' .. target_filename)
if target_filename ~= "" then
-- move stacked image to source folder and import
if df.file_move(full_filename,target_filename) then
-- stacked tif now in correct folder and ready for import
local imported_image = dt.database.import(target_filename)
if imported_image == nil then
dt.print_log("Unable to import " .. target_filename)
dt.print(_("Unable to move " .. this_file .. " to " .. firstimagepath .. " please check manually"))
break
end
-- group
-- first group all source images
if GUI.optionwidgets.group.value == true then
for _,imagetogroup in pairs( images_to_group ) do
imagetogroup:group_with( source_img_table[ 1 ] )
end
-- now add stacked image to group and make it leader
imported_image:group_with(source_img_table[1])
imported_image:make_group_leader()
end
-- tags
if GUI.optionwidgets.copy_tags.value == true then
insert_tags(imported_image,all_tags)
end
add_additional_tags(imported_image)
-- metadata
if GUI.optionwidgets.copy_metadata.value == true then
imported_image.title = meta_data.title
imported_image.description = meta_data.description
imported_image.creator = meta_data.creator
imported_image.rights = meta_data.rights
end
else
-- create_unique_filename may fail if 100 other files with same basename exist, also pernissions may cause move to fail
dt.print_log("Unable to move " .. this_file .. " to " .. firstimagepath .. " please check manually")
dt.print(_("Unable to import " .. target_filename))
end
end
end
end
-- *************************************************
-- GUI and preferences set up, register lib
-- *************************************************
GUI.optionwidgets.group = dt.new_widget('check_button') {
label = _('group'),
value = false,
tooltip = _('group selected source images and imported result image(s) together'),
clicked_callback = function(self)
dt.print_log( "group: "..tostring( self.value ) )
end,
reset_callback = function(self)
self.value = false
end
}
GUI.optionwidgets.copy_metadata = dt.new_widget('check_button') {
label = _('copy metadata'),
value = false,
tooltip = _('copy metadata first source image to the imported result image(s)'),
clicked_callback = function(self)
dt.print_log( "copy metadata: "..tostring( self.value ) )
end,
reset_callback = function(self) self.value = false end
}
GUI.optionwidgets.copy_tags = dt.new_widget('check_button') {
label = _('copy tags'),
value = false,
tooltip = _('copy tags from first source image to the imported result image(s)'),
clicked_callback = function(self)
dt.print_log( "copy tags: "..tostring( self.value ) )
end,
reset_callback = function(self) self.value = false end
}
GUI.optionwidgets.label_settings = dt.new_widget('section_label'){
label = _('settings')
}
GUI.optionwidgets.label_import_options = dt.new_widget('section_label'){
label = _('import options')
}
GUI.optionwidgets.add_tags_label = dt.new_widget('label') {
label = _('new tags'),
ellipsize = 'start',
halign = 'start'
}
GUI.optionwidgets.add_tags = dt.new_widget('entry'){
tooltip = _('Additional tags to be added on import. Seperate with commas, all spaces will be removed'),
placeholder = _('Enter tags, seperated by commas'),
editable = true
}
GUI.optionwidgets.add_tags_box = dt.new_widget('box') {
orientation = 'horizontal',
GUI.optionwidgets.add_tags_label,
GUI.optionwidgets.add_tags
}
GUI.options = dt.new_widget('box') {
orientation = 'vertical',
GUI.optionwidgets.label_import_options,
GUI.optionwidgets.group,
GUI.optionwidgets.copy_metadata,
GUI.optionwidgets.copy_tags,
GUI.optionwidgets.add_tags_box
}
GUI.run = dt.new_widget('button'){
label = _('stack with Zerene Stacker'),
tooltip =_('run zerene Focus to stack selected images'),
clicked_callback = function() start_stacking() end
}
-- Preferences - locate Zerene App and staging folder used for image export and script
dt.preferences.register(
mod, -- script
"StackerStagingFolder", -- name
"directory", -- type
_('Stacker Staging Folder'), -- label
_('Select the staging folder to be used for stacking'), -- tooltip
"" -- default,
)
dt.preferences.register(
mod, -- script
"ZereneJavaFolder", -- name
"directory", -- type
_('Zerene Stacker Java Folder'), -- label
_('Select the Zerene Stacker Java folder'), -- tooltip
"" -- default,
)
dt.preferences.register(
mod, -- script
"ZereneLicFolder", -- name
"directory", -- type
_('Zerene Licence Folder'), -- label
_('Select the folder holding the Zerene licence key'), -- tooltip
"" -- default,
)
load_preferences()
local function install_module()
if not mE.module_installed then
dt.register_lib( -- register module
'ZereneStacker_Lib', -- Module name
_('Zerene Stacker'), -- name
true, -- expandable
true, -- resetable
{[dt.gui.views.lighttable] = {'DT_UI_CONTAINER_PANEL_RIGHT_CENTER', 99}}, -- containers
dt.new_widget('box'){
orientation = 'vertical',
GUI.options,
GUI.run
},
nil,-- view_enter
nil -- view_leave
)
end
end
local function destroy()
dt.gui.libs["ZereneStacker_Lib"].visible = false
end
local function restart()
dt.gui.libs["ZereneStacker_Lib"].visible = true
end
if dt.gui.current_view().id == "lighttable" then -- make sure we are in lighttable view
install_module() -- register the lib
else
if not mE.event_registered then -- if we are not in lighttable view then register an event to signal when we might be
-- https://www.darktable.org/lua-api/index.html#darktable_register_event
dt.register_event(
"mdouleExample", "view-changed", -- we want to be informed when the view changes
function(event, old_view, new_view)
if new_view.name == "lighttable" and old_view.name == "darkroom" then -- if the view changes from darkroom to lighttable
install_module() -- register the lib
end
end
)
mE.event_registered = true -- keep track of whether we have an event handler installed
end
end
script_data.destroy = destroy
script_data.restart = restart
script_data.destroy_method = "hide"
script_data.show = restart
return script_data