ConfigTreeNode.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Mon, 22 May 2023 14:37:15 +0200
changeset 3812 92e528718733
parent 3785 29bc2bebf1d4
child 4000 87f11a874477
permissions -rw-r--r--
CLI: simpler status polling, fixing pyro5 thread
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
     1
#!/usr/bin/env python
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
     2
# -*- coding: utf-8 -*-
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
     3
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
     6
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
     8
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
     9
# See COPYING file for copyrights details.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    10
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    11
# This program is free software; you can redistribute it and/or
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    12
# modify it under the terms of the GNU General Public License
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    13
# as published by the Free Software Foundation; either version 2
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    14
# of the License, or (at your option) any later version.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    15
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    16
# This program is distributed in the hope that it will be useful,
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    19
# GNU General Public License for more details.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    20
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    21
# You should have received a copy of the GNU General Public License
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    22
# along with this program; if not, write to the Free Software
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1332
diff changeset
    24
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    25
"""
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    26
Config Tree Node base class.
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    27
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    28
- A Beremiz project is organized in a tree each node derivate from ConfigTreeNode
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    29
- Project tree organization match filesystem organization of project directory.
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    30
- Each node of the tree have its own xml configuration, whose grammar is defined for each node type, as XSD
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    31
- ... TODO : document
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    32
"""
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    33
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3674
diff changeset
    34
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    35
import os
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    36
import traceback
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    37
import types
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    38
import shutil
2523
aa7f138648f3 WIP adding searching capabilities in python files:
Edouard Tisserant
parents: 2443
diff changeset
    39
from operator import add
2551
245644bfcd24 Make spaghetti-code-quality great again.
Edouard Tisserant
parents: 2524
diff changeset
    40
from functools import reduce
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2418
diff changeset
    41
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
    42
from lxml import etree
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
    43
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
    44
from xmlclass import GenerateParserFromXSDstring
1850
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
    45
from PLCControler import LOCATION_CONFNODE
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 801
diff changeset
    46
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
2711
ecfb59e4ecb0 Fix missing import, consequence of bad resolution of conflicting hg graft of f0a822ef9fa0 into d15a997859b1
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2696
diff changeset
    47
from POULibrary import UserAddressedException
274
8628f3dd0979 Adding support for defining plugin library as a plcopen xml file in plugin folder
greg
parents: 273
diff changeset
    48
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
    49
_BaseParamsParser = GenerateParserFromXSDstring("""<?xml version="1.0" encoding="ISO-8859-1" ?>
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    50
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    51
          <xsd:element name="BaseParams">
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    52
            <xsd:complexType>
86
f0a9d74e3b26 Adding support for the new version of xmlclass
lbessard
parents: 82
diff changeset
    53
              <xsd:attribute name="Name" type="xsd:string" use="optional" default="__unnamed__"/>
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 16
diff changeset
    54
              <xsd:attribute name="IEC_Channel" type="xsd:integer" use="required"/>
86
f0a9d74e3b26 Adding support for the new version of xmlclass
lbessard
parents: 82
diff changeset
    55
              <xsd:attribute name="Enabled" type="xsd:boolean" use="optional" default="true"/>
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    56
            </xsd:complexType>
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    57
          </xsd:element>
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
    58
        </xsd:schema>""")
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    59
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    60
NameTypeSeparator = '@'
1722
89824afffef2 fix some typos
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1581
diff changeset
    61
XSDSchemaErrorMessage = _("{a1} XML file doesn't follow XSD schema at line {a2}:\n{a3}")
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    62
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    63
1831
56b48961cc68 fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1828
diff changeset
    64
class ConfigTreeNode(object):
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    65
    """
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
    66
    This class is the one that define confnodes.
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    67
    """
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    68
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    69
    XSD = None
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    70
    CTNChildrenTypes = []
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    71
    CTNMaxCount = None
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
    72
    ConfNodeMethods = []
274
8628f3dd0979 Adding support for defining plugin library as a plcopen xml file in plugin folder
greg
parents: 273
diff changeset
    73
    LibraryControler = None
743
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 741
diff changeset
    74
    EditorType = ConfTreeNodeEditor
738
413946c04c87 refactoring
laurent
parents: 734
diff changeset
    75
    IconPath = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
    76
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    77
    def _AddParamsMembers(self):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    78
        self.CTNParams = None
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
    79
        if self.XSD:
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
    80
            self.Parser = GenerateParserFromXSDstring(self.XSD)
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
    81
            obj = self.Parser.CreateRoot()
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
    82
            name = obj.getLocalTag()
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
    83
            self.CTNParams = (name, obj)
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
    84
            setattr(self, name, obj)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 16
diff changeset
    85
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 16
diff changeset
    86
    def __init__(self):
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
    87
        # Create BaseParam
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
    88
        self.BaseParams = _BaseParamsParser.CreateRoot()
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 16
diff changeset
    89
        self.MandatoryParams = ("BaseParams", self.BaseParams)
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    90
        self._AddParamsMembers()
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    91
        self.Children = {}
656
c1792dfc8c7e Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 655
diff changeset
    92
        self._View = None
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
    93
        # copy ConfNodeMethods so that it can be later customized
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
    94
        self.ConfNodeMethods = [dic.copy() for dic in self.ConfNodeMethods]
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
    95
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    96
    def ConfNodeBaseXmlFilePath(self, CTNName=None):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    97
        return os.path.join(self.CTNPath(CTNName), "baseconfnode.xml")
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
    98
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    99
    def ConfNodeXmlFilePath(self, CTNName=None):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   100
        return os.path.join(self.CTNPath(CTNName), "confnode.xml")
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   101
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   102
    def CTNPath(self, CTNName=None, project_path=None):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   103
        if not CTNName:
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   104
            CTNName = self.CTNName()
1061
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1033
diff changeset
   105
        if not project_path:
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1033
diff changeset
   106
            project_path = self.CTNParent.CTNPath()
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1033
diff changeset
   107
        return os.path.join(project_path,
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   108
                            CTNName + NameTypeSeparator + self.CTNType)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   109
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   110
    def CTNName(self):
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 674
diff changeset
   111
        return self.BaseParams.getName()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   112
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   113
    def CTNEnabled(self):
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 674
diff changeset
   114
        return self.BaseParams.getEnabled()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   115
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   116
    def CTNFullName(self):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   117
        parent = self.CTNParent.CTNFullName()
