# HG changeset patch # User Edouard Tisserant # Date 1555328049 -7200 # Node ID f1e182818434742036ae7f6976882b5431408214 # Parent 62c5c35897699aaccbd18e030fe6849caeeb2b90 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. diff -r 62c5c3589769 -r f1e182818434 ProjectController.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"), diff -r 62c5c3589769 -r f1e182818434 images/icons.svg --- 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" /> + + + + + %% editIECrawcode editWXGLADE editPYTHONcode EditCfile Transfer Connect Disconnect Debug IDManager %% + style="font-size:12.76095104px;line-height:1.25">%% editIECrawcode editWXGLADE editPYTHONcode EditCfile Transfer Connect Disconnect Debug IDManager Repair %% + + + diff -r 62c5c3589769 -r f1e182818434 runtime/PLCObject.py --- 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