PLCOpenEditor.py
author Schlumpf <schlumpf@kr-ll.de>
Fri, 15 Mar 2019 17:34:24 +0100
branchgenerate-button
changeset 2531 f5891ce3228e
parent 2497 e04824ad26e4
child 2532 b9d6f5d7e0f1
permissions -rw-r--r--
Add "Generate Program" to toolbar in PLCOpenEditor standalone mode.

Currently you can find the "Generate Program" action only in the file menu,
but this action is very often used in standalone mode, so I added toolbuffon.
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
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1815
diff changeset
    26
1881
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1872
diff changeset
    27
from __future__ import absolute_import
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1815
diff changeset
    28
from __future__ import print_function
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    29
import os
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    30
import sys
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    31
import getopt
1792
4d1de8b0183f unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1791
diff changeset
    32
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1826
diff changeset
    33
import wx
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1826
diff changeset
    34
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
    35
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
    36
import util.paths as paths
1792
4d1de8b0183f unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1791
diff changeset
    37
import util.ExceptionHandler
1834
cd42b426028b fix ungrouped imports from package X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    38
from util.misc import InstallLocalRessources
1872
866fb3ab8778 fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
    39
from docutil.docpdf import open_pdf
1814
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    40
from IDEFrame import IDEFrame, AppendMenu
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    41
from IDEFrame import \
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    42
    TITLE, \
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    43
    EDITORTOOLBAR, \
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    44
    FILEMENU, \
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    45
    EDITMENU, \
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    46
    DISPLAYMENU, \
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    47
    PROJECTTREE, \
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    48
    POUINSTANCEVARIABLESPANEL, \
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    49
    LIBRARYTREE, \
1850
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
    50
    PAGETITLES, \
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
    51
    DecodeFileSystemPath
1814
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    52
from editors.Viewer import Viewer
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    53
from PLCControler import PLCControler
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    54
from dialogs import ProjectDialog
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    55
from dialogs.AboutDialog import ShowAboutDialog
1791
3216ed1ba1f7 fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1783
diff changeset
    56
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
    58
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
#                            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
    60
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
# 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
    63