656
c1792dfc8c7e Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 655
diff changeset
   118
        if parent != "":
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   119
            return parent + "." + self.CTNName()
656
c1792dfc8c7e Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 655
diff changeset
   120
        return self.BaseParams.getName()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   121
2523
aa7f138648f3 WIP adding searching capabilities in python files:
Edouard Tisserant
parents: 2443
diff changeset
   122
    def CTNSearch(self, criteria):
aa7f138648f3 WIP adding searching capabilities in python files:
Edouard Tisserant
parents: 2443
diff changeset
   123
        # TODO match config's fields name and fields contents
aa7f138648f3 WIP adding searching capabilities in python files:
Edouard Tisserant
parents: 2443
diff changeset
   124
        return reduce(add, [
aa7f138648f3 WIP adding searching capabilities in python files:
Edouard Tisserant
parents: 2443
diff changeset
   125
            CTNChild.CTNSearch(criteria)
2579
8fb5c6eddc72 Conform to pep8 and pylint :
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2552
diff changeset
   126
            for CTNChild in self.IterChildren()], [])
2523
aa7f138648f3 WIP adding searching capabilities in python files:
Edouard Tisserant
parents: 2443
diff changeset
   127
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 780
diff changeset
   128
    def GetIconName(self):
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents: 728
diff changeset
   129
        return None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   130
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   131
    def CTNTestModified(self):
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 115
diff changeset
   132
        return self.ChangesToSave
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 115
diff changeset
   133
3674
d10a7907fb43 OPC-UA: Update CTN "ChangesToSave" status when variable selection change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3641
diff changeset
   134
    def CTNMarkModified(self):
d10a7907fb43 OPC-UA: Update CTN "ChangesToSave" status when variable selection change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3641
diff changeset
   135
        oldChangesToSave = self.ChangesToSave
d10a7907fb43 OPC-UA: Update CTN "ChangesToSave" status when variable selection change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3641
diff changeset
   136
        self.ChangesToSave = True
d10a7907fb43 OPC-UA: Update CTN "ChangesToSave" status when variable selection change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3641
diff changeset
   137
        if not oldChangesToSave:
d10a7907fb43 OPC-UA: Update CTN "ChangesToSave" status when variable selection change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3641
diff changeset
   138
            appframe = self.GetCTRoot().AppFrame
d10a7907fb43 OPC-UA: Update CTN "ChangesToSave" status when variable selection change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3641
diff changeset
   139
            if appframe is not None:
d10a7907fb43 OPC-UA: Update CTN "ChangesToSave" status when variable selection change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3641
diff changeset
   140
                appframe.RefreshTitle()
d10a7907fb43 OPC-UA: Update CTN "ChangesToSave" status when variable selection change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3641
diff changeset
   141
                appframe.RefreshPageTitles()
d10a7907fb43 OPC-UA: Update CTN "ChangesToSave" status when variable selection change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3641
diff changeset
   142
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 115
diff changeset
   143
    def ProjectTestModified(self):
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 115
diff changeset
   144
        """
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 115
diff changeset
   145
        recursively check modified status
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 115
diff changeset
   146
        """
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   147
        if self.CTNTestModified():
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 115
diff changeset
   148
            return True
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 115
diff changeset
   149
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   150
        for CTNChild in self.IterChildren():
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   151
            if CTNChild.ProjectTestModified():
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 115
diff changeset
   152
                return True
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 115
diff changeset
   153
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   154
        return False
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   155
699
6ff64cadb1ff Adding support for executing python scripts on remote runtime
laurent
parents: 696
diff changeset
   156
    def RemoteExec(self, script, **kwargs):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   157
        return self.CTNParent.RemoteExec(script, **kwargs)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   158
1061
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1033
diff changeset
   159
    def OnCTNSave(self, from_project_path=None):
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1778
diff changeset
   160
        """Default, do nothing and return success"""
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   161
        return True
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   162
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   163
    def GetParamsAttributes(self, path=None):
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   164
        if path:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   165
            parts = path.split(".", 1)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   166
            if self.MandatoryParams and parts[0] == self.MandatoryParams[0]:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   167
                return self.MandatoryParams[1].getElementInfos(parts[0], parts[1])
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   168
            elif self.CTNParams and parts[0] == self.CTNParams[0]:
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   169
                return self.CTNParams[1].getElementInfos(parts[0], parts[1])
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 16
diff changeset
   170
        else:
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   171
            params = []
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   172
            if self.CTNParams:
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   173
                params.append(self.CTNParams[1].getElementInfos(self.CTNParams[0]))
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   174
            return params
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   175
203
cb9901076a21 Added concepts :
etisserant
parents: 202
diff changeset
   176
    def SetParamsAttribute(self, path, value):
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 115
diff changeset
   177
        self.ChangesToSave = True
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   178
        # Filter IEC_Channel and Name, that have specific behavior
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   179
        if path == "BaseParams.IEC_Channel":
443
34c9788bd933 Adding support for updating located variables when changing plugin IEC_Channel
laurent
parents: 440
diff changeset
   180
            old_leading = ".".join(map(str, self.GetCurrentLocation()))
34c9788bd933 Adding support for updating located variables when changing plugin IEC_Channel
laurent
parents: 440
diff changeset
   181
            new_value = self.FindNewIEC_Channel(value)
842
3c4c1e076a34 Fix bug when modifying IEC_Channel
Laurent Bessard
parents: 841
diff changeset
   182
            if new_value != value:
3c4c1e076a34 Fix bug when modifying IEC_Channel
Laurent Bessard
parents: 841
diff changeset
   183
                new_leading = ".".join(map(str, self.CTNParent.GetCurrentLocation() + (new_value,)))
3c4c1e076a34 Fix bug when modifying IEC_Channel
Laurent Bessard
parents: 841
diff changeset
   184
                self.GetCTRoot().UpdateProjectVariableLocation(old_leading, new_leading)
443
34c9788bd933 Adding support for updating located variables when changing plugin IEC_Channel
laurent
parents: 440
diff changeset
   185
            return new_value, True
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   186
        elif path == "BaseParams.Name":
