-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathgui_action.lua
More file actions
142 lines (121 loc) · 4.09 KB
/
gui_action.lua
File metadata and controls
142 lines (121 loc) · 4.09 KB
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
local dt = require "darktable"
local NaN = 0/0
local wg = {}
local gettext = dt.gettext.gettext
local function _(msgid)
return gettext(msgid)
end
-- return data structure for script_manager
local script_data = {}
script_data.metadata = {
name = _("gui action"),
purpose = _("example of how to use darktable.gui.action() calls"),
author = "Diederik ter Rahe",
help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/examples/gui_action"
}
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
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
wg.action = dt.new_widget("entry"){
text = "lib/filter/view",
placeholder = _("action path"),
tooltip = _("enter the full path of an action, for example 'lib/filter/view'")
}
wg.instance = dt.new_widget("combobox"){
label = _("instance"),
tooltip = _("the instance of an image processing module to execute action on"),
"0", "+1", "-1", "+2", "-2", "+3", "-3", "+4", "-4", "+5", "-5", "+6", "-6", "+7", "-7", "+8", "-8", "+9", "-9"
}
wg.element = dt.new_widget("entry"){
text = "",
placeholder = _("action element"),
tooltip = _("enter the element of an action, for example 'selection', or leave empty for default")
}
wg.effect = dt.new_widget("entry"){
text = "next",
placeholder = _("action effect"),
tooltip = _("enter the effect of an action, for example 'next', or leave empty for default")
}
wg.speed = dt.new_widget("entry"){
text = "1",
placeholder = _("action speed"),
tooltip = _("enter the speed to use in action execution, or leave empty to only read state")
}
wg.check = dt.new_widget("check_button"){
label = _('perform action'),
tooltip = _('perform action or only read return'),
clicked_callback = function()
wg.speed.sensitive = wg.check.value
end,
value = true
}
wg.return_value = dt.new_widget("entry"){
text = "",
sensitive = false
}
dt.register_lib(
"execute_action", -- Module name
_("execute gui actions"), -- name
true, -- expandable
false, -- resetable
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER", 100},
[dt.gui.views.darkroom] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER", 100}},
dt.new_widget("box")
{
orientation = "vertical",
dt.new_widget("box")
{
orientation = "horizontal",
dt.new_widget("label"){label = _("action path"), halign = "start"},
wg.action
},
wg.instance,
dt.new_widget("box")
{
orientation = "horizontal",
dt.new_widget("label"){label = _("element"), halign = "start"},
wg.element
},
dt.new_widget("box")
{
orientation = "horizontal",
dt.new_widget("label"){label = _("effect"), halign = "start"},
wg.effect
},
wg.check,
dt.new_widget("box")
{
orientation = "horizontal",
dt.new_widget("label"){label = _("speed"), halign = "start"},
wg.speed
},
dt.new_widget("button")
{
label = _("execute action"),
tooltip = _("execute the action specified in the fields above"),
clicked_callback = function(_)
local sp = NaN
if wg.check.value then sp = wg.speed.text end
wg.return_value.text = dt.gui.action(wg.action.text, tonumber(wg.instance.value), wg.element.text, wg.effect.text, tonumber(sp))
end
},
dt.new_widget("box")
{
orientation = "horizontal",
dt.new_widget("label"){label = "return value:", halign = "start"},
wg.return_value
},
}
)
local function restart()
dt.gui.libs["execute_action"].visible = true
end
local function destroy()
dt.gui.libs["execute_action"].visible = false
end
script_data.destroy = destroy
script_data.destroy_method = "hide"
script_data.restart = restart
script_data.show = restart
return script_data