runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Fri, 18 Dec 2020 11:50:28 +0100
changeset 2700 144b149cded4
parent 2699 467ff0e58327
child 2701 f4dac054cfa3
runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
runtime/NevowServer.py
--- a/runtime/NevowServer.py	Thu Dec 10 15:48:15 2020 +0100
+++ b/runtime/NevowServer.py	Fri Dec 18 11:50:28 2020 +0100
@@ -39,6 +39,7 @@
 
 import util.paths as paths
 from runtime.loglevels import LogLevels, LogLevelsDict
+from runtime import MainWorker, GetPLCObjectSingleton
 
 PAGE_TITLE = 'Beremiz Runtime Web Interface'
 
@@ -217,6 +218,18 @@
                                                "Send a message to the log"),
                                            action=_("Send"))
 
+    # pylint: disable=no-self-argument
+    def restartOrResetPLC(
+            ctx=annotate.Context(),
+            action=annotate.Choice(["Restart", "Reset"],
+                                  required=True,
+                                  label=_("Action"))):
+        pass
+
+    restartOrResetPLC = annotate.autocallable(restartOrResetPLC,
+                                           label=_(
+                                               "Restart or Reset"),
+                                           action=_("Do"))
 
 customSettingsURLs = {
 }
@@ -284,9 +297,16 @@
 
     def sendLogMessage(self, level, message, **kwargs):
         level = LogLevelsDict[level]
-        if _PySrv.plcobj is not None:
-            _PySrv.plcobj.LogMessage(
-                level, "Web form log message: " + message)
+        GetPLCObjectSingleton().LogMessage(
+            level, "Web form log message: " + message)
+
+    def restartOrResetPLC(self, action, **kwargs):
+        if(action == "Reset"):
+            GetPLCObjectSingleton().RepairPLC()
+        else:
+            MainWorker.quit()
+            
+        
 
     def locateChild(self, ctx, segments):
         if segments[0] in customSettingsURLs: