POULibrary.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 18 Apr 2016 19:08:29 +0300
changeset 1480 79e54c5dead5
parent 772 98786137232d
child 1511 91538d0c242c
permissions -rw-r--r--
fix issue, then it wasn't possible to remove functional blocks from
project using right click and popup menu.

The problem is that, PopupMenu was called using IDEFrame object and as
a result item in ProjectTree loosed focus and focus went to IDEFrame.
Therefore later functions couldn't detect which item in ProjectTree
was selected.
from weakref import ref

class POULibrary:
    def __init__(self, CTR, LibName, TypeStack):
        from PLCControler import PLCControler
        self.CTR = ref(CTR)
        self.LibName = LibName
        self.LibraryControler = PLCControler()
        self.LibraryControler.OpenXMLFile(self.GetLibraryPath())
        self.LibraryControler.ClearConfNodeTypes()
        self.LibraryControler.AddConfNodeTypesList(TypeStack)
        self.program = None;

    def GetSTCode(self):
        if not self.program:
            self.program = self.LibraryControler.GenerateProgram()[0]+"\n"
        return self.program 

    def GetName(self):
        return self.LibName

    def GetCTR(self):
        return self.CTR()
        
    def GetTypes(self):
        return {"name" : self.GetName(), "types": self.LibraryControler.Project}

    def GetLibraryPath(self):
        raise Exception("Not implemented")

    def Generate_C(self, buildpath, varlist, IECCFLAGS):
        # Pure python or IEC libs doesn't produce C code
        return ((""), [], False), ""