Splash screen (Phoenix)

Keywords : SplashScreen, Bitmap, Timeout.


Introduction

Most GUI programs display a splash screen before launching real applications.

This snippet demonstrates the basics of how to use a wx.adv.SplashScreen in an application.


What Objects are Involved


Special Concerns

A JPEG image named "wxPyWiki.jpg" must exist in the working directory.


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


Splash screen

img_sample_one.png

ICON file : icon_wxWidgets.ico

IMAGE file : wxPyWiki.jpg

   1 # sample_one.py
   2 
   3 """
   4 This is a minimal wxPython program to show a SplashScreen widget.
   5 """
   6 
   7 import wx
   8 from   wx.adv import SplashScreen as SplashScreen
   9 
  10 # class MyGui
  11 # class MySplashScreen
  12 # class MyApp
  13 
  14 #---------------------------------------------------------------------------
  15 
  16 class MyGui(wx.Frame):
  17     """
  18     Hello World!
  19     """
  20     def __init__(self, parent, id, title):
  21         wx.Frame.__init__(self, parent, id, title)
  22 
  23         #------------
  24 
  25         frameicon = wx.Icon("icon_wxWidgets.ico")
  26         self.SetIcon(frameicon)
  27 
  28         #------------
  29 
  30         # Put more GUI code here for a fancier application.
  31         self.panel = wx.Panel(self, -1)
  32 
  33         #------------
  34 
  35         # MainSizer is the top-level one that manages everything.
  36         mainSizer = wx.BoxSizer(wx.VERTICAL)
  37 
  38         # Finally, tell the panel to use the sizer for layout.
  39         self.panel.SetAutoLayout(True)
  40         self.panel.SetSizer(mainSizer)
  41 
  42         mainSizer.Fit(self.panel)
  43 
  44 #---------------------------------------------------------------------------
  45 
  46 class MySplashScreen(SplashScreen):
  47     """
  48     Create a splash screen widget.
  49     """
  50     def __init__(self, parent=None):
  51 
  52         #------------
  53 
  54         # This is a recipe to a the screen.
  55         # Modify the following variables as necessary.
  56         bitmap = wx.Bitmap(name="wxPyWiki.jpg", type=wx.BITMAP_TYPE_JPEG)
  57         splash = wx.adv.SPLASH_CENTRE_ON_SCREEN | wx.adv.SPLASH_TIMEOUT
  58         duration = 3000 # milliseconds
  59 
  60         # Call the constructor with the above arguments
  61         # in exactly the following order.
  62         super(MySplashScreen, self).__init__(bitmap=bitmap,
  63                                              splashStyle=splash,
  64                                              milliseconds=duration,
  65                                              parent=None,
  66                                              id=-1,
  67                                              pos=wx.DefaultPosition,
  68                                              size=wx.DefaultSize,
  69                                              style=wx.STAY_ON_TOP |
  70                                                    wx.BORDER_NONE)
  71 
  72         self.Bind(wx.EVT_CLOSE, self.OnExit)
  73 
  74     #-----------------------------------------------------------------------
  75 
  76     def OnExit(self, event):
  77         """
  78         ...
  79         """
  80 
  81         # The program will freeze without this line.
  82         event.Skip()  # Make sure the default handler runs too...
  83         self.Hide()
  84 
  85         #------------
  86 
  87         # MyFrame is the main frame.
  88         MyFrame = MyGui(None, -1, "Hello from wxPython")
  89         MyFrame.CenterOnScreen(wx.BOTH)
  90         MyFrame.Show(True)
  91 
  92 #---------------------------------------------------------------------------
  93 
  94 class MyApp(wx.App):
  95     """
  96     ...
  97     """
  98     def OnInit(self):
  99 
 100         #------------
 101 
 102         MySplash = MySplashScreen()
 103         MySplash.CenterOnScreen(wx.BOTH)
 104         MySplash.Show(True)
 105 
 106         return True
 107 
 108 #---------------------------------------------------------------------------
 109 
 110 def main():
 111     app = MyApp(redirect=True, filename = "demo.log")
 112     app.MainLoop()
 113 
 114 #---------------------------------------------------------------------------
 115 
 116 if __name__ == "__main__" :
 117     main()


Download source

source.zip


Additional Information

Link :

https://www.blog.pythonlibrary.org/2018/09/

https://wiki.wxpython.org/Splash%20screen%20while%20loading%20%28Phoenix%29

https://wiki.wxpython.org/Customized%20splash%20screen%20%28Phoenix%29

https://stackoverflow.com/questions/12181185/wxpython-and-splash-screen

https://stackoverflow.com/questions/9435498/wxpython-splash-screen-trouble

http://wxpython-users.1045709.n5.nabble.com/Splash-Screen-td2368727.html

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Tian Xie (sample_one.py coding) and the wxPython community...


About this page

Date (d/m/y) Person (bot) Comments :

03/05/05 - Tian Xie (Originally created).

08/05/18 - Ecco (Updated example and page for wxPython Phoenix).


Comments

- Please test this program on other platforms or versions. If it doesn't work, find a fix and correct it here. Thanks.

- Although this example will work fine, it overlooks the main reason programmers add a splash screen ;

to give the user feedback while a program is loading.

- blah, blah, blah...

Splash screen (Phoenix) (last edited 2019-08-31 13:55:14 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.