[
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    64
    ID_PLCOPENEDITORFILEMENUGENERATE,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
] = [wx.NewId() for _init_coll_FileMenu_Items in range(1)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    67
1814
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    68
beremiz_dir = paths.AbsDir(__file__)
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    69
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    70
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
class PLCOpenEditor(IDEFrame):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
    def _init_coll_FileMenu_Items(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
        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
    75
                   kind=wx.ITEM_NORMAL, text=_(u'New') + '\tCTRL+N')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
        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
    77
                   kind=wx.ITEM_NORMAL, text=_(u'Open') + '\tCTRL+O')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
        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
    79
                   kind=wx.ITEM_NORMAL, text=_(u'Close Tab') + '\tCTRL+W')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
        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
    81
                   kind=wx.ITEM_NORMAL, text=_(u'Close Project') + '\tCTRL+SHIFT+W')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
        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
    84
                   kind=wx.ITEM_NORMAL, text=_(u'Save') + '\tCTRL+S')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
        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
    86
                   kind=wx.ITEM_NORMAL, text=_(u'Save As...') + '\tCTRL+SHIFT+S')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        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
    88
                   kind=wx.ITEM_NORMAL, text=_(u'Generate Program') + '\tCTRL+G')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
        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
    91
                   kind=wx.ITEM_NORMAL, text=_(u'Page Setup') + '\tCTRL+ALT+P')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
        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
    93
                   kind=wx.ITEM_NORMAL, text=_(u'Preview') + '\tCTRL+SHIFT+P')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
        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
    95
                   kind=wx.ITEM_NORMAL, text=_(u'Print') + '\tCTRL+P')
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
        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
    98
                   kind=wx.ITEM_NORMAL, text=_(u'&Properties'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
        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
   101
                   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
   102
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
        self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
        self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   105
        self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
        self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
        self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
        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
   110
                  id=ID_PLCOPENEDITORFILEMENUGENERATE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
        self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
        self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
        self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
        self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
        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
   116
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
        self.AddToMenuToolBar([(wx.ID_NEW, "new", _(u'New'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
                               (wx.ID_OPEN, "open", _(u'Open'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
                               (wx.ID_SAVE, "save", _(u'Save'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
                               (wx.ID_SAVEAS, "saveas", _(u'Save As...'), None),
2531
f5891ce3228e Add "Generate Program" to toolbar in PLCOpenEditor standalone mode.
Schlumpf <schlumpf@kr-ll.de>
parents: 2497
diff changeset
   121
                               (wx.ID_PRINT, "print", _(u'Print'), None),
f5891ce3228e Add "Generate Program" to toolbar in PLCOpenEditor standalone mode.
Schlumpf <schlumpf@kr-ll.de>
parents: 2497
diff changeset
   122
                               (ID_PLCOPENEDITORFILEMENUGENERATE, "Build", _(u'Generate Program'), 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
   123
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   124
    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
   125
        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
   126
                   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
   127
        # AppendMenu(parent, help='', id=wx.ID_HELP_CONTENTS,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
        #      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
   129
        # AppendMenu(parent, help='', id=wx.ID_HELP_CONTEXT,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
        #      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
   131
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
   132
        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
   133
            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
   134
                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
   135
                _(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
   136
                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
   137
1692
9cb4d1392baf add information about community support channel to Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1680
diff changeset
   138
        id = wx.NewId()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1718
diff changeset
   139
        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
   140
        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
   141
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
        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
   143
                   kind=wx.ITEM_NORMAL, text=_(u'About'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   144
        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
   145
        # self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, id=wx.ID_HELP_CONTENTS)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
        self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   148
    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
   149
        """ 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
   150
b112bfdde5cc clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   151
        :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
   152
        :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
   153
        """
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
   154
        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
   155
        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
   156
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
        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
   158
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
        # Open the filepath if defined
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
        if fileOpen is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
            fileOpen = DecodeFileSystemPath(fileOpen, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   162
            if os.path.isfile(fileOpen):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
                # Create a new controller
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
                controler = PLCControler()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
                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
   166
                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
   167
                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
   168
                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
   169
                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
   170
                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
   171
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   172
        # 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
   173
        self.SetIcon(self.icon)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
        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
   176
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
        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
   178
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
        if result is not None:
1581
2295fdc5c271 fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1580
diff changeset
   180
            (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
   181
            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
   182
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
    def OnCloseFrame(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   184
        if self.Controler is None or self.CheckSaveBeforeClosing(_("Close Application")):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
            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
   186
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
            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
   188
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   189
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
            event.Veto()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
    def RefreshTitle(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   194
        name = _("PLCOpenEditor")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   195
        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
   196
            self.SetTitle("%s - %s" % (name, self.Controler.GetFilename()))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   198
            self.SetTitle(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   200
    # -------------------------------------------------------------------------------
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   201
    #                            File Menu Functions
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   202
    # -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
    def RefreshFileMenu(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
        MenuToolBar = self.Panes["MenuToolBar"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
        if self.Controler is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
            selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
            if selected >= 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
                graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   210
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   211
                graphic_viewer = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   212
            if self.TabsOpened.GetPageCount() > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
                self.FileMenu.Enable(wx.ID_CLOSE, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   214
                if graphic_viewer:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
                    self.FileMenu.Enable(wx.ID_PREVIEW, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   216
                    self.FileMenu.Enable(wx.ID_PRINT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   217
                    MenuToolBar.EnableTool(wx.ID_PRINT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
                    self.FileMenu.Enable(wx.ID_PREVIEW, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
                    self.FileMenu.Enable(wx.ID_PRINT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
                    MenuToolBar.EnableTool(wx.ID_PRINT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   222
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   223
                self.FileMenu.Enable(wx.ID_CLOSE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   224
                self.FileMenu.Enable(wx.ID_PREVIEW, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   225
                self.FileMenu.Enable(wx.ID_PRINT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   226
                MenuToolBar.EnableTool(wx.ID_PRINT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   227
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
            project_modified = not self.Controler.ProjectIsSaved()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   229
            self.FileMenu.Enable(wx.ID_SAVE, project_modified)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   230
            MenuToolBar.EnableTool(wx.ID_SAVE, project_modified)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
            self.FileMenu.Enable(wx.ID_PROPERTIES, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
            self.FileMenu.Enable(wx.ID_SAVEAS, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
            MenuToolBar.EnableTool(wx.ID_SAVEAS, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   235
            self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, True)
2531
f5891ce3228e Add "Generate Program" to toolbar in PLCOpenEditor standalone mode.
Schlumpf <schlumpf@kr-ll.de>
parents: 2497
diff changeset
   236
            MenuToolBar.EnableTool(ID_PLCOPENEDITORFILEMENUGENERATE, True)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
            self.FileMenu.Enable(wx.ID_CLOSE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
            self.FileMenu.Enable(wx.ID_PREVIEW, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
            self.FileMenu.Enable(wx.ID_PRINT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
            MenuToolBar.EnableTool(wx.ID_PRINT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
            self.FileMenu.Enable(wx.ID_SAVE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
            MenuToolBar.EnableTool(wx.ID_SAVE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
            self.FileMenu.Enable(wx.ID_PROPERTIES, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
            self.FileMenu.Enable(wx.ID_SAVEAS, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
            MenuToolBar.EnableTool(wx.ID_SAVEAS, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
            self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, False)
2531
f5891ce3228e Add "Generate Program" to toolbar in PLCOpenEditor standalone mode.
Schlumpf <schlumpf@kr-ll.de>
parents: 2497
diff changeset
   250
            MenuToolBar.EnableTool(ID_PLCOPENEDITORFILEMENUGENERATE, False)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   252
    def OnNewProjectMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
        if self.Controler is not None and not self.CheckSaveBeforeClosing():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
            return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   255
        dialog = ProjectDialog(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
            properties = dialog.GetValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
            self.ResetView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   259
            self.Controler = PLCControler()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   260
            self.Controler.CreateNewProject(properties)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
            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
   262
            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
   263
            self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   264
                          LIBRARYTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   265
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   266
    def OnOpenProjectMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   267
        if self.Controler is not None and not self.CheckSaveBeforeClosing():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   268
            return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   269
        filepath = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   270
        if self.Controler is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   271
            filepath = self.Controler.GetFilePath()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   272
        if filepath != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   273
            directory = os.path.dirname(filepath)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   274
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   275
            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
   276
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   277
        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
   278
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   279
        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
   280
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   281
            filepath = dialog.GetPath()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   282
            if os.path.isfile(filepath):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   283
                self.ResetView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
                controler = PLCControler()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   285
                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
   286
                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
   287
                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
   288
                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
   289
                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
   290
                self._Refresh(PROJECTTREE, LIBRARYTREE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
            self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   292
        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
   293
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
        if result is not None:
1581
2295fdc5c271 fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1580
diff changeset
   295
            (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
   296
            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
   297
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
    def OnCloseProjectMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
        if not self.CheckSaveBeforeClosing():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
            return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   301
        self.ResetView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   302
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   303
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
    def OnSaveProjectMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
        self.SaveProject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   307
    def OnSaveProjectAsMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   308
        self.SaveProjectAs()
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 OnGenerateProgramMenu(self, event):
2497
e04824ad26e4 Fix an exception on wx-3.0-gtk3 in PLCOpenEditor when generating ST files.
Schlumpf <schlumpf@kr-ll.de>
parents: 2177
diff changeset
   311
        dialog = wx.FileDialog(self, _("Choose a file"), os.getcwd(), os.path.basename(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
   312
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
            filepath = dialog.GetPath()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
            message_text = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
            header, icon = _("Done"), wx.ICON_INFORMATION
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
            if os.path.isdir(os.path.dirname(filepath)):
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1834
diff changeset
   317
                _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
   318
                message_text += "".join([_("warning: %s\n") % warning for warning in warnings])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
                if len(errors) > 0:
1312
250c3ae0787c Fixed bug when printing program generating errors and warnings in PLCOpenEditor
Laurent Bessard
parents: 1295
diff changeset
   320
                    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
   321
                    message_text += _("Can't generate program to file %s!") % filepath
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   322
                    header, icon = _("Error"), wx.ICON_ERROR
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   323
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   324
                    message_text += _("Program was successfully generated!")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   325
            else:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   326
                message_text += _("\"%s\" is not a valid folder!") % os.path.dirname(filepath)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
                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
   328
            message = wx.MessageDialog(self, message_text, header, wx.OK | icon)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
            message.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
            message.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   331
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   332
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   333
    def OnPLCOpenEditorMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   334
        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
   335
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
    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
   337
        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
   338
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   339
    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
   340
        info = version.GetAboutDialogInfo()
894f31f8ca64 make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1560
diff changeset
   341
        info.Name = "PLCOpenEditor"
894f31f8ca64 make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1560
diff changeset
   342
        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
   343
                             "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
   344
        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
   345
        ShowAboutDialog(self, info)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   346
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   347
    def SaveProject(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   348
        result = self.Controler.SaveXMLFile()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   349
        if not result:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   350
            self.SaveProjectAs()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   351
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   352
            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
   353
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   354
    def SaveProjectAs(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   355
        filepath = self.Controler.GetFilePath()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   356
        if filepath != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   357
            directory, filename = os.path.split(filepath)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   358
        else:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   359
            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
   360
        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
   361
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   362
            filepath = dialog.GetPath()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   363
            if os.path.isdir(os.path.dirname(filepath)):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   364
                result = self.Controler.SaveXMLFile(filepath)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   365
                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
   366
                    self.ShowErrorMessage(_("Can't save project to file %s!") % filepath)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   367
            else:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   368
                self.ShowErrorMessage(_("\"%s\" is not a valid folder!") % os.path.dirname(filepath))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   369
            self._Refresh(TITLE, FILEMENU, PAGETITLES)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   370
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   371
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
   372
1814
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   373
class PLCOpenEditorApp(wx.App):
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   374
    # def SetOpenFile(
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   375
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   376
    def PrintUsage(self):
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1815
diff changeset
   377
        print("\nUsage of PLCOpenEditor.py :")
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1815
diff changeset
   378
        print("\n   %s [Filepath]\n" % sys.argv[0])
1814
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   379
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   380
    def ParseCommandLine(self):
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   381
        # Parse options given to PLCOpenEditor in command line
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   382
        try:
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   383
            opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   384
        except getopt.GetoptError:
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   385
            # print help information and exit:
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   386
            self.PrintUsage()
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   387
            sys.exit(2)
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   388
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   389
        # Extract if help has been requested
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1834
diff changeset
   390
        for o, _a in opts:
1814
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   391
            if o in ("-h", "--help"):
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   392
                self.PrintUsage()
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   393
                sys.exit()
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   394
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   395
        # Extract the optional filename to open
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   396
        self.fileOpen = None
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   397
        if len(args) > 1:
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   398
            self.PrintUsage()
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   399
            sys.exit()
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   400
        elif len(args) == 1:
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   401
            self.fileOpen = args[0]
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   402
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   403
    def OnInit(self):
1815
f0600fe03a89 add application name for PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1814
diff changeset
   404
        self.SetAppName('plcopeneditor')
1814
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   405
        self.ParseCommandLine()
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   406
        InstallLocalRessources(beremiz_dir)
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   407
        if wx.VERSION < (3, 0, 0):
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   408
            wx.InitAllImageHandlers()
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   409
        util.ExceptionHandler.AddExceptHook(version.app_version)
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   410
        self.frame = PLCOpenEditor(None, fileOpen=self.fileOpen)
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   411
        return True
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   412
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   413
    def Show(self):
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   414
        self.frame.Show()
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   415
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   416
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   417
if __name__ == '__main__':
1814
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   418
    app = PLCOpenEditorApp()
fc387c4fc1d4 rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   419
    app.Show()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   420
    app.MainLoop()