|
| 1 | +--[[ |
| 2 | +
|
| 3 | + cycle_group_leader.lua - change image grouip leader |
| 4 | +
|
| 5 | + Copyright (C) 2024 Bill Ferguson <[email protected]> |
| 6 | +
|
| 7 | + This program is free software: you can redistribute it and/or modify |
| 8 | + it under the terms of the GNU General Public License as published by |
| 9 | + the Free Software Foundation; either version 3 of the License, or |
| 10 | + (at your option) any later version. |
| 11 | +
|
| 12 | + This program is distributed in the hope that it will be useful, |
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + GNU General Public License for more details. |
| 16 | +
|
| 17 | + You should have received a copy of the GNU General Public License |
| 18 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | +]] |
| 20 | +--[[ |
| 21 | + cycle_group_leader - change image grouip leader |
| 22 | +
|
| 23 | + cycle_group_leader changes the group leader to the next |
| 24 | + image in the group. If the end of the group is reached |
| 25 | + then the next image is wrapped around to the first image. |
| 26 | +
|
| 27 | + ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT |
| 28 | + None |
| 29 | +
|
| 30 | + USAGE |
| 31 | + * enable with script_manager |
| 32 | + * assign a key to the shortcut |
| 33 | +
|
| 34 | + BUGS, COMMENTS, SUGGESTIONS |
| 35 | + |
| 36 | +
|
| 37 | + CHANGES |
| 38 | +]] |
| 39 | + |
| 40 | +local dt = require "darktable" |
| 41 | +local du = require "lib/dtutils" |
| 42 | +local df = require "lib/dtutils.file" |
| 43 | + |
| 44 | +-- - - - - - - - - - - - - - - - - - - - - - - - |
| 45 | +-- C O N S T A N T S |
| 46 | +-- - - - - - - - - - - - - - - - - - - - - - - - |
| 47 | + |
| 48 | +local MODULE = "cycle_group_leader" |
| 49 | + |
| 50 | +-- - - - - - - - - - - - - - - - - - - - - - - - |
| 51 | +-- A P I C H E C K |
| 52 | +-- - - - - - - - - - - - - - - - - - - - - - - - |
| 53 | + |
| 54 | +du.check_min_api_version("7.0.0", MODULE) |
| 55 | + |
| 56 | + |
| 57 | +-- - - - - - - - - - - - - - - - - - - - - - - - - - |
| 58 | +-- S C R I P T M A N A G E R I N T E G R A T I O N |
| 59 | +-- - - - - - - - - - - - - - - - - - - - - - - - - - |
| 60 | + |
| 61 | +local script_data = {} |
| 62 | + |
| 63 | +script_data.destroy = nil -- function to destory the script |
| 64 | +script_data.destroy_method = nil -- set to hide for libs since we can't destroy them commpletely yet |
| 65 | +script_data.restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again |
| 66 | +script_data.show = nil -- only required for libs since the destroy_method only hides them |
| 67 | + |
| 68 | +-- - - - - - - - - - - - - - - - - - - - - - - - - - |
| 69 | +-- I 1 8 N |
| 70 | +-- - - - - - - - - - - - - - - - - - - - - - - - - - |
| 71 | + |
| 72 | +local gettext = dt.gettext |
| 73 | + |
| 74 | +-- Tell gettext where to find the .mo file translating messages for a particular domain |
| 75 | +gettext.bindtextdomain(MODULE, dt.configuration.config_dir .. "/lua/locale/") |
| 76 | + |
| 77 | +local function _(msgid) |
| 78 | + return gettext.dgettext(MODULE, msgid) |
| 79 | +end |
| 80 | + |
| 81 | +-- - - - - - - - - - - - - - - - - - - - - - - - |
| 82 | +-- F U N C T I O N S |
| 83 | +-- - - - - - - - - - - - - - - - - - - - - - - - |
| 84 | + |
| 85 | +local function toggle_global_toolbox_grouping() |
| 86 | + dt.gui.libs.global_toolbox.grouping = false |
| 87 | + dt.gui.libs.global_toolbox.grouping = true |
| 88 | +end |
| 89 | + |
| 90 | +local function hinter_msg(msg) |
| 91 | + dt.print_hinter(msg) |
| 92 | + dt.control.sleep(1500) |
| 93 | + dt.print_hinter(" ") |
| 94 | +end |
| 95 | + |
| 96 | +-- - - - - - - - - - - - - - - - - - - - - - - - |
| 97 | +-- M A I N P R O G R A M |
| 98 | +-- - - - - - - - - - - - - - - - - - - - - - - - |
| 99 | + |
| 100 | +local function cycle_group_leader(image) |
| 101 | + local group_images = image:get_group_members() |
| 102 | + if #group_images < 2 then |
| 103 | + hinter_msg(_("No images to cycle to in group")) |
| 104 | + return |
| 105 | + else |
| 106 | + local position = nil |
| 107 | + for i, img in ipairs(group_images) do |
| 108 | + if image == img then |
| 109 | + position = i |
| 110 | + end |
| 111 | + end |
| 112 | + |
| 113 | + if position == #group_images then |
| 114 | + position = 1 |
| 115 | + else |
| 116 | + position = position + 1 |
| 117 | + end |
| 118 | + |
| 119 | + new_leader = group_images[position] |
| 120 | + new_leader:make_group_leader() |
| 121 | + dt.gui.selection({new_leader}) |
| 122 | + |
| 123 | + if dt.gui.libs.global_toolbox.grouping then |
| 124 | + -- toggle the grouping to make the new leader show |
| 125 | + toggle_global_toolbox_grouping() |
| 126 | + end |
| 127 | + end |
| 128 | +end |
| 129 | + |
| 130 | +-- - - - - - - - - - - - - - - - - - - - - - - - |
| 131 | +-- D A R K T A B L E I N T E G R A T I O N |
| 132 | +-- - - - - - - - - - - - - - - - - - - - - - - - |
| 133 | + |
| 134 | +local function destroy() |
| 135 | + -- put things to destroy (events, storages, etc) here |
| 136 | + dt.destroy_event(MODULE, "shortcut") |
| 137 | +end |
| 138 | + |
| 139 | +script_data.destroy = destroy |
| 140 | + |
| 141 | +-- - - - - - - - - - - - - - - - - - - - - - - - |
| 142 | +-- E V E N T S |
| 143 | +-- - - - - - - - - - - - - - - - - - - - - - - - |
| 144 | + |
| 145 | +dt.register_event(MODULE, "shortcut", |
| 146 | + function(event, shortcut) |
| 147 | + -- ignore the film roll, it contains all the images, not just the imported |
| 148 | + local images = dt.gui.selection() |
| 149 | + if #images < 1 then |
| 150 | + dt.print(_("No image selected. Please select an image and try again")) |
| 151 | + else |
| 152 | + cycle_group_leader(images[1]) |
| 153 | + end |
| 154 | + end, |
| 155 | + _("cycle group leader") |
| 156 | +) |
| 157 | + |
| 158 | +return script_data |
0 commit comments