203
cb9901076a21 Added concepts :
etisserant
parents: 202
diff changeset
   187
            res = self.FindNewName(value)
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   188
            self.CTNRequestSave()
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 115
diff changeset
   189
            return res, True
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   190
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   191
        parts = path.split(".", 1)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   192
        if self.MandatoryParams and parts[0] == self.MandatoryParams[0]:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   193
            self.MandatoryParams[1].setElementValue(parts[1], value)
1179
3e7bd88fcff7 Fixed inconsistency in value display when setting integer value for float parameter
Laurent Bessard
parents: 1063
diff changeset
   194
            value = self.MandatoryParams[1].getElementInfos(parts[0], parts[1])["value"]
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   195
        elif self.CTNParams and parts[0] == self.CTNParams[0]:
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   196
            self.CTNParams[1].setElementValue(parts[1], value)
1179
3e7bd88fcff7 Fixed inconsistency in value display when setting integer value for float parameter
Laurent Bessard
parents: 1063
diff changeset
   197
            value = self.CTNParams[1].getElementInfos(parts[0], parts[1])["value"]
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   198
        return value, False
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 16
diff changeset
   199
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   200
    def CTNMakeDir(self):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   201
        os.mkdir(self.CTNPath())
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   202
1061
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1033
diff changeset
   203
    def CTNRequestSave(self, from_project_path=None):
3318
aee9e98c856a IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3163
diff changeset
   204
        if self.GetCTRoot().CheckProjectPathPerm():
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   205
            # If confnode do not have corresponding directory
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   206
            ctnpath = self.CTNPath()
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   207
            if not os.path.isdir(ctnpath):
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 423
diff changeset
   208
                # Create it
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   209
                os.mkdir(ctnpath)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   210
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   211
            # generate XML for base XML parameters controller of the confnode
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 423
diff changeset
   212
            if self.MandatoryParams:
3755
ca814b175391 fix string encoding
GP Orcullo <kinsamanka@gmail.com>
parents: 3752
diff changeset
   213
                BaseXMLFile = open(self.ConfNodeBaseXmlFilePath(), 'w', encoding='utf-8')
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
   214
                BaseXMLFile.write(etree.tostring(
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   215
                    self.MandatoryParams[1],
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   216
                    pretty_print=True,
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   217
                    xml_declaration=True,
3755
ca814b175391 fix string encoding
GP Orcullo <kinsamanka@gmail.com>
parents: 3752
diff changeset
   218
                    encoding='utf-8').decode())
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 423
diff changeset
   219
                BaseXMLFile.close()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   220
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   221
            # generate XML for XML parameters controller of the confnode
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   222
            if self.CTNParams:
3755
ca814b175391 fix string encoding
GP Orcullo <kinsamanka@gmail.com>
parents: 3752
diff changeset
   223
                XMLFile = open(self.ConfNodeXmlFilePath(), 'w', encoding='utf-8')
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
   224
                XMLFile.write(etree.tostring(
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   225
                    self.CTNParams[1],
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   226
                    pretty_print=True,
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   227
                    xml_declaration=True,
3755
ca814b175391 fix string encoding
GP Orcullo <kinsamanka@gmail.com>
parents: 3752
diff changeset
   228
                    encoding='utf-8').decode())
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 423
diff changeset
   229
                XMLFile.close()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   230
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   231
            # Call the confnode specific OnCTNSave method
1061
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1033
diff changeset
   232
            result = self.OnCTNSave(from_project_path)
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 423
diff changeset
   233
            if not result:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1733
diff changeset
   234
                return _("Error while saving \"%s\"\n") % self.CTNPath()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   235
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   236
            # mark confnode as saved
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 423
diff changeset
   237
            self.ChangesToSave = False
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   238
            # go through all children and do the same
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   239
            for CTNChild in self.IterChildren():
1063
9b5995303db1 Fixed bug in Save function in Beremiz
Laurent Bessard
parents: 1061
diff changeset
   240
                CTNChildPath = None
9b5995303db1 Fixed bug in Save function in Beremiz
Laurent Bessard
parents: 1061
diff changeset
   241
                if from_project_path is not None:
9b5995303db1 Fixed bug in Save function in Beremiz
Laurent Bessard
parents: 1061
diff changeset
   242
                    CTNChildPath = CTNChild.CTNPath(project_path=from_project_path)
9b5995303db1 Fixed bug in Save function in Beremiz
Laurent Bessard
parents: 1061
diff changeset
   243
                result = CTNChild.CTNRequestSave(CTNChildPath)
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 423
diff changeset
   244
                if result:
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 423
diff changeset
   245
                    return result
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 16
diff changeset
   246
        return None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   247
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   248
    def CTNImport(self, src_CTNPath):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   249
        shutil.copytree(src_CTNPath, self.CTNPath)
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   250
        return True
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   251
883
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 842
diff changeset
   252
    def CTNGlobalInstances(self):
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 842
diff changeset
   253
        """
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 842
diff changeset
   254
        @return: [(instance_name, instance_type),...]
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 842
diff changeset
   255
        """
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 842
diff changeset
   256
        return []
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   257
883
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 842
diff changeset
   258
    def _GlobalInstances(self):
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 842
diff changeset
   259
        instances = self.CTNGlobalInstances()
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 842
diff changeset
   260
        for CTNChild in self.IECSortedChildren():
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 842
diff changeset
   261
            instances.extend(CTNChild._GlobalInstances())
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 842
diff changeset
   262
        return instances
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   263
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   264
    def CTNGenerate_C(self, buildpath, locations):
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   265
        """
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   266
        Generate C code
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   267
        @param locations: List of complete variables locations \
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   268
            [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   269
            "NAME" : name of the variable (generally "__IW0_1_2" style)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   270
            "DIR" : direction "Q","I" or "M"
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   271
            "SIZE" : size "X", "B", "W", "D", "L"
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   272
            "LOC" : tuple of interger for IEC location (0,1,2,...)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   273
            }, ...]
18
0fac6d621a24 Base build mechanism layout.
etisserant
parents: 17
diff changeset
   274
        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
0fac6d621a24 Base build mechanism layout.
etisserant
parents: 17
diff changeset
   275
        """
