PLCControler.py
changeset 13 69075340d6a9
parent 6 c8cf918ee7ea
child 24 364320323b4d
--- a/PLCControler.py	Fri Apr 13 17:54:40 2007 +0200
+++ b/PLCControler.py	Wed Apr 18 16:39:28 2007 +0200
@@ -758,20 +758,32 @@
     # Return Block types checking for recursion
     def GetBlockTypes(self):
         if self.CurrentElementEditing != None:
-            current_name = self.ElementsOpened[self.CurrentElementEditing]
-            words = current_name.split("::")
-            if len(words) == 1:
-                name = current_name
+            if self.Project:
+                current_name = self.ElementsOpened[self.CurrentElementEditing]
+                words = current_name.split("::")
+                if len(words) == 1:
+                    name = current_name
+                else:
+                    name = words[1]
+                type = self.GetPouType(name)
             else:
-                name = words[1]
-            blocktypes = [category for category in BlockTypes[:-1]]
-            blocktypes.append({"name" : "User-defined POUs", "list": []})
+                name = ""
+                type = None
+            if type == "function":
+                blocktypes = []
+                for category in BlockTypes[:-1]:
+                    cat = {"name" : category["name"], "list" : []}
+                    for block in category["list"]:
+                        if block["type"] == "function":
+                            cat["list"].append(block)
+                    if len(cat["list"]) > 0:
+                        blocktypes.append(cat)
+            else:
+                blocktypes = [category for category in BlockTypes[:-1]]
             if self.Project:
-                pou = self.Project.getPou(name)
-                name = pou.getName()
-                type = pou.pouType.getValue()
+                blocktypes.append({"name" : "User-defined POUs", "list": []})
                 for blocktype in BlockTypes[-1]["list"]:
-                    if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] == "functionBlock"):
+                    if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"):
                         blocktypes[-1]["list"].append(blocktype)
             return blocktypes
         return []
@@ -926,6 +938,17 @@
         self.CurrentElementEditing = index
 
     # Return language in which current pou editing is written
+    def GetCurrentElementEditingType(self):
+        if self.CurrentElementEditing != None:
+            name = self.ElementsOpened[self.CurrentElementEditing]
+            words = name.split("::")
+            if len(words) == 1:
+                return self.GetPouType(name)
+            else:
+                return self.GetPouType(words[1])
+        return None
+
+    # Return language in which current pou editing is written
     def GetCurrentElementEditingBodyType(self):
         if self.CurrentElementEditing != None:
             name = self.ElementsOpened[self.CurrentElementEditing]