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@1663: andrej@1663: import os, sys, getopt andrej@1663: import time andrej@1663: import __builtin__ andrej@1663: andrej@1663: class BeremizIDELauncher: andrej@1663: def __init__(self): andrej@1663: self.updateinfo_url = None andrej@1663: self.extensions = [] andrej@1663: self.app_dir = os.path.dirname(os.path.realpath(__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@1663: return os.path.join(self.app_dir,*args) andrej@1663: andrej@1663: def ShowSplashScreen(self): andrej@1663: from wx.lib.agw.advancedsplash import AdvancedSplash 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@1663: for i in range(0,30): andrej@1663: wx.Yield() andrej@1663: time.sleep(0.01); andrej@1663: andrej@1663: andrej@1663: def Usage(self): andrej@1663: print "\nUsage:" andrej@1663: print "\n %s [Projectpath] [Buildpath]\n"%sys.argv[0] 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@1663: if os.path.exists("BEREMIZ_DEBUG"): andrej@1663: __builtin__.__dict__["BMZ_DBG"] = True andrej@1663: else : andrej@1663: __builtin__.__dict__["BMZ_DBG"] = False andrej@1663: andrej@1663: global wxversion, wx andrej@1663: import wxversion andrej@1663: wxversion.select(['2.8', '3.0']) andrej@1663: import wx 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: self.app.MainLoop() 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@1663: updateinfo = _("Fetching %s") % self.updateinfo_url andrej@1663: andrej@1663: def updateinfoproc(): andrej@1663: global updateinfo andrej@1663: try : andrej@1663: import urllib2 andrej@1663: updateinfo = urllib2.urlopen(self.updateinfo_url,None).read() andrej@1663: except : andrej@1663: updateinfo = _("update info unavailable.") andrej@1663: andrej@1663: from threading import Thread andrej@1663: self.splash.SetText(text=updateinfo) andrej@1663: updateinfoThread = Thread(target=updateinfoproc) andrej@1663: updateinfoThread.start() andrej@1663: updateinfoThread.join(2) andrej@1663: self.splash.SetText(text=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@1663: import tempfile andrej@1663: logpath = tempfile.gettempdir()+os.sep+'Beremiz' andrej@1663: BeremizIDE.AddExceptHook(logpath,version.app_version) andrej@1663: andrej@1663: def ShowUI(self): 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@1663: def Start(self): andrej@1663: self.ProcessCommandLineArgs() andrej@1663: self.CreateApplication() andrej@1663: andrej@1663: if __name__ == '__main__': andrej@1663: beremiz = BeremizIDELauncher() andrej@1663: beremiz.Start()