Skip to content

Commit bccc86c

Browse files
authored
Merge pull request darktable-org#362 from dterrahe/lua_action
simple module to call dt_action_process
2 parents 12640c7 + 28ae2ea commit bccc86c

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

‎examples/gui_action.lua‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
local dt = require "darktable"
2+
3+
local NaN = 0/0
4+
5+
local wg = {}
6+
7+
wg.action = dt.new_widget("entry"){
8+
text = "lib/filter/view",
9+
placeholder = "action path",
10+
tooltip = "enter the full path of an action, for example 'lib/filter/view'"
11+
}
12+
13+
wg.instance = dt.new_widget("combobox"){
14+
label = "instance",
15+
tooltip = "the instance of an image processing module to execute action on",
16+
"0", "+1", "-1", "+2", "-2", "+3", "-3", "+4", "-4", "+5", "-5", "+6", "-6", "+7", "-7", "+8", "-8", "+9", "-9"
17+
}
18+
19+
wg.element = dt.new_widget("entry"){
20+
text = "",
21+
placeholder = "action element",
22+
tooltip = "enter the element of an action, for example 'selection', or leave empty for default"
23+
}
24+
25+
wg.effect = dt.new_widget("entry"){
26+
text = "next",
27+
placeholder = "action effect",
28+
tooltip = "enter the effect of an action, for example 'next', or leave empty for default"
29+
}
30+
31+
wg.speed = dt.new_widget("entry"){
32+
text = "1",
33+
placeholder = "action speed",
34+
tooltip = "enter the speed to use in action execution, or leave empty to only read state"
35+
}
36+
37+
wg.check = dt.new_widget("check_button"){
38+
label = 'perform action',
39+
tooltip = 'perform action or only read return',
40+
clicked_callback = function()
41+
wg.speed.sensitive = wg.check.value
42+
end,
43+
value = true
44+
}
45+
46+
wg.return_value = dt.new_widget("entry"){
47+
text = "",
48+
sensitive = false
49+
}
50+
51+
dt.register_lib(
52+
"execute_action", -- Module name
53+
"execute gui actions", -- name
54+
true, -- expandable
55+
false, -- resetable
56+
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER", 100},
57+
[dt.gui.views.darkroom] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER", 100}},
58+
dt.new_widget("box")
59+
{
60+
orientation = "vertical",
61+
62+
dt.new_widget("box")
63+
{
64+
orientation = "horizontal",
65+
dt.new_widget("label"){label = "action path", halign = "start"},
66+
wg.action
67+
},
68+
wg.instance,
69+
dt.new_widget("box")
70+
{
71+
orientation = "horizontal",
72+
dt.new_widget("label"){label = "element", halign = "start"},
73+
wg.element
74+
},
75+
dt.new_widget("box")
76+
{
77+
orientation = "horizontal",
78+
dt.new_widget("label"){label = "effect", halign = "start"},
79+
wg.effect
80+
},
81+
wg.check,
82+
dt.new_widget("box")
83+
{
84+
orientation = "horizontal",
85+
dt.new_widget("label"){label = "speed", halign = "start"},
86+
wg.speed
87+
},
88+
dt.new_widget("button")
89+
{
90+
label = "execute action",
91+
tooltip = "execute the action specified in the fields above",
92+
clicked_callback = function(_)
93+
local sp = nan
94+
if wg.check.value then sp = wg.speed.text end
95+
wg.return_value.text = dt.gui.action(wg.action.text, wg.instance.value, wg.element.text, wg.effect.text, sp)
96+
end
97+
},
98+
dt.new_widget("box")
99+
{
100+
orientation = "horizontal",
101+
dt.new_widget("label"){label = "return value:", halign = "start"},
102+
wg.return_value
103+
},
104+
}
105+
)

0 commit comments

Comments
 (0)