= How to create a splash screen (Phoenix) =
'''Keywords :''' SplashScreen, Bitmap, Timeout.

<<TableOfContents>>

--------
= 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 =
 * '''wx.adv.SplashScreen'''

 . The purpose of this wxPyWiki.

 * '''wx.Bitmap'''

 . Used to load a splash image of some type (e.g., JPEG, etc.).

 * '''wx.Frame'''

 . Used to implement various widgets.

 * '''wx.App'''

 . Need I say more ? :)

--------
= 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 ==
{{attachment:img_sample_one.png}}

'''ICON''' file : [[attachment:icon_wxWidgets.ico]]

'''IMAGE''' file : [[attachment:wxPyWiki.jpg]]

{{{#!python
# sample_one.py

"""
This is a minimal wxPython program to show a SplashScreen widget.
"""

import wx
from   wx.adv import SplashScreen as SplashScreen

# class MyGui
# class MySplashScreen
# class MyApp

#---------------------------------------------------------------------------

class MyGui(wx.Frame):
    """
    Hello World!
    """
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)

        #------------

        frameicon = wx.Icon("icon_wxWidgets.ico")
        self.SetIcon(frameicon)

        #------------

        # Put more GUI code here for a fancier application.
        self.panel = wx.Panel(self, -1)

        #------------

        # MainSizer is the top-level one that manages everything.
        mainSizer = wx.BoxSizer(wx.VERTICAL)

        # Finally, tell the panel to use the sizer for layout.
        self.panel.SetAutoLayout(True)
        self.panel.SetSizer(mainSizer)

        mainSizer.Fit(self.panel)

#---------------------------------------------------------------------------

class MySplashScreen(SplashScreen):
    """
    Create a splash screen widget.
    """
    def __init__(self, parent=None):

        #------------

        # This is a recipe to a the screen.
        # Modify the following variables as necessary.
        bitmap = wx.Bitmap(name="wxPyWiki.jpg", type=wx.BITMAP_TYPE_JPEG)
        splash = wx.adv.SPLASH_CENTRE_ON_SCREEN | wx.adv.SPLASH_TIMEOUT
        duration = 3000 # milliseconds

        # Call the constructor with the above arguments
        # in exactly the following order.
        super(MySplashScreen, self).__init__(bitmap=bitmap,
                                             splashStyle=splash,
                                             milliseconds=duration,
                                             parent=None,
                                             id=-1,
                                             pos=wx.DefaultPosition,
                                             size=wx.DefaultSize,
                                             style=wx.STAY_ON_TOP |
                                                   wx.BORDER_NONE)

        self.Bind(wx.EVT_CLOSE, self.OnExit)

    #-----------------------------------------------------------------------

    def OnExit(self, event):
        """
        ...
        """

        # The program will freeze without this line.
        event.Skip()  # Make sure the default handler runs too...
        self.Hide()

        #------------

        # MyFrame is the main frame.
        MyFrame = MyGui(None, -1, "Hello from wxPython")
        MyFrame.CenterOnScreen(wx.BOTH)
        MyFrame.Show(True)

#---------------------------------------------------------------------------

class MyApp(wx.App):
    """
    ...
    """
    def OnInit(self):

        #------------

        MySplash = MySplashScreen()
        MySplash.CenterOnScreen(wx.BOTH)
        MySplash.Show(True)

        return True

#---------------------------------------------------------------------------

def main():
    app = MyApp(redirect=True, filename = "demo.log")
    app.MainLoop()

#---------------------------------------------------------------------------

if __name__ == "__main__" :
    main()
}}}
--------
= Download source =
[[attachment:source.zip]]

--------
= Additional Information =
'''Link :'''

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

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), 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 [[SplashScreen While Loading|feedback while a program is loading]].

- blah, blah, blah....