|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
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 ![]() |
|
#2
|
||||
|
||||
|
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 *** |
|
#3
|
|||
|
|||
|
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 ![]() |
|
#4
|
|||
|
|||
|
i guess what i am asking is:
is it possible to display splash screen before the mainloop is entered? Thanx. ![]() |
|
#5
|
||||
|
||||
|
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 ![]() |
|
#6
|
||||
|
||||
|
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()
|
|
#7
|
||||
|
||||
|
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 |
|
#8
|
|||
|
|||
|
thank you
u r the best ![]() |
|
#9
|
||||
|
||||
|
Quote:
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()
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > splash screen in wxPython |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|