Beremiz.py
changeset 1661 78f28f40bc10
parent 1659 aec0ed4b6f39
equal deleted inserted replaced
1659:aec0ed4b6f39 1661:78f28f40bc10
     3 
     3 
     4 # This file is part of Beremiz, a Integrated Development Environment for
     4 # This file is part of Beremiz, a Integrated Development Environment for
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
     6 #
     6 #
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
       
     8 # Copyright (C) 2016: Andrey Skvortsov <andrej.skvortzov@gmail.com>
     8 #
     9 #
     9 # See COPYING file for copyrights details.
    10 # See COPYING file for copyrights details.
    10 #
    11 #
    11 # This program is free software; you can redistribute it and/or
    12 # This program is free software; you can redistribute it and/or
    12 # modify it under the terms of the GNU General Public License
    13 # modify it under the terms of the GNU General Public License
    20 #
    21 #
    21 # You should have received a copy of the GNU General Public License
    22 # You should have received a copy of the GNU General Public License
    22 # along with this program; if not, write to the Free Software
    23 # along with this program; if not, write to the Free Software
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    25 
    25 updateinfo_url = None
    26 
    26 
    27 import os, sys
    27 import os, sys, getopt
       
    28 import __builtin__
       
    29 import tempfile
    28 import tempfile
    30 import shutil
    29 import shutil
    31 import random
    30 import random
    32 import time
    31 import time
    33 import version
    32 import version
    34 from types import ListType
    33 from types import ListType
    35 
    34 
    36 beremiz_dir = os.path.dirname(os.path.realpath(__file__))
    35 beremiz_dir = os.path.dirname(os.path.realpath(__file__))
    37 
    36 
    38 if __name__ == '__main__':
       
    39     import wxversion
       
    40     wxversion.select(['2.8', '3.0'])
       
    41     import wx
       
    42     
       
    43 from wx.lib.agw.advancedsplash import AdvancedSplash
       
    44 
       
    45 def Bpath(*args):
    37 def Bpath(*args):
    46     return os.path.join(beremiz_dir,*args)
    38     return os.path.join(beremiz_dir,*args)
    47 
    39 
    48 def ShowSplashScreen():
       
    49     bmp = wx.Image(Bpath("images", "splash.png")).ConvertToBitmap()
       
    50     #splash=AdvancedSplash(None, bitmap=bmp, style=wx.SPLASH_CENTRE_ON_SCREEN, timeout=4000)
       
    51     splash = AdvancedSplash(None, bitmap=bmp)
       
    52 
       
    53     # process all events
       
    54     # even the events generated by splash themself during showing
       
    55     for i in range(0,30):
       
    56         wx.Yield()
       
    57         time.sleep(0.01);
       
    58     return splash
       
    59 
       
    60 if __name__ == '__main__':
       
    61     def usage():
       
    62         print "\nUsage of Beremiz.py :"
       
    63         print "\n   %s [Projectpath] [Buildpath]\n"%sys.argv[0]
       
    64 
       
    65     try:
       
    66         opts, args = getopt.getopt(sys.argv[1:], "hu:e:", ["help", "updatecheck=", "extend="])
       
    67     except getopt.GetoptError:
       
    68         # print help information and exit:
       
    69         usage()
       
    70         sys.exit(2)
       
    71 
       
    72     extensions=[]
       
    73 
       
    74     for o, a in opts:
       
    75         if o in ("-h", "--help"):
       
    76             usage()
       
    77             sys.exit()
       
    78         if o in ("-u", "--updatecheck"):
       
    79             updateinfo_url = a
       
    80         if o in ("-e", "--extend"):
       
    81             extensions.append(a)
       
    82 
       
    83     if len(args) > 2:
       
    84         usage()
       
    85         sys.exit()
       
    86     elif len(args) == 1:
       
    87         projectOpen = args[0]
       
    88         buildpath = None
       
    89     elif len(args) == 2:
       
    90         projectOpen = args[0]
       
    91         buildpath = args[1]
       
    92     else:
       
    93         projectOpen = None
       
    94         buildpath = None
       
    95 
       
    96     if os.path.exists("BEREMIZ_DEBUG"):
       
    97         __builtin__.__dict__["BMZ_DBG"] = True
       
    98     else :
       
    99         __builtin__.__dict__["BMZ_DBG"] = False
       
   100 
       
   101     if wx.VERSION >= (3, 0, 0):
       
   102         app = wx.App(redirect=BMZ_DBG)
       
   103     else:
       
   104         app = wx.PySimpleApp(redirect=BMZ_DBG)
       
   105 
       
   106     app.SetAppName('beremiz')
       
   107     if wx.VERSION < (3, 0, 0):
       
   108         wx.InitAllImageHandlers()
       
   109 
       
   110     # popup splash
       
   111     splash = ShowSplashScreen()
       
   112 
       
   113     # load internatialization files
       
   114     from util.misc import InstallLocalRessources
       
   115     InstallLocalRessources(beremiz_dir)
       
   116     
       
   117     if updateinfo_url is not None:
       
   118         updateinfo = _("Fetching %s") % updateinfo_url
       
   119         # warn for possible updates
       
   120         def updateinfoproc():
       
   121             global updateinfo
       
   122             try :
       
   123                 import urllib2
       
   124                 updateinfo = urllib2.urlopen(updateinfo_url,None).read()
       
   125             except :
       
   126                 updateinfo = _("update info unavailable.")
       
   127 
       
   128         from threading import Thread
       
   129         splash.SetText(text=updateinfo)
       
   130         wx.Yield()
       
   131         updateinfoThread = Thread(target=updateinfoproc)
       
   132         updateinfoThread.start()
       
   133         updateinfoThread.join(2)
       
   134         splash.SetText(text=updateinfo)
       
   135         wx.Yield()
       
   136 
       
   137     # Load extensions
       
   138     for extfilename in extensions:
       
   139         from util.TranslationCatalogs import AddCatalog
       
   140         from util.BitmapLibrary import AddBitmapFolder
       
   141         extension_folder = os.path.split(os.path.realpath(extfilename))[0]
       
   142         sys.path.append(extension_folder)
       
   143         AddCatalog(os.path.join(extension_folder, "locale"))
       
   144         AddBitmapFolder(os.path.join(extension_folder, "images"))
       
   145         execfile(extfilename, locals())
       
   146 
    40 
   147 
    41 
   148 import wx.lib.buttons, wx.lib.statbmp, wx.stc
    42 import wx.lib.buttons, wx.lib.statbmp, wx.stc
   149 import cPickle
    43 import cPickle
   150 import types, time, re, platform, time, traceback, commands
    44 import types, time, re, platform, time, traceback, commands
  1279                 raise
  1173                 raise
  1280             except:
  1174             except:
  1281                 sys.excepthook(*sys.exc_info())
  1175                 sys.excepthook(*sys.exc_info())
  1282         self.run = run_with_except_hook
  1176         self.run = run_with_except_hook
  1283     threading.Thread.__init__ = init
  1177     threading.Thread.__init__ = init
  1284 
       
  1285 if __name__ == '__main__':
       
  1286     # Install a exception handle for bug reports
       
  1287     logpath = tempfile.gettempdir()+os.sep+'Beremiz'
       
  1288     AddExceptHook(logpath ,version.app_version)
       
  1289 
       
  1290     frame = Beremiz(None, projectOpen, buildpath)
       
  1291     if splash:
       
  1292         splash.Close()
       
  1293     frame.Show()
       
  1294     app.MainLoop()