PLCOpenEditor.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 21 Aug 2017 22:41:37 +0300
changeset 1783 3311eea28d56
parent 1782 5b6ad7a7fd9d
child 1791 3216ed1ba1f7
permissions -rwxr-xr-x
clean-up: fix PEP8 E402 module level import not at top of file
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
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: 1581
diff changeset
     8
# Copyright (C) 2017: Andrey Skvortsov
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
    10
# See COPYING file for copyrights details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
    12
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
    13
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
    14
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
    15
# of the License, or (at your option) any later version.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
    17
# This program is distributed in the hope that it will be useful,
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
    18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
    19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
    20
# GNU General Public License for more details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
    22
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
    23
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1565
diff changeset
    24
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
import wx
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    27
import os
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    28
import sys
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    29
import platform
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    30
import time
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    31
import traceback
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    32
import getopt
1560
4ce8492159ab add version with commit hash to 'About' dialogs for Beremiz IDE and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1533
diff changeset
    33
import version
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1581
diff changeset
    34
import util.paths as paths
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1581
diff changeset
    35
1783
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    36
from docutil import *
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    37
from IDEFrame import IDEFrame, AppendMenu
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    38
from IDEFrame import \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    39
    TITLE, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    40
    EDITORTOOLBAR, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    41
    FILEMENU, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    42
    EDITMENU, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    43
    DISPLAYMENU, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    44
    PROJECTTREE, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    45
    POUINSTANCEVARIABLESPANEL, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    46
    LIBRARYTREE, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    47
    PAGETITLES
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    48
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    49
from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    50
from editors.Viewer import Viewer
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    51
from PLCControler import PLCControler
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    52
from dialogs import ProjectDialog
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    53
from dialogs.AboutDialog import ShowAboutDialog
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    54
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    55
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1581
diff changeset
    56