1833
2269739dd098 fix unnecessary lambda and enable corresponding pylint check
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1831
diff changeset
   276
        self.GetCTRoot().logger.write_warning(".".join(map(str, self.GetCurrentLocation())) + " -> Nothing to do\n")
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   277
        return [], "", False
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   278
203
cb9901076a21 Added concepts :
etisserant
parents: 202
diff changeset
   279
    def _Generate_C(self, buildpath, locations):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   280
        # Generate confnodes [(Cfiles, CFLAGS)], LDFLAGS, DoCalls, extra_files
203
cb9901076a21 Added concepts :
etisserant
parents: 202
diff changeset
   281
        # extra_files = [(fname,fobject), ...]
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   282
        gen_result = self.CTNGenerate_C(buildpath, locations)
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   283
        CTNCFilesAndCFLAGS, CTNLDFLAGS, DoCalls = gen_result[:3]
203
cb9901076a21 Added concepts :
etisserant
parents: 202
diff changeset
   284
        extra_files = gen_result[3:]
361
331d698e1118 Adding support for internationalization
laurent
parents: 356
diff changeset
   285
        # if some files have been generated put them in the list with their location
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   286
        if CTNCFilesAndCFLAGS:
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   287
            LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), CTNCFilesAndCFLAGS, DoCalls)]
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   288
        else:
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   289
            LocationCFilesAndCFLAGS = []
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   290
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   291
        # confnode asks for some LDFLAGS
2003
2076df8743b5 Support unicode in LDFLAGS returned by extensions
Edouard Tisserant
parents: 1932
diff changeset
   292
        LDFLAGS = []
2076df8743b5 Support unicode in LDFLAGS returned by extensions
Edouard Tisserant
parents: 1932
diff changeset
   293
        if CTNLDFLAGS is not None:
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   294
            # LDFLAGS can be either string
3752
9f6f46dbe3ae removed Python2 modules
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
   295
            if isinstance(CTNLDFLAGS, str):
2003
2076df8743b5 Support unicode in LDFLAGS returned by extensions
Edouard Tisserant
parents: 1932
diff changeset
   296
                LDFLAGS += [CTNLDFLAGS]
1733
dea107dce0c4 clean-up: fix some PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   297
            # or list of strings
1778
1c6a704bd39c clean-up: fix PEP8 E721 do not compare types, use 'isinstance()'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   298
            elif isinstance(CTNLDFLAGS, list):
2003
2076df8743b5 Support unicode in LDFLAGS returned by extensions
Edouard Tisserant
parents: 1932
diff changeset
   299
                LDFLAGS += CTNLDFLAGS
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   300
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   301
        # recurse through all children, and stack their results
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   302
        for CTNChild in self.IECSortedChildren():
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   303
            new_location = CTNChild.GetCurrentLocation()
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
   304
            # How deep are we in the tree ?
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
   305
            depth = len(new_location)
203
cb9901076a21 Added concepts :
etisserant
parents: 202
diff changeset
   306
            _LocationCFilesAndCFLAGS, _LDFLAGS, _extra_files = \
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   307
                CTNChild._Generate_C(
1733
dea107dce0c4 clean-up: fix some PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   308
                    # keep the same path
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   309
                    buildpath,
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   310
                    # filter locations that start with current IEC location
1746
45d6f5fba016 clean-up: fix PEP8 E202 whitespace before ')'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   311
                    [loc for loc in locations if loc["LOC"][0:depth] == new_location])
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   312
            # stack the result
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   313
            LocationCFilesAndCFLAGS += _LocationCFilesAndCFLAGS
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   314
            LDFLAGS += _LDFLAGS
203
cb9901076a21 Added concepts :
etisserant
parents: 202
diff changeset
   315
            extra_files += _extra_files
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   316
203
cb9901076a21 Added concepts :
etisserant
parents: 202
diff changeset
   317
        return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   318
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   319
    def IterChildren(self):
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3674
diff changeset
   320
        for _CTNType, Children in list(self.Children.items()):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   321
            for CTNInstance in Children:
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   322
                yield CTNInstance
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   323
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   324
    def IECSortedChildren(self):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   325
        # reorder children by IEC_channels
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   326
        ordered = [(chld.BaseParams.getIEC_Channel(), chld) for chld in self.IterChildren()]
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   327
        if ordered:
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   328
            ordered.sort()
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3674
diff changeset
   329
            return list(zip(*ordered))[1]
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   330
        else:
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   331
            return []
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   332
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   333
    def _GetChildBySomething(self, something, toks):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   334
        for CTNInstance in self.IterChildren():
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   335
            # if match component of the name
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   336
            if getattr(CTNInstance.BaseParams, something) == toks[0]:
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   337
                # if Name have other components
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   338
                if len(toks) >= 2:
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   339
                    # Recurse in order to find the latest object
1747
6046ffa2280f clean-up: fix PEP8 E201 whitespace after '{'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1746
diff changeset
   340
                    return CTNInstance._GetChildBySomething(something, toks[1:])
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   341
                # No sub name -> found
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   342
                return CTNInstance
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   343
        # Not found
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   344
        return None
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   345
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   346
    def GetChildByName(self, Name):
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   347
        if Name:
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   348
            toks = Name.split('.')
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   349
            return self._GetChildBySomething("Name", toks)
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   350
        else:
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   351
            return self
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   352
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   353
    def GetChildByIECLocation(self, Location):
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   354
        if Location:
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   355
            return self._GetChildBySomething("IEC_Channel", Location)
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   356
        else:
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   357
            return self
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   358
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   359
    def GetCurrentLocation(self):
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
   360
        """
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   361
        @return:  Tupple containing confnode IEC location of current confnode : %I0.0.4.5 => (0,0,4,5)
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
   362
        """
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   363
        return self.CTNParent.GetCurrentLocation() + (self.BaseParams.getIEC_Channel(),)
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   364
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   365
    def GetCurrentName(self):
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   366
        """
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   367
        @return:  String "ParentParentName.ParentName.Name"
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   368
        """
1738
d2e979738700 clean-up: fix PEP8 E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   369
        return self.CTNParent._GetCurrentName() + self.BaseParams.getName()
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   370
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   371
    def _GetCurrentName(self):
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   372
        """
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   373
        @return:  String "ParentParentName.ParentName.Name."
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 41
diff changeset
   374
        """
