--- a/Beremiz.py Tue Sep 11 17:27:45 2007 +0200
+++ b/Beremiz.py Tue Sep 11 17:29:27 2007 +0200
@@ -358,10 +358,25 @@
root = self.PluginTree.GetRootItem()
if not root.IsOk():
root = self.PluginTree.AddRoot(infos["name"])
+ last_selected = self.GetSelectedPluginName()
self.GenerateTreeBranch(root, infos, True)
self.PluginTree.Expand(self.PluginTree.GetRootItem())
+ self.SelectedPluginByName(root,last_selected)
self.RefreshPluginParams()
+ def SelectedPluginByName(self, root, name):
+ toks = name.split('.',1)
+ item, root_cookie = self.PluginTree.GetFirstChild(root)
+ while item.IsOk():
+ if self.PluginTree.GetPyData(item) == toks[0]:
+ if len(toks)>1:
+ return self.SelectedPluginByName(item, toks[1])
+ else:
+ self.PluginTree.SelectItem(item, True)
+ return True
+ item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
+ return False
+
def GenerateTreeBranch(self, root, infos, first = False):
to_delete = []
self.PluginTree.SetItemText(root, infos["name"])
@@ -380,18 +395,27 @@
for item in to_delete:
self.PluginTree.Delete(item)
- def GetSelectedPlugin(self):
+ def GetSelectedPluginName(self):
selected = self.PluginTree.GetSelection()
if not selected.IsOk():
return None
if selected == self.PluginTree.GetRootItem():
+ return ""
+ else:
+ name = self.PluginTree.GetPyData(selected)
+ item = self.PluginTree.GetItemParent(selected)
+ while item.IsOk() and item != self.PluginTree.GetRootItem():
+ name = "%s.%s"%(self.PluginTree.GetPyData(item), name)
+ item = self.PluginTree.GetItemParent(item)
+ return name
+
+ def GetSelectedPlugin(self):
+ name = self.GetSelectedPluginName()
+ if not name:
+ return None
+ elif name == "":
return self.PluginRoot
else:
- name = self.PluginTree.GetItemText(selected)
- item = self.PluginTree.GetItemParent(selected)
- while item.IsOk() and item != self.PluginTree.GetRootItem():
- name = "%s.%s"%(self.PluginTree.GetItemText(item), name)
- item = self.PluginTree.GetItemParent(item)
return self.PluginRoot.GetChildByName(name)
def OnPluginTreeItemSelected(self, event):
--- a/plugger.py Tue Sep 11 17:27:45 2007 +0200
+++ b/plugger.py Tue Sep 11 17:29:27 2007 +0200
@@ -92,7 +92,7 @@
def SetParamsAttribute(self, path, value, logger):
# Filter IEC_Channel and Name, that have specific behavior
if path == "BaseParams.IEC_Channel":
- return self.FindNewIEC_Channel(value,logger), False
+ return self.FindNewIEC_Channel(value,logger), True
elif path == "BaseParams.Name":
res = self.FindNewName(value,logger)
self.PlugRequestSave()
@@ -221,9 +221,13 @@
def GetPlugInfos(self):
childs = []
- for child in self.IterChilds():
- childs.append(child.GetPlugInfos())
- return {"name" : self.BaseParams.getName(), "type" : None, "values" : childs}
+ # reorder childs by IEC_channels
+ ordered = [(chld.BaseParams.getIEC_Channel(),chld) for chld in self.IterChilds()]
+ if ordered:
+ ordered.sort()
+ for child in zip(*ordered)[1]:
+ childs.append(child.GetPlugInfos())
+ return {"name" : "%s (%d)"%(self.BaseParams.getName(),self.BaseParams.getIEC_Channel()), "type" : self.BaseParams.getName(), "values" : childs}
def FindNewName(self, DesiredName, logger):
@@ -283,7 +287,10 @@
while res in AllChannels: # While channel not free
if res < CurrentChannel: # Want to go down ?
res -= 1 # Test for n-1
- if res < 0 : return CurrentChannel # Can't go bellow 0, do nothing
+ if res < 0 :
+ if logger :
+ 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
# Finally set IEC Channel
@@ -549,7 +556,7 @@
childs = []
for child in self.IterChilds():
childs.append(child.GetPlugInfos())
- return {"name" : os.path.split(self.ProjectPath)[1], "type" : None, "values" : childs}
+ return {"name" : "PLC (%s)"%os.path.split(self.ProjectPath)[1], "type" : None, "values" : childs}
def NewProject(self, ProjectPath):
"""