py_ext/py_ext.py
author Edouard Tisserant <edouard@beremiz.fr>
Wed, 16 Oct 2024 15:45:15 +0200
changeset 4048 b3ea419a4d47
parent 3750 f62625418bff
child 4056 4b2de1a0fbf9
permissions -rw-r--r--
SVGHMI: swap position and range of ForEach widget so that both range and size can be optional.
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1132
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: 1132
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: 1132
diff changeset
     3
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1132
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: 1132
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: 1132
diff changeset
     6
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1132
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
     8
# Copyright (C) 2017: Andrey Skvortsov
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1132
diff changeset
     9
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1132
diff changeset
    10
# 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: 1132
diff changeset
    11
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1132
diff changeset
    12
# 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: 1132
diff changeset
    13
# 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: 1132
diff changeset
    14
# 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: 1132
diff changeset
    15
# 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: 1132
diff changeset
    16
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1132
diff changeset
    17
# 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: 1132
diff changeset
    18
# 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: 1132
diff changeset
    19
# 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: 1132
diff changeset
    20
# 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: 1132
diff changeset
    21
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1132
diff changeset
    22
# 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: 1132
diff changeset
    23
# 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: 1132
diff changeset
    24
# 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: 1132
diff changeset
    25
1853
47a3f39bead0 fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1746
diff changeset
    26
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3707
diff changeset
    27
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    28
import os
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    29
from POULibrary import POULibrary
1853
47a3f39bead0 fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1746
diff changeset
    30
from py_ext.PythonFileCTNMixin import PythonFileCTNMixin
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    31
import util.paths as paths
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    32
3707
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    33
pyext_python_lib_code = """
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    34
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    35
import csv
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    36
from collections import OrderedDict
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    37
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    38
csv_int_files = {}
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    39
def CSVRdInt(fname, rowidx, colidx):
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    40
    \"\"\"
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    41
    Return value at row/column pointed by integer indexes
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    42
    Assumes data starts at first row and first column, no headers.
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    43
    \"\"\"
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    44
    global csv_int_files
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    45
    data = csv_int_files.get(fname, None)
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    46
    if data is None:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    47
        data = list()
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    48
        try:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    49
            csvfile = open(fname, 'rb')
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    50
        except IOError:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    51
            return "#FILE_NOT_FOUND"
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    52
        try:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    53
            dialect = csv.Sniffer().sniff(csvfile.read(1024))
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    54
            csvfile.seek(0)
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    55
            reader = csv.reader(csvfile, dialect)
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    56
            for row in reader:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    57
                data.append(row)
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    58
        except csv.Error:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    59
            return "#CSV_ERROR"
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    60
        finally:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    61
            csvfile.close()
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    62
        csv_int_files[fname] = data
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    63
    
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    64
    try:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    65
        row = data[rowidx]
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    66
    except IndexError:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    67
        return "#ROW_NOT_FOUND"
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    68
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    69
    try:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    70
        return row[colidx]
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    71
    except IndexError:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    72
        return "#COL_NOT_FOUND"
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    73
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    74
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    75
csv_str_files = {}
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    76
def CSVRdStr(fname, rowname, colname):
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    77
    \"\"\"
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    78
    Return value at row/column pointed by a pair of names as string
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    79
    Assumes first row is column headers and first column is row name.
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    80
    \"\"\"
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    81
    global csv_str_files
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    82
    entry = csv_str_files.get(fname, None)
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    83
    if entry is None:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    84
        data = dict()
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    85
        try:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    86
            csvfile = open(fname, 'rb')
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    87
        except IOError:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    88
            return "#FILE_NOT_FOUND"
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    89
        try:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    90
            dialect = csv.Sniffer().sniff(csvfile.read(1024))
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    91
            csvfile.seek(0)
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    92
            reader = csv.reader(csvfile, dialect)
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    93
            headers = dict([(name, index) for index, name in enumerate(reader.next()[1:])])
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    94
            for row in reader:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    95
                data[row[0]] = row[1:]
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    96
        except csv.Error:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    97
            return "#CSV_ERROR"
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    98
        finally:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
    99
            csvfile.close()
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   100
        csv_str_files[fname] = (headers, data)
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   101
    else:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   102
        headers, data = entry
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   103
    
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   104
    try:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   105
        row = data[rowname]
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   106
    except KeyError:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   107
        return "#ROW_NOT_FOUND"
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   108
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   109
    try:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   110
        colidx = headers[colname]
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   111
    except KeyError:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   112
        return "#COL_NOT_FOUND"
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   113
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   114
    try:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   115
        return row[colidx]
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   116
    except IndexError:
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   117
        return "#COL_NOT_FOUND"
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   118
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   119
def pyext_csv_reload():
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   120
    global csv_int_files, csv_str_files
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   121
    csv_int_files.clear()
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   122
    csv_str_files.clear()
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   123
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   124
"""
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   125
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
   126
class PythonLibrary(POULibrary):
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
   127
    def GetLibraryPath(self):
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1680
diff changeset
   128
        return paths.AbsNeighbourFile(__file__, "pous.xml")
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   129
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
   130
    def Generate_C(self, buildpath, varlist, IECCFLAGS):
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1680
diff changeset
   131
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
   132
        plc_python_filepath = paths.AbsNeighbourFile(__file__, "plc_python.c")
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   133
        plc_python_file = open(plc_python_filepath, 'r')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   134
        plc_python_code = plc_python_file.read()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   135
        plc_python_file.close()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   136
        python_eval_fb_list = []
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
   137
        for v in varlist:
1132
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   138
            if v["vartype"] == "FB" and v["type"] in ["PYTHON_EVAL",
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   139
                                                      "PYTHON_POLL"]:
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   140
                python_eval_fb_list.append(v)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   141
        python_eval_fb_count = max(1, len(python_eval_fb_list))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1680
diff changeset
   142
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   143
        # prepare python code
1132
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   144
        plc_python_code = plc_python_code % {
1746
45d6f5fba016 clean-up: fix PEP8 E202 whitespace before ')'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
   145
            "python_eval_fb_count": python_eval_fb_count}
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1680
diff changeset
   146
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
   147
        Gen_Pythonfile_path = os.path.join(buildpath, "py_ext.c")
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   148
        pythonfile = open(Gen_Pythonfile_path, 'w')
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   149
        pythonfile.write(plc_python_code)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
   150
        pythonfile.close()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1680
diff changeset
   151
3707
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   152
        runtimefile_path = os.path.join(buildpath, "runtime_00_pyext.py")
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   153
        runtimefile = open(runtimefile_path, 'w')
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   154
        runtimefile.write(pyext_python_lib_code)
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   155
        runtimefile.close()
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   156
        return ((["py_ext"], [(Gen_Pythonfile_path, IECCFLAGS)], True), "",
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   157
                ("runtime_00_pyext.py", open(runtimefile_path, "rb")))
3c60c78dfa5d py_ext: add CSV file reading POUs in python extension library
Edouard Tisserant
parents: 1853
diff changeset
   158
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
   159
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   160
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
   161
class PythonFile(PythonFileCTNMixin):
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1680
diff changeset
   162
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 742
diff changeset
   163
    def GetIconName(self):
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 742
diff changeset
   164
        return "Pyfile"