# HG changeset patch # User Edouard Tisserant # Date 1336411148 -7200 # Node ID 5d4dc150b956d794a868cb3b3def5ef5d55152ce # Parent 1c23952dbde1d9f366432c4253f593e15a4234c7 refactoring diff -r 1c23952dbde1 -r 5d4dc150b956 Beremiz.py --- a/Beremiz.py Mon May 07 18:47:29 2012 +0200 +++ b/Beremiz.py Mon May 07 19:19:08 2012 +0200 @@ -674,7 +674,7 @@ ResourceEditor, ConfigurationEditor, DataTypeEditor))): - return ("confnode", tab.Controler.PlugFullName()) + return ("confnode", tab.Controler.CTNFullName()) elif (isinstance(tab, TextViewer) and (tab.Controler is None or isinstance(tab.Controler, MiniTextControler))): return ("confnode", None, tab.GetInstancePath()) @@ -852,7 +852,7 @@ if self.CTR is not None: plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) - if self.CTR.PlugTestModified(): + if self.CTR.CTNTestModified(): bkgdclr = CHANGED_TITLE_COLOUR else: bkgdclr = TITLE_COLOUR @@ -933,7 +933,7 @@ self.Thaw() def GenerateEnableButton(self, parent, sizer, confnode): - enabled = confnode.PlugEnabled() + enabled = confnode.CTNEnabled() if enabled is not None: enablebutton_id = wx.NewId() enablebutton = wx.lib.buttons.GenBitmapToggleButton(id=enablebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Disabled.png')), @@ -1046,7 +1046,7 @@ self.Freeze() self.ClearSizer(self.ConfNodeTreeSizer) if self.CTR is not None: - for child in self.CTR.IECSortedChilds(): + for child in self.CTR.IECSortedChildren(): self.GenerateTreeBranch(child) if not self.ConfNodeInfos[child]["expanded"]: self.CollapseConfNode(child) @@ -1131,7 +1131,7 @@ def GenerateTreeBranch(self, confnode): leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) - if confnode.PlugTestModified(): + if confnode.CTNTestModified(): bkgdclr=CHANGED_WINDOW_COLOUR else: bkgdclr=WINDOW_COLOUR @@ -1141,7 +1141,7 @@ if not self.ConfNodeInfos.has_key(confnode): self.ConfNodeInfos[confnode] = {"expanded" : False, "right_visible" : False} - self.ConfNodeInfos[confnode]["children"] = confnode.IECSortedChilds() + self.ConfNodeInfos[confnode]["children"] = confnode.IECSortedChildren() confnode_locations = [] if len(self.ConfNodeInfos[confnode]["children"]) == 0: confnode_locations = confnode.GetVariableLocationTree()["children"] @@ -1174,7 +1174,7 @@ #self.GenerateEnableButton(leftwindow, rolesizer, confnode) roletext = wx.StaticText(leftwindow, -1) - roletext.SetLabel(confnode.PlugHelp) + roletext.SetLabel(confnode.CTNHelp) rolesizer.AddWindow(roletext, 0, border=5, flag=wx.RIGHT|wx.ALIGN_LEFT) confnode_IECChannel = confnode.BaseParams.getIEC_Channel() @@ -1216,7 +1216,7 @@ deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(confnode), id=deletebutton_id) adddeletesizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) - if len(confnode.PlugChildsTypes) > 0: + if len(confnode.CTNChildrenTypes) > 0: addbutton_id = wx.NewId() addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')), name='AddConfNodeButton', parent=leftwindow, pos=wx.Point(0, 0), @@ -1415,8 +1415,8 @@ def Gen_AddConfNodeMenu(self, confnode): def AddConfNodeMenu(event): main_menu = wx.Menu(title='') - if len(confnode.PlugChildsTypes) > 0: - for name, XSDClass, help in confnode.PlugChildsTypes: + if len(confnode.CTNChildrenTypes) > 0: + for name, XSDClass, help in confnode.CTNChildrenTypes: new_id = wx.NewId() main_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=_("Append ")+help) self.Bind(wx.EVT_MENU, self._GetAddConfNodeFunction(name, confnode), id=new_id) @@ -1774,9 +1774,9 @@ def GetAddButtonFunction(self, confnode, window): def AddButtonFunction(event): - if confnode and len(confnode.PlugChildsTypes) > 0: + if confnode and len(confnode.CTNChildrenTypes) > 0: confnode_menu = wx.Menu(title='') - for name, XSDClass, help in confnode.PlugChildsTypes: + for name, XSDClass, help in confnode.CTNChildrenTypes: new_id = wx.NewId() confnode_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=name) self.Bind(wx.EVT_MENU, self._GetAddConfNodeFunction(name, confnode), id=new_id) @@ -1796,7 +1796,7 @@ dialog = wx.TextEntryDialog(self, _("Please enter a name for confnode:"), _("Add ConfNode"), "", wx.OK|wx.CANCEL) if dialog.ShowModal() == wx.ID_OK: ConfNodeName = dialog.GetValue() - confnode.PlugAddChild(ConfNodeName, ConfNodeType) + confnode.CTNAddChild(ConfNodeName, ConfNodeType) self.CTR.RefreshConfNodesBlockLists() self._Refresh(TITLE, FILEMENU) self.RefreshConfNodeTree() @@ -1807,7 +1807,7 @@ dialog = wx.MessageDialog(self, _("Really delete confnode ?"), _("Remove confnode"), wx.YES_NO|wx.NO_DEFAULT) if dialog.ShowModal() == wx.ID_YES: self.ConfNodeInfos.pop(confnode) - confnode.PlugRemove() + confnode.CTNRemove() del confnode self.CTR.RefreshConfNodesBlockLists() self._Refresh(TITLE, FILEMENU) diff -r 1c23952dbde1 -r 5d4dc150b956 ConfigTree.py --- a/ConfigTree.py Mon May 07 18:47:29 2012 +0200 +++ b/ConfigTree.py Mon May 07 19:19:08 2012 +0200 @@ -36,7 +36,7 @@ def __init__(self, filepath): self.FilePath = filepath - def PlugFullName(self): + def CTNFullName(self): return "" def SetEditedElementText(self, tagname, text): @@ -96,21 +96,21 @@ """ XSD = None - PlugChildsTypes = [] - PlugMaxCount = None + CTNChildrenTypes = [] + CTNMaxCount = None ConfNodeMethods = [] LibraryControler = None EditorType = None def _AddParamsMembers(self): - self.PlugParams = None + self.CTNParams = None if self.XSD: self.Classes = GenerateClassesFromXSDstring(self.XSD) Classes = [(name, XSDclass) for name, XSDclass in self.Classes.items() if XSDclass.IsBaseClass] if len(Classes) == 1: name, XSDclass = Classes[0] obj = XSDclass() - self.PlugParams = (name, obj) + self.CTNParams = (name, obj) setattr(self, name, obj) def __init__(self): @@ -118,65 +118,65 @@ self.BaseParams = _BaseParamsClass() self.MandatoryParams = ("BaseParams", self.BaseParams) self._AddParamsMembers() - self.PluggedChilds = {} + self.Children = {} self._View = None # copy ConfNodeMethods so that it can be later customized self.ConfNodeMethods = [dic.copy() for dic in self.ConfNodeMethods] self.LoadSTLibrary() - def ConfNodeBaseXmlFilePath(self, PlugName=None): - return os.path.join(self.PlugPath(PlugName), "baseconfnode.xml") - - def ConfNodeXmlFilePath(self, PlugName=None): - return os.path.join(self.PlugPath(PlugName), "confnode.xml") + def ConfNodeBaseXmlFilePath(self, CTNName=None): + return os.path.join(self.CTNPath(CTNName), "baseconfnode.xml") + + def ConfNodeXmlFilePath(self, CTNName=None): + return os.path.join(self.CTNPath(CTNName), "confnode.xml") def ConfNodeLibraryFilePath(self): return os.path.join(self.ConfNodePath(), "pous.xml") def ConfNodePath(self): - return os.path.join(self.PlugParent.ConfNodePath(), self.PlugType) - - def PlugPath(self,PlugName=None): - if not PlugName: - PlugName = self.PlugName() - return os.path.join(self.PlugParent.PlugPath(), - PlugName + NameTypeSeparator + self.PlugType) - - def PlugName(self): + return os.path.join(self.CTNParent.ConfNodePath(), self.CTNType) + + def CTNPath(self,CTNName=None): + if not CTNName: + CTNName = self.CTNName() + return os.path.join(self.CTNParent.CTNPath(), + CTNName + NameTypeSeparator + self.CTNType) + + def CTNName(self): return self.BaseParams.getName() - def PlugEnabled(self): + def CTNEnabled(self): return self.BaseParams.getEnabled() - def PlugFullName(self): - parent = self.PlugParent.PlugFullName() + def CTNFullName(self): + parent = self.CTNParent.CTNFullName() if parent != "": - return parent + "." + self.PlugName() + return parent + "." + self.CTNName() return self.BaseParams.getName() def GetIconPath(self, name): return opjimg(name) - def PlugTestModified(self): + def CTNTestModified(self): return self.ChangesToSave def ProjectTestModified(self): """ recursively check modified status """ - if self.PlugTestModified(): + if self.CTNTestModified(): return True - for PlugChild in self.IterChilds(): - if PlugChild.ProjectTestModified(): + for CTNChild in self.IterChildren(): + if CTNChild.ProjectTestModified(): return True return False def RemoteExec(self, script, **kwargs): - return self.PlugParent.RemoteExec(script, **kwargs) - - def OnPlugSave(self): + return self.CTNParent.RemoteExec(script, **kwargs) + + def OnCTNSave(self): #Default, do nothing and return success return True @@ -185,14 +185,14 @@ parts = path.split(".", 1) if self.MandatoryParams and parts[0] == self.MandatoryParams[0]: return self.MandatoryParams[1].getElementInfos(parts[0], parts[1]) - elif self.PlugParams and parts[0] == self.PlugParams[0]: - return self.PlugParams[1].getElementInfos(parts[0], parts[1]) + elif self.CTNParams and parts[0] == self.CTNParams[0]: + return self.CTNParams[1].getElementInfos(parts[0], parts[1]) else: params = [] if wx.VERSION < (2, 8, 0) and self.MandatoryParams: params.append(self.MandatoryParams[1].getElementInfos(self.MandatoryParams[0])) - if self.PlugParams: - params.append(self.PlugParams[1].getElementInfos(self.PlugParams[0])) + if self.CTNParams: + params.append(self.CTNParams[1].getElementInfos(self.CTNParams[0])) return params def SetParamsAttribute(self, path, value): @@ -201,31 +201,31 @@ if path == "BaseParams.IEC_Channel": old_leading = ".".join(map(str, self.GetCurrentLocation())) new_value = self.FindNewIEC_Channel(value) - new_leading = ".".join(map(str, self.PlugParent.GetCurrentLocation() + (new_value,))) - self.GetPlugRoot().UpdateProjectVariableLocation(old_leading, new_leading) + new_leading = ".".join(map(str, self.CTNParent.GetCurrentLocation() + (new_value,))) + self.GetCTRoot().UpdateProjectVariableLocation(old_leading, new_leading) return new_value, True elif path == "BaseParams.Name": res = self.FindNewName(value) - self.PlugRequestSave() + self.CTNRequestSave() return res, True parts = path.split(".", 1) if self.MandatoryParams and parts[0] == self.MandatoryParams[0]: self.MandatoryParams[1].setElementValue(parts[1], value) - elif self.PlugParams and parts[0] == self.PlugParams[0]: - self.PlugParams[1].setElementValue(parts[1], value) + elif self.CTNParams and parts[0] == self.CTNParams[0]: + self.CTNParams[1].setElementValue(parts[1], value) return value, False - def PlugMakeDir(self): - os.mkdir(self.PlugPath()) - - def PlugRequestSave(self): - if self.GetPlugRoot().CheckProjectPathPerm(False): + def CTNMakeDir(self): + os.mkdir(self.CTNPath()) + + def CTNRequestSave(self): + if self.GetCTRoot().CheckProjectPathPerm(False): # If confnode do not have corresponding directory - plugpath = self.PlugPath() - if not os.path.isdir(plugpath): + ctnpath = self.CTNPath() + if not os.path.isdir(ctnpath): # Create it - os.mkdir(plugpath) + os.mkdir(ctnpath) # generate XML for base XML parameters controller of the confnode if self.MandatoryParams: @@ -235,31 +235,31 @@ BaseXMLFile.close() # generate XML for XML parameters controller of the confnode - if self.PlugParams: + if self.CTNParams: XMLFile = open(self.ConfNodeXmlFilePath(),'w') XMLFile.write("\n") - XMLFile.write(self.PlugParams[1].generateXMLText(self.PlugParams[0], 0).encode("utf-8")) + XMLFile.write(self.CTNParams[1].generateXMLText(self.CTNParams[0], 0).encode("utf-8")) XMLFile.close() - # Call the confnode specific OnPlugSave method - result = self.OnPlugSave() + # Call the confnode specific OnCTNSave method + result = self.OnCTNSave() if not result: - return _("Error while saving \"%s\"\n")%self.PlugPath() + return _("Error while saving \"%s\"\n")%self.CTNPath() # mark confnode as saved self.ChangesToSave = False - # go through all childs and do the same - for PlugChild in self.IterChilds(): - result = PlugChild.PlugRequestSave() + # go through all children and do the same + for CTNChild in self.IterChildren(): + result = CTNChild.CTNRequestSave() if result: return result return None - def PlugImport(self, src_PlugPath): - shutil.copytree(src_PlugPath, self.PlugPath) + def CTNImport(self, src_CTNPath): + shutil.copytree(src_CTNPath, self.CTNPath) return True - def PlugGenerate_C(self, buildpath, locations): + def CTNGenerate_C(self, buildpath, locations): """ Generate C code @param locations: List of complete variables locations \ @@ -271,39 +271,39 @@ }, ...] @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND """ - self.GetPlugRoot().logger.write_warning(".".join(map(lambda x:str(x), self.GetCurrentLocation())) + " -> Nothing to do\n") + self.GetCTRoot().logger.write_warning(".".join(map(lambda x:str(x), self.GetCurrentLocation())) + " -> Nothing to do\n") return [],"",False def _Generate_C(self, buildpath, locations): # Generate confnodes [(Cfiles, CFLAGS)], LDFLAGS, DoCalls, extra_files # extra_files = [(fname,fobject), ...] - gen_result = self.PlugGenerate_C(buildpath, locations) - PlugCFilesAndCFLAGS, PlugLDFLAGS, DoCalls = gen_result[:3] + gen_result = self.CTNGenerate_C(buildpath, locations) + CTNCFilesAndCFLAGS, CTNLDFLAGS, DoCalls = gen_result[:3] extra_files = gen_result[3:] # if some files have been generated put them in the list with their location - if PlugCFilesAndCFLAGS: - LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), PlugCFilesAndCFLAGS, DoCalls)] + if CTNCFilesAndCFLAGS: + LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), CTNCFilesAndCFLAGS, DoCalls)] else: LocationCFilesAndCFLAGS = [] # confnode asks for some LDFLAGS - if PlugLDFLAGS: + if CTNLDFLAGS: # LDFLAGS can be either string - if type(PlugLDFLAGS)==type(str()): - LDFLAGS=[PlugLDFLAGS] + if type(CTNLDFLAGS)==type(str()): + LDFLAGS=[CTNLDFLAGS] #or list of strings - elif type(PlugLDFLAGS)==type(list()): - LDFLAGS=PlugLDFLAGS[:] + elif type(CTNLDFLAGS)==type(list()): + LDFLAGS=CTNLDFLAGS[:] else: LDFLAGS=[] - # recurse through all childs, and stack their results - for PlugChild in self.IECSortedChilds(): - new_location = PlugChild.GetCurrentLocation() + # recurse through all children, and stack their results + for CTNChild in self.IECSortedChildren(): + new_location = CTNChild.GetCurrentLocation() # How deep are we in the tree ? depth=len(new_location) _LocationCFilesAndCFLAGS, _LDFLAGS, _extra_files = \ - PlugChild._Generate_C( + CTNChild._Generate_C( #keep the same path buildpath, # filter locations that start with current IEC location @@ -317,16 +317,16 @@ def ConfNodeTypesFactory(self): if self.LibraryControler is not None: - return [{"name" : self.PlugType, "types": self.LibraryControler.Project}] + return [{"name" : self.CTNType, "types": self.LibraryControler.Project}] return [] def ParentsTypesFactory(self): - return self.PlugParent.ParentsTypesFactory() + self.ConfNodeTypesFactory() + return self.CTNParent.ParentsTypesFactory() + self.ConfNodeTypesFactory() def ConfNodesTypesFactory(self): list = self.ConfNodeTypesFactory() - for PlugChild in self.IterChilds(): - list += PlugChild.ConfNodesTypesFactory() + for CTNChild in self.IterChildren(): + list += CTNChild.ConfNodesTypesFactory() return list def STLibraryFactory(self): @@ -337,18 +337,18 @@ def ConfNodesSTLibraryFactory(self): program = self.STLibraryFactory() - for PlugChild in self.IECSortedChilds(): - program += PlugChild.ConfNodesSTLibraryFactory() + for CTNChild in self.IECSortedChildren(): + program += CTNChild.ConfNodesSTLibraryFactory() return program - def IterChilds(self): - for PlugType, PluggedChilds in self.PluggedChilds.items(): - for PlugInstance in PluggedChilds: - yield PlugInstance - - def IECSortedChilds(self): - # reorder childs by IEC_channels - ordered = [(chld.BaseParams.getIEC_Channel(),chld) for chld in self.IterChilds()] + def IterChildren(self): + for CTNType, Children in self.Children.items(): + for CTNInstance in Children: + yield CTNInstance + + def IECSortedChildren(self): + # reorder children by IEC_channels + ordered = [(chld.BaseParams.getIEC_Channel(),chld) for chld in self.IterChildren()] if ordered: ordered.sort() return zip(*ordered)[1] @@ -356,15 +356,15 @@ return [] def _GetChildBySomething(self, something, toks): - for PlugInstance in self.IterChilds(): + for CTNInstance in self.IterChildren(): # if match component of the name - if getattr(PlugInstance.BaseParams, something) == toks[0]: + if getattr(CTNInstance.BaseParams, something) == toks[0]: # if Name have other components if len(toks) >= 2: # Recurse in order to find the latest object - return PlugInstance._GetChildBySomething( something, toks[1:]) + return CTNInstance._GetChildBySomething( something, toks[1:]) # No sub name -> found - return PlugInstance + return CTNInstance # Not found return None @@ -385,29 +385,29 @@ """ @return: Tupple containing confnode IEC location of current confnode : %I0.0.4.5 => (0,0,4,5) """ - return self.PlugParent.GetCurrentLocation() + (self.BaseParams.getIEC_Channel(),) + return self.CTNParent.GetCurrentLocation() + (self.BaseParams.getIEC_Channel(),) def GetCurrentName(self): """ @return: String "ParentParentName.ParentName.Name" """ - return self.PlugParent._GetCurrentName() + self.BaseParams.getName() + return self.CTNParent._GetCurrentName() + self.BaseParams.getName() def _GetCurrentName(self): """ @return: String "ParentParentName.ParentName.Name." """ - return self.PlugParent._GetCurrentName() + self.BaseParams.getName() + "." - - def GetPlugRoot(self): - return self.PlugParent.GetPlugRoot() + return self.CTNParent._GetCurrentName() + self.BaseParams.getName() + "." + + def GetCTRoot(self): + return self.CTNParent.GetCTRoot() def GetFullIEC_Channel(self): return ".".join([str(i) for i in self.GetCurrentLocation()]) + ".x" def GetLocations(self): location = self.GetCurrentLocation() - return [loc for loc in self.PlugParent.GetLocations() if loc["LOC"][0:len(location)] == location] + return [loc for loc in self.CTNParent.GetLocations() if loc["LOC"][0:len(location)] == location] def GetVariableLocationTree(self): ''' @@ -419,7 +419,7 @@ - location is a string of this variable's location, like "%IX0.0.0" ''' children = [] - for child in self.IECSortedChilds(): + for child in self.IECSortedChildren(): children.append(child.GetVariableLocationTree()) return {"name": self.BaseParams.getName(), "type": LOCATION_CONFNODE, @@ -435,11 +435,11 @@ CurrentName = self.BaseParams.getName() # Do nothing if no change #if CurrentName == DesiredName: return CurrentName - # Build a list of used Name out of parent's PluggedChilds + # Build a list of used Name out of parent's Children AllNames=[] - for PlugInstance in self.PlugParent.IterChilds(): - if PlugInstance != self: - AllNames.append(PlugInstance.BaseParams.getName()) + for CTNInstance in self.CTNParent.IterChildren(): + if CTNInstance != self: + AllNames.append(CTNInstance.BaseParams.getName()) # Find a free name, eventually appending digit res = DesiredName @@ -449,24 +449,24 @@ suffix += 1 # Get old path - oldname = self.PlugPath() + oldname = self.CTNPath() # Check previous confnode existance dontexist = self.BaseParams.getName() == "__unnamed__" # Set the new name self.BaseParams.setName(res) # Rename confnode dir if exist if not dontexist: - shutil.move(oldname, self.PlugPath()) + shutil.move(oldname, self.CTNPath()) # warn user he has two left hands if DesiredName != res: - self.GetPlugRoot().logger.write_warning(_("A child names \"%s\" already exist -> \"%s\"\n")%(DesiredName,res)) + self.GetCTRoot().logger.write_warning(_("A child names \"%s\" already exist -> \"%s\"\n")%(DesiredName,res)) return res def GetAllChannels(self): AllChannels=[] - for PlugInstance in self.PlugParent.IterChilds(): - if PlugInstance != self: - AllChannels.append(PlugInstance.BaseParams.getIEC_Channel()) + for CTNInstance in self.CTNParent.IterChildren(): + if CTNInstance != self: + AllChannels.append(CTNInstance.BaseParams.getIEC_Channel()) AllChannels.sort() return AllChannels @@ -479,7 +479,7 @@ CurrentChannel = self.BaseParams.getIEC_Channel() # Do nothing if no change #if CurrentChannel == DesiredChannel: return CurrentChannel - # Build a list of used Channels out of parent's PluggedChilds + # Build a list of used Channels out of parent's Children AllChannels = self.GetAllChannels() # Now, try to guess the nearest available channel @@ -488,7 +488,7 @@ if res < CurrentChannel: # Want to go down ? res -= 1 # Test for n-1 if res < 0 : - self.GetPlugRoot().logger.write_warning(_("Cannot find lower free IEC channel than %d\n")%CurrentChannel) + self.GetCTRoot().logger.write_warning(_("Cannot find lower free IEC channel than %d\n")%CurrentChannel) return CurrentChannel # Can't go bellow 0, do nothing else : # Want to go up ? res += 1 # Test for n-1 @@ -498,11 +498,11 @@ def _OpenView(self, name=None): if self.EditorType is not None and self._View is None: - app_frame = self.GetPlugRoot().AppFrame + app_frame = self.GetCTRoot().AppFrame self._View = self.EditorType(app_frame.TabsOpened, self, app_frame) - app_frame.EditProjectElement(self._View, self.PlugName()) + app_frame.EditProjectElement(self._View, self.CTNName()) return self._View return None @@ -511,103 +511,103 @@ if self._View == view: self._View = None - def OnPlugClose(self): + def OnCTNClose(self): if self._View is not None: - app_frame = self.GetPlugRoot().AppFrame + app_frame = self.GetCTRoot().AppFrame if app_frame is not None: app_frame.DeletePage(self._View) return True - def _doRemoveChild(self, PlugInstance): - # Remove all childs of child - for SubPlugInstance in PlugInstance.IterChilds(): - PlugInstance._doRemoveChild(SubPlugInstance) + def _doRemoveChild(self, CTNInstance): + # Remove all children of child + for SubCTNInstance in CTNInstance.IterChildren(): + CTNInstance._doRemoveChild(SubCTNInstance) # Call the OnCloseMethod - PlugInstance.OnPlugClose() + CTNInstance.OnCTNClose() # Delete confnode dir - shutil.rmtree(PlugInstance.PlugPath()) - # Remove child of PluggedChilds - self.PluggedChilds[PlugInstance.PlugType].remove(PlugInstance) + shutil.rmtree(CTNInstance.CTNPath()) + # Remove child of Children + self.Children[CTNInstance.CTNType].remove(CTNInstance) # Forget it... (View have to refresh) - def PlugRemove(self): + def CTNRemove(self): # Fetch the confnode - #PlugInstance = self.GetChildByName(PlugName) + #CTNInstance = self.GetChildByName(CTNName) # Ask to his parent to remove it - self.PlugParent._doRemoveChild(self) - - def PlugAddChild(self, PlugName, PlugType, IEC_Channel=0): + self.CTNParent._doRemoveChild(self) + + def CTNAddChild(self, CTNName, CTNType, IEC_Channel=0): """ Create the confnodes that may be added as child to this node self - @param PlugType: string desining the confnode class name (get name from PlugChildsTypes) - @param PlugName: string for the name of the confnode instance - """ - # reorgabize self.PlugChildsTypes tuples from (name, PlugClass, Help) - # to ( name, (PlugClass, Help)), an make a dict - transpose = zip(*self.PlugChildsTypes) - PlugChildsTypes = dict(zip(transpose[0],zip(transpose[1],transpose[2]))) + @param CTNType: string desining the confnode class name (get name from CTNChildrenTypes) + @param CTNName: string for the name of the confnode instance + """ + # reorgabize self.CTNChildrenTypes tuples from (name, CTNClass, Help) + # to ( name, (CTNClass, Help)), an make a dict + transpose = zip(*self.CTNChildrenTypes) + CTNChildrenTypes = dict(zip(transpose[0],zip(transpose[1],transpose[2]))) # Check that adding this confnode is allowed try: - PlugClass, PlugHelp = PlugChildsTypes[PlugType] + CTNClass, CTNHelp = CTNChildrenTypes[CTNType] except KeyError: - raise Exception, _("Cannot create child %s of type %s ")%(PlugName, PlugType) - - # if PlugClass is a class factory, call it. (prevent unneeded imports) - if type(PlugClass) == types.FunctionType: - PlugClass = PlugClass() + raise Exception, _("Cannot create child %s of type %s ")%(CTNName, CTNType) + + # if CTNClass is a class factory, call it. (prevent unneeded imports) + if type(CTNClass) == types.FunctionType: + CTNClass = CTNClass() # Eventualy Initialize child instance list for this class of confnode - PluggedChildsWithSameClass = self.PluggedChilds.setdefault(PlugType, list()) + ChildrenWithSameClass = self.Children.setdefault(CTNType, list()) # Check count - if getattr(PlugClass, "PlugMaxCount", None) and len(PluggedChildsWithSameClass) >= PlugClass.PlugMaxCount: - raise Exception, _("Max count (%d) reached for this confnode of type %s ")%(PlugClass.PlugMaxCount, PlugType) + if getattr(CTNClass, "CTNMaxCount", None) and len(ChildrenWithSameClass) >= CTNClass.CTNMaxCount: + raise Exception, _("Max count (%d) reached for this confnode of type %s ")%(CTNClass.CTNMaxCount, CTNType) # create the final class, derived of provided confnode and template - class FinalPlugClass(PlugClass, ConfigTreeNode): + class FinalCTNClass(CTNClass, ConfigTreeNode): """ - ConfNode class is derivated into FinalPlugClass before being instanciated + ConfNode class is derivated into FinalCTNClass before being instanciated This way __init__ is overloaded to ensure ConfigTreeNode.__init__ is called - before PlugClass.__init__, and to do the file related stuff. + before CTNClass.__init__, and to do the file related stuff. """ def __init__(_self): # self is the parent - _self.PlugParent = self + _self.CTNParent = self # Keep track of the confnode type name - _self.PlugType = PlugType + _self.CTNType = CTNType # remind the help string, for more fancy display - _self.PlugHelp = PlugHelp + _self.CTNHelp = CTNHelp # Call the base confnode template init - change XSD into class members ConfigTreeNode.__init__(_self) # check name is unique - NewPlugName = _self.FindNewName(PlugName) + NewCTNName = _self.FindNewName(CTNName) # If dir have already be made, and file exist - if os.path.isdir(_self.PlugPath(NewPlugName)): #and os.path.isfile(_self.ConfNodeXmlFilePath(PlugName)): + if os.path.isdir(_self.CTNPath(NewCTNName)): #and os.path.isfile(_self.ConfNodeXmlFilePath(CTNName)): #Load the confnode.xml file into parameters members - _self.LoadXMLParams(NewPlugName) + _self.LoadXMLParams(NewCTNName) # Basic check. Better to fail immediately. - if (_self.BaseParams.getName() != NewPlugName): - raise Exception, _("Project tree layout do not match confnode.xml %s!=%s ")%(NewPlugName, _self.BaseParams.getName()) - - # Now, self.PlugPath() should be OK + if (_self.BaseParams.getName() != NewCTNName): + raise Exception, _("Project tree layout do not match confnode.xml %s!=%s ")%(NewCTNName, _self.BaseParams.getName()) + + # Now, self.CTNPath() should be OK # Check that IEC_Channel is not already in use. _self.FindNewIEC_Channel(_self.BaseParams.getIEC_Channel()) # Call the confnode real __init__ - if getattr(PlugClass, "__init__", None): - PlugClass.__init__(_self) - #Load and init all the childs - _self.LoadChilds() + if getattr(CTNClass, "__init__", None): + CTNClass.__init__(_self) + #Load and init all the children + _self.LoadChildren() #just loaded, nothing to saved _self.ChangesToSave = False else: # If confnode do not have corresponding file/dirs - they will be created on Save - _self.PlugMakeDir() + _self.CTNMakeDir() # Find an IEC number _self.FindNewIEC_Channel(IEC_Channel) # Call the confnode real __init__ - if getattr(PlugClass, "__init__", None): - PlugClass.__init__(_self) - _self.PlugRequestSave() + if getattr(CTNClass, "__init__", None): + CTNClass.__init__(_self) + _self.CTNRequestSave() #just created, must be saved _self.ChangesToSave = True @@ -615,16 +615,16 @@ return self._getBuildPath() # Create the object out of the resulting class - newConfNodeOpj = FinalPlugClass() - # Store it in PluggedChils - PluggedChildsWithSameClass.append(newConfNodeOpj) + newConfNodeOpj = FinalCTNClass() + # Store it in CTNgedChils + ChildrenWithSameClass.append(newConfNodeOpj) return newConfNodeOpj - def ClearPluggedChilds(self): - for child in self.IterChilds(): - child.ClearPluggedChilds() - self.PluggedChilds = {} + def ClearChildren(self): + for child in self.IterChildren(): + child.ClearChildren() + self.Children = {} def LoadSTLibrary(self): # Get library blocks if plcopen library exist @@ -635,44 +635,44 @@ self.LibraryControler.ClearConfNodeTypes() self.LibraryControler.AddConfNodeTypesList(self.ParentsTypesFactory()) - def LoadXMLParams(self, PlugName = None): - methode_name = os.path.join(self.PlugPath(PlugName), "methods.py") + def LoadXMLParams(self, CTNName = None): + methode_name = os.path.join(self.CTNPath(CTNName), "methods.py") if os.path.isfile(methode_name): execfile(methode_name) # Get the base xml tree if self.MandatoryParams: try: - basexmlfile = open(self.ConfNodeBaseXmlFilePath(PlugName), 'r') + basexmlfile = open(self.ConfNodeBaseXmlFilePath(CTNName), 'r') basetree = minidom.parse(basexmlfile) self.MandatoryParams[1].loadXMLTree(basetree.childNodes[0]) basexmlfile.close() except Exception, exc: - self.GetPlugRoot().logger.write_error(_("Couldn't load confnode base parameters %s :\n %s") % (PlugName, str(exc))) - self.GetPlugRoot().logger.write_error(traceback.format_exc()) + self.GetCTRoot().logger.write_error(_("Couldn't load confnode base parameters %s :\n %s") % (CTNName, str(exc))) + self.GetCTRoot().logger.write_error(traceback.format_exc()) # Get the xml tree - if self.PlugParams: + if self.CTNParams: try: - xmlfile = open(self.ConfNodeXmlFilePath(PlugName), 'r') + xmlfile = open(self.ConfNodeXmlFilePath(CTNName), 'r') tree = minidom.parse(xmlfile) - self.PlugParams[1].loadXMLTree(tree.childNodes[0]) + self.CTNParams[1].loadXMLTree(tree.childNodes[0]) xmlfile.close() except Exception, exc: - self.GetPlugRoot().logger.write_error(_("Couldn't load confnode parameters %s :\n %s") % (PlugName, str(exc))) - self.GetPlugRoot().logger.write_error(traceback.format_exc()) - - def LoadChilds(self): - # Iterate over all PlugName@PlugType in confnode directory, and try to open them - for PlugDir in os.listdir(self.PlugPath()): - if os.path.isdir(os.path.join(self.PlugPath(), PlugDir)) and \ - PlugDir.count(NameTypeSeparator) == 1: - pname, ptype = PlugDir.split(NameTypeSeparator) + self.GetCTRoot().logger.write_error(_("Couldn't load confnode parameters %s :\n %s") % (CTNName, str(exc))) + self.GetCTRoot().logger.write_error(traceback.format_exc()) + + def LoadChildren(self): + # Iterate over all CTNName@CTNType in confnode directory, and try to open them + for CTNDir in os.listdir(self.CTNPath()): + if os.path.isdir(os.path.join(self.CTNPath(), CTNDir)) and \ + CTNDir.count(NameTypeSeparator) == 1: + pname, ptype = CTNDir.split(NameTypeSeparator) try: - self.PlugAddChild(pname, ptype) + self.CTNAddChild(pname, ptype) except Exception, exc: - self.GetPlugRoot().logger.write_error(_("Could not add child \"%s\", type %s :\n%s\n")%(pname, ptype, str(exc))) - self.GetPlugRoot().logger.write_error(traceback.format_exc()) + self.GetCTRoot().logger.write_error(_("Could not add child \"%s\", type %s :\n%s\n")%(pname, ptype, str(exc))) + self.GetCTRoot().logger.write_error(traceback.format_exc()) def EnableMethod(self, method, value): for d in self.ConfNodeMethods: @@ -742,13 +742,13 @@ - Managing project directory - Building project - Handling PLCOpenEditor controler and view - - Loading user confnodes and instanciante them as childs + - Loading user confnodes and instanciante them as children - ... """ - # For root object, available Childs Types are modules of the confnode packages. - PlugChildsTypes = [(name, _GetClassFunction(name), help) for name, help in zip(confnodes.__all__,confnodes.helps)] + # For root object, available Children Types are modules of the confnode packages. + CTNChildrenTypes = [(name, _GetClassFunction(name), help) for name, help in zip(confnodes.__all__,confnodes.helps)] XSD = """ @@ -790,15 +790,15 @@ #This method are not called here... but in NewProject and OpenProject #self._AddParamsMembers() - #self.PluggedChilds = {} + #self.Children = {} # In both new or load scenario, no need to save self.ChangesToSave = False # root have no parent - self.PlugParent = None + self.CTNParent = None # Keep track of the confnode type name - self.PlugType = "Beremiz" - self.PluggedChilds = {} + self.CTNType = "Beremiz" + self.Children = {} # After __init__ root confnode is not valid self.ProjectPath = None self._setBuildPath(None) @@ -838,13 +838,13 @@ def ConfNodeLibraryFilePath(self): return os.path.join(os.path.split(__file__)[0], "pous.xml") - def PlugTestModified(self): + def CTNTestModified(self): return self.ChangesToSave or not self.ProjectIsSaved() - def PlugFullName(self): + def CTNFullName(self): return "" - def GetPlugRoot(self): + def GetCTRoot(self): return self def GetIECLibPath(self): @@ -936,7 +936,7 @@ self.CreateNewProject(values) # Change XSD into class members self._AddParamsMembers() - self.PluggedChilds = {} + self.Children = {} # Keep track of the root confnode (i.e. project path) self.ProjectPath = ProjectPath self._setBuildPath(BuildPath) @@ -963,18 +963,18 @@ return result # Change XSD into class members self._AddParamsMembers() - self.PluggedChilds = {} + self.Children = {} # Keep track of the root confnode (i.e. project path) self.ProjectPath = ProjectPath self._setBuildPath(BuildPath) # If dir have already be made, and file exist - if os.path.isdir(self.PlugPath()) and os.path.isfile(self.ConfNodeXmlFilePath()): + if os.path.isdir(self.CTNPath()) and os.path.isfile(self.ConfNodeXmlFilePath()): #Load the confnode.xml file into parameters members result = self.LoadXMLParams() if result: return result - #Load and init all the childs - self.LoadChilds() + #Load and init all the children + self.LoadChildren() self.RefreshConfNodesBlockLists() if os.path.exists(self._getBuildPath()): @@ -986,13 +986,13 @@ return None def CloseProject(self): - self.ClearPluggedChilds() + self.ClearChildren() self.ResetAppFrame(None) def SaveProject(self): if self.CheckProjectPathPerm(False): self.SaveXMLFile(os.path.join(self.ProjectPath, 'plc.xml')) - result = self.PlugRequestSave() + result = self.CTNRequestSave() if result: self.logger.write_error(result) @@ -1017,7 +1017,7 @@ # Update PLCOpenEditor ConfNode Block types from loaded confnodes def RefreshConfNodesBlockLists(self): - if getattr(self, "PluggedChilds", None) is not None: + if getattr(self, "Children", None) is not None: self.ClearConfNodeTypes() self.AddConfNodeTypesList(self.ConfNodesTypesFactory()) if self.AppFrame is not None: @@ -1045,18 +1045,18 @@ - location is a string of this variable's location, like "%IX0.0.0" ''' children = [] - for child in self.IECSortedChilds(): + for child in self.IECSortedChildren(): children.append(child.GetVariableLocationTree()) return children def ConfNodePath(self): return os.path.join(os.path.split(__file__)[0], "confnodes") - def PlugPath(self, PlugName=None): + def CTNPath(self, CTNName=None): return self.ProjectPath - def ConfNodeXmlFilePath(self, PlugName=None): - return os.path.join(self.PlugPath(PlugName), "beremiz.xml") + def ConfNodeXmlFilePath(self, CTNName=None): + return os.path.join(self.CTNPath(CTNName), "beremiz.xml") def ParentsTypesFactory(self): return self.ConfNodeTypesFactory() @@ -1102,7 +1102,7 @@ def _getIECrawcodepath(self): # define name for IEC raw code file - return os.path.join(self.PlugPath(), "raw_plc.st") + return os.path.join(self.CTNPath(), "raw_plc.st") def GetLocations(self): locations = [] @@ -1222,7 +1222,7 @@ self.logger.write(_("Extracting Located Variables...\n")) # Keep track of generated located variables for later use by self._Generate_C self.PLCGeneratedLocatedVars = self.GetLocations() - # Keep track of generated C files for later use by self.PlugGenerate_C + # Keep track of generated C files for later use by self.CTNGenerate_C self.PLCGeneratedCFiles = C_files # compute CFLAGS for plc self.plcCFLAGS = "\"-I"+self.ieclib_path+"\"" @@ -1274,7 +1274,7 @@ # ####################################################################### - def PlugGenerate_C(self, buildpath, locations): + def CTNGenerate_C(self, buildpath, locations): """ Return C code generated by iec2c compiler when _generate_softPLC have been called diff -r 1c23952dbde1 -r 5d4dc150b956 LPCBeremiz.py --- a/LPCBeremiz.py Mon May 07 18:47:29 2012 +0200 +++ b/LPCBeremiz.py Mon May 07 19:19:08 2012 +0200 @@ -68,7 +68,7 @@ havecanfestival = False try: from confnodes.canfestival import RootClass as CanOpenRootClass - from confnodes.canfestival.canfestival import _SlavePlug, _NodeListPlug, NodeManager + from confnodes.canfestival.canfestival import _SlaveCTN, _NodeListCTN, NodeManager havecanfestival = True except: havecanfestival = False @@ -197,7 +197,7 @@ return self.VariableLocationTree raise KeyError, "Only 'children' key is available" - def PlugEnabled(self): + def CTNEnabled(self): return None def SetIcon(self, icon): @@ -207,10 +207,10 @@ return _GetModuleBySomething({"children" : self.VariableLocationTree}, something, toks) def GetBaseTypes(self): - return self.GetPlugRoot().GetBaseTypes() + return self.GetCTRoot().GetBaseTypes() def GetSizeOfType(self, type): - return LOCATION_SIZES[self.GetPlugRoot().GetBaseType(type)] + return LOCATION_SIZES[self.GetCTRoot().GetBaseType(type)] def _GetVariableLocationTree(self, current_location, infos): if infos["type"] == LOCATION_MODULE: @@ -246,13 +246,13 @@ "children": [self._GetVariableLocationTree(self.GetCurrentLocation(), child) for child in self.VariableLocationTree]} - def PlugTestModified(self): + def CTNTestModified(self): return False - def PlugMakeDir(self): + def CTNMakeDir(self): pass - def PlugRequestSave(self): + def CTNRequestSave(self): return None def ResetUsedLocations(self): @@ -288,7 +288,7 @@ return self._CheckLocationConflicts(self.UsedLocations, list(location)) return False - def PlugGenerate_C(self, buildpath, locations): + def CTNGenerate_C(self, buildpath, locations): """ Generate C code @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) @@ -346,7 +346,7 @@ "Publish": variable["publish"], }) break - base_types = self.GetPlugRoot().GetBaseTypes() + base_types = self.GetCTRoot().GetBaseTypes() for var in vars: prefix = "" if var["Type"] in base_types: @@ -363,7 +363,7 @@ module.write(BUS_TEXT % code_str) module.close() - matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath()) + matiec_flags = '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()) return [(Gen_Module_path, matiec_flags)],"",True #------------------------------------------------------------------------------- @@ -378,7 +378,7 @@ "Master_NodeId": 1, } - class LPCCanOpenSlave(_SlavePlug): + class LPCCanOpenSlave(_SlaveCTN): XSD = """ @@ -414,12 +414,12 @@ "", # prfile filepath "heartbeat", # NMT []) # options - self.OnPlugSave() + self.OnCTNSave() def GetCanDevice(self): return str(self.BaseParams.getIEC_Channel()) - class LPCCanOpenMaster(_NodeListPlug): + class LPCCanOpenMaster(_NodeListCTN): XSD = """ @@ -437,21 +437,21 @@ class LPCCanOpen(CanOpenRootClass): XSD = None - PlugChildsTypes = [("CanOpenNode",LPCCanOpenMaster, "CanOpen Master"), + CTNChildrenTypes = [("CanOpenNode",LPCCanOpenMaster, "CanOpen Master"), ("CanOpenSlave",LPCCanOpenSlave, "CanOpen Slave")] def GetCanDriver(self): return "" - def LoadChilds(self): - ConfigTreeNode.LoadChilds(self) + def LoadChildren(self): + ConfigTreeNode.LoadChildren(self) if self.GetChildByName("Master") is None: - master = self.PlugAddChild("Master", "CanOpenNode", 0) + master = self.CTNAddChild("Master", "CanOpenNode", 0) master.BaseParams.setEnabled(False) if self.GetChildByName("Slave") is None: - slave = self.PlugAddChild("Slave", "CanOpenSlave", 1) + slave = self.CTNAddChild("Slave", "CanOpenSlave", 1) slave.BaseParams.setEnabled(False) @@ -513,10 +513,10 @@ ConfigTreeRoot.__init__(self, frame, logger) if havecanfestival: - self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")] + self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")] else: - self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus")] - self.PlugType = "LPC" + self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus")] + self.CTNType = "LPC" self.OnlineMode = "OFF" self.LPCConnector = None @@ -676,7 +676,7 @@ # Change XSD into class members self._AddParamsMembers() - self.PluggedChilds = {} + self.Children = {} # Keep track of the root confnode (i.e. project path) self.ProjectPath = ProjectPath @@ -686,20 +686,20 @@ mycopytree(self.OrigBuildPath, self.BuildPath) # If dir have already be made, and file exist - if os.path.isdir(self.PlugPath()) and os.path.isfile(self.ConfNodeXmlFilePath()): + if os.path.isdir(self.CTNPath()) and os.path.isfile(self.ConfNodeXmlFilePath()): #Load the confnode.xml file into parameters members result = self.LoadXMLParams() if result: return result - #Load and init all the childs - self.LoadChilds() + #Load and init all the children + self.LoadChildren() if havecanfestival and self.GetChildByName("CanOpen") is None: - canopen = self.PlugAddChild("CanOpen", "CanOpen", 0) + canopen = self.CTNAddChild("CanOpen", "CanOpen", 0) canopen.BaseParams.setEnabled(False) - canopen.LoadChilds() - - if self.PlugTestModified(): + canopen.LoadChildren() + + if self.CTNTestModified(): self.SaveProject() if wx.GetApp() is None: @@ -881,22 +881,22 @@ # CSV file generated by IEC2C compiler. self.ResetIECProgramsAndVariables() - gen_result = self.PlugGenerate_C(buildpath, self.PLCGeneratedLocatedVars) - PlugCFilesAndCFLAGS, PlugLDFLAGS, DoCalls = gen_result[:3] + gen_result = self.CTNGenerate_C(buildpath, self.PLCGeneratedLocatedVars) + CTNCFilesAndCFLAGS, CTNLDFLAGS, DoCalls = gen_result[:3] # if some files have been generated put them in the list with their location - if PlugCFilesAndCFLAGS: - self.LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), PlugCFilesAndCFLAGS, DoCalls)] + if CTNCFilesAndCFLAGS: + self.LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), CTNCFilesAndCFLAGS, DoCalls)] else: self.LocationCFilesAndCFLAGS = [] # confnode asks for some LDFLAGS - if PlugLDFLAGS: + if CTNLDFLAGS: # LDFLAGS can be either string - if type(PlugLDFLAGS)==type(str()): - self.LDFLAGS=[PlugLDFLAGS] + if type(CTNLDFLAGS)==type(str()): + self.LDFLAGS=[CTNLDFLAGS] #or list of strings - elif type(PlugLDFLAGS)==type(list()): - self.LDFLAGS=PlugLDFLAGS[:] + elif type(CTNLDFLAGS)==type(list()): + self.LDFLAGS=CTNLDFLAGS[:] else: self.LDFLAGS=[] @@ -1183,7 +1183,7 @@ if self.CTR is not None: plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) - if self.CTR.PlugTestModified(): + if self.CTR.CTNTestModified(): bkgdclr = CHANGED_TITLE_COLOUR else: bkgdclr = TITLE_COLOUR @@ -1218,7 +1218,7 @@ def GenerateTreeBranch(self, confnode): leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) - if confnode.PlugTestModified(): + if confnode.CTNTestModified(): bkgdclr=CHANGED_WINDOW_COLOUR else: bkgdclr=WINDOW_COLOUR @@ -1228,7 +1228,7 @@ if confnode not in self.ConfNodeInfos: self.ConfNodeInfos[confnode] = {"expanded" : False, "left_visible" : False, "right_visible" : False} - self.ConfNodeInfos[confnode]["children"] = confnode.IECSortedChilds() + self.ConfNodeInfos[confnode]["children"] = confnode.IECSortedChildren() confnode_infos = confnode.GetVariableLocationTree() confnode_locations = [] if len(self.ConfNodeInfos[confnode]["children"]) == 0: @@ -1477,12 +1477,12 @@ self.RestartTimer() def AddBus(self, iec_channel, name, icon=None): - for child in self.CTR.IterChilds(): + for child in self.CTR.IterChildren(): if child.BaseParams.getName() == name: return "Error: A bus named %s already exists\n" % name elif child.BaseParams.getIEC_Channel() == iec_channel: return "Error: A bus with IEC_channel %d already exists\n" % iec_channel - bus = self.CTR.PlugAddChild(name, "LPCBus", iec_channel) + bus = self.CTR.CTNAddChild(name, "LPCBus", iec_channel) if bus is None: return "Error: Unable to create bus\n" bus.SetIcon(icon) @@ -1492,7 +1492,7 @@ bus = self.CTR.GetChildByIECLocation((iec_channel,)) if bus is None: return "Error: No bus found\n" - for child in self.CTR.IterChilds(): + for child in self.CTR.IterChildren(): if child != bus and child.BaseParams.getName() == name: return "Error: A bus named %s already exists\n" % name bus.BaseParams.setName(name) @@ -1502,7 +1502,7 @@ bus = self.CTR.GetChildByIECLocation((old_iec_channel,)) if bus is None: return "Error: No bus found\n" - for child in self.CTR.IterChilds(): + for child in self.CTR.IterChildren(): if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel: return "Error: A bus with IEC_channel %d already exists\n" % new_iec_channel if wx.GetApp() is None: @@ -1520,7 +1520,7 @@ if bus is None: return "Error: No bus found\n" self.CTR.RemoveProjectVariableByFilter(str(iec_channel)) - self.CTR.PluggedChilds["LPCBus"].remove(bus) + self.CTR.Children["LPCBus"].remove(bus) self.RestartTimer() def AddModule(self, parent, iec_channel, name, icode, icon=None): diff -r 1c23952dbde1 -r 5d4dc150b956 confnodes/c_ext/CFileEditor.py --- a/confnodes/c_ext/CFileEditor.py Mon May 07 18:47:29 2012 +0200 +++ b/confnodes/c_ext/CFileEditor.py Mon May 07 19:19:08 2012 +0200 @@ -887,7 +887,7 @@ self.Controler.OnCloseEditor(self) def GetTitle(self): - fullname = self.Controler.PlugFullName() + fullname = self.Controler.CTNFullName() if not self.Controler.CFileIsSaved(): return "~%s~" % fullname return fullname diff -r 1c23952dbde1 -r 5d4dc150b956 confnodes/c_ext/c_ext.py --- a/confnodes/c_ext/c_ext.py Mon May 07 18:47:29 2012 +0200 +++ b/confnodes/c_ext/c_ext.py Mon May 07 19:19:08 2012 +0200 @@ -43,19 +43,19 @@ self.CreateCFileBuffer(True) else: self.CreateCFileBuffer(False) - self.OnPlugSave() + self.OnCTNSave() def CFileName(self): - return os.path.join(self.PlugPath(), "cfile.xml") + return os.path.join(self.CTNPath(), "cfile.xml") def GetBaseTypes(self): - return self.GetPlugRoot().GetBaseTypes() + return self.GetCTRoot().GetBaseTypes() def GetDataTypes(self, basetypes = False, only_locatables = False): - return self.GetPlugRoot().GetDataTypes(basetypes=basetypes, only_locatables=only_locatables) + return self.GetCTRoot().GetDataTypes(basetypes=basetypes, only_locatables=only_locatables) def GetSizeOfType(self, type): - return TYPECONVERSION.get(self.GetPlugRoot().GetBaseType(type), None) + return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None) def SetVariables(self, variables): self.CFile.variables.setvariable([]) @@ -147,10 +147,10 @@ "method" : "_OpenView"}, ] - def PlugTestModified(self): + def CTNTestModified(self): return self.ChangesToSave or not self.CFileIsSaved() - def OnPlugSave(self): + def OnCTNSave(self): filepath = self.CFileName() text = "\n" @@ -166,7 +166,7 @@ self.MarkCFileAsSaved() return True - def PlugGenerate_C(self, buildpath, locations): + def CTNGenerate_C(self, buildpath, locations): """ Generate C code @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) @@ -215,7 +215,7 @@ outputs += 1 vars.append(var) text += "/* Beremiz c_ext confnode user variables definition */\n" - base_types = self.GetPlugRoot().GetBaseTypes() + base_types = self.GetCTRoot().GetBaseTypes() for var in vars: if var["Type"] in base_types: prefix = "IEC_" @@ -256,7 +256,7 @@ cfile.write(text) cfile.close() - matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath()) + matiec_flags = '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()) return [(Gen_Cfile_path, str(self.CExtension.getCFLAGS() + matiec_flags))],str(self.CExtension.getLDFLAGS()),True @@ -307,9 +307,9 @@ class RootClass: - PlugChildsTypes = [("C_File",_Cfile, "C file")] - - def PlugGenerate_C(self, buildpath, locations): + CTNChildrenTypes = [("C_File",_Cfile, "C file")] + + def CTNGenerate_C(self, buildpath, locations): return [],"",False diff -r 1c23952dbde1 -r 5d4dc150b956 confnodes/canfestival/NetworkEditor.py --- a/confnodes/canfestival/NetworkEditor.py Mon May 07 18:47:29 2012 +0200 +++ b/confnodes/canfestival/NetworkEditor.py Mon May 07 19:19:08 2012 +0200 @@ -101,7 +101,7 @@ confnode_menu.Enable(ID_NETWORKEDITORCONFNODEMENUMASTER, self.NetworkNodes.GetSelection() == 0) def GetTitle(self): - fullname = self.Controler.PlugFullName() + fullname = self.Controler.CTNFullName() if not self.Manager.CurrentIsSaved(): return "~%s~" % fullname return fullname diff -r 1c23952dbde1 -r 5d4dc150b956 confnodes/canfestival/SlaveEditor.py --- a/confnodes/canfestival/SlaveEditor.py Mon May 07 18:47:29 2012 +0200 +++ b/confnodes/canfestival/SlaveEditor.py Mon May 07 19:19:08 2012 +0200 @@ -64,7 +64,7 @@ confnode_menu.Enable(ID_SLAVEEDITORCONFNODEMENUDSOTHERPROFILE, False) def GetTitle(self): - fullname = self.Controler.PlugFullName() + fullname = self.Controler.CTNFullName() if not self.Controler.CurrentIsSaved(): return "~%s~" % fullname return fullname diff -r 1c23952dbde1 -r 5d4dc150b956 confnodes/canfestival/canfestival.py --- a/confnodes/canfestival/canfestival.py Mon May 07 18:47:29 2012 +0200 +++ b/confnodes/canfestival/canfestival.py Mon May 07 19:19:08 2012 +0200 @@ -41,7 +41,7 @@ # SLAVE #-------------------------------------------------- -class _SlavePlug(NodeManager): +class _SlaveCTN(NodeManager): XSD = """ @@ -99,10 +99,10 @@ "heartbeat", # NMT []) # options dialog.Destroy() - self.OnPlugSave() + self.OnCTNSave() def GetSlaveODPath(self): - return os.path.join(self.PlugPath(), 'slave.od') + return os.path.join(self.CTNPath(), 'slave.od') def GetCanDevice(self): return self.CanFestivalSlaveNode.getCan_Device() @@ -119,14 +119,14 @@ "method" : "_OpenView"}, ] - def OnPlugClose(self): + def OnCTNClose(self): if self._View: self._View.Close() - def PlugTestModified(self): + def CTNTestModified(self): return self.ChangesToSave or self.OneFileHasChanged() - def OnPlugSave(self): + def OnCTNSave(self): return self.SaveCurrentInFile(self.GetSlaveODPath()) def SetParamsAttribute(self, path, value): @@ -138,7 +138,7 @@ return result - def PlugGenerate_C(self, buildpath, locations): + def CTNGenerate_C(self, buildpath, locations): """ Generate C code @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) @@ -194,13 +194,13 @@ def OnCloseEditor(self, view): self.Parent.OnCloseEditor(view) - def PlugFullName(self): + def CTNFullName(self): return self.Fullname def GetBufferState(self): return self.GetCurrentBufferState() -class _NodeListPlug(NodeList): +class _NodeListCTN(NodeList): XSD = """ @@ -219,7 +219,7 @@ def __init__(self): manager = NodeManager() NodeList.__init__(self, manager) - self.LoadProject(self.PlugPath()) + self.LoadProject(self.CTNPath()) self.SetNetworkName(self.BaseParams.getName()) def GetCanDevice(self): @@ -247,24 +247,24 @@ buildpath = self._getBuildPath() # Eventually create build dir if not os.path.exists(buildpath): - self.GetPlugRoot().logger.write_error(_("Error: No PLC built\n")) + self.GetCTRoot().logger.write_error(_("Error: No PLC built\n")) return masterpath = os.path.join(buildpath, "MasterGenerated.od") if not os.path.exists(masterpath): - self.GetPlugRoot().logger.write_error(_("Error: No Master generated\n")) + self.GetCTRoot().logger.write_error(_("Error: No Master generated\n")) return - app_frame = self.GetPlugRoot().AppFrame - - manager = MiniNodeManager(self, masterpath, self.PlugFullName() + ".generated_master") + app_frame = self.GetCTRoot().AppFrame + + manager = MiniNodeManager(self, masterpath, self.CTNFullName() + ".generated_master") self._GeneratedView = SlaveEditor(app_frame.TabsOpened, manager, app_frame, False) app_frame.EditProjectElement(self._GeneratedView, "MasterGenerated") def _CloseGenerateView(self): if self._GeneratedView is not None: - app_frame = self.GetPlugRoot().AppFrame + app_frame = self.GetCTRoot().AppFrame if app_frame is not None: app_frame.DeletePage(self._GeneratedView) @@ -284,19 +284,19 @@ if self._GeneratedView == view: self._GeneratedView = None - def OnPlugClose(self): - ConfigTreeNode.OnPlugClose(self) + def OnCTNClose(self): + ConfigTreeNode.OnCTNClose(self) self._CloseGenerateView() return True - def PlugTestModified(self): + def CTNTestModified(self): return self.ChangesToSave or self.HasChanged() - def OnPlugSave(self): - self.SetRoot(self.PlugPath()) + def OnCTNSave(self): + self.SetRoot(self.CTNPath()) return self.SaveProject() is None - def PlugGenerate_C(self, buildpath, locations): + def CTNGenerate_C(self, buildpath, locations): """ Generate C code @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) @@ -351,8 +351,8 @@ """ % DEFAULT_SETTINGS - PlugChildsTypes = [("CanOpenNode",_NodeListPlug, "CanOpen Master"), - ("CanOpenSlave",_SlavePlug, "CanOpen Slave")] + CTNChildrenTypes = [("CanOpenNode",_NodeListCTN, "CanOpen Master"), + ("CanOpenSlave",_SlaveCTN, "CanOpen Slave")] def GetParamsAttributes(self, path = None): infos = ConfigTreeNode.GetParamsAttributes(self, path = None) for element in infos: @@ -373,7 +373,7 @@ can_driver += '.dll' return can_driver - def PlugGenerate_C(self, buildpath, locations): + def CTNGenerate_C(self, buildpath, locations): format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())), "candriver" : self.GetCanDriver(), @@ -390,7 +390,7 @@ "post_sync" : "", "post_sync_register" : "", } - for child in self.IECSortedChilds(): + for child in self.IECSortedChildren(): childlocstr = "_".join(map(str,child.GetCurrentLocation())) nodename = "OD_%s" % childlocstr diff -r 1c23952dbde1 -r 5d4dc150b956 confnodes/python/PythonEditor.py --- a/confnodes/python/PythonEditor.py Mon May 07 18:47:29 2012 +0200 +++ b/confnodes/python/PythonEditor.py Mon May 07 19:19:08 2012 +0200 @@ -241,7 +241,7 @@ self.Controler.OnCloseEditor(self) def GetTitle(self): - fullname = self.Controler.PlugFullName() + fullname = self.Controler.CTNFullName() if not self.Controler.PythonIsSaved(): return "~%s~" % fullname return fullname diff -r 1c23952dbde1 -r 5d4dc150b956 confnodes/python/modules/svgui/svgui.py --- a/confnodes/python/modules/svgui/svgui.py Mon May 07 18:47:29 2012 +0200 +++ b/confnodes/python/modules/svgui/svgui.py Mon May 07 19:19:08 2012 +0200 @@ -22,16 +22,16 @@ ] def ConfNodePath(self): - return os.path.join(self.PlugParent.ConfNodePath(), "modules", self.PlugType) + return os.path.join(self.CTNParent.ConfNodePath(), "modules", self.CTNType) def _getSVGpath(self): # define name for IEC raw code file - return os.path.join(self.PlugPath(), "gui.svg") + return os.path.join(self.CTNPath(), "gui.svg") def _getSVGUIserverpath(self): return os.path.join(os.path.dirname(__file__), "svgui_server.py") - def PlugGenerate_C(self, buildpath, locations): + def CTNGenerate_C(self, buildpath, locations): """ Return C code generated by iec2c compiler when _generate_softPLC have been called @@ -87,20 +87,20 @@ return res def _ImportSVG(self): - dialog = wx.FileDialog(self.GetPlugRoot().AppFrame, _("Choose a SVG file"), os.getcwd(), "", _("SVG files (*.svg)|*.svg|All files|*.*"), wx.OPEN) + dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose a SVG file"), os.getcwd(), "", _("SVG files (*.svg)|*.svg|All files|*.*"), wx.OPEN) if dialog.ShowModal() == wx.ID_OK: svgpath = dialog.GetPath() if os.path.isfile(svgpath): shutil.copy(svgpath, self._getSVGpath()) else: - self.GetPlugRoot().logger.write_error(_("No such SVG file: %s\n")%svgpath) + self.GetCTRoot().logger.write_error(_("No such SVG file: %s\n")%svgpath) dialog.Destroy() def _StartInkscape(self): svgfile = self._getSVGpath() open_inkscape = True - if not self.GetPlugRoot().CheckProjectPathPerm(): - dialog = wx.MessageDialog(self.GetPlugRoot().AppFrame, + if not self.GetCTRoot().CheckProjectPathPerm(): + dialog = wx.MessageDialog(self.GetCTRoot().AppFrame, _("You don't have write permissions.\nOpen Inkscape anyway ?"), _("Open Inkscape"), wx.YES_NO|wx.ICON_QUESTION) diff -r 1c23952dbde1 -r 5d4dc150b956 confnodes/python/modules/wxglade_hmi/wxglade_hmi.py --- a/confnodes/python/modules/wxglade_hmi/wxglade_hmi.py Mon May 07 18:47:29 2012 +0200 +++ b/confnodes/python/modules/wxglade_hmi/wxglade_hmi.py Mon May 07 19:19:08 2012 +0200 @@ -16,7 +16,7 @@ def _getWXGLADEpath(self): # define name for IEC raw code file - return os.path.join(self.PlugPath(), "hmi.wxg") + return os.path.join(self.CTNPath(), "hmi.wxg") def launch_wxglade(self, options, wait=False): from wxglade import __file__ as fileName @@ -28,7 +28,7 @@ os.spawnv(mode, sys.executable, ["\"%s\""%sys.executable] + [glade] + options) - def PlugGenerate_C(self, buildpath, locations): + def CTNGenerate_C(self, buildpath, locations): """ Return C code generated by iec2c compiler when _generate_softPLC have been called @@ -101,8 +101,8 @@ def _editWXGLADE(self): wxg_filename = self._getWXGLADEpath() open_wxglade = True - if not self.GetPlugRoot().CheckProjectPathPerm(): - dialog = wx.MessageDialog(self.GetPlugRoot().AppFrame, + if not self.GetCTRoot().CheckProjectPathPerm(): + dialog = wx.MessageDialog(self.GetCTRoot().AppFrame, _("You don't have write permissions.\nOpen wxGlade anyway ?"), _("Open wxGlade"), wx.YES_NO|wx.ICON_QUESTION) diff -r 1c23952dbde1 -r 5d4dc150b956 confnodes/python/python.py --- a/confnodes/python/python.py Mon May 07 18:47:29 2012 +0200 +++ b/confnodes/python/python.py Mon May 07 19:19:08 2012 +0200 @@ -38,13 +38,13 @@ self.CreatePythonBuffer(True) else: self.CreatePythonBuffer(False) - self.OnPlugSave() + self.OnCTNSave() def ConfNodePath(self): - return os.path.join(self.PlugParent.ConfNodePath(), "modules", self.PlugType) + return os.path.join(self.CTNParent.ConfNodePath(), "modules", self.CTNType) def PythonFileName(self): - return os.path.join(self.PlugPath(), "python.xml") + return os.path.join(self.CTNPath(), "python.xml") def GetFilename(self): if self.PythonBuffer.IsCurrentSaved(): @@ -58,10 +58,10 @@ def GetPythonCode(self): return self.PythonCode.gettext() - def PlugTestModified(self): + def CTNTestModified(self): return self.ChangesToSave or not self.PythonIsSaved() - def OnPlugSave(self): + def OnCTNSave(self): filepath = self.PythonFileName() text = "\n" @@ -129,13 +129,13 @@ class RootClass(PythonCodeTemplate): - # For root object, available Childs Types are modules of the modules packages. - PlugChildsTypes = [(name, _GetClassFunction(name), help) for name, help in zip(modules.__all__,modules.helps)] + # For root object, available Children Types are modules of the modules packages. + CTNChildrenTypes = [(name, _GetClassFunction(name), help) for name, help in zip(modules.__all__,modules.helps)] def ConfNodePath(self): - return os.path.join(self.PlugParent.ConfNodePath(), self.PlugType) + return os.path.join(self.CTNParent.ConfNodePath(), self.CTNType) - def PlugGenerate_C(self, buildpath, locations): + def CTNGenerate_C(self, buildpath, locations): """ Generate C code @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) @@ -152,7 +152,7 @@ # define a unique name for the generated C file location_str = "_".join(map(lambda x:str(x), current_location)) - ctr = self.GetPlugRoot() + ctr = self.GetCTRoot() ctr.GetIECProgramsAndVariables() plc_python_filepath = os.path.join(os.path.split(__file__)[0], "plc_python.c") @@ -180,6 +180,6 @@ runtimefile.write(self.GetPythonCode()) runtimefile.close() - matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath()) + matiec_flags = '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()) return [(Gen_Pythonfile_path, matiec_flags)], "", True, ("runtime_%s.py"%location_str, file(runtimefile_path,"rb"))