108 if not PlugName: |
108 if not PlugName: |
109 PlugName = self.BaseParams.getName() |
109 PlugName = self.BaseParams.getName() |
110 return os.path.join(self.PlugParent.PlugPath(), PlugName + NameTypeSeparator + self.PlugType) |
110 return os.path.join(self.PlugParent.PlugPath(), PlugName + NameTypeSeparator + self.PlugType) |
111 |
111 |
112 def PlugTestModified(self): |
112 def PlugTestModified(self): |
|
113 return self.ChangesToSave |
|
114 |
|
115 def ProjectTestModified(self): |
|
116 """ |
|
117 recursively check modified status |
|
118 """ |
|
119 if self.PlugTestModified(): |
|
120 return True |
|
121 |
|
122 for PlugChild in self.IterChilds(): |
|
123 if PlugChild.ProjectTestModified(): |
|
124 return True |
|
125 |
113 return False |
126 return False |
114 |
127 |
115 def OnPlugSave(self): |
128 def OnPlugSave(self): |
116 #Default, do nothing and return success |
129 #Default, do nothing and return success |
117 return True |
130 return True |
130 if self.PlugParams: |
143 if self.PlugParams: |
131 params.append(self.PlugParams[1].getElementInfos(self.PlugParams[0])) |
144 params.append(self.PlugParams[1].getElementInfos(self.PlugParams[0])) |
132 return params |
145 return params |
133 |
146 |
134 def SetParamsAttribute(self, path, value, logger): |
147 def SetParamsAttribute(self, path, value, logger): |
|
148 self.ChangesToSave = True |
135 # Filter IEC_Channel and Name, that have specific behavior |
149 # Filter IEC_Channel and Name, that have specific behavior |
136 if path == "BaseParams.IEC_Channel": |
150 if path == "BaseParams.IEC_Channel": |
137 return self.FindNewIEC_Channel(value,logger), True |
151 return self.FindNewIEC_Channel(value,logger), True |
138 elif path == "BaseParams.Name": |
152 elif path == "BaseParams.Name": |
139 res = self.FindNewName(value,logger) |
153 res = self.FindNewName(value,logger) |
140 self.PlugRequestSave() |
154 self.PlugRequestSave() |
141 return res, False |
155 return res, True |
142 |
156 |
143 parts = path.split(".", 1) |
157 parts = path.split(".", 1) |
144 if self.MandatoryParams and parts[0] == self.MandatoryParams[0]: |
158 if self.MandatoryParams and parts[0] == self.MandatoryParams[0]: |
145 self.MandatoryParams[1].setElementValue(parts[1], value) |
159 self.MandatoryParams[1].setElementValue(parts[1], value) |
146 elif self.PlugParams and parts[0] == self.PlugParams[0]: |
160 elif self.PlugParams and parts[0] == self.PlugParams[0]: |
170 |
184 |
171 # Call the plugin specific OnPlugSave method |
185 # Call the plugin specific OnPlugSave method |
172 result = self.OnPlugSave() |
186 result = self.OnPlugSave() |
173 if not result: |
187 if not result: |
174 return "Error while saving \"%s\""%self.PlugPath() |
188 return "Error while saving \"%s\""%self.PlugPath() |
175 |
189 |
|
190 # mark plugin as saved |
|
191 self.ChangesToSave = False |
176 # go through all childs and do the same |
192 # go through all childs and do the same |
177 for PlugChild in self.IterChilds(): |
193 for PlugChild in self.IterChilds(): |
178 result = PlugChild.PlugRequestSave() |
194 result = PlugChild.PlugRequestSave() |
179 if result: |
195 if result: |
180 return result |
196 return result |
471 # Call the plugin real __init__ |
487 # Call the plugin real __init__ |
472 if getattr(PlugClass, "__init__", None): |
488 if getattr(PlugClass, "__init__", None): |
473 PlugClass.__init__(_self) |
489 PlugClass.__init__(_self) |
474 #Load and init all the childs |
490 #Load and init all the childs |
475 _self.LoadChilds(logger) |
491 _self.LoadChilds(logger) |
|
492 #just loaded, nothing to saved |
|
493 _self.ChangesToSave = False |
476 else: |
494 else: |
477 # If plugin do not have corresponding file/dirs - they will be created on Save |
495 # If plugin do not have corresponding file/dirs - they will be created on Save |
478 os.mkdir(_self.PlugPath()) |
496 os.mkdir(_self.PlugPath()) |
479 # Find an IEC number |
497 # Find an IEC number |
480 _self.FindNewIEC_Channel(0, None) |
498 _self.FindNewIEC_Channel(0, None) |
481 # Call the plugin real __init__ |
499 # Call the plugin real __init__ |
482 if getattr(PlugClass, "__init__", None): |
500 if getattr(PlugClass, "__init__", None): |
483 PlugClass.__init__(_self) |
501 PlugClass.__init__(_self) |
484 _self.PlugRequestSave() |
502 _self.PlugRequestSave() |
|
503 #just created, must be saved |
|
504 _self.ChangesToSave = True |
485 |
505 |
486 def _getBuildPath(_self): |
506 def _getBuildPath(_self): |
487 return self._getBuildPath() |
507 return self._getBuildPath() |
488 |
508 |
489 # Create the object out of the resulting class |
509 # Create the object out of the resulting class |
656 """ |
676 """ |
657 This method are not called here... but in NewProject and OpenProject |
677 This method are not called here... but in NewProject and OpenProject |
658 self._AddParamsMembers() |
678 self._AddParamsMembers() |
659 self.PluggedChilds = {} |
679 self.PluggedChilds = {} |
660 """ |
680 """ |
661 |
681 # In both new or load scenario, no need to save |
|
682 self.ChangesToSave = False |
662 # root have no parent |
683 # root have no parent |
663 self.PlugParent = None |
684 self.PlugParent = None |
664 # Keep track of the plugin type name |
685 # Keep track of the plugin type name |
665 self.PlugType = "Beremiz" |
686 self.PlugType = "Beremiz" |
666 |
|
667 # After __init__ root plugin is not valid |
687 # After __init__ root plugin is not valid |
668 self.ProjectPath = None |
688 self.ProjectPath = None |
669 self.PLCEditor = None |
689 self.PLCEditor = None |
670 |
|
671 # copy PluginMethods so that it can be later customized |
690 # copy PluginMethods so that it can be later customized |
672 self.PluginMethods = [dic.copy() for dic in self.PluginMethods] |
691 self.PluginMethods = [dic.copy() for dic in self.PluginMethods] |
673 |
692 # special root member for handlig PLC execution |
674 self.runningPLC = None |
693 self.runningPLC = None |
675 |
694 |
676 |
695 def PlugTestModified(self): |
|
696 return self.ChangesToSave or not self.ProjectIsSaved() |
|
697 |
677 def HasProjectOpened(self): |
698 def HasProjectOpened(self): |
678 """ |
699 """ |
679 Return if a project is actually opened |
700 Return if a project is actually opened |
680 """ |
701 """ |
681 return self.ProjectPath != None |
702 return self.ProjectPath != None |