NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
authorEdouard Tisserant
Mon, 13 Aug 2018 13:24:28 +0200
changeset 2262 4195545e2d17
parent 2261 37ef7a3c6b8b
child 2263 5227f54f6369
NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
runtime/NevowServer.py
runtime/WampClient.py
--- a/runtime/NevowServer.py	Mon Aug 13 11:10:23 2018 +0200
+++ b/runtime/NevowServer.py	Mon Aug 13 13:24:28 2018 +0200
@@ -135,11 +135,34 @@
     def __init__(self):
         configurable.Configurable.__init__(self, None)
         self.bindingsNames = []
+        self.infostringcount = 0
 
     def getBindingNames(self, ctx):
         return self.bindingsNames
 
-    def addExtension(self, name, desc, fields, btnlabel, callback):
+    def addInfoString(self, label, value, name=None):
+        if type(value) is str:
+            def default(*k):
+                return value
+        else:
+            def default(*k):
+                return value()
+
+        if name is None:
+            name = "_infostring_" + str(self.infostringcount)
+            self.infostringcount = self.infostringcount + 1
+
+        def _bind(ctx):
+            return annotate.Property(
+                name,
+                annotate.String(
+                    label=label,
+                    default=default,
+                    immutable=True))
+        setattr(self, 'bind_' + name, _bind)
+        self.bindingsNames.append(name)
+
+    def addSettings(self, name, desc, fields, btnlabel, callback):
         def _bind(ctx):
             return annotate.MethodBinding(
                 'action_' + name,
--- a/runtime/WampClient.py	Mon Aug 13 11:10:23 2018 +0200
+++ b/runtime/WampClient.py	Mon Aug 13 13:24:28 2018 +0200
@@ -427,7 +427,8 @@
 
 
 def RegisterWebSettings(NS):
-    NS.ConfigurableSettings.addExtension(
+
+    NS.ConfigurableSettings.addSettings(
         "wamp",
         _("Wamp Settings"),
         webFormInterface,