70 r".*\.st:(\d+)-(\d+)\.\.(\d+)-(\d+): (?:error)|(?:warning) : (.*)$") |
70 r".*\.st:(\d+)-(\d+)\.\.(\d+)-(\d+): (?:error)|(?:warning) : (.*)$") |
71 |
71 |
72 |
72 |
73 def ExtractChildrenTypesFromCatalog(catalog): |
73 def ExtractChildrenTypesFromCatalog(catalog): |
74 children_types = [] |
74 children_types = [] |
75 for n, d, _h, c in catalog: |
75 for name, displayname, _helpstr, moduleclassname in catalog: |
76 if isinstance(c, list): |
76 if isinstance(moduleclassname, list): |
77 children_types.extend(ExtractChildrenTypesFromCatalog(c)) |
77 children_types.extend(ExtractChildrenTypesFromCatalog(moduleclassname)) |
78 else: |
78 else: |
79 children_types.append((n, GetClassImporter(c), d)) |
79 children_types.append((name, GetClassImporter(moduleclassname), displayname)) |
80 return children_types |
80 return children_types |
81 |
81 |
82 |
82 |
83 def ExtractMenuItemsFromCatalog(catalog): |
83 def ExtractMenuItemsFromCatalog(catalog): |
84 menu_items = [] |
84 menu_items = [] |
85 for n, d, h, c in catalog: |
85 for name, displayname, helpstr, moduleclassname in catalog: |
86 if isinstance(c, list): |
86 if isinstance(moduleclassname, list): |
87 children = ExtractMenuItemsFromCatalog(c) |
87 children = ExtractMenuItemsFromCatalog(moduleclassname) |
88 else: |
88 else: |
89 children = [] |
89 children = [] |
90 menu_items.append((n, d, h, children)) |
90 menu_items.append((name, displayname, helpstr, children)) |
91 return menu_items |
91 return menu_items |
92 |
92 |
93 |
93 |
94 def GetAddMenuItems(): |
94 def GetAddMenuItems(): |
95 return ExtractMenuItemsFromCatalog(features.catalog) |
95 return ExtractMenuItemsFromCatalog(features.catalog) |
201 <xsd:element name="Libraries" minOccurs="0"> |
201 <xsd:element name="Libraries" minOccurs="0"> |
202 <xsd:complexType> |
202 <xsd:complexType> |
203 """ + "\n".join(['<xsd:attribute name=' + |
203 """ + "\n".join(['<xsd:attribute name=' + |
204 '"Enable_' + libname + '_Library" ' + |
204 '"Enable_' + libname + '_Library" ' + |
205 'type="xsd:boolean" use="optional" default="' + |
205 'type="xsd:boolean" use="optional" default="' + |
206 ('true' if default else 'false') + '"/>' |
206 ('false' if type(default)==str or default==False else 'true') + '"/>' |
207 for libname, _lib, default in features.libraries]) + """ |
207 for libname, _lib, default in features.libraries]) + """ |
208 </xsd:complexType> |
208 </xsd:complexType> |
209 </xsd:element>""") if len(features.libraries) > 0 else '') + """ |
209 </xsd:element>""") if len(features.libraries) > 0 else '') + """ |
210 </xsd:sequence> |
210 </xsd:sequence> |
211 <xsd:attribute name="URI_location" type="xsd:string" use="optional" default=""/> |
211 <xsd:attribute name="URI_location" type="xsd:string" use="optional" default=""/> |
280 self.LastBuiltIECcodeDigest = None |
280 self.LastBuiltIECcodeDigest = None |
281 |
281 |
282 def LoadLibraries(self): |
282 def LoadLibraries(self): |
283 self.Libraries = [] |
283 self.Libraries = [] |
284 TypeStack = [] |
284 TypeStack = [] |
285 for libname, clsname, lib_enabled in features.libraries: |
285 for libname, clsname, default in features.libraries: |
|
286 lib_enabled = False if type(default)==str else default |
286 if self.BeremizRoot.Libraries is not None: |
287 if self.BeremizRoot.Libraries is not None: |
287 enable_attr = getattr(self.BeremizRoot.Libraries, |
288 enable_attr = getattr(self.BeremizRoot.Libraries, |
288 "Enable_" + libname + "_Library") |
289 "Enable_" + libname + "_Library") |
289 if enable_attr is not None: |
290 if enable_attr is not None: |
290 lib_enabled = enable_attr |
291 lib_enabled = enable_attr |
291 |
292 |
292 if lib_enabled: |
293 if lib_enabled: |
293 Lib = GetClassImporter(clsname)()(self, libname, TypeStack) |
294 Lib = GetClassImporter(clsname)()(self, libname, TypeStack) |
294 TypeStack.append(Lib.GetTypes()) |
295 TypeStack.append(Lib.GetTypes()) |
295 self.Libraries.append(Lib) |
296 self.Libraries.append(Lib) |
|
297 |
|
298 def CTNAddChild(self, CTNName, CTNType, IEC_Channel=0): |
|
299 """ |
|
300 Project controller applies libraries requirements when adding new CTN |
|
301 """ |
|
302 res = ConfigTreeNode.CTNAddChild(self, CTNName, CTNType, IEC_Channel) |
|
303 |
|
304 # find library associated with new CTN, if any |
|
305 associated_lib = {default:libname |
|
306 for libname, _clsname, default |
|
307 in features.libraries}.get(CTNType, None) |
|
308 |
|
309 # if any, then enable it if it wasn't and inform user |
|
310 if associated_lib is not None: |
|
311 # FIXME: This should be done with GetParamsAttribute |
|
312 # but it fails with missing optional attributes |
|
313 attrname = "Enable_" + associated_lib + "_Library" |
|
314 libobj = self.BeremizRoot.Libraries |
|
315 lib_enabled = False if libobj is None else getattr(libobj, attrname) |
|
316 if not lib_enabled: |
|
317 # use SetParamsAttribute to trigger reload of libs |
|
318 self.SetParamsAttribute("BeremizRoot.Libraries.Enable_" + associated_lib + "_Library", True) |
|
319 msg = _("Enabled {a1} library, required by {a2} extension\n").format( |
|
320 a1=associated_lib, a2=CTNType) |
|
321 self.GetCTRoot().logger.write(msg) |
|
322 |
|
323 return res |
296 |
324 |
297 def SetAppFrame(self, frame, logger): |
325 def SetAppFrame(self, frame, logger): |
298 self.AppFrame = frame |
326 self.AppFrame = frame |
299 self.logger = logger |
327 self.logger = logger |
300 self.StatusTimer = None |
328 self.StatusTimer = None |