beremiz_dir = paths.AbsDir(__file__)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
__version__ = "$Revision: 1.130 $"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
if __name__ == '__main__':
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
    61
    # Usage message displayed when help request or when error detected in
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
    # command line
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
    def usage():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
        print "\nUsage of PLCOpenEditor.py :"
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
    65
        print "\n   %s [Filepath]\n" % sys.argv[0]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
    # Parse options given to PLCOpenEditor in command line
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
    try:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
        opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
    except getopt.GetoptError:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
        # print help information and exit:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
        usage()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
        sys.exit(2)
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
    74
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
    # Extract if help has been requested
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
    for o, a in opts:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
        if o in ("-h", "--help"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
            usage()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
            sys.exit()
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
    80
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
    # Extract the optional filename to open
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
    fileOpen = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
    if len(args) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
        usage()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
        sys.exit()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
    elif len(args) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        fileOpen = args[0]
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
    88
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
    # Create wxApp (Need to create App before internationalization because of
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
    90
    # Windows)
1533
aca8f43483e9 fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1492
diff changeset
    91
    if wx.VERSION >= (3, 0, 0):
aca8f43483e9 fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1492
diff changeset
    92
        app = wx.App()
aca8f43483e9 fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1492
diff changeset
    93
    else:
aca8f43483e9 fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1492
diff changeset
    94
        app = wx.PySimpleApp()
aca8f43483e9 fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1492
diff changeset
    95
1388
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1330
diff changeset
    96
    from util.misc import InstallLocalRessources
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
    97
    InstallLocalRessources(beremiz_dir)
1388
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1330
diff changeset
    98
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   100
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
#                            PLCOpenEditor Main Class
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   102
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
# Define PLCOpenEditor FileMenu extra items id
1773
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   105
[
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   106
    ID_PLCOPENEDITORFILEMENUGENERATE,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
] = [wx.NewId() for _init_coll_FileMenu_Items in range(1)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   109
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
class PLCOpenEditor(IDEFrame):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
    # Compatibility function for wx versions < 2.6
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
    if wx.VERSION < (2, 6, 0):
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   114
        def Bind(self, event, function, id=None):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
            if id is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   116
                event(self, id, function)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
                event(self, function)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
    def _init_coll_FileMenu_Items(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
        AppendMenu(parent, help='', id=wx.ID_NEW,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   122
                   kind=wx.ITEM_NORMAL, text=_(u'New') + '\tCTRL+N')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
        AppendMenu(parent, help='', id=wx.ID_OPEN,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   124
                   kind=wx.ITEM_NORMAL, text=_(u'Open') + '\tCTRL+O')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
        AppendMenu(parent, help='', id=wx.ID_CLOSE,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   126
                   kind=wx.ITEM_NORMAL, text=_(u'Close Tab') + '\tCTRL+W')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
        AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   128
                   kind=wx.ITEM_NORMAL, text=_(u'Close Project') + '\tCTRL+SHIFT+W')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
        AppendMenu(parent, help='', id=wx.ID_SAVE,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   131
                   kind=wx.ITEM_NORMAL, text=_(u'Save') + '\tCTRL+S')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   132
        AppendMenu(parent, help='', id=wx.ID_SAVEAS,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   133
                   kind=wx.ITEM_NORMAL, text=_(u'Save As...') + '\tCTRL+SHIFT+S')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
        AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUGENERATE,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   135
                   kind=wx.ITEM_NORMAL, text=_(u'Generate Program') + '\tCTRL+G')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
        AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   138
                   kind=wx.ITEM_NORMAL, text=_(u'Page Setup') + '\tCTRL+ALT+P')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   139
        AppendMenu(parent, help='', id=wx.ID_PREVIEW,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   140
                   kind=wx.ITEM_NORMAL, text=_(u'Preview') + '\tCTRL+SHIFT+P')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
        AppendMenu(parent, help='', id=wx.ID_PRINT,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   142
                   kind=wx.ITEM_NORMAL, text=_(u'Print') + '\tCTRL+P')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   143
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   144
        AppendMenu(parent, help='', id=wx.ID_PROPERTIES,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   145
                   kind=wx.ITEM_NORMAL, text=_(u'&Properties'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
        AppendMenu(parent, help='', id=wx.ID_EXIT,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   148
                   kind=wx.ITEM_NORMAL, text=_(u'Quit') + '\tCTRL+Q')
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   149
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
        self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
        self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
        self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
        self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
        self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
        self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
        self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   157
                  id=ID_PLCOPENEDITORFILEMENUGENERATE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
        self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
        self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
        self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
        self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   162
        self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   163
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
        self.AddToMenuToolBar([(wx.ID_NEW, "new", _(u'New'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
                               (wx.ID_OPEN, "open", _(u'Open'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
                               (wx.ID_SAVE, "save", _(u'Save'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
                               (wx.ID_SAVEAS, "saveas", _(u'Save As...'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
                               (wx.ID_PRINT, "print", _(u'Print'), None)])
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   169
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
    def _init_coll_HelpMenu_Items(self, parent):
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   171
        AppendMenu(parent, help='', id=wx.ID_HELP,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   172
                   kind=wx.ITEM_NORMAL, text=_(u'PLCOpenEditor') + '\tF1')
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   173
        # AppendMenu(parent, help='', id=wx.ID_HELP_CONTENTS,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
        #      kind=wx.ITEM_NORMAL, text=u'PLCOpen\tF2')
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   175
        # AppendMenu(parent, help='', id=wx.ID_HELP_CONTEXT,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   176
        #      kind=wx.ITEM_NORMAL, text=u'IEC 61131-3\tF3')
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1718
diff changeset
   177
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   178
        def handler(event):
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   179
            return wx.MessageBox(
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   180
                version.GetCommunityHelpMsg(),
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   181
                _(u'Community support'),
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   182
                wx.OK | wx.ICON_INFORMATION)
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   183
1692
9cb4d1392baf add information about community support channel to Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1680
diff changeset
   184
        id = wx.NewId()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1718
diff changeset
   185
        parent.Append(help='', id=id, kind=wx.ITEM_NORMAL, text=_(u'Community support'))
1692
9cb4d1392baf add information about community support channel to Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1680
diff changeset
   186
        self.Bind(wx.EVT_MENU, handler, id=id)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1718
diff changeset
   187
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
        AppendMenu(parent, help='', id=wx.ID_ABOUT,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   189
                   kind=wx.ITEM_NORMAL, text=_(u'About'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
        self.Bind(wx.EVT_MENU, self.OnPLCOpenEditorMenu, id=wx.ID_HELP)
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   191
        # self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, id=wx.ID_HELP_CONTENTS)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
        self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   194
    def __init__(self, parent, fileOpen=None):
1781
b112bfdde5cc clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   195
        """ Constructor of the PLCOpenEditor class.
b112bfdde5cc clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   196
b112bfdde5cc clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   197
        :param parent: The parent window.
b112bfdde5cc clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   198
        :param fileOpen: The filepath to open if no controler defined (default: None).
b112bfdde5cc clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   199
        """
1533
aca8f43483e9 fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1492
diff changeset
   200
        self.icon = wx.Icon(os.path.join(beremiz_dir, "images", "poe.ico"), wx.BITMAP_TYPE_ICO)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
        IDEFrame.__init__(self, parent)
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   202
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
        result = None
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   204
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
        # Open the filepath if defined
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
        if fileOpen is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
            fileOpen = DecodeFileSystemPath(fileOpen, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
            if os.path.isfile(fileOpen):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
                # Create a new controller
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   210
                controler = PLCControler()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   211
                result = controler.OpenXMLFile(fileOpen)
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: 1312
diff changeset
   212
                self.Controler = controler
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: 1312
diff changeset
   213
                self.LibraryPanel.SetController(controler)
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: 1312
diff changeset
   214
                self.ProjectTree.Enable(True)
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: 1312
diff changeset
   215
                self.PouInstanceVariablesPanel.SetController(controler)
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: 1312
diff changeset
   216
                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   217
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
        # Define PLCOpenEditor icon
1533
aca8f43483e9 fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1492
diff changeset
   219
        self.SetIcon(self.icon)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   222
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   223
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   224
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   225
        if result is not None:
1581
2295fdc5c271 fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1580
diff changeset
   226
            (num, line) = result
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   227
            self.ShowErrorMessage(_("PLC syntax error at line {a1}:\n{a2}").format(a1=num, a2=line))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   229
    def OnCloseFrame(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   230
        if self.Controler is None or self.CheckSaveBeforeClosing(_("Close Application")):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
            self.AUIManager.UnInit()
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   232
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
            self.SaveLastState()
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   234
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   235
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   236
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
            event.Veto()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
    def RefreshTitle(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
        name = _("PLCOpenEditor")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
        if self.Controler is not None:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   242
            self.SetTitle("%s - %s" % (name, self.Controler.GetFilename()))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
            self.SetTitle(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   246
    # -------------------------------------------------------------------------------
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   247
    #                            File Menu Functions
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   248
    # -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
    def RefreshFileMenu(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
        MenuToolBar = self.Panes["MenuToolBar"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   252
        if self.Controler is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
            selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
            if selected >= 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   255
                graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
                graphic_viewer = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
            if self.TabsOpened.GetPageCount() > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   259
                self.FileMenu.Enable(wx.ID_CLOSE, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   260
                if graphic_viewer:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
                    self.FileMenu.Enable(wx.ID_PREVIEW, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   262
                    self.FileMenu.Enable(wx.ID_PRINT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   263
                    MenuToolBar.EnableTool(wx.ID_PRINT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   264
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   265
                    self.FileMenu.Enable(wx.ID_PREVIEW, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   266
                    self.FileMenu.Enable(wx.ID_PRINT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   267
                    MenuToolBar.EnableTool(wx.ID_PRINT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   268
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   269
                self.FileMenu.Enable(wx.ID_CLOSE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   270
                self.FileMenu.Enable(wx.ID_PREVIEW, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   271
                self.FileMenu.Enable(wx.ID_PRINT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   272
                MenuToolBar.EnableTool(wx.ID_PRINT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   273
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   274
            project_modified = not self.Controler.ProjectIsSaved()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   275
            self.FileMenu.Enable(wx.ID_SAVE, project_modified)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   276
            MenuToolBar.EnableTool(wx.ID_SAVE, project_modified)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   277
            self.FileMenu.Enable(wx.ID_PROPERTIES, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   278
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   279
            self.FileMenu.Enable(wx.ID_SAVEAS, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   280
            MenuToolBar.EnableTool(wx.ID_SAVEAS, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   281
            self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   282
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   283
            self.FileMenu.Enable(wx.ID_CLOSE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   285
            self.FileMenu.Enable(wx.ID_PREVIEW, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   286
            self.FileMenu.Enable(wx.ID_PRINT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   287
            MenuToolBar.EnableTool(wx.ID_PRINT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   288
            self.FileMenu.Enable(wx.ID_SAVE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   289
            MenuToolBar.EnableTool(wx.ID_SAVE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
            self.FileMenu.Enable(wx.ID_PROPERTIES, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   292
            self.FileMenu.Enable(wx.ID_SAVEAS, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
            MenuToolBar.EnableTool(wx.ID_SAVEAS, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
            self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
    def OnNewProjectMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   297
        if self.Controler is not None and not self.CheckSaveBeforeClosing():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
            return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
        dialog = ProjectDialog(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   301
            properties = dialog.GetValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   302
            self.ResetView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   303
            self.Controler = PLCControler()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
            self.Controler.CreateNewProject(properties)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
            self.LibraryPanel.SetController(self.Controler)
1295
2ad168756c5e Fixed bug no contextual menu displayed in left panel tree when creating new project
Laurent Bessard
parents: 1030
diff changeset
   306
            self.ProjectTree.Enable(True)
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   307
            self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   308
                          LIBRARYTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
    def OnOpenProjectMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
        if self.Controler is not None and not self.CheckSaveBeforeClosing():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   312
            return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
        filepath = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
        if self.Controler is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
            filepath = self.Controler.GetFilePath()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
        if filepath != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   317
            directory = os.path.dirname(filepath)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
            directory = os.getcwd()
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   320
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   321
        result = None
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   322
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   323
        dialog = wx.FileDialog(self, _("Choose a file"), directory, "",  _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.OPEN)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   324
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   325
            filepath = dialog.GetPath()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   326
            if os.path.isfile(filepath):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
                self.ResetView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
                controler = PLCControler()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
                result = controler.OpenXMLFile(filepath)
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: 1312
diff changeset
   330
                self.Controler = controler
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: 1312
diff changeset
   331
                self.LibraryPanel.SetController(controler)
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: 1312
diff changeset
   332
                self.ProjectTree.Enable(True)
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: 1312
diff changeset
   333
                self.PouInstanceVariablesPanel.SetController(controler)
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: 1312
diff changeset
   334
                self._Refresh(PROJECTTREE, LIBRARYTREE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   335
            self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
        dialog.Destroy()
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   337
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   338
        if result is not None:
1581
2295fdc5c271 fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1580
diff changeset
   339
            (num, line) = result
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   340
            self.ShowErrorMessage(_("PLC syntax error at line {a1}:\n{a2}").format(a1=num, a2=line))
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   341
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   342
    def OnCloseProjectMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   343
        if not self.CheckSaveBeforeClosing():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   344
            return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   345
        self.ResetView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   346
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   347
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   348
    def OnSaveProjectMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   349
        self.SaveProject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   350
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   351
    def OnSaveProjectAsMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   352
        self.SaveProjectAs()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   353
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   354
    def OnGenerateProgramMenu(self, event):
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   355
        dialog = wx.FileDialog(self, _("Choose a file"), os.getcwd(), self.Controler.GetProgramFilePath(),  _("ST files (*.st)|*.st|All files|*.*"), wx.SAVE | wx.CHANGE_DIR)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   356
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   357
            filepath = dialog.GetPath()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   358
            message_text = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   359
            header, icon = _("Done"), wx.ICON_INFORMATION
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   360
            if os.path.isdir(os.path.dirname(filepath)):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   361
                program, errors, warnings = self.Controler.GenerateProgram(filepath)
1312
250c3ae0787c Fixed bug when printing program generating errors and warnings in PLCOpenEditor
Laurent Bessard
parents: 1295
diff changeset
   362
                message_text += "".join([_("warning: %s\n") % warning for warning in warnings])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   363
                if len(errors) > 0:
1312
250c3ae0787c Fixed bug when printing program generating errors and warnings in PLCOpenEditor
Laurent Bessard
parents: 1295
diff changeset
   364
                    message_text += "".join([_("error: %s\n") % error for error in errors])
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   365
                    message_text += _("Can't generate program to file %s!") % filepath
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   366
                    header, icon = _("Error"), wx.ICON_ERROR
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   367
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   368
                    message_text += _("Program was successfully generated!")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   369
            else:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   370
                message_text += _("\"%s\" is not a valid folder!") % os.path.dirname(filepath)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   371
                header, icon = _("Error"), wx.ICON_ERROR
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   372
            message = wx.MessageDialog(self, message_text, header, wx.OK | icon)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   373
            message.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   374
            message.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   375
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   376
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   377
    def OnPLCOpenEditorMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   378
        wx.MessageBox(_("No documentation available.\nComing soon."))
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   379
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   380
    def OnPLCOpenMenu(self, event):
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   381
        open_pdf(os.path.join(beremiz_dir, "plcopen", "TC6_XML_V101.pdf"))
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   382
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   383
    def OnAboutMenu(self, event):
1565
894f31f8ca64 make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1560
diff changeset
   384
        info = version.GetAboutDialogInfo()
894f31f8ca64 make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1560
diff changeset
   385
        info.Name = "PLCOpenEditor"
894f31f8ca64 make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1560
diff changeset
   386
        info.Description = _("PLCOpenEditor is part of Beremiz project.\n\n"
894f31f8ca64 make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1560
diff changeset
   387
                             "Beremiz is an ") + info.Description
894f31f8ca64 make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1560
diff changeset
   388
        info.Icon = wx.Icon(os.path.join(beremiz_dir, "images", "aboutlogo.png"), wx.BITMAP_TYPE_PNG)
894f31f8ca64 make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1560
diff changeset
   389
        ShowAboutDialog(self, info)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   390
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   391
    def SaveProject(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   392
        result = self.Controler.SaveXMLFile()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   393
        if not result:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
            self.SaveProjectAs()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   395
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   396
            self._Refresh(TITLE, FILEMENU, PAGETITLES)
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   397
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   398
    def SaveProjectAs(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   399
        filepath = self.Controler.GetFilePath()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   400
        if filepath != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   401
            directory, filename = os.path.split(filepath)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   402
        else:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   403
            directory, filename = os.getcwd(), "%(projectName)s.xml" % self.Controler.GetProjectProperties()
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   404
        dialog = wx.FileDialog(self, _("Choose a file"), directory, filename,  _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.SAVE | wx.OVERWRITE_PROMPT)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   405
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   406
            filepath = dialog.GetPath()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   407
            if os.path.isdir(os.path.dirname(filepath)):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   408
                result = self.Controler.SaveXMLFile(filepath)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   409
                if not result:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   410
                    self.ShowErrorMessage(_("Can't save project to file %s!") % filepath)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   411
            else:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   412
                self.ShowErrorMessage(_("\"%s\" is not a valid folder!") % os.path.dirname(filepath))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   413
            self._Refresh(TITLE, FILEMENU, PAGETITLES)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   414
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   415
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   416
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   417
#                               Exception Handler
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   418
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   419
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
   420
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   421
Max_Traceback_List_Size = 20
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   422
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   423
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   424
def Display_Exception_Dialog(e_type, e_value, e_tb):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   425
    trcbck_lst = []
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   426
    for i, line in enumerate(traceback.extract_tb(e_tb)):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   427
        trcbck = " " + str(i+1) + _(". ")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   428
        if line[0].find(os.getcwd()) == -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   429
            trcbck += _("file : ") + str(line[0]) + _(",   ")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   430
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   431
            trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(",   ")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   432
        trcbck += _("line : ") + str(line[1]) + _(",   ") + _("function : ") + str(line[2])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   433
        trcbck_lst.append(trcbck)
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   434
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   435
    # Allow clicking....
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   436
    cap = wx.Window_GetCapture()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   437
    if cap:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   438
        cap.ReleaseMouse()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   439
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   440
    dlg = wx.SingleChoiceDialog(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   441
        None,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   442
        _("""
1580
f37b88d3edc6 change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   443
An unhandled exception (bug) occured. Bug report saved at :
f37b88d3edc6 change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   444
(%s)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   445
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   446
Please be kind enough to send this file to:
1580
f37b88d3edc6 change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   447
beremiz-devel@lists.sourceforge.net
f37b88d3edc6 change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   448
f37b88d3edc6 change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   449
You should now restart program.
f37b88d3edc6 change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   450
f37b88d3edc6 change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   451
Traceback:
f37b88d3edc6 change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   452
""") % bug_report_path +
f37b88d3edc6 change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   453
        repr(e_type) + " : " + repr(e_value),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   454
        _("Error"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   455
        trcbck_lst)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   456
    try:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   457
        res = (dlg.ShowModal() == wx.ID_OK)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   458
    finally:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   459
        dlg.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   460
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   461
    return res
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   462
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   463
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   464
def Display_Error_Dialog(e_value):
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   465
    message = wx.MessageDialog(None, str(e_value), _("Error"), wx.OK | wx.ICON_ERROR)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   466
    message.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   467
    message.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   468
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   469
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   470
def get_last_traceback(tb):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   471
    while tb.tb_next:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   472
        tb = tb.tb_next
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   473
    return tb
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   474
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   475
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   476
def format_namespace(d, indent='    '):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   477
    return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   478
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   479
1737
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   480
ignored_exceptions = []  # a problem with a line in a module is only reported once per session
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   481
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   482
1760
ed2e2afb9573 clean-up: fix PEP8 E262 inline comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   483
def AddExceptHook(path, app_version='[No version]'):
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   484
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   485
    def handle_exception(e_type, e_value, e_traceback):
1737
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   486
        traceback.print_exception(e_type, e_value, e_traceback)  # this is very helpful when there's an exception in the rest of this func
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   487
        last_tb = get_last_traceback(e_traceback)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   488
        ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   489
        if str(e_value).startswith("!!!"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   490
            Display_Error_Dialog(e_value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   491
        elif ex not in ignored_exceptions:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   492
            result = Display_Exception_Dialog(e_type, e_value, e_traceback)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   493
            if result:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   494
                ignored_exceptions.append(ex)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   495
                info = {
1760
ed2e2afb9573 clean-up: fix PEP8 E262 inline comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   496
                    'app-title': wx.GetApp().GetAppName(),
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   497
                    'app-version': app_version,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   498
                    'wx-version': wx.VERSION_STRING,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   499
                    'wx-platform': wx.Platform,
1760
ed2e2afb9573 clean-up: fix PEP8 E262 inline comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   500
                    'python-version': platform.python_version(),
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   501
                    'platform': platform.platform(),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   502
                    'e-type': e_type,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   503
                    'e-value': e_value,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   504
                    'date': time.ctime(),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   505
                    'cwd': os.getcwd(),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   506
                    }
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   507
                if e_traceback:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   508
                    info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   509
                    last_tb = get_last_traceback(e_traceback)
1737
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   510
                    exception_locals = last_tb.tb_frame.f_locals  # the locals at the level of the stack trace where the exception actually occurred
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   511
                    info['locals'] = format_namespace(exception_locals)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   512
                    if 'self' in exception_locals:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   513
                        info['self'] = format_namespace(exception_locals['self'].__dict__)
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   514
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   515
                output = open(path+os.sep+"bug_report_"+time.strftime("%Y_%m_%d__%H-%M-%S")+".txt", 'w')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   516
                lst = info.keys()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   517
                lst.sort()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   518
                for a in lst:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   519
                    output.write(a+":\n"+str(info[a])+"\n\n")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   520
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   521
    # sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   522
    sys.excepthook = handle_exception
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   523
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
   524
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   525
if __name__ == '__main__':
1533
aca8f43483e9 fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1492
diff changeset
   526
    if wx.VERSION < (3, 0, 0):
aca8f43483e9 fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1492
diff changeset
   527
        wx.InitAllImageHandlers()
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   528
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   529
    # Install a exception handle for bug reports
1560
4ce8492159ab add version with commit hash to 'About' dialogs for Beremiz IDE and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1533
diff changeset
   530
    AddExceptHook(os.getcwd(), version.app_version)
1451
94e620cbd9de Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents: 1388
diff changeset
   531
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   532
    frame = PLCOpenEditor(None, fileOpen=fileOpen)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   533
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   534
    frame.Show()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   535
    app.MainLoop()