Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 30th, 2004, 05:39 PM
lentyaka lentyaka is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 6 lentyaka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
splash screen in wxPython

Hello,

does someone know if it is possible to create 'end' splash screen in wxPython that is outside of mainloop()? By 'end' splash screen i mean a little picture that displays 'thank you' message after the user closed the app.
I have no problem displaying 'welcome' splash screen when mainloop() is called. But what to do when i need splash screen after mainloop()????

Thank you

Reply With Quote
  #2  
Old March 31st, 2004, 12:30 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
After the application mainloop() returns just create a new window and call it's mainloop() method:
Code:
if __name__ == '__main__':
    from wxPython.wx import *
    from wxPython.lib.anchors import LayoutAnchors
    
    class MyApp(wxApp):
        def OnInit(self):
            self.frame = wxFrame(NULL, -1, "Hello from wxPython")
            self.frame.Show(true)
            self.SetTopWindow(self.frame)
            return true
        
    class SplashApp(wxApp):
        def OnInit(self):
            self.frame = wxFrame(NULL, -1, "Splash with wxPython")
            self.frame.Show(true)
            self.SetTopWindow(self.frame)
            return true
    
    app = MyApp(0)
    app.MainLoop()
    app = SplashApp(0)
    app.MainLoop()    

__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
  #3  
Old March 31st, 2004, 02:50 PM
lentyaka lentyaka is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 6 lentyaka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mmm,
it causes the program to hang, i have to 'stop execution', since it fails to respond. can you explain a bit more please.

thank you for ur help

Reply With Quote
  #4  
Old March 31st, 2004, 04:28 PM
lentyaka lentyaka is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 6 lentyaka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i guess what i am asking is:
is it possible to display splash screen before the mainloop is entered?

Thanx.

Reply With Quote
  #5  
Old April 1st, 2004, 01:54 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
Here is a modified version of my example that shows the second window closing automiatically after 5 seconds:
Code:
if __name__ == '__main__': 
    from wxPython.wx import *
    from wxPython.lib.anchors import LayoutAnchors
    
    class MyApp(wxApp): 
        def OnInit(self): 
            self.frame = wxFrame(NULL, -1, "Hello from wxPython")
            self.frame.Show(true)
            self.SetTopWindow(self.frame)
            return true
        
    class SplashApp(wxApp): 
        def OnInit(self): 
            self.frame = wxFrame(NULL, -1, "Splash with wxPython")
            self.frame.Show(true)
            self.SetTopWindow(self.frame)
            return true

        def end(self, evt): 
            self.frame.Destroy()
    
    app = MyApp(0)
    app.MainLoop()
    sApp = SplashApp(0)
    ID_Timer = wxNewId()
    timer = wxTimer(sApp, ID_Timer)
    EVT_TIMER(sApp, ID_Timer, sApp.end)
    timer.Start(5000)
    sApp.MainLoop()


An alternative is to handle the main app exit event, hide the main frame, pop up a dialog for a few seconds then carry on the normal exit. If I have time I'll post an example.

Grim

Reply With Quote
  #6  
Old April 1st, 2004, 02:05 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
Here the timeout is contained in the splash:
Code:
    class SplashApp(wxApp): 
        def OnInit(self): 
            self.frame = wxFrame(NULL, -1, "Splash with wxPython")
            self.frame.Show(true)
            self.SetTopWindow(self.frame)
            self.ID_Timer = wxNewId()
            self.timer = wxTimer(self, self.ID_Timer)
            EVT_TIMER(self, self.ID_Timer, self.end)
            self.timer.Start(5000)
            return true

        def end(self, evt): 
            self.frame.Destroy()
    
    app = MyApp(0)
    app.MainLoop()
    sApp = SplashApp(0)
    sApp.MainLoop()

Reply With Quote
  #7  
Old April 1st, 2004, 03:07 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
This splash dialog gets called when the main app is closed. The user can wait 5 seconds or he can click the OK button.
Code:
from wxPython.wx import *
from wxPython.lib.anchors import LayoutAnchors

#This dialog shows as normal but after 5 seconds it closes automatically
class SplashDialog(wxDialog): 
    def __init__(self, fparent, ID, title='Splash', 
                 line1='Line 1', 
                 line2='Line 2', 
                 pos=wxDefaultPosition, size=wxDefaultSize, 
                 style=wxDEFAULT_DIALOG_STYLE): 
        wxDialog.__init__(self, id = 1, name = '', parent = fparent, 
              pos = wxPoint(413, 268), size = wxSize(416, 262), 
              title = title)
        sizer = wxBoxSizer(wxVERTICAL)
        label = wxStaticText(self, -1, line1)
        sizer.Add(label, 0, wxALIGN_CENTRE|wxALL, 5)
        label = wxStaticText(self, -1, line2)
        sizer.Add(label, 0, wxALIGN_CENTRE|wxALL, 5)
        btn = wxButton(self, wxID_OK, " OK ")
        btn.SetDefault()
        sizer.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5)
        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        sizer.Fit(self)
        #build the timeout event
        self.ID_Timer = wxNewId()
        self.timer = wxTimer(self, self.ID_Timer)
        EVT_TIMER(self, self.ID_Timer, self.end)
        self.timer.Start(5000)

    def end(self, evt): 
        #This is the event handler assigned to our timer
        self.Destroy()

