Customizable update of toolbar buttons (i.e. 'methods') according to PLCStatus nevow_service_rework
authorEdouard Tisserant
Thu, 19 Jul 2018 13:32:27 +0200
branchnevow_service_rework
changeset 2224 ebd83ec387f9
parent 2223 909216419e45
child 2225 2a9549e4380e
child 2560 2e9cc1b811d1
Customizable update of toolbar buttons (i.e. 'methods') according to PLCStatus
ProjectController.py
--- a/ProjectController.py	Fri Jul 13 09:06:01 2018 +0200
+++ b/ProjectController.py	Thu Jul 19 13:32:27 2018 +0200
@@ -1352,6 +1352,31 @@
             if self.AppFrame is not None:
                 self.AppFrame.LogViewer.SetLogCounters(log_count)
 
+    DefaultMethods = {
+        "_Run": False,
+        "_Stop": False,
+        "_Transfer": False,
+        "_Connect": True,
+        "_Disconnect": False
+    }
+
+    MethodsFromStatus = {
+        "Started":      {"_Stop": True,
+                         "_Transfer": True,
+                         "_Connect": False,
+                         "_Disconnect": True},
+        "Stopped":      {"_Run": True,
+                         "_Transfer": True,
+                         "_Connect": False,
+                         "_Disconnect": True},
+        "Empty":        {"_Transfer": True,
+                         "_Connect": False,
+                         "_Disconnect": True},
+        "Broken":       {"_Connect": False,
+                         "_Disconnect": True},
+        "Disconnected": {},
+    }
+
     def UpdateMethodsFromPLCStatus(self):
         updated = False
         status = None
@@ -1364,21 +1389,11 @@
             self._SetConnector(None, False)
             status = "Disconnected"
         if self.previous_plcstate != status:
-            for args in {
-                    "Started":      [("_Run", False),
-                                     ("_Stop", True)],
-                    "Stopped":      [("_Run", True),
-                                     ("_Stop", False)],
-                    "Empty":        [("_Run", False),
-                                     ("_Stop", False)],
-                    "Broken":       [],
-                    "Disconnected": [("_Run", False),
-                                     ("_Stop", False),
-                                     ("_Transfer", False),
-                                     ("_Connect", True),
-                                     ("_Disconnect", False)],
-            }.get(status, []):
-                self.ShowMethod(*args)
+            allmethods = self.DefaultMethods.copy()
+            allmethods.update(
+                self.MethodsFromStatus.get(status, {}))
+            for method, active in allmethods.items():
+                self.ShowMethod(method,active)
             self.previous_plcstate = status
             if self.AppFrame is not None:
                 updated = True
@@ -1713,10 +1728,6 @@
             # Oups.
             self.logger.write_error(_("Connection failed to %s!\n") % uri)
         else:
-            self.ShowMethod("_Connect", False)
-            self.ShowMethod("_Disconnect", True)
-            self.ShowMethod("_Transfer", True)
-
             self.CompareLocalAndRemotePLC()
 
             # Init with actual PLC status and print it