Beremiz.py
author Edouard Tisserant <edouard@beremiz.fr>
Fri, 11 Oct 2024 10:34:15 +0200
changeset 4026 a3cf9f635952
parent 3793 9958cf865da0
permissions -rwxr-xr-x
SVGHMI: add ForEach widget example
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/env python
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     3
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     6
#
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     7
# Copyright (C) 2016 - 2017: Andrey Skvortsov <andrej.skvortzov@gmail.com>
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     8
#
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     9
# See COPYING file for copyrights details.
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    10
#
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    11
# This program is free software; you can redistribute it and/or
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    12
# modify it under the terms of the GNU General Public License
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    13
# as published by the Free Software Foundation; either version 2
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    14
# of the License, or (at your option) any later version.
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    15
#
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    16
# This program is distributed in the hope that it will be useful,
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    19
# GNU General Public License for more details.
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    20
#
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    21
# You should have received a copy of the GNU General Public License
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    22
# along with this program; if not, write to the Free Software
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    24
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    25
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    26
import os
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    27
import sys
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    28
import getopt
1872
866fb3ab8778 fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
    29
866fb3ab8778 fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
    30
import wx
1941
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
    31
from wx.lib.agw.advancedsplash import AdvancedSplash, AS_NOTIMEOUT, AS_CENTER_ON_SCREEN
1872
866fb3ab8778 fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
    32
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1666
diff changeset
    33
import util.paths as paths
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    34
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1947
diff changeset
    35
1831
56b48961cc68 fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1826
diff changeset
    36
class BeremizIDELauncher(object):
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    37
    def __init__(self):
1796
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    38
        self.app = None
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    39
        self.frame = None
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    40
        self.updateinfo_url = None
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    41
        self.extensions = []
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1666
diff changeset
    42
        self.app_dir = paths.AbsDir(__file__)
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    43
        self.projectOpen = None
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    44
        self.buildpath = None
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    45
        self.splash = None
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    46
        self.splashPath = self.Bpath("images", "splash.png")
1935
f2b0d849ea77 Prevent compiling XSLT on each call of GetInstanceList. To be continued. More optimization needed here. 100x would be fine...
Edouard Tisserant
parents: 1926
diff changeset
    47
        self.modules = ["BeremizIDE"]
1926
d430a67c8462 Launcher : add a debug attribute, instead of BMZ_DBG, so that customization can use it.
Edouard Tisserant
parents: 1924
diff changeset
    48
        self.debug = os.path.exists("BEREMIZ_DEBUG")
1960
372ec456664c Prevent catching exception if exception handling was not enabled (or disabled by test test app).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1953
diff changeset
    49
        self.handle_exception = None
3423
84afcc0ebadd IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2570
diff changeset
    50
        self.logf = None
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    51
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    52
    def Bpath(self, *args):
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
    53
        return os.path.join(self.app_dir, *args)
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    54
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    55
    def Usage(self):
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1805
diff changeset
    56
        print("Usage:")
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1805
diff changeset
    57
        print("%s [Options] [Projectpath] [Buildpath]" % sys.argv[0])
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1805
diff changeset
    58
        print("")
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1805
diff changeset
    59
        print("Supported options:")
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1805
diff changeset
    60
        print("-h --help                    Print this help")
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1805
diff changeset
    61
        print("-u --updatecheck URL         Retrieve update information by checking URL")
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1805
diff changeset
    62
        print("-e --extend PathToExtension  Extend IDE functionality by loading at start additional extensions")
3423
84afcc0ebadd IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2570
diff changeset
    63
        print("-l --log path                write content of console tab to given file")
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1805
diff changeset
    64
        print("")
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1805
diff changeset
    65
        print("")
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    66
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    67
    def SetCmdOptions(self):
3423
84afcc0ebadd IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2570
diff changeset
    68
        self.shortCmdOpts = "hu:e:l:"
84afcc0ebadd IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2570
diff changeset
    69
        self.longCmdOpts = ["help", "updatecheck=", "extend=", "log="]
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    70
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    71
    def ProcessOption(self, o, a):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    72
        if o in ("-h", "--help"):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    73
            self.Usage()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    74
            sys.exit()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    75
        if o in ("-u", "--updatecheck"):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    76
            self.updateinfo_url = a
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    77
        if o in ("-e", "--extend"):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    78
            self.extensions.append(a)
