Beremiz.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Sat, 16 Sep 2017 21:19:19 +0300
changeset 1816 724722c03db4
parent 1805 52daabbb6f90
child 1826 91796f408540
permissions -rwxr-xr-x
rework Beremiz application "testCheckProject" test to allow easier reuse later
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
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    29
import time
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1666
diff changeset
    30
import util.paths as paths
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    31
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    32
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    33
class BeremizIDELauncher:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    34
    def __init__(self):
1796
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    35
        self.app = None
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
    36
        self.frame = None
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    37
        self.updateinfo_url = None
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    38
        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
    39
        self.app_dir = paths.AbsDir(__file__)
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    40
        self.projectOpen = None
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    41
        self.buildpath = None
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    42
        self.splash = None
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    43
        self.splashPath = self.Bpath("images", "splash.png")
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    44
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    45
    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
    46
        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
    47
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    48
    def ShowSplashScreen(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    49
        from wx.lib.agw.advancedsplash import AdvancedSplash
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    50
        bmp = wx.Image(self.splashPath).ConvertToBitmap()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    51
        self.splash = AdvancedSplash(None, bitmap=bmp)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    52
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    53
        # process all events
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    54
        # even the events generated by splash themself during showing
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    55
        if wx.Platform == '__WXMSW__':
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    56
            self.splash.Show()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    57
            self.splash.ProcessEvent(wx.PaintEvent())
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    58
        else:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
    59
            for i in range(0, 30):
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    60
                wx.Yield()
1752
d14ff9d7eb76 clean-up: fix PEP8 E703 statement ends with a semicolon
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
    61
                time.sleep(0.01)
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    62
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    63
    def Usage(self):
1666
d3603b5a1cbc make command line help message for Beremiz more verbose
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1663
diff changeset
    64
        print "Usage:"
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
    65
        print "%s [Options] [Projectpath] [Buildpath]" % sys.argv[0]
1666
d3603b5a1cbc make command line help message for Beremiz more verbose
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1663
diff changeset
    66
        print ""
d3603b5a1cbc make command line help message for Beremiz more verbose
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1663
diff changeset
    67
        print "Supported options:"
d3603b5a1cbc make command line help message for Beremiz more verbose
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1663
diff changeset
    68
        print "-h --help                    Print this help"
d3603b5a1cbc make command line help message for Beremiz more verbose
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1663
diff changeset
    69
        print "-u --updatecheck URL         Retrieve update information by checking URL"
d3603b5a1cbc make command line help message for Beremiz more verbose
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1663
diff changeset
    70
        print "-e --extend PathToExtension  Extend IDE functionality by loading at start additional extensions"
d3603b5a1cbc make command line help message for Beremiz more verbose
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1663
diff changeset
    71
        print ""
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1680
diff changeset
    72
        print ""
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    73
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    74
    def SetCmdOptions(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    75
        self.shortCmdOpts = "hu:e:"
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    76
        self.longCmdOpts = ["help", "updatecheck=", "extend="]
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    77
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    78
    def ProcessOption(self, o, a):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    79
        if o in ("-h", "--help"):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    80
            self.Usage()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    81
            sys.exit()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    82
        if o in ("-u", "--updatecheck"):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    83
            self.updateinfo_url = a
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    84
        if o in ("-e", "--extend"):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    85
            self.extensions.append(a)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    86
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    87
    def ProcessCommandLineArgs(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    88
        self.SetCmdOptions()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    89
        try:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    90
            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
    91
        except getopt.GetoptError:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    92
            # print help information and exit:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    93
            self.Usage()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    94
            sys.exit(2)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    95
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    96
        for o, a in opts:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    97
            self.ProcessOption(o, a)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    98
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    99
        if len(args) > 2:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   100
            self.Usage()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   101
            sys.exit()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   102
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   103
        elif len(args) == 1:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   104
            self.projectOpen = args[0]
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   105
            self.buildpath = None
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   106
        elif len(args) == 2:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   107
            self.projectOpen = args[0]
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   108
            self.buildpath = args[1]
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   109
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   110
    def CreateApplication(self):
1805
52daabbb6f90 remove builtin BMZ_DBG. It's not used.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1796
diff changeset
   111
        BMZ_DBG = os.path.exists("BEREMIZ_DEBUG")
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   112
1790
47fc06c13b37 don't check any particular wx version
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   113
        global wx
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   114
        import wx
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   115
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   116
        if wx.VERSION >= (3, 0, 0):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   117
            self.app = wx.App(redirect=BMZ_DBG)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   118
        else:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   119
            self.app = wx.PySimpleApp(redirect=BMZ_DBG)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   120
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   121
        self.app.SetAppName('beremiz')
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   122
        if wx.VERSION < (3, 0, 0):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   123
            wx.InitAllImageHandlers()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   124
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   125
        self.ShowSplashScreen()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   126
        self.BackgroundInitialization()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   127
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   128
    def BackgroundInitialization(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   129
        self.InitI18n()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   130
        self.CheckUpdates()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   131
        self.LoadExtensions()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   132
        self.ImportModules()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   133
        self.InstallExceptionHandler()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   134
        self.ShowUI()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   135
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   136
    def InitI18n(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   137
        from util.misc import InstallLocalRessources
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   138
        InstallLocalRessources(self.app_dir)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   139
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   140
    def LoadExtensions(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   141
        for extfilename in self.extensions:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   142
            from util.TranslationCatalogs import AddCatalog
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   143
            from util.BitmapLibrary import AddBitmapFolder
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   144
            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
   145
            sys.path.append(extension_folder)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   146
            AddCatalog(os.path.join(extension_folder, "locale"))
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   147
            AddBitmapFolder(os.path.join(extension_folder, "images"))
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   148
            execfile(extfilename, locals())
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   149
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   150
    def CheckUpdates(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   151
        if self.updateinfo_url is not None:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   152
            updateinfo = _("Fetching %s") % self.updateinfo_url
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   153
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   154
            def updateinfoproc():
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   155
                global updateinfo
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   156
                try:
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   157
                    import urllib2
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   158
                    updateinfo = urllib2.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
   159
                except Exception:
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   160
                    updateinfo = _("update info unavailable.")
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
            from threading import Thread
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   163
            self.splash.SetText(text=updateinfo)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   164
            updateinfoThread = Thread(target=updateinfoproc)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   165
            updateinfoThread.start()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   166
            updateinfoThread.join(2)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   167
            self.splash.SetText(text=updateinfo)
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
    def ImportModules(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   170
        global BeremizIDE
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   171
        import BeremizIDE
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   172
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   173
    def InstallExceptionHandler(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   174
        import version
1792
4d1de8b0183f unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1790
diff changeset
   175
        import util.ExceptionHandler
4d1de8b0183f unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1790
diff changeset
   176
        util.ExceptionHandler.AddExceptHook(version.app_version)
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   177
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   178
    def ShowUI(self):
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   179
        self.frame = BeremizIDE.Beremiz(None, self.projectOpen, self.buildpath)
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   180
        if self.splash:
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   181
            self.splash.Close()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   182
        self.frame.Show()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   183
1796
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   184
    def PreStart(self):
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   185
        self.ProcessCommandLineArgs()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   186
        self.CreateApplication()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   187
1796
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   188
    def MainLoop(self):
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   189
        self.app.MainLoop()
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   190
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   191
    def Start(self):
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   192
        self.PreStart()
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   193
        self.MainLoop()
4f7a0c40a7c3 add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1792
diff changeset
   194
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
   195
1663
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   196
if __name__ == '__main__':
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   197
    beremiz = BeremizIDELauncher()
81f6781f7fec rename BeremizIDELauncher.py to Beremiz.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   198
    beremiz.Start()