18
18
--[[
19
19
20
20
USAGE
21
- * require this script from your main lua file
21
+ * require this script from your luarc file
22
22
To do this add this line to the file .config/darktable/luarc:
23
- require "moduleExample"
23
+ require "examples/ moduleExample"
24
24
25
25
* it creates a new example lighttable module
26
26
@@ -35,105 +35,90 @@ local du = require "lib/dtutils"
35
35
36
36
du .check_min_api_version (" 3.0.0" , " moduleExample" )
37
37
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
41
39
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
43
57
local entry = dt .new_widget (" entry" )
44
58
{
45
59
text = " test" ,
46
- placeholder = " placeholder" ,
60
+ placeholder = _ ( " placeholder" ) ,
47
61
is_password = false ,
48
62
editable = true ,
49
- tooltip = " Tooltip Text" ,
63
+ tooltip = _ ( " Tooltip Text" ) ,
50
64
reset_callback = function (self ) self .text = " text" end
51
65
}
52
66
67
+ -- https://www.darktable.org/lua-api/types_lua_file_chooser_button.html
53
68
local file_chooser_button = dt .new_widget (" file_chooser_button" )
54
69
{
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
56
71
value = " " , -- The currently selected file
57
72
is_directory = false -- True if the file chooser button only allows directories to be selecte
58
73
}
59
74
75
+ -- https://www.darktable.org/lua-api/types_lua_label.html
60
76
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
62
78
79
+ -- https://www.darktable.org/lua-api/types_lua_separator.html
63
80
local separator = dt .new_widget (" separator" ){}
81
+
82
+ -- https://www.darktable.org/lua-api/types_lua_slider.html
64
83
local slider = dt .new_widget (" slider" )
65
84
{
66
- label = " MySlider" ,
85
+ label = _ ( " MySlider" ) ,
67
86
soft_min = 10 , -- The soft minimum value for the slider, the slider can't go beyond this point
68
87
soft_max = 100 , -- The soft maximum value for the slider, the slider can't go beyond this point
69
88
hard_min = 0 , -- The hard minimum value for the slider, the user can't manually enter a value beyond this point
70
89
hard_max = 1000 , -- The hard maximum value for the slider, the user can't manually enter a value beyond this point
71
90
value = 52 -- The current value of the slider
72
91
}
73
92
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
76
102
{
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" )
87
105
{
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
104
110
},
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
+ )
137
122
138
123
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua
139
124
-- kate: hl Lua;
0 commit comments