andrej@1663: #!/usr/bin/env python andrej@1663: # -*- coding: utf-8 -*- andrej@1663: andrej@1663: # This file is part of Beremiz, a Integrated Development Environment for andrej@1663: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. andrej@1663: # andrej@1663: # Copyright (C) 2016 - 2017: Andrey Skvortsov andrej@1663: # andrej@1663: # See COPYING file for copyrights details. andrej@1663: # andrej@1663: # This program is free software; you can redistribute it and/or andrej@1663: # modify it under the terms of the GNU General Public License andrej@1663: # as published by the Free Software Foundation; either version 2 andrej@1663: # of the License, or (at your option) any later version. andrej@1663: # andrej@1663: # This program is distributed in the hope that it will be useful, andrej@1663: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1663: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1663: # GNU General Public License for more details. andrej@1663: # andrej@1663: # You should have received a copy of the GNU General Public License andrej@1663: # along with this program; if not, write to the Free Software andrej@1663: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. andrej@1663: andrej@1663: andrej@1881: from __future__ import absolute_import andrej@1826: from __future__ import print_function andrej@1732: import os andrej@1732: import sys andrej@1732: import getopt andrej@1663: import time andrej@1872: andrej@1872: import wx andrej@1872: from wx.lib.agw.advancedsplash import AdvancedSplash andrej@1872: andrej@1680: import util.paths as paths andrej@1663: andrej@1736: andrej@1831: class BeremizIDELauncher(object): andrej@1663: def __init__(self): andrej@1796: self.app = None andrej@1796: self.frame = None andrej@1663: self.updateinfo_url = None andrej@1663: self.extensions = [] andrej@1680: self.app_dir = paths.AbsDir(__file__) andrej@1663: self.projectOpen = None andrej@1663: self.buildpath = None andrej@1663: self.splash = None andrej@1663: self.splashPath = self.Bpath("images", "splash.png") andrej@1663: andrej@1663: def Bpath(self, *args): andrej@1740: return os.path.join(self.app_dir, *args) andrej@1663: andrej@1663: def ShowSplashScreen(self): andrej@1663: bmp = wx.Image(self.splashPath).ConvertToBitmap() andrej@1663: self.splash = AdvancedSplash(None, bitmap=bmp) andrej@1663: andrej@1663: # process all events andrej@1663: # even the events generated by splash themself during showing andrej@1663: if wx.Platform == '__WXMSW__': andrej@1663: self.splash.Show() andrej@1663: self.splash.ProcessEvent(wx.PaintEvent()) andrej@1663: else: andrej@1847: for dummy in range(0, 30): andrej@1663: wx.Yield() andrej@1752: time.sleep(0.01) andrej@1663: andrej@1663: def Usage(self): andrej@1826: print("Usage:") andrej@1826: print("%s [Options] [Projectpath] [Buildpath]" % sys.argv[0]) andrej@1826: print("") andrej@1826: print("Supported options:") andrej@1826: print("-h --help Print this help") andrej@1826: print("-u --updatecheck URL Retrieve update information by checking URL") andrej@1826: print("-e --extend PathToExtension Extend IDE functionality by loading at start additional extensions") andrej@1826: print("") andrej@1826: print("") andrej@1663: andrej@1663: def SetCmdOptions(self): andrej@1663: self.shortCmdOpts = "hu:e:" andrej@1663: self.longCmdOpts = ["help", "updatecheck=", "extend="] andrej@1663: andrej@1663: def ProcessOption(self, o, a): andrej@1663: if o in ("-h", "--help"): andrej@1663: self.Usage() andrej@1663: sys.exit() andrej@1663: if o in ("-u", "--updatecheck"): andrej@1663: self.updateinfo_url = a andrej@1663: if o in ("-e", "--extend"): andrej@1663: self.extensions.append(a) andrej@1663: andrej@1663: def ProcessCommandLineArgs(self): andrej@1663: self.SetCmdOptions() andrej@1663: try: andrej@1663: opts, args = getopt.getopt(sys.argv[1:], self.shortCmdOpts, self.longCmdOpts) andrej@1663: except getopt.GetoptError: andrej@1663: # print help information and exit: andrej@1663: self.Usage() andrej@1663: sys.exit(2) andrej@1663: andrej@1663: for o, a in opts: andrej@1663: self.ProcessOption(o, a) andrej@1663: andrej@1663: if len(args) > 2: andrej@1663: self.Usage() andrej@1663: sys.exit() andrej@1663: andrej@1663: elif len(args) == 1: andrej@1663: self.projectOpen = args[0] andrej@1663: self.buildpath = None andrej@1663: elif len(args) == 2: andrej@1663: self.projectOpen = args[0] andrej@1663: self.buildpath = args[1] andrej@1663: andrej@1663: def CreateApplication(self): andrej@1805: BMZ_DBG = os.path.exists("BEREMIZ_DEBUG") andrej@1663: andrej@1663: if wx.VERSION >= (3, 0, 0): andrej@1663: self.app = wx.App(redirect=BMZ_DBG) andrej@1663: else: andrej@1663: self.app = wx.PySimpleApp(redirect=BMZ_DBG) andrej@1663: andrej@1663: self.app.SetAppName('beremiz') andrej@1663: if wx.VERSION < (3, 0, 0): andrej@1663: wx.InitAllImageHandlers() andrej@1663: andrej@1663: self.ShowSplashScreen() andrej@1663: self.BackgroundInitialization() andrej@1663: andrej@1663: def BackgroundInitialization(self): andrej@1663: self.InitI18n() andrej@1663: self.CheckUpdates() andrej@1663: self.LoadExtensions() andrej@1663: self.ImportModules() andrej@1663: self.InstallExceptionHandler() andrej@1663: self.ShowUI() andrej@1663: andrej@1663: def InitI18n(self): andrej@1663: from util.misc import InstallLocalRessources andrej@1663: InstallLocalRessources(self.app_dir) andrej@1663: andrej@1663: def LoadExtensions(self): andrej@1663: for extfilename in self.extensions: andrej@1663: from util.TranslationCatalogs import AddCatalog andrej@1663: from util.BitmapLibrary import AddBitmapFolder andrej@1663: extension_folder = os.path.split(os.path.realpath(extfilename))[0] andrej@1663: sys.path.append(extension_folder) andrej@1663: AddCatalog(os.path.join(extension_folder, "locale")) andrej@1663: AddBitmapFolder(os.path.join(extension_folder, "images")) andrej@1663: execfile(extfilename, locals()) andrej@1663: andrej@1663: def CheckUpdates(self): andrej@1663: if self.updateinfo_url is not None: andrej@1874: self.updateinfo = _("Fetching %s") % self.updateinfo_url andrej@1663: andrej@1663: def updateinfoproc(): andrej@1739: try: andrej@1663: import urllib2 andrej@1874: self.updateinfo = urllib2.urlopen(self.updateinfo_url, None).read() andrej@1780: except Exception: andrej@1874: self.updateinfo = _("update info unavailable.") andrej@1663: andrej@1663: from threading import Thread andrej@1874: self.splash.SetText(text=self.updateinfo) andrej@1663: updateinfoThread = Thread(target=updateinfoproc) andrej@1663: updateinfoThread.start() andrej@1663: updateinfoThread.join(2) andrej@1874: self.splash.SetText(text=self.updateinfo) andrej@1663: andrej@1663: def ImportModules(self): andrej@1663: global BeremizIDE andrej@1663: import BeremizIDE andrej@1663: andrej@1663: def InstallExceptionHandler(self): andrej@1663: import version andrej@1792: import util.ExceptionHandler andrej@1792: util.ExceptionHandler.AddExceptHook(version.app_version) andrej@1663: andrej@1663: def ShowUI(self): andrej@1872: import BeremizIDE andrej@1663: self.frame = BeremizIDE.Beremiz(None, self.projectOpen, self.buildpath) andrej@1663: if self.splash: andrej@1663: self.splash.Close() andrej@1663: self.frame.Show() andrej@1663: andrej@1796: def PreStart(self): andrej@1663: self.ProcessCommandLineArgs() andrej@1663: self.CreateApplication() andrej@1663: andrej@1796: def MainLoop(self): andrej@1796: self.app.MainLoop() andrej@1796: andrej@1796: def Start(self): andrej@1796: self.PreStart() andrej@1796: self.MainLoop() andrej@1796: andrej@1749: andrej@1663: if __name__ == '__main__': andrej@1663: beremiz = BeremizIDELauncher() andrej@1663: beremiz.Start()