Added PurgePLC() method to PLCObject, to be invoked when PLC Status is broken. It clears PLC shared object an extra files and force status to Empty. Added correponding Repair button to toolbar, visible only when PLC status is broken.
authorEdouard Tisserant
Mon, 15 Apr 2019 13:34:09 +0200
changeset 2594 f1e182818434
parent 2593 62c5c3589769
child 2595 a0d2741a6722
Added PurgePLC() method to PLCObject, to be invoked when PLC Status is broken. It clears PLC shared object an extra files and force status to Empty. Added correponding Repair button to toolbar, visible only when PLC status is broken.
ProjectController.py
images/icons.svg
runtime/PLCObject.py
--- a/ProjectController.py	Thu Apr 11 13:45:27 2019 +0200
+++ b/ProjectController.py	Mon Apr 15 13:34:09 2019 +0200
@@ -1422,6 +1422,7 @@
         "_Stop": False,
         "_Transfer": False,
         "_Connect": True,
+        "_Repair": False,
         "_Disconnect": False
     }
 
@@ -1438,6 +1439,7 @@
                                  "_Connect": False,
                                  "_Disconnect": True},
         PlcStatus.Broken:       {"_Connect": False,
+                                 "_Repair": True,
                                  "_Disconnect": True},
         PlcStatus.Disconnected: {},
     }
@@ -1913,6 +1915,17 @@
 
         wx.CallAfter(self.UpdateMethodsFromPLCStatus)
 