1738
d2e979738700 clean-up: fix PEP8 E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   375
        return self.CTNParent._GetCurrentName() + self.BaseParams.getName() + "."
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   376
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   377
    def GetCTRoot(self):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   378
        return self.CTNParent.GetCTRoot()
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   379
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 96
diff changeset
   380
    def GetFullIEC_Channel(self):
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 96
diff changeset
   381
        return ".".join([str(i) for i in self.GetCurrentLocation()]) + ".x"
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 96
diff changeset
   382
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 96
diff changeset
   383
    def GetLocations(self):
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 96
diff changeset
   384
        location = self.GetCurrentLocation()
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   385
        return [loc for loc in self.CTNParent.GetLocations() if loc["LOC"][0:len(location)] == location]
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 96
diff changeset
   386
401
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 396
diff changeset
   387
    def GetVariableLocationTree(self):
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 396
diff changeset
   388
        '''
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   389
        This function is meant to be overridden by confnodes.
401
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 396
diff changeset
   390
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 396
diff changeset
   391
        It should returns an list of dictionaries
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   392
401
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 396
diff changeset
   393
        - IEC_type is an IEC type like BOOL/BYTE/SINT/...
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 396
diff changeset
   394
        - location is a string of this variable's location, like "%IX0.0.0"
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 396
diff changeset
   395
        '''
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 396
diff changeset
   396
        children = []
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   397
        for child in self.IECSortedChildren():
402
984e238e63d0 Bugs on displaying plugin available variables in PluginTree fixed
laurent
parents: 401
diff changeset
   398
            children.append(child.GetVariableLocationTree())
984e238e63d0 Bugs on displaying plugin available variables in PluginTree fixed
laurent
parents: 401
diff changeset
   399
        return {"name": self.BaseParams.getName(),
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   400
                "type": LOCATION_CONFNODE,
402
984e238e63d0 Bugs on displaying plugin available variables in PluginTree fixed
laurent
parents: 401
diff changeset
   401
                "location": self.GetFullIEC_Channel(),
984e238e63d0 Bugs on displaying plugin available variables in PluginTree fixed
laurent
parents: 401
diff changeset
   402
                "children": children}
401
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 396
diff changeset
   403
203
cb9901076a21 Added concepts :
etisserant
parents: 202
diff changeset
   404
    def FindNewName(self, DesiredName):
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   405
        """
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   406
        Changes Name to DesiredName if available, Name-N if not.
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   407
        @param DesiredName: The desired Name (string)
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   408
        """
1846
14b40afccd69 remove unused variables found by pylint
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1833
diff changeset
   409
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   410
        # Build a list of used Name out of parent's Children
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
   411
        AllNames = []
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   412
        for CTNInstance in self.CTNParent.IterChildren():
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   413
            if CTNInstance != self:
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   414
                AllNames.append(CTNInstance.BaseParams.getName())
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   415
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   416
        # Find a free name, eventually appending digit
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   417
        res = DesiredName
833
3f997fb22928 Fix confnode new name format that generates an error with frame class name in wxGlade extension
laurent
parents: 814
diff changeset
   418
        if DesiredName.endswith("_0"):
841
8e19df12b596 Fix unexpected warning message when adding extension to project
Laurent Bessard
parents: 833
diff changeset
   419
            BaseDesiredName = DesiredName[:-2]
8e19df12b596 Fix unexpected warning message when adding extension to project
Laurent Bessard
parents: 833
diff changeset
   420
        else:
8e19df12b596 Fix unexpected warning message when adding extension to project
Laurent Bessard
parents: 833
diff changeset
   421
            BaseDesiredName = DesiredName
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   422
        suffix = 1
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   423
        while res in AllNames:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1733
diff changeset
   424
            res = "%s_%d" % (BaseDesiredName, suffix)
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   425
            suffix += 1
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   426
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   427
        # Check previous confnode existance
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   428
        dontexist = self.BaseParams.getName() == "__unnamed__"
1932
65d2dbbf7022 Better variable naming, and small optimization.
Edouard Tisserant
parents: 1881
diff changeset
   429
        if not dontexist:
65d2dbbf7022 Better variable naming, and small optimization.
Edouard Tisserant
parents: 1881
diff changeset
   430
            # Get old path
65d2dbbf7022 Better variable naming, and small optimization.
Edouard Tisserant
parents: 1881
diff changeset
   431
            oldpath = self.CTNPath()
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   432
        # Set the new name
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   433
        self.BaseParams.setName(res)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   434
        # Rename confnode dir if exist
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   435
        if not dontexist:
1932
65d2dbbf7022 Better variable naming, and small optimization.
Edouard Tisserant
parents: 1881
diff changeset
   436
            shutil.move(oldpath, self.CTNPath())
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   437
        # warn user he has two left hands
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   438
        if DesiredName != res:
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   439
            msg = _("A child named \"{a1}\" already exists -> \"{a2}\"\n").format(a1=DesiredName, a2=res)
1581
2295fdc5c271 fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
   440
            self.GetCTRoot().logger.write_warning(msg)
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   441
        return res
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   442
683
57aa9da845d5 Fix wrong panel size making strange background in topology plugin element
laurent
parents: 677
diff changeset
   443
    def GetAllChannels(self):
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
   444
        AllChannels = []
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   445
        for CTNInstance in self.CTNParent.IterChildren():
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   446
            if CTNInstance != self:
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   447
                AllChannels.append(CTNInstance.BaseParams.getIEC_Channel())
683
57aa9da845d5 Fix wrong panel size making strange background in topology plugin element
laurent
parents: 677
diff changeset
   448
        AllChannels.sort()
57aa9da845d5 Fix wrong panel size making strange background in topology plugin element
laurent
parents: 677
diff changeset
   449
        return AllChannels
57aa9da845d5 Fix wrong panel size making strange background in topology plugin element
laurent
parents: 677
diff changeset
   450