3423
84afcc0ebadd IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2570
diff changeset
    79
        if o in ("-l", "--log"):
84afcc0ebadd IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2570
diff changeset
    80
            self.logf = open(a, 'a')
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    81
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    82
    def ProcessCommandLineArgs(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    83
        self.SetCmdOptions()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    84
        try:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    85
            opts, args = getopt.getopt(sys.argv[1:], self.shortCmdOpts, self.longCmdOpts)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    86
        except getopt.GetoptError:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    87
            # print help information and exit:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    88
            self.Usage()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    89
            sys.exit(2)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    90
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    91
        for o, a in opts:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    92
            self.ProcessOption(o, a)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    93
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    94
        if len(args) > 2:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    95
            self.Usage()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    96
            sys.exit()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    97
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    98
        elif len(args) == 1:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    99
            self.projectOpen = args[0]
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   100
            self.buildpath = None
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   101
        elif len(args) == 2:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   102
            self.projectOpen = args[0]
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   103
            self.buildpath = args[1]
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   104
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   105
    def CreateApplication(self):
1941
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   106
3793
9958cf865da0 IDE: fixed/remove checks wxPython versions
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3752
diff changeset
   107
        BeremizAppType = wx.App
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1947
diff changeset
   108
1941
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   109
        class BeremizApp(BeremizAppType):
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1947
diff changeset
   110
            def OnInit(_self):  # pylint: disable=no-self-argument
1941
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   111
                self.ShowSplashScreen()
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   112
                return True
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   113
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   114
        self.app = BeremizApp(redirect=self.debug)
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   115
        self.app.SetAppName('beremiz')
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   116
1947
7c2cd9d33070 Hook Beremiz Launcher AppStart to AdvancedSplash OnPaint event in order to ensure image is beeing displayed before loading.
Edouard Tisserant
parents: 1941
diff changeset
   117
    def ShowSplashScreen(self):
7c2cd9d33070 Hook Beremiz Launcher AppStart to AdvancedSplash OnPaint event in order to ensure image is beeing displayed before loading.
Edouard Tisserant
parents: 1941
diff changeset
   118
        class Splash(AdvancedSplash):
1976
5d72971a36a3 Fixed bug that was creating many frames at starup on Windows
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1960
diff changeset
   119
            Painted = False
1977
9b3655ed2e24 PEP-8...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1976
diff changeset
   120
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1947
diff changeset
   121
            def OnPaint(_self, event):  # pylint: disable=no-self-argument
1947
7c2cd9d33070 Hook Beremiz Launcher AppStart to AdvancedSplash OnPaint event in order to ensure image is beeing displayed before loading.
Edouard Tisserant
parents: 1941
diff changeset
   122
                AdvancedSplash.OnPaint(_self, event)
1976
5d72971a36a3 Fixed bug that was creating many frames at starup on Windows
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1960
diff changeset
   123
                if not _self.Painted:  # trigger app start only once
5d72971a36a3 Fixed bug that was creating many frames at starup on Windows
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1960
diff changeset
   124
                    _self.Painted = True
5d72971a36a3 Fixed bug that was creating many frames at starup on Windows
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1960
diff changeset
   125
                    wx.CallAfter(self.AppStart)
1947
7c2cd9d33070 Hook Beremiz Launcher AppStart to AdvancedSplash OnPaint event in order to ensure image is beeing displayed before loading.
Edouard Tisserant
parents: 1941
diff changeset
   126
        bmp = wx.Image(self.splashPath).ConvertToBitmap()
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1947
diff changeset
   127
        self.splash = Splash(None,
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1947
diff changeset
   128
                             bitmap=bmp,
1947
7c2cd9d33070 Hook Beremiz Launcher AppStart to AdvancedSplash OnPaint event in order to ensure image is beeing displayed before loading.
Edouard Tisserant
parents: 1941
diff changeset
   129
                             agwStyle=AS_NOTIMEOUT | AS_CENTER_ON_SCREEN)
7c2cd9d33070 Hook Beremiz Launcher AppStart to AdvancedSplash OnPaint event in order to ensure image is beeing displayed before loading.
Edouard Tisserant
parents: 1941
diff changeset
   130
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   131
    def BackgroundInitialization(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   132
        self.InitI18n()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   133
        self.CheckUpdates()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   134
        self.LoadExtensions()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   135
        self.ImportModules()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   136
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   137
    def InitI18n(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   138
        from util.misc import InstallLocalRessources
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   139
        InstallLocalRessources(self.app_dir)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   140
1921
cf54939e6b0c Launcher: allows customizations to specify what globals passed to extensions
Edouard Tisserant
parents: 1915
diff changeset
   141
    def globals(self):
cf54939e6b0c Launcher: allows customizations to specify what globals passed to extensions
Edouard Tisserant
parents: 1915
diff changeset
   142
        """
cf54939e6b0c Launcher: allows customizations to specify what globals passed to extensions
Edouard Tisserant
parents: 1915
diff changeset
   143
        allows customizations to specify what globals
cf54939e6b0c Launcher: allows customizations to specify what globals passed to extensions
Edouard Tisserant
parents: 1915
diff changeset
   144
        are passed to extensions
cf54939e6b0c Launcher: allows customizations to specify what globals passed to extensions
Edouard Tisserant
parents: 1915
diff changeset
   145
        """
cf54939e6b0c Launcher: allows customizations to specify what globals passed to extensions
Edouard Tisserant
parents: 1915
diff changeset
   146
        return globals()
cf54939e6b0c Launcher: allows customizations to specify what globals passed to extensions
Edouard Tisserant
parents: 1915
diff changeset
   147
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   148
    def LoadExtensions(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   149
        for extfilename in self.extensions:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   150
            from util.TranslationCatalogs import AddCatalog
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   151
            from util.BitmapLibrary import AddBitmapFolder
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   152
            extension_folder = os.path.split(os.path.realpath(extfilename))[0]
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   153
            sys.path.append(extension_folder)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   154
            AddCatalog(os.path.join(extension_folder, "locale"))
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   155
            AddBitmapFolder(os.path.join(extension_folder, "images"))
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3444
diff changeset
   156
            exec(compile(open(extfilename, "rb").read(), extfilename, 'exec'), self.globals())
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   157
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   158
    def CheckUpdates(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   159
        if self.updateinfo_url is not None:
1874
a347459df3a4 fix displaying result of update check during Beremiz startup
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1872
diff changeset
   160
            self.updateinfo = _("Fetching %s") % self.updateinfo_url
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   161
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   162
            def updateinfoproc():
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   163
                try:
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3444
diff changeset
   164
                    import urllib.request, urllib.error, urllib.parse
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3444
diff changeset
   165
                    self.updateinfo = urllib.request.urlopen(self.updateinfo_url, None).read()
1780
c52d1460cea8 clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1752
diff changeset
   166
                except Exception:
1874
a347459df3a4 fix displaying result of update check during Beremiz startup
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1872
diff changeset
   167
                    self.updateinfo = _("update info unavailable.")
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   168
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   169
            from threading import Thread
1874
a347459df3a4 fix displaying result of update check during Beremiz startup
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1872
diff changeset
   170
            self.splash.SetText(text=self.updateinfo)
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   171
            updateinfoThread = Thread(target=updateinfoproc)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   172
            updateinfoThread.start()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   173
            updateinfoThread.join(2)
1874
a347459df3a4 fix displaying result of update check during Beremiz startup
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1872
diff changeset
   174
            self.splash.SetText(text=self.updateinfo)
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   175
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   176
    def ImportModules(self):
1924
fc67b02d44e0 More changes in Launcher. Modules to be loaded in the background are given in a list, and assigned as object attributes. Also splitted CreateUI into CloseSplashScreen and CreatueUI.
Edouard Tisserant
parents: 1922
diff changeset
   177
        for modname in self.modules:
fc67b02d44e0 More changes in Launcher. Modules to be loaded in the background are given in a list, and assigned as object attributes. Also splitted CreateUI into CloseSplashScreen and CreatueUI.
Edouard Tisserant
parents: 1922
diff changeset
   178
            mod = __import__(modname)
fc67b02d44e0 More changes in Launcher. Modules to be loaded in the background are given in a list, and assigned as object attributes. Also splitted CreateUI into CloseSplashScreen and CreatueUI.
Edouard Tisserant
parents: 1922
diff changeset
   179
            setattr(self, modname, mod)
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   180
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   181
    def InstallExceptionHandler(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   182
        import version
1792
4d1de8b0183f unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1790
diff changeset
   183
        import util.ExceptionHandler
3444
91b2c014494e IDE: in case of unhandled exception, write bug report to given log file, so that test report can have it.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3423
diff changeset
   184
        self.handle_exception = util.ExceptionHandler.AddExceptHook(version.app_version, logf=self.logf)
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   185
1924
fc67b02d44e0 More changes in Launcher. Modules to be loaded in the background are given in a list, and assigned as object attributes. Also splitted CreateUI into CloseSplashScreen and CreatueUI.
Edouard Tisserant
parents: 1922
diff changeset
   186
    def CreateUI(self):
3423
84afcc0ebadd IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2570
diff changeset
   187
        self.frame = self.BeremizIDE.Beremiz(None, self.projectOpen, self.buildpath, logf=self.logf)
1924
fc67b02d44e0 More changes in Launcher. Modules to be loaded in the background are given in a list, and assigned as object attributes. Also splitted CreateUI into CloseSplashScreen and CreatueUI.
Edouard Tisserant
parents: 1922
diff changeset
   188
fc67b02d44e0 More changes in Launcher. Modules to be loaded in the background are given in a list, and assigned as object attributes. Also splitted CreateUI into CloseSplashScreen and CreatueUI.
Edouard Tisserant
parents: 1922
diff changeset
   189
    def CloseSplash(self):
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   190
        if self.splash:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   191
            self.splash.Close()
1924
fc67b02d44e0 More changes in Launcher. Modules to be loaded in the background are given in a list, and assigned as object attributes. Also splitted CreateUI into CloseSplashScreen and CreatueUI.
Edouard Tisserant
parents: 1922
diff changeset
   192
fc67b02d44e0 More changes in Launcher. Modules to be loaded in the background are given in a list, and assigned as object attributes. Also splitted CreateUI into CloseSplashScreen and CreatueUI.
Edouard Tisserant
parents: 1922
diff changeset
   193
    def ShowUI(self):
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   194
        self.frame.Show()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   195
1796
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   196
    def PreStart(self):
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   197
        self.ProcessCommandLineArgs()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   198
        self.CreateApplication()
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1947
diff changeset
   199
1941
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   200
    def AppStart(self):
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   201
        try:
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   202
            self.BackgroundInitialization()
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   203
            self.CreateUI()
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   204
            self.CloseSplash()
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   205
            self.ShowUI()
1960
372ec456664c Prevent catching exception if exception handling was not enabled (or disabled by test test app).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1953
diff changeset
   206
        except (KeyboardInterrupt, SystemExit):
372ec456664c Prevent catching exception if exception handling was not enabled (or disabled by test test app).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1953
diff changeset
   207
            raise
1941
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   208
        except Exception:
1960
372ec456664c Prevent catching exception if exception handling was not enabled (or disabled by test test app).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1953
diff changeset
   209
            if self.handle_exception is not None:
372ec456664c Prevent catching exception if exception handling was not enabled (or disabled by test test app).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1953
diff changeset
   210
                self.handle_exception(*sys.exc_info(), exit=True)
372ec456664c Prevent catching exception if exception handling was not enabled (or disabled by test test app).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1953
diff changeset
   211
            else:
372ec456664c Prevent catching exception if exception handling was not enabled (or disabled by test test app).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1953
diff changeset
   212
                raise
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   213
1796
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   214
    def MainLoop(self):
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   215
        self.app.MainLoop()
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   216
1924
fc67b02d44e0 More changes in Launcher. Modules to be loaded in the background are given in a list, and assigned as object attributes. Also splitted CreateUI into CloseSplashScreen and CreatueUI.
Edouard Tisserant
parents: 1922
diff changeset
   217
    def Start(self):
1796
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   218
        self.PreStart()
1941
cde74a39df51 Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1935
diff changeset
   219
        self.InstallExceptionHandler()
1796
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   220
        self.MainLoop()
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   221
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   222
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   223
if __name__ == '__main__':
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   224
    beremiz = BeremizIDELauncher()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   225
    beremiz.Start()