if __name__ == '__main__': 

    #an appllcation created just to show the splash dialog 
    class MyApp(wxApp): 
        def OnInit(self): 
            self.frame = wxFrame(NULL, -1, "Splash Demo")
            self.frame.Show(true)
            self.SetTopWindow(self.frame)
            
            #Handle the window closing event
            EVT_CLOSE(self.frame, self.appClose)
            return true
        
        def appClose(self, evt): 
            #Hide the main window then bring up the splash dialog
            self.frame.Show(false)
            dlg = SplashDialog(self.frame, -1, "Splash down!!", 
                               "Don't forget to mail me at\n me@mine.org!", 
                               "See more at www.python.org", 
                               size = wxSize(350, 200), 
                     style = wxDEFAULT_DIALOG_STYLE)
            dlg.ShowModal()
            #let wxWindows do its stuff and delete things
            evt.Skip()
    #create an instance of MyApp
    app = MyApp(0)
    #Now service the GUI events
    app.MainLoop()

Not the tidiest code but it works

Grim

Last edited by Grim Archon : April 1st, 2004 at 03:19 AM. Reason: Added a few comments

Reply With Quote
  #8  
Old April 1st, 2004, 05:15 PM
lentyaka lentyaka is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 6 lentyaka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thank you
u r the best

Reply With Quote
  #9  
Old April 2nd, 2004, 05:34 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
Quote:
Originally Posted by lentyaka
thank you
u r the best

Just a bit of fun
Here's a version that uses HTML to render the content, I've also added extra configuration for the window (timeout, fullscreen enable, okay button display).
Code:
from wxPython.wx import *
from wxPython.html import *
'''This Module defines a wxPython Splash dialog with HTML rendering and many options.

SplashDialog(parent,ID,title,page,fullscreen,showok,timeout,pos,size,style)
    parent = parent wxApp
    ID = Frame ID (use -1)
    title = sring Title of window
    page = string HTML to be shown
    fullscreen = Boolean flag, if true show full screen
    showok = Boolean flag, if true Display OK button
    timeout = In mille seconds, if 0 don't timeout.
    pos = Location on screen (use wxSize)
    size = Size of inner HTML window (dialog shrinks to fit)
    style = wxWindows style
    #This dialog shows as normal but after 5 seconds it closes automatically

Run this module to see two examples - Application start and Application close.
'''

class SplashDialog(wxDialog): 
    
    def __init__(self, parent, ID, title='Splash', 
                 page='<html><body><b>Hello, world!</b></body></html>', 
                 fullscreen=False, 
                 showok=True, 
                 timeout=5000, 
                 pos=wxDefaultPosition, size=wxDefaultSize, 
                 style=wxDEFAULT_DIALOG_STYLE): 
        
        wxDialog.__init__(self, id = 1, name = '', parent = parent, 
              pos = pos, size = size, title = title)
        sizer = wxBoxSizer(wxVERTICAL)
        self.panel = wxHtmlWindow(self, -1, size = size)
        self.panel.SetPage(page)
        sizer.Add(self.panel, 1, wxEXPAND, 0)
        if showok: 
            btn = wxButton(self, wxID_OK, " OK ")
            btn.SetDefault()
            sizer.Add(btn, 0, wxEXPAND, 0)
        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        sizer.Fit(self)
        #build the timeout event
        if timeout > 0: 
            self.ID_Timer = wxNewId()
            self.timer = wxTimer(self, self.ID_Timer)
            EVT_TIMER(self, self.ID_Timer, self.end)
            self.timer.Start(timeout)
        if fullscreen: 
            self.ShowFullScreen(true)

    def end(self, evt): 
        #This is the event handler assigned to our timer
        self.Destroy()
        
sample = '''<center><br><br>
Some content:
<pre  style="background: #EFEFEF;color: #000000; font-size: 8pt; font-weight: normal; font-style: normal; font-variant: normal;margin:0px; padding:6px; border:1px inset;  overflow:auto">        <font color="orange">def</font><font color="blue"> appClose</font>(self, evt): 
            <font color="red">#Hide the main window then bring up the splash dialog
</font>            self.frame.Show(false)
            dlg = SplashDialog(self.frame, -1, <font color="green">"Splash down!!"</font>, 
                               showok = True, 
                               fullscreen = False, 
                               timeout = 10000, 
                               size = wxSize(300, 300), 
                     style = wxDEFAULT_DIALOG_STYLE)
            dlg.ShowModal()
</pre><br>This window will not timeout</center>
<FONT SIZE=+3>
<center><a href="http://www.python.org/">>This is a link to Python's Home<</a></font><br></center>
'''
if __name__ == '__main__': 

    #an appllcation created just to show the splash dialog 
    class MyApp(wxApp): 
        def OnInit(self): 
            self.frame = wxFrame(NULL, -1, "Splash Demo")
            self.frame.Show(true)
            self.SetTopWindow(self.frame)
            #Handle the window closing event
            EVT_CLOSE(self.frame, self.appClose)
            return true
        
        def appClose(self, evt): 
            #Hide the main window then bring up the splash dialog
            self.frame.Show(false)
            dlg = SplashDialog(self.frame, -1, "Splash Down!!", 
                               showok = True, 
                               page = sample, 
                               fullscreen = True, 
                               timeout = 0, 
                               size = wxSize(300, 100), 
                     style = wxDEFAULT_DIALOG_STYLE)
            dlg.ShowModal()
            #let wxWindows do its stuff and delete things
            evt.Skip()
    #create an instance of MyApp
    app = MyApp(0)
    dlg = SplashDialog(app.frame, -1, "Splash Up!!", 
                       page = '''<center><FONT COLOR="#0000FF"><FONT SIZE=+6><br><br>Welcome</FONT></FONT></center>''', 
                       fullscreen = False, 
                       timeout = 2000, 
                       showok = False, 
                       size = wxSize(600, 100), 
             style = wxDEFAULT_DIALOG_STYLE)
    dlg.ShowModal()
    #Now service the GUI events
    app.MainLoop()




Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > splash screen in wxPython

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap