@@ -46,6 +46,44 @@ local function _(msgid)
46
46
return gettext .dgettext (" moduleExample" , msgid )
47
47
end
48
48
49
+ -- declare a local namespace and a couple of variables we'll need to install the module
50
+ local mE = {}
51
+ mE .widgets = {}
52
+ mE .event_registered = false -- keep track of whether we've added an event callback or not
53
+ mE .module_installed = false -- keep track of whether the module is module_installed
54
+
55
+ --[[ We have to create the module in one of two ways depending on which view darktable starts
56
+ in. In orker to not repeat code, we wrap the darktable.register_lib in a local function.
57
+ ]]
58
+
59
+ local function install_module ()
60
+ if not mE .module_installed then
61
+ -- https://www.darktable.org/lua-api/index.html#darktable_register_lib
62
+ dt .register_lib (
63
+ " exampleModule" , -- Module name
64
+ " exampleModule" , -- name
65
+ true , -- expandable
66
+ false , -- resetable
67
+ {[dt .gui .views .lighttable ] = {" DT_UI_CONTAINER_PANEL_RIGHT_CENTER" , 100 }}, -- containers
68
+ -- https://www.darktable.org/lua-api/types_lua_box.html
69
+ dt .new_widget (" box" ) -- widget
70
+ {
71
+ orientation = " vertical" ,
72
+ dt .new_widget (" button" )
73
+ {
74
+ label = _ (" MyButton" ),
75
+ clicked_callback = function (_ )
76
+ dt .print (_ (" Button clicked" ))
77
+ end
78
+ },
79
+ table.unpack (mE .widgets ),
80
+ },
81
+ nil ,-- view_enter
82
+ nil -- view_leave
83
+ )
84
+ mE .module_installed = true
85
+ end
86
+ end
49
87
50
88
-- https://www.darktable.org/lua-api/types_lua_check_button.html
51
89
local check_button = dt .new_widget (" check_button" ){label = _ (" MyCheck_button" ), value = true }
@@ -90,35 +128,35 @@ local slider = dt.new_widget("slider")
90
128
value = 52 -- The current value of the slider
91
129
}
92
130
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
102
- {
103
- orientation = " vertical" ,
104
- dt .new_widget (" button" )
105
- {
106
- label = _ (" MyButton" ),
107
- clicked_callback = function (_ )
108
- dt .print (_ (" Button clicked" ))
131
+ -- pack the widgets in a table for loading in the module
132
+
133
+ table.insert (mE .widgets , check_button )
134
+ table.insert (mE .widgets , combobox )
135
+ table.insert (mE .widgets , entry )
136
+ table.insert (mE .widgets , file_chooser_button )
137
+ table.insert (mE .widgets , label )
138
+ table.insert (mE .widgets , separator )
139
+ table.insert (mE .widgets , slider )
140
+
141
+ -- ... and tell dt about it all
142
+
143
+
144
+ if dt .gui .current_view ().name == " lighttable" then -- make sure we are in lighttable view
145
+ install_module () -- register the lib
146
+ else
147
+ if not mE .event_registered then -- if we are not in lighttable view then register an event to signal when we might be
148
+ -- https://www.darktable.org/lua-api/index.html#darktable_register_event
149
+ dt .register_event (
150
+ " view-changed" , -- we want to be informed when the view changes
151
+ function (event , old_view , new_view )
152
+ if new_view .name == " lighttable" and old_view .name == " darkroom" then -- if the view changes from darkroom to lighttable
153
+ install_module () -- register the lib
154
+ end
109
155
end
110
- },
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
- )
156
+ )
157
+ mE .event_registered = true -- keep track of whether we have an event handler installed
158
+ end
159
+ end
122
160
123
161
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua
124
162
-- kate: hl Lua;
0 commit comments