+    def _Repair(self):
+        dialog = wx.MessageDialog(
+            self.AppFrame,
+            _('Delete target PLC application?'),
+            _('Repair'),
+            wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
+        answer = dialog.ShowModal()
+        dialog.Destroy()
+        if answer == wx.ID_YES:
+            self._connector.PurgePLC()
+
     StatusMethods = [
         {
             "bitmap":    "Build",
@@ -1955,6 +1968,13 @@
             "shown":      False,
         },
         {
+            "bitmap":    "Repair",
+            "name":    _("Repair"),
+            "tooltip": _("Repair broken PLC"),
+            "method":   "_Repair",
+            "shown":      False,
+        },
+        {
             "bitmap":    "Disconnect",
             "name":    _("Disconnect"),
             "tooltip": _("Disconnect from PLC"),
--- a/images/icons.svg	Thu Apr 11 13:45:27 2019 +0200
+++ b/images/icons.svg	Mon Apr 15 13:34:09 2019 +0200
@@ -43,12 +43,12 @@
      pagecolor="#ffffff"
      id="base"
      showgrid="false"
-     inkscape:zoom="16"
-     inkscape:cx="754.13513"
-     inkscape:cy="907.03479"
+     inkscape:zoom="5.6568543"
+     inkscape:cx="766.02087"
+     inkscape:cy="916.07252"
      inkscape:window-x="0"
      inkscape:window-y="24"
-     inkscape:current-layer="svg2"
+     inkscape:current-layer="g10453"
      showguides="true"
      inkscape:guide-bbox="true"
      inkscape:window-maximized="1"
@@ -87442,6 +87442,27 @@
        r="111.6605"
        gradientTransform="matrix(0.95160132,-0.01357563,0.01391374,0.97645493,3.8528826,4.1473681)"
        gradientUnits="userSpaceOnUse" />
+    <linearGradient
+       id="linearGradient10435"
+       y2="24.944"
+       xlink:href="#radialGradient2553-7-9"
+       gradientUnits="userSpaceOnUse"
+       x2="25.701"
+       gradientTransform="scale(0.89256,1.1204)"
+       y1="51.917"
+       x1="68.289001"
+       inkscape:collect="always" />
+    <linearGradient
+       id="linearGradient7925">
+      <stop
+         id="stop7926"
+         style="stop-color:#d0d0d0"
+         offset="0" />
+      <stop
+         id="stop7927"
+         style="stop-color:#a6a3a3"
+         offset="1" />
+    </linearGradient>
   </defs>
   <g
      id="g19063"
@@ -89948,7 +89969,7 @@
        id="tspan16268"
        x="73.295929"
        y="121.52582"
-       style="font-size:12.76095104px;line-height:1.25">%% editIECrawcode editWXGLADE editPYTHONcode EditCfile Transfer Connect Disconnect Debug IDManager %%</tspan></text>
+       style="font-size:12.76095104px;line-height:1.25">%% editIECrawcode editWXGLADE editPYTHONcode EditCfile Transfer Connect Disconnect Debug IDManager Repair %%</tspan></text>
   <rect
      width="24"
      height="24"
@@ -93341,12 +93362,21 @@
        id="path18654"
        inkscape:connector-curvature="0" />
   </g>
+  <g
+     id="g10453"
+     transform="matrix(0.27063582,0.04354624,-0.04354624,0.27063582,790.21268,127.46614)">
+    <path
+       id="path1683"
+       style="fill:url(#linearGradient10435);stroke:#606060;stroke-width:1.25;stroke-linecap:round;stroke-linejoin:round;fill-opacity:1.0"
+       inkscape:connector-curvature="0"
+       d="m 64.661,6.0611 c -4.831,1.9764 -8.619,6.2529 -9.679,11.757 -0.673,3.493 -0.092,6.917 1.339,9.901 -3.895,8.12 -19.113,29.069 -26.331,36.587 -6.581,0.93 -12.171,5.856 -13.497,12.74 -1.006,5.227 0.712,10.321 4.096,13.932 l 2.098,-10.894 c 0.523,-2.72 3.135,-4.488 5.855,-3.964 l 7.917,1.525 c 2.72,0.523 4.488,3.135 3.964,5.855 l -2.186,11.354 c 4.83,-1.977 8.619,-6.253 9.679,-11.757 0.842,-4.372 -0.202,-8.667 -2.544,-12.074 5.389,-9.026 18.947,-28.336 26.036,-34.225 7.218,-0.328 13.571,-5.527 14.996,-12.929 1.007,-5.228 -0.711,-10.321 -4.095,-13.932 l -2.098,10.894 c -0.524,2.72 -3.135,4.488 -5.855,3.964 l -7.917,-1.525 c -2.721,-0.524 -4.489,-3.135 -3.965,-5.855 l 2.187,-11.354 z" />
+  </g>
   <rect
      inkscape:label="#rect16270"
-     style="display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:0;fill-rule:evenodd;stroke:#6e6e6e;stroke-width:0.1;marker:none;enable-background:accumulate;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
-     id="rect19460"
+     style="display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:0;fill-rule:evenodd;stroke:none;stroke-width:1;marker:none;enable-background:accumulate"
+     id="Repair"
      y="131.36218"
-     x="730"
+     x="790"
      height="24"
      width="24" />
 </svg>
--- a/runtime/PLCObject.py	Thu Apr 11 13:45:27 2019 +0200
+++ b/runtime/PLCObject.py	Mon Apr 15 13:34:09 2019 +0200
@@ -530,31 +530,45 @@
         os.close(fobj)
         shutil.move(path, newpath)
 
+    def _extra_files_log_path(self):
+        return os.path.join(self.workingdir, "extra_files.txt")
+
+    @RunInMain
+    def PurgePLC(self):
+
+        extra_files_log = self._extra_files_log_path()
+
+        old_PLC_filename = os.path.join(self.workingdir, self.CurrentPLCFilename) \
+            if self.CurrentPLCFilename is not None \
+            else None
+
+        try:
+            os.remove(old_PLC_filename)
+            for filename in open(extra_files_log, "rt").readlines() + [extra_files_log]:
+                try:
+                    os.remove(os.path.join(self.workingdir, filename.strip()))
+                except Exception:
+                    pass
+        except Exception:
+            pass
+
+        self.PLCStatus = PlcStatus.Empty
+
+        # TODO: PLCObject restart
+
     @RunInMain
     def NewPLC(self, md5sum, plc_object, extrafiles):
         if self.PLCStatus in [PlcStatus.Stopped, PlcStatus.Empty, PlcStatus.Broken]:
             NewFileName = md5sum + lib_ext
-            extra_files_log = os.path.join(self.workingdir, "extra_files.txt")
-
-            old_PLC_filename = os.path.join(self.workingdir, self.CurrentPLCFilename) \
-                if self.CurrentPLCFilename is not None \
-                else None
+            extra_files_log = self._extra_files_log_path()
+
             new_PLC_filename = os.path.join(self.workingdir, NewFileName)
 
             self.UnLoadPLC()
 
+            self.PurgePLC()
+
             self.LogMessage("NewPLC (%s)" % md5sum)
-            self.PLCStatus = PlcStatus.Empty
-
-            try:
-                os.remove(old_PLC_filename)
-                for filename in open(extra_files_log, "rt").readlines() + [extra_files_log]:
-                    try:
-                        os.remove(os.path.join(self.workingdir, filename.strip()))
-                    except Exception:
-                        pass
-            except Exception:
-                pass
 
             try:
                 # Create new PLC file