Skip to content

Commit 6a7cd31

Browse files
authored
Merge pull request darktable-org#249 from wpferguson/fix_moduleExample
Update examples/moduleExample.lua
2 parents 2515db3 + 0856858 commit 6a7cd31

File tree

1 file changed

+56
-71
lines changed

1 file changed

+56
-71
lines changed

examples/moduleExample.lua

Lines changed: 56 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
--[[
1919
2020
USAGE
21-
* require this script from your main lua file
21+
* require this script from your luarc file
2222
To do this add this line to the file .config/darktable/luarc:
23-
require "moduleExample"
23+
require "examples/moduleExample"
2424
2525
* it creates a new example lighttable module
2626
@@ -35,105 +35,90 @@ local du = require "lib/dtutils"
3535

3636
du.check_min_api_version("3.0.0", "moduleExample")
3737

38-
-- add a new lib
39-
local check_button = dt.new_widget("check_button"){label = "MyCheck_button", value = true}
40-
local combobox = dt.new_widget("combobox"){label = "MyCombobox", value = 2, "8", "16", "32"}
38+
-- translation
4139

42-
--https://www.darktable.org/lua-api/ar01s02s54.html.php
40+
-- https://www.darktable.org/lua-api/index.html#darktable_gettext
41+
local gettext = dt.gettext
42+
43+
gettext.bindtextdomain("moduleExample", dt.configuration.config_dir .. "/lua/locale/")
44+
45+
local function _(msgid)
46+
return gettext.dgettext("moduleExample", msgid)
47+
end
48+
49+
50+
-- https://www.darktable.org/lua-api/types_lua_check_button.html
51+
local check_button = dt.new_widget("check_button"){label = _("MyCheck_button"), value = true}
52+
53+
-- https://www.darktable.org/lua-api/types_lua_combobox.html
54+
local combobox = dt.new_widget("combobox"){label = _("MyCombobox"), value = 2, "8", "16", "32"}
55+
56+
-- https://www.darktable.org/lua-api/types_lua_entry.html
4357
local entry = dt.new_widget("entry")
4458
{
4559
text = "test",
46-
placeholder = "placeholder",
60+
placeholder = _("placeholder"),
4761
is_password = false,
4862
editable = true,
49-
tooltip = "Tooltip Text",
63+
tooltip = _("Tooltip Text"),
5064
reset_callback = function(self) self.text = "text" end
5165
}
5266

67+
-- https://www.darktable.org/lua-api/types_lua_file_chooser_button.html
5368
local file_chooser_button = dt.new_widget("file_chooser_button")
5469
{
55-
title = "MyFile_chooser_button", -- The title of the window when choosing a file
70+
title = _("MyFile_chooser_button"), -- The title of the window when choosing a file
5671
value = "", -- The currently selected file
5772
is_directory = false -- True if the file chooser button only allows directories to be selecte
5873
}
5974

75+
-- https://www.darktable.org/lua-api/types_lua_label.html
6076
local label = dt.new_widget("label")
61-
label.label = "MyLabel" -- This is an alternative way to the "{}" syntax to set a property
77+
label.label = _("MyLabel") -- This is an alternative way to the "{}" syntax to set a property
6278

79+
-- https://www.darktable.org/lua-api/types_lua_separator.html
6380
local separator = dt.new_widget("separator"){}
81+
82+
-- https://www.darktable.org/lua-api/types_lua_slider.html
6483
local slider = dt.new_widget("slider")
6584
{
66-
label = "MySlider",
85+
label = _("MySlider"),
6786
soft_min = 10, -- The soft minimum value for the slider, the slider can't go beyond this point
6887
soft_max = 100, -- The soft maximum value for the slider, the slider can't go beyond this point
6988
hard_min = 0, -- The hard minimum value for the slider, the user can't manually enter a value beyond this point
7089
hard_max = 1000, -- The hard maximum value for the slider, the user can't manually enter a value beyond this point
7190
value = 52 -- The current value of the slider
7291
}
7392

74-
if (dt.configuration.api_version_major >= 6) then
75-
local section_label = dt.new_widget("section_label")
93+
-- https://www.darktable.org/lua-api/index.html#darktable_register_lib
94+
dt.register_lib(
95+
"exampleModule", -- Module name
96+
"exampleModule", -- name
97+
true, -- expandable
98+
false, -- resetable
99+
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, -- containers
100+
-- https://www.darktable.org/lua-api/types_lua_box.html
101+
dt.new_widget("box") -- widget
76102
{
77-
label = "MySectionLabel"
78-
}
79-
80-
dt.register_lib(
81-
"exampleModule", -- Module name
82-
"exampleModule", -- name
83-
true, -- expandable
84-
false, -- resetable
85-
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, -- containers
86-
dt.new_widget("box") -- widget
103+
orientation = "vertical",
104+
dt.new_widget("button")
87105
{
88-
orientation = "vertical",
89-
dt.new_widget("button")
90-
{
91-
label = "MyButton",
92-
clicked_callback = function (_)
93-
dt.print("Button clicked")
94-
end
95-
},
96-
check_button,
97-
combobox,
98-
entry,
99-
file_chooser_button,
100-
label,
101-
separator,
102-
slider,
103-
section_label
106+
label = _("MyButton"),
107+
clicked_callback = function (_)
108+
dt.print(_("Button clicked"))
109+
end
104110
},
105-
nil,-- view_enter
106-
nil -- view_leave
107-
)
108-
else
109-
dt.register_lib(
110-
"exampleModule", -- Module name
111-
"exampleModule", -- name
112-
true, -- expandable
113-
false, -- resetable
114-
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, -- containers
115-
dt.new_widget("box") -- widget
116-
{
117-
orientation = "vertical",
118-
dt.new_widget("button")
119-
{
120-
label = "MyButton",
121-
clicked_callback = function (_)
122-
dt.print("Button clicked")
123-
end
124-
},
125-
check_button,
126-
combobox,
127-
entry,
128-
file_chooser_button,
129-
label,
130-
separator,
131-
slider
132-
},
133-
nil,-- view_enter
134-
nil -- view_leave
135-
)
136-
end
111+
check_button,
112+
combobox,
113+
entry,
114+
file_chooser_button,
115+
label,
116+
separator,
117+
slider
118+
},
119+
nil,-- view_enter
120+
nil -- view_leave
121+
)
137122

138123
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua
139124
-- kate: hl Lua;

0 commit comments

Comments
 (0)