ProjectController.py
changeset 1282 f427352f9727
parent 1262 7b9259945453
child 1315 ff14a66bbd12
equal deleted inserted replaced
1281:47131e3388f4 1282:f427352f9727
     5 import time
     5 import time
     6 import features
     6 import features
     7 import shutil
     7 import shutil
     8 import wx
     8 import wx
     9 import re, tempfile
     9 import re, tempfile
       
    10 from types import ListType
    10 from threading import Timer, Lock, Thread
    11 from threading import Timer, Lock, Thread
    11 from time import localtime
    12 from time import localtime
    12 from datetime import datetime
    13 from datetime import datetime
    13 from weakref import WeakKeyDictionary
    14 from weakref import WeakKeyDictionary
    14 
    15 
    35 DEBUG_RETRIES_WARN = 3
    36 DEBUG_RETRIES_WARN = 3
    36 DEBUG_RETRIES_REREGISTER = 4
    37 DEBUG_RETRIES_REREGISTER = 4
    37 
    38 
    38 ITEM_CONFNODE = 25
    39 ITEM_CONFNODE = 25
    39 
    40 
       
    41 def ExtractChildrenTypesFromCatalog(catalog):
       
    42     children_types = []
       
    43     for n,d,h,c in catalog:
       
    44         if isinstance(c, ListType):
       
    45             children_types.extend(ExtractChildrenTypesFromCatalog(c))
       
    46         else:
       
    47             children_types.append((n, GetClassImporter(c), d))
       
    48     return children_types
       
    49 
       
    50 def ExtractMenuItemsFromCatalog(catalog):
       
    51     menu_items = []
       
    52     for n,d,h,c in catalog:
       
    53         if isinstance(c, ListType):
       
    54             children = ExtractMenuItemsFromCatalog(c)
       
    55         else:
       
    56             children = []
       
    57         menu_items.append((n, d, h, children))
       
    58     return menu_items
       
    59 
       
    60 def GetAddMenuItems():
       
    61     return ExtractMenuItemsFromCatalog(features.catalog)
       
    62 
    40 class ProjectController(ConfigTreeNode, PLCControler):
    63 class ProjectController(ConfigTreeNode, PLCControler):
    41     """
    64     """
    42     This class define Root object of the confnode tree. 
    65     This class define Root object of the confnode tree. 
    43     It is responsible of :
    66     It is responsible of :
    44     - Managing project directory
    67     - Managing project directory
    48     - ...
    71     - ...
    49     
    72     
    50     """
    73     """
    51 
    74 
    52     # For root object, available Children Types are modules of the confnode packages.
    75     # For root object, available Children Types are modules of the confnode packages.
    53     CTNChildrenTypes =  [(n, GetClassImporter(c), d) for n,d,h,c in features.catalog]
    76     CTNChildrenTypes = ExtractChildrenTypesFromCatalog(features.catalog)
    54 
    77 
    55     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
    78     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
    56     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    79     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    57       <xsd:element name="BeremizRoot">
    80       <xsd:element name="BeremizRoot">
    58         <xsd:complexType>
    81         <xsd:complexType>
   114         self.debug_break = False
   137         self.debug_break = False
   115         self.previous_plcstate = None
   138         self.previous_plcstate = None
   116         # copy ConfNodeMethods so that it can be later customized
   139         # copy ConfNodeMethods so that it can be later customized
   117         self.StatusMethods = [dic.copy() for dic in self.StatusMethods]
   140         self.StatusMethods = [dic.copy() for dic in self.StatusMethods]
   118 
   141 
       
   142     def __del__(self):
       
   143         if self.DebugTimer:
       
   144             self.DebugTimer.cancel()
       
   145         self.KillDebugThread()
       
   146     
   119     def LoadLibraries(self):
   147     def LoadLibraries(self):
   120         self.Libraries = []
   148         self.Libraries = []
   121         TypeStack=[]
   149         TypeStack=[]
   122         for libname,clsname in features.libraries:
   150         for libname,clsname in features.libraries:
   123             if self.BeremizRoot.Libraries is None or getattr(self.BeremizRoot.Libraries, "Enable_"+libname+"_Library"):
   151             if self.BeremizRoot.Libraries is None or getattr(self.BeremizRoot.Libraries, "Enable_"+libname+"_Library"):
   124                 Lib = GetClassImporter(clsname)()(self, libname, TypeStack)
   152                 Lib = GetClassImporter(clsname)()(self, libname, TypeStack)
   125                 TypeStack.append(Lib.GetTypes())
   153                 TypeStack.append(Lib.GetTypes())
   126                 self.Libraries.append(Lib)
   154                 self.Libraries.append(Lib)
   127 
       
   128     def __del__(self):
       
   129         if self.DebugTimer:
       
   130             self.DebugTimer.cancel()
       
   131         self.KillDebugThread()
       
   132     
   155     
   133     def SetAppFrame(self, frame, logger):
   156     def SetAppFrame(self, frame, logger):
   134         self.AppFrame = frame
   157         self.AppFrame = frame
   135         self.logger = logger
   158         self.logger = logger
   136         self.StatusTimer = None
   159         self.StatusTimer = None