Coverage for larch/wxxas/larix_app.py: 42%
50 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-10-16 21:04 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2024-10-16 21:04 +0000
1import time
2import sys
3import locale
4from threading import Thread
5from pathlib import Path
6import wx
7import wx.adv, wx.richtext
8from wx.lib.mixins.inspection import InspectionMixin
10from larch.site_config import icondir
12LARIX_TITLE = "Larix: XAS Visualization and Analysis"
13ICON_FILE = 'onecone.ico'
14SPLASH_STYLE = wx.adv.SPLASH_CENTRE_ON_SCREEN|wx.adv.SPLASH_TIMEOUT
16class LarixApp(wx.App, InspectionMixin):
17 def __init__(self, _larch=None, filename=None, check_version=True,
18 mode='xas', with_c_locale=True, with_wx_inspect=False, **kws):
19 self._larch = _larch
20 self.filename = filename
21 self.mode = mode
22 self.with_c_locale = with_c_locale
23 self.with_wx_inspect = with_wx_inspect
24 self.check_version = check_version
25 wx.App.__init__(self,**kws)
27 def OnInit(self):
28 wx.SystemOptions.SetOption("mac.window-plain-transition", 1)
29 LarixSplashScreen(filename=self.filename,
30 check_version=self.check_version,
31 mode=self.mode,
32 with_wx_inspect=self.with_wx_inspect)
33 return True
35 def createApp(self):
36 return True
38 def InitLocale(self):
39 """over-ride wxPython default initial locale"""
40 if self.with_c_locale:
41 self._initial_locale = None
42 locale.setlocale(locale.LC_ALL, 'C')
43 else:
44 lang, enc = locale.getdefaultlocale()
45 self._initial_locale = wx.Locale(lang, lang[:2], lang)
46 locale.setlocale(locale.LC_ALL, lang)
48class LarixSplashScreen(wx.adv.SplashScreen):
49 def __init__(self, **kws):
50 self.kws = kws
51 bmp = wx.Image(Path(icondir, ICON_FILE).as_posix()).ConvertToBitmap()
52 wx.adv.SplashScreen.__init__(self, bmp, SPLASH_STYLE, 9000, None, -1)
53 self.import_thread = Thread(target=self.importer)
54 self.import_thread.start()
55 wx.CallAfter(self.ShowMain)
57 def importer(self, evt=None):
58 from larch.wxxas.xasgui import LarixFrame
60 def ShowMain(self):
61 self.import_thread.join()
62 from larch.wxxas.xasgui import LarixFrame
63 self.frame = LarixFrame(**self.kws)
64 wx.GetApp().SetTopWindow(self.frame)
65 return True