203
cb9901076a21 Added concepts :
etisserant
parents: 202
diff changeset
   451
    def FindNewIEC_Channel(self, DesiredChannel):
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   452
        """
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   453
        Changes IEC Channel number to DesiredChannel if available, nearest available if not.
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   454
        @param DesiredChannel: The desired IEC channel (int)
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   455
        """
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   456
        # Get Current IEC channel
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   457
        CurrentChannel = self.BaseParams.getIEC_Channel()
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   458
        # Do nothing if no change
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1778
diff changeset
   459
        # if CurrentChannel == DesiredChannel: return CurrentChannel
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   460
        # Build a list of used Channels out of parent's Children
683
57aa9da845d5 Fix wrong panel size making strange background in topology plugin element
laurent
parents: 677
diff changeset
   461
        AllChannels = self.GetAllChannels()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   462
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   463
        # Now, try to guess the nearest available channel
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   464
        res = DesiredChannel
1737
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   465
        while res in AllChannels:  # While channel not free
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   466
            if res < CurrentChannel:  # Want to go down ?
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1747
diff changeset
   467
                res -= 1  # Test for n-1
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   468
                if res < 0:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1733
diff changeset
   469
                    self.GetCTRoot().logger.write_warning(_("Cannot find lower free IEC channel than %d\n") % CurrentChannel)
1737
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   470
                    return CurrentChannel  # Can't go bellow 0, do nothing
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   471
            else:  # Want to go up ?
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1747
diff changeset
   472
                res += 1  # Test for n-1
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   473
        # Finally set IEC Channel
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   474
        self.BaseParams.setIEC_Channel(res)
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   475
        return res
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   476
967
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 883
diff changeset
   477
    def GetContextualMenuItems(self):
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 883
diff changeset
   478
        return None
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 883
diff changeset
   479
2696
9bd639e9124e Project tree: avoid flickering and glitches in notebook when selecting some still not opened ConfigTreeNode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2695
diff changeset
   480
    def GetView(self, onlyopened=False):
3641
d8dc29dfc344 IDE: fix exception when re-opening previously closed tab
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3318
diff changeset
   481
        if not self._View and not onlyopened and self.EditorType is not None:
2524
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2523
diff changeset
   482
            app_frame = self.GetCTRoot().AppFrame
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2523
diff changeset
   483
            self._View = self.EditorType(app_frame.TabsOpened, self, app_frame)
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2523
diff changeset
   484
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2523
diff changeset
   485
        return self._View
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2523
diff changeset
   486
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents: 781
diff changeset
   487
    def _OpenView(self, name=None, onlyopened=False):
2696
9bd639e9124e Project tree: avoid flickering and glitches in notebook when selecting some still not opened ConfigTreeNode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2695
diff changeset
   488
        view = self.GetView(onlyopened)
2524
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2523
diff changeset
   489
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2523
diff changeset
   490
        if view is not None:
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2523
diff changeset
   491
            if name is None:
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2523
diff changeset
   492
                name = self.CTNFullName()
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents: 781
diff changeset
   493
            app_frame = self.GetCTRoot().AppFrame
2695
a4704fb40b0b Project tree: Clicking on ConfigTreeNode should have same behaviour as for POUS and other IEC types : simple click to select and double click to open.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2645
diff changeset
   494
            app_frame.EditProjectElement(view, name, onlyopened)
2524
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2523
diff changeset
   495
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2523
diff changeset
   496
        return view
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 674
diff changeset
   497
774
78b5fa92dd1c Fix bug when opening and closing confnode extra viewers
laurent
parents: 744
diff changeset
   498
    def _CloseView(self, view):
78b5fa92dd1c Fix bug when opening and closing confnode extra viewers
laurent
parents: 744
diff changeset
   499
        app_frame = self.GetCTRoot().AppFrame
78b5fa92dd1c Fix bug when opening and closing confnode extra viewers
laurent
parents: 744
diff changeset
   500
        if app_frame is not None:
78b5fa92dd1c Fix bug when opening and closing confnode extra viewers
laurent
parents: 744
diff changeset
   501
            app_frame.DeletePage(view)
78b5fa92dd1c Fix bug when opening and closing confnode extra viewers
laurent
parents: 744
diff changeset
   502
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 674
diff changeset
   503
    def OnCloseEditor(self, view):
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 674
diff changeset
   504
        if self._View == view:
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 674
diff changeset
   505
            self._View = None
656
c1792dfc8c7e Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 655
diff changeset
   506
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   507
    def OnCTNClose(self):
656
c1792dfc8c7e Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 655
diff changeset
   508
        if self._View is not None:
780
70632f4612a1 Fix bug when deleting conf tree node and conf tree node editor opened for this same node
laurent
parents: 774
diff changeset
   509
            self._CloseView(self._View)
774
78b5fa92dd1c Fix bug when opening and closing confnode extra viewers
laurent
parents: 744
diff changeset
   510
            self._View = None
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   511
        return True
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   512
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   513
    def _doRemoveChild(self, CTNInstance):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   514
        # Remove all children of child
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   515
        for SubCTNInstance in CTNInstance.IterChildren():
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   516
            CTNInstance._doRemoveChild(SubCTNInstance)
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   517
        # Call the OnCloseMethod
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   518
        CTNInstance.OnCTNClose()
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   519
        # Delete confnode dir
2004
28af541d776b Allow deleting configuration tree node with no corresponding directory in project tree
Edouard Tisserant
parents: 2003
diff changeset
   520
        try:
28af541d776b Allow deleting configuration tree node with no corresponding directory in project tree
Edouard Tisserant
parents: 2003
diff changeset
   521
            shutil.rmtree(CTNInstance.CTNPath())
2182
eeca1aff0691 Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2004
diff changeset
   522
        except Exception:
2004
28af541d776b Allow deleting configuration tree node with no corresponding directory in project tree
Edouard Tisserant
parents: 2003
diff changeset
   523
            pass
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   524
        # Remove child of Children
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   525
        self.Children[CTNInstance.CTNType].remove(CTNInstance)
1033
1eec9b855e47 Clean Config Tree Node children list by type after removing one child
Laurent Bessard
parents: 967
diff changeset
   526
        if len(self.Children[CTNInstance.CTNType]) == 0:
1eec9b855e47 Clean Config Tree Node children list by type after removing one child
Laurent Bessard
parents: 967
diff changeset
   527
            self.Children.pop(CTNInstance.CTNType)
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   528
        # Forget it... (View have to refresh)
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   529
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   530
    def CTNRemove(self):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   531
        # Fetch the confnode
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1778
diff changeset
   532
        # CTNInstance = self.GetChildByName(CTNName)
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   533
        # Ask to his parent to remove it
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   534
        self.CTNParent._doRemoveChild(self)
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   535
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   536
    def CTNAddChild(self, CTNName, CTNType, IEC_Channel=0):
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   537
        """
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   538
        Create the confnodes that may be added as child to this node self
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   539
        @param CTNType: string desining the confnode class name (get name from CTNChildrenTypes)
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   540
        @param CTNName: string for the name of the confnode instance
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   541
        """
720
6be032177e2a refactoring
Edouard Tisserant
parents: 718
diff changeset
   542
        # reorganize self.CTNChildrenTypes tuples from (name, CTNClass, Help)
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   543
        # to ( name, (CTNClass, Help)), an make a dict
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3674
diff changeset
   544
        transpose = list(zip(*self.CTNChildrenTypes))
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3674
diff changeset
   545
        CTNChildrenTypes = dict(list(zip(transpose[0], list(zip(transpose[1], transpose[2])))))
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   546
        # Check that adding this confnode is allowed
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   547
        try:
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   548
            CTNClass, CTNHelp = CTNChildrenTypes[CTNType]
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   549
        except KeyError:
1765
ccf59c1f0b45 clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   550
            raise Exception(_("Cannot create child {a1} of type {a2} ").
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1765
diff changeset
   551
                            format(a1=CTNName, a2=CTNType))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   552
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   553
        # if CTNClass is a class factory, call it. (prevent unneeded imports)
1778
1c6a704bd39c clean-up: fix PEP8 E721 do not compare types, use 'isinstance()'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   554
        if isinstance(CTNClass, types.FunctionType):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   555
            CTNClass = CTNClass()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   556
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   557
        # Eventualy Initialize child instance list for this class of confnode
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   558
        ChildrenWithSameClass = self.Children.setdefault(CTNType, list())
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   559
        # Check count
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   560
        if getattr(CTNClass, "CTNMaxCount", None) and len(ChildrenWithSameClass) >= CTNClass.CTNMaxCount:
3785
29bc2bebf1d4 Generate warning instead of Exception if CTNMaxCount is exceeded for a confnode
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   561
29bc2bebf1d4 Generate warning instead of Exception if CTNMaxCount is exceeded for a confnode
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   562
            msg = _("Max count ({a1}) reached for this confnode of type {a2} ").format(
29bc2bebf1d4 Generate warning instead of Exception if CTNMaxCount is exceeded for a confnode
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   563
                    a1=CTNClass.CTNMaxCount, a2=CTNType)
29bc2bebf1d4 Generate warning instead of Exception if CTNMaxCount is exceeded for a confnode
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   564
            self.GetCTRoot().logger.write_warning(msg)
29bc2bebf1d4 Generate warning instead of Exception if CTNMaxCount is exceeded for a confnode
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   565
29bc2bebf1d4 Generate warning instead of Exception if CTNMaxCount is exceeded for a confnode
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   566
            return None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   567
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   568
        # create the final class, derived of provided confnode and template
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   569
        class FinalCTNClass(CTNClass, ConfigTreeNode):
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   570
            """
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   571
            ConfNode class is derivated into FinalCTNClass before being instanciated
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   572
            This way __init__ is overloaded to ensure ConfigTreeNode.__init__ is called
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   573
            before CTNClass.__init__, and to do the file related stuff.
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   574
            """
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   575
            def __init__(self, parent):
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   576
                self.CTNParent = parent
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   577
                # Keep track of the confnode type name
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   578
                self.CTNType = CTNType
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   579
                # remind the help string, for more fancy display
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   580
                self.CTNHelp = CTNHelp
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   581
                # Call the base confnode template init - change XSD into class members
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   582
                ConfigTreeNode.__init__(self)
29
282380dea497 Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents: 25
diff changeset
   583
                # check name is unique
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   584
                NewCTNName = self.FindNewName(CTNName)
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   585
                # If dir have already be made, and file exist
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   586
                if os.path.isdir(self.CTNPath(NewCTNName)):  # and os.path.isfile(self.ConfNodeXmlFilePath(CTNName)):
1733
dea107dce0c4 clean-up: fix some PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   587
                    # Load the confnode.xml file into parameters members
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   588
                    self.LoadXMLParams(NewCTNName)
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
   589
                    # Basic check. Better to fail immediately.
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   590
                    if self.BaseParams.getName() != NewCTNName:
1765
ccf59c1f0b45 clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   591
                        raise Exception(
ccf59c1f0b45 clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   592
                            _("Project tree layout do not match confnode.xml {a1}!={a2} ").
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   593
                            format(a1=NewCTNName, a2=self.BaseParams.getName()))
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   594
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   595
                    # Now, self.CTNPath() should be OK
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   596
15
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 14
diff changeset
   597
                    # Check that IEC_Channel is not already in use.
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   598
                    self.FindNewIEC_Channel(self.BaseParams.getIEC_Channel())
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   599
                    # Call the confnode real __init__
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   600
                    if getattr(CTNClass, "__init__", None):
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   601
                        CTNClass.__init__(self)
1733
dea107dce0c4 clean-up: fix some PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   602
                    # Load and init all the children
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   603
                    self.LoadChildren()
1733
dea107dce0c4 clean-up: fix some PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   604
                    # just loaded, nothing to saved
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   605
                    self.ChangesToSave = False
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   606
                else:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   607
                    # If confnode do not have corresponding file/dirs - they will be created on Save
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   608
                    self.CTNMakeDir()
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   609
                    # Find an IEC number
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   610
                    self.FindNewIEC_Channel(IEC_Channel)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   611
                    # Call the confnode real __init__
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   612
                    if getattr(CTNClass, "__init__", None):
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   613
                        CTNClass.__init__(self)
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   614
                    self.CTNRequestSave()
1733
dea107dce0c4 clean-up: fix some PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   615
                    # just created, must be saved
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   616
                    self.ChangesToSave = True
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   617
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   618
            def _getBuildPath(self):
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   619
                return self.CTNParent._getBuildPath()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   620
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   621
        # Create the object out of the resulting class
