py_ext/py_ext.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 20 Apr 2017 13:01:45 +0300
changeset 1680 6db967480b7d
parent 1511 91538d0c242c
child 1730 64d8f52bc8c8
permissions -rw-r--r--
make run Beremiz and PLCOpen Editor, if full path contain non-lating
characters

There was a problem in About dialog and in project properites tab and
probably in my other places, when str is automatically converted to
unicode string using ascii.
This patch converts str to unicode using proper encoding at the very beggining.
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
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    26
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
    27
from POULibrary import POULibrary
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    28
from 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
    29
import util.paths as paths
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    30
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    31
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
    32
    def GetLibraryPath(self):
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    33
        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
    34
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    35
    def Generate_C(self, buildpath, varlist, IECCFLAGS):
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    36
        
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    37
        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
    38
        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
    39
        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
    40
        plc_python_file.close()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    41
        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
    42
        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
    43
            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
    44
                                                      "PYTHON_POLL"]:
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    45
                python_eval_fb_list.append(v)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    46
        python_eval_fb_count = max(1, len(python_eval_fb_list))
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    47
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    48
        # 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
    49
        plc_python_code = plc_python_code % {
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
    50
            "python_eval_fb_count": python_eval_fb_count }
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    51
        
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    52
        Gen_Pythonfile_path = os.path.join(buildpath, "py_ext.c")
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    53
        pythonfile = open(Gen_Pythonfile_path,'w')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    54
        pythonfile.write(plc_python_code)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    55
        pythonfile.close()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    56
        
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    57
        return (["py_ext"], [(Gen_Pythonfile_path, IECCFLAGS)], True), ""
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    58
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    59
class PythonFile(PythonFileCTNMixin):
738
413946c04c87 refactoring
laurent
parents: 731
diff changeset
    60
    
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 742
diff changeset
    61
    def GetIconName(self):
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 742
diff changeset
    62
        return "Pyfile"
738
413946c04c87 refactoring
laurent
parents: 731
diff changeset
    63
    
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    64