24 |
24 |
25 |
25 |
26 from __future__ import absolute_import |
26 from __future__ import absolute_import |
27 from __future__ import print_function |
27 from __future__ import print_function |
28 import os |
28 import os |
|
29 import collections |
29 import platform as platform_module |
30 import platform as platform_module |
30 from zope.interface import implements |
31 from zope.interface import implements |
31 from nevow import appserver, inevow, tags, loaders, athena, url, rend |
32 from nevow import appserver, inevow, tags, loaders, athena, url, rend |
32 from nevow.page import renderer |
33 from nevow.page import renderer |
33 from nevow.static import File |
34 from nevow.static import File |
178 setattr(self, 'bind_' + name, _bind) |
179 setattr(self, 'bind_' + name, _bind) |
179 |
180 |
180 setattr(self, 'action_' + name, callback) |
181 setattr(self, 'action_' + name, callback) |
181 |
182 |
182 self.bindingsNames.append(name) |
183 self.bindingsNames.append(name) |
183 |
184 |
184 |
185 |
185 ConfigurableSettings = ConfigurableBindings() |
186 ConfigurableSettings = ConfigurableBindings() |
186 |
187 |
|
188 def newExtensionSetting(display, token): |
|
189 global extensions_settings_od |
|
190 settings = ConfigurableBindings() |
|
191 extensions_settings_od[token] = (settings, display) |
|
192 return settings |
|
193 |
|
194 def removeExtensionSetting(token): |
|
195 global extensions_settings_od |
|
196 extensions_settings_od.pop(token) |
187 |
197 |
188 class ISettings(annotate.TypedInterface): |
198 class ISettings(annotate.TypedInterface): |
189 platform = annotate.String(label=_("Platform"), |
199 platform = annotate.String(label=_("Platform"), |
190 default=platform_module.system() + |
200 default=platform_module.system() + |
191 " " + platform_module.release(), |
201 " " + platform_module.release(), |
209 |
219 |
210 |
220 |
211 customSettingsURLs = { |
221 customSettingsURLs = { |
212 } |
222 } |
213 |
223 |
|
224 extensions_settings_od = collections.OrderedDict() |
214 |
225 |
215 class SettingsPage(rend.Page): |
226 class SettingsPage(rend.Page): |
216 # We deserve a slash |
227 # We deserve a slash |
217 addSlash = True |
228 addSlash = True |
218 |
229 |
219 # This makes webform_css url answer some default CSS |
230 # This makes webform_css url answer some default CSS |
220 child_webform_css = webform.defaultCSS |
231 child_webform_css = webform.defaultCSS |
221 child_webinterface_css = File(paths.AbsNeighbourFile(__file__, 'webinterface.css'), 'text/css') |
232 child_webinterface_css = File(paths.AbsNeighbourFile(__file__, 'webinterface.css'), 'text/css') |
222 |
233 |
223 implements(ISettings) |
234 implements(ISettings) |
|
235 |
|
236 def __getattr__(self, name): |
|
237 global extensions_settings_od |
|
238 if name.startswith('configurable_'): |
|
239 token = name[13:] |
|
240 def configurable_something(ctx): |
|
241 settings, _display = extensions_settings_od[token] |
|
242 return settings |
|
243 return configurable_something |
|
244 raise AttributeError |
|
245 |
|
246 def extensions_settings(self, context, data): |
|
247 """ Project extensions settings |
|
248 Extensions added to Configuration Tree in IDE have their setting rendered here |
|
249 """ |
|
250 global extensions_settings_od |
|
251 res = [] |
|
252 for token in extensions_settings_od: |
|
253 _settings, display = extensions_settings_od[token] |
|
254 res += [tags.h2[display], webform.renderForms(token)] |
|
255 return res |
224 |
256 |
225 docFactory = loaders.stan([tags.html[ |
257 docFactory = loaders.stan([tags.html[ |
226 tags.head[ |
258 tags.head[ |
227 tags.title[_("Beremiz Runtime Settings")], |
259 tags.title[_("Beremiz Runtime Settings")], |
228 tags.link(rel='stylesheet', |
260 tags.link(rel='stylesheet', |
236 tags.a(href='/')['Back'], |
268 tags.a(href='/')['Back'], |
237 tags.h1["Runtime settings:"], |
269 tags.h1["Runtime settings:"], |
238 webform.renderForms('staticSettings'), |
270 webform.renderForms('staticSettings'), |
239 tags.h1["Extensions settings:"], |
271 tags.h1["Extensions settings:"], |
240 webform.renderForms('dynamicSettings'), |
272 webform.renderForms('dynamicSettings'), |
|
273 extensions_settings |
241 ]]]) |
274 ]]]) |
242 |
275 |
243 def configurable_staticSettings(self, ctx): |
276 def configurable_staticSettings(self, ctx): |
244 return configurable.TypedInterfaceConfigurable(self) |
277 return configurable.TypedInterfaceConfigurable(self) |
245 |
278 |
246 def configurable_dynamicSettings(self, ctx): |
279 def configurable_dynamicSettings(self, ctx): |
|
280 """ Runtime Extensions settings |
|
281 Extensions loaded through Beremiz_service -e or optional runtime features render setting forms here |
|
282 """ |
247 return ConfigurableSettings |
283 return ConfigurableSettings |
248 |
284 |
249 def sendLogMessage(self, level, message, **kwargs): |
285 def sendLogMessage(self, level, message, **kwargs): |
250 level = LogLevelsDict[level] |
286 level = LogLevelsDict[level] |
251 if _PySrv.plcobj is not None: |
287 if _PySrv.plcobj is not None: |