1868
616c3f4bcbcb fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   622
        newConfNodeOpj = FinalCTNClass(self)
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   623
        # Store it in CTNgedChils
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   624
        ChildrenWithSameClass.append(newConfNodeOpj)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   625
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   626
        return newConfNodeOpj
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   627
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   628
    def ClearChildren(self):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   629
        for child in self.IterChildren():
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   630
            child.ClearChildren()
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   631
        self.Children = {}
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   632
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   633
    def LoadXMLParams(self, CTNName=None):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   634
        methode_name = os.path.join(self.CTNPath(CTNName), "methods.py")
105
434aed8dc58d Added ability to override plugin methods with arbitrary python code (methods.py) when loading plugins
etisserant
parents: 97
diff changeset
   635
        if os.path.isfile(methode_name):
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3674
diff changeset
   636
            exec(compile(open(methode_name, "rb").read(), methode_name, 'exec'))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   637
1332
ac7d39f4e376 Fixed error message printed when error in XML files is detected
Laurent Bessard
parents: 1330
diff changeset
   638
        ConfNodeName = CTNName if CTNName is not None else self.CTNName()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   639
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 16
diff changeset
   640
        # Get the base xml tree
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
   641
        if self.MandatoryParams:
203
cb9901076a21 Added concepts :
etisserant
parents: 202
diff changeset
   642
            try:
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   643
                basexmlfile = open(self.ConfNodeBaseXmlFilePath(CTNName), 'r')
1330
96b242e4c59d Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 1315
diff changeset
   644
                self.BaseParams, error = _BaseParamsParser.LoadXMLString(basexmlfile.read())
96b242e4c59d Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 1315
diff changeset
   645
                if error is not None:
1581
2295fdc5c271 fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
   646
                    (fname, lnum, src) = ((ConfNodeName + " BaseParams",) + error)
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   647
                    self.GetCTRoot().logger.write_warning(XSDSchemaErrorMessage.format(a1=fname, a2=lnum, a3=src))
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
   648
                self.MandatoryParams = ("BaseParams", self.BaseParams)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   649
                basexmlfile.close()
2418
5587c490a070 Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2414
diff changeset
   650
            except Exception as exc:
3752
9f6f46dbe3ae removed Python2 modules
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
   651
                msg = _("Couldn't load confnode base parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=str(exc))
1581
2295fdc5c271 fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
   652
                self.GetCTRoot().logger.write_error(msg)
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   653
                self.GetCTRoot().logger.write_error(traceback.format_exc())
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   654
14
eb9fdd316a40 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   655
        # Get the xml tree
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   656
        if self.CTNParams:
203
cb9901076a21 Added concepts :
etisserant
parents: 202
diff changeset
   657
            try:
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   658
                xmlfile = open(self.ConfNodeXmlFilePath(CTNName), 'r')
1330
96b242e4c59d Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 1315
diff changeset
   659
                obj, error = self.Parser.LoadXMLString(xmlfile.read())
96b242e4c59d Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 1315
diff changeset
   660
                if error is not None:
1581
2295fdc5c271 fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
   661
                    (fname, lnum, src) = ((ConfNodeName,) + error)
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   662
                    self.GetCTRoot().logger.write_warning(XSDSchemaErrorMessage.format(a1=fname, a2=lnum, a3=src))
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
   663
                name = obj.getLocalTag()
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
   664
                setattr(self, name, obj)
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1179
diff changeset
   665
                self.CTNParams = (name, obj)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   666
                xmlfile.close()
2418
5587c490a070 Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2414
diff changeset
   667
            except Exception as exc:
3752
9f6f46dbe3ae removed Python2 modules
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
   668
                msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=str(exc))
1581
2295fdc5c271 fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
   669
                self.GetCTRoot().logger.write_error(msg)
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   670
                self.GetCTRoot().logger.write_error(traceback.format_exc())
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1722
diff changeset
   671
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   672
    def LoadChildren(self):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   673
        # Iterate over all CTNName@CTNType in confnode directory, and try to open them
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   674
        for CTNDir in os.listdir(self.CTNPath()):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   675
            if os.path.isdir(os.path.join(self.CTNPath(), CTNDir)) and \
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   676
               CTNDir.count(NameTypeSeparator) == 1:
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   677
                pname, ptype = CTNDir.split(NameTypeSeparator)
203
cb9901076a21 Added concepts :
etisserant
parents: 202
diff changeset
   678
                try:
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   679
                    self.CTNAddChild(pname, ptype)
2418
5587c490a070 Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2414
diff changeset
   680
                except Exception as exc:
3752
9f6f46dbe3ae removed Python2 modules
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
   681
                    msg = _("Could not add child \"{a1}\", type {a2} :\n{a3}\n").format(a1=pname, a2=ptype, a3=str(exc))
1581
2295fdc5c271 fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
   682
                    self.GetCTRoot().logger.write_error(msg)
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   683
                    self.GetCTRoot().logger.write_error(traceback.format_exc())
2640
1b4b335e19ea Add FatalError() method to ConfigTreeNode.
Edouard Tisserant
parents: 2620
diff changeset
   684
1b4b335e19ea Add FatalError() method to ConfigTreeNode.
Edouard Tisserant
parents: 2620
diff changeset
   685
1b4b335e19ea Add FatalError() method to ConfigTreeNode.
Edouard Tisserant
parents: 2620
diff changeset
   686
    def FatalError(self, message):
1b4b335e19ea Add FatalError() method to ConfigTreeNode.
Edouard Tisserant
parents: 2620
diff changeset
   687
        """ Raise an exception that will trigger error message intended to 
1b4b335e19ea Add FatalError() method to ConfigTreeNode.
Edouard Tisserant
parents: 2620
diff changeset
   688
            the user, but without backtrace since it is not a software error """
1b4b335e19ea Add FatalError() method to ConfigTreeNode.
Edouard Tisserant
parents: 2620
diff changeset
   689
1b4b335e19ea Add FatalError() method to ConfigTreeNode.
Edouard Tisserant
parents: 2620
diff changeset
   690
        raise UserAddressedException(message)
1b4b335e19ea Add FatalError() method to ConfigTreeNode.
Edouard Tisserant
parents: 2620
diff changeset
   691