2001-10-18 16:41:33 -04:00
|
|
|
# demo for ErrorDialogs.py
|
|
|
|
# usual wxWindows license stuff here.
|
|
|
|
# by Chris Fama, with thanks to Robin Dunn, and others on the wxPython-users
|
|
|
|
# mailing list.
|
2003-12-08 20:23:28 -05:00
|
|
|
#
|
|
|
|
# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o Updated for wx namespace
|
|
|
|
#
|
|
|
|
# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o Looks like we have issues until the library is updated.
|
|
|
|
# - Had to rename back to wx* naming conventions
|
|
|
|
# - Getting unusual failures in the library itself when that is done.
|
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import wx
|
|
|
|
import wx.lib.ErrorDialogs as edlg
|
2001-10-18 16:41:33 -04:00
|
|
|
|
|
|
|
_debug = 0
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2001-11-12 22:09:28 -05:00
|
|
|
ID_TEXT = 10000
|
|
|
|
ID_BUTTON_wxPyNonFatalError = 10001
|
|
|
|
ID_BUTTON_wxPyFatalError = 10002
|
|
|
|
ID_BUTTON_wxPyFatalErrorDialog = 10003
|
|
|
|
ID_BUTTON_wxPyNonFatalErrorDialog = 10004
|
|
|
|
ID_BUTTON_wxPyFatalErrorDialogWithTraceback = 10005
|
|
|
|
ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback = 10006
|
2001-10-18 16:41:33 -04:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
def ErrorDialogsDemoPanelFunc( parent, call_fit = True, set_sizer = True ):
|
2003-12-08 20:23:28 -05:00
|
|
|
item0 = wx.BoxSizer( wx.VERTICAL )
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item1 = wx.StaticText(
|
|
|
|
parent, ID_TEXT,
|
|
|
|
"Please select one of the buttons below for an example using explicit errors..."
|
|
|
|
)
|
|
|
|
|
|
|
|
item0.AddWindow( item1, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
2001-10-18 16:41:33 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item2 = wx.FlexGridSizer( 0, 2, 0, 0 )
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item3 = wx.Button( parent, ID_BUTTON_wxPyNonFatalError, "wxPyNonFatalError")
|
|
|
|
item2.AddWindow( item3, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
2001-10-18 16:41:33 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item4 = wx.Button( parent, ID_BUTTON_wxPyFatalError, "wxPyFatalError")
|
|
|
|
item2.AddWindow( item4, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
2001-10-18 16:41:33 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item0.AddSizer( item2, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
2001-10-18 16:41:33 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item5 = wx.StaticText( parent, ID_TEXT, "Please select one of the buttons below for interpreter errors...")
|
|
|
|
item0.AddWindow( item5, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
2001-11-12 22:09:28 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item6 = wx.FlexGridSizer( 0, 2, 0, 0 )
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item7 = wx.Button( parent, ID_BUTTON_wxPyFatalErrorDialog, "wxPyFatalErrorDialog")
|
|
|
|
item6.AddWindow( item7, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
2001-11-12 22:09:28 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item8 = wx.Button( parent, ID_BUTTON_wxPyNonFatalErrorDialog, "wxPyNonFatalErrorDialog")
|
|
|
|
item6.AddWindow( item8, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
2001-11-12 22:09:28 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item9 = wx.Button(
|
|
|
|
parent, ID_BUTTON_wxPyFatalErrorDialogWithTraceback,
|
|
|
|
"wxPyFatalErrorDialogWithTraceback"
|
|
|
|
)
|
|
|
|
item6.AddWindow( item9, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
2001-11-12 22:09:28 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item10 = wx.Button(
|
|
|
|
parent, ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback,
|
|
|
|
"wxPyNonFatalErrorDialogWithTraceback"
|
|
|
|
)
|
2001-11-12 22:09:28 -05:00
|
|
|
item10.SetDefault()
|
2003-12-08 20:23:28 -05:00
|
|
|
item6.AddWindow( item10, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
2001-11-12 22:09:28 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item0.AddSizer( item6, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
2001-11-12 22:09:28 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item11 = wx.FlexGridSizer( 0, 2, 0, 0 )
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
item0.AddSizer( item11, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
2001-11-12 22:09:28 -05:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
if set_sizer == True:
|
|
|
|
parent.SetAutoLayout( True )
|
2001-10-18 16:41:33 -04:00
|
|
|
parent.SetSizer( item0 )
|
2003-03-25 01:35:27 -05:00
|
|
|
if call_fit == True:
|
2001-10-18 16:41:33 -04:00
|
|
|
item0.Fit( parent )
|
|
|
|
item0.SetSizeHints( parent )
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2001-10-18 16:41:33 -04:00
|
|
|
return item0
|
|
|
|
|
2001-11-12 22:09:28 -05:00
|
|
|
# Menu bar functions
|
|
|
|
|
|
|
|
# Bitmap functions
|
|
|
|
|
|
|
|
|
|
|
|
# End of generated file
|
2001-10-18 16:41:33 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class MyPanel(wx.Panel):
|
2001-10-18 16:41:33 -04:00
|
|
|
def __init__(self,parent=None):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self,parent,-1)
|
|
|
|
|
2001-10-18 16:41:33 -04:00
|
|
|
args = (None, -1)
|
|
|
|
kwargs = {
|
|
|
|
'programname': "sumthing",
|
|
|
|
'mailto': "me@sumwear",
|
2003-12-08 20:23:28 -05:00
|
|
|
'whendismissed': "from wxPython.wx import * ; wxBell()"
|
|
|
|
}
|
|
|
|
|
2001-10-18 16:41:33 -04:00
|
|
|
self.dialogs = map(apply,
|
2003-12-08 20:23:28 -05:00
|
|
|
[edlg.wxPyNonFatalErrorDialogWithTraceback,
|
|
|
|
edlg.wxPyNonFatalErrorDialog,#WithTraceback
|
|
|
|
edlg.wxPyFatalErrorDialogWithTraceback,
|
|
|
|
edlg.wxPyFatalErrorDialog #WithTraceback
|
|
|
|
],
|
2001-10-18 16:41:33 -04:00
|
|
|
(args,) * 4,
|
2003-12-08 20:23:28 -05:00
|
|
|
(kwargs,) * 4
|
|
|
|
)
|
2001-10-18 16:41:33 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
ErrorDialogsDemoPanelFunc(self)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.DoDialog, id=ID_BUTTON_wxPyFatalErrorDialog)
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.DoDialog, id=ID_BUTTON_wxPyNonFatalError)
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.DoDialog, id=ID_BUTTON_wxPyFatalError)
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.DoDialog, id=ID_BUTTON_wxPyFatalErrorDialogWithTraceback)
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.DoDialog, id=ID_BUTTON_wxPyNonFatalErrorDialog)
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.DoDialog, id=ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2001-10-18 16:41:33 -04:00
|
|
|
IndexFromID = {
|
|
|
|
ID_BUTTON_wxPyFatalErrorDialog: 3,
|
|
|
|
ID_BUTTON_wxPyFatalErrorDialogWithTraceback: 2,
|
|
|
|
ID_BUTTON_wxPyNonFatalErrorDialog: 1,
|
|
|
|
ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback: 0
|
|
|
|
}
|
|
|
|
|
|
|
|
def DoDialog(self,event):
|
2001-11-12 22:09:28 -05:00
|
|
|
id = event.GetId()
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2001-11-12 22:09:28 -05:00
|
|
|
if id in [ID_BUTTON_wxPyFatalError,ID_BUTTON_wxPyNonFatalError]:
|
|
|
|
if id == ID_BUTTON_wxPyFatalError:
|
|
|
|
print "%s.DoDialog(): testing explicit wxPyFatalError..."\
|
|
|
|
% self
|
2003-12-08 20:23:28 -05:00
|
|
|
edlg.wxPyFatalError(self,"Test Non-fatal error.<p>"
|
2001-11-12 22:09:28 -05:00
|
|
|
"Nearly arbitrary HTML (i.e., that which is"
|
|
|
|
" understood by <B><I>wxHtmlWindow</i></b>)."
|
|
|
|
"<p><table border=\"2\"><tr><td>This</td><td>is</td></tr>"
|
|
|
|
"<tr><td>a</td><td>table</td></tr></table></p>")
|
|
|
|
else:
|
|
|
|
print "%s.DoDialog(): testing explicit wxPyNonFatalError..."\
|
|
|
|
% self
|
2003-12-08 20:23:28 -05:00
|
|
|
edlg.wxPyNonFatalError(self,"Test Non-fatal error.<p>"
|
2001-11-12 22:09:28 -05:00
|
|
|
"Nearly arbitrary HTML (i.e., that which is"
|
|
|
|
" understood by <B><I>wxHtmlWindow</i></b>)."
|
|
|
|
"<p><table border=\"2\"><tr><td>This</td><td>is</td></tr>"
|
|
|
|
"<tr><td>a</td><td>table</td></tr></table></p>")
|
|
|
|
else:
|
|
|
|
sys.stderr = self.dialogs[self.IndexFromID[id]]
|
|
|
|
print "%s.DoDialog(): testing %s..." % (self,sys.stderr)
|
|
|
|
this_will_generate_a_NameError_exception
|
2001-10-18 16:41:33 -04:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
def ShutdownDemo(self):
|
2001-10-18 16:41:33 -04:00
|
|
|
for d in self.dialogs:
|
2003-03-25 01:35:27 -05:00
|
|
|
d.Destroy()
|
|
|
|
|
|
|
|
|
2001-10-18 16:41:33 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class MyFrame(wx.Frame):
|
2001-10-18 16:41:33 -04:00
|
|
|
def __init__(self,parent=None):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Frame.__init__(self,parent,-1,
|
2001-10-18 16:41:33 -04:00
|
|
|
"Please make a selection...",
|
|
|
|
)
|
2003-12-08 20:23:28 -05:00
|
|
|
self.panel = MyPanel(self)
|
|
|
|
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
2001-10-18 16:41:33 -04:00
|
|
|
|
|
|
|
def OnCloseWindow(self,event):
|
|
|
|
self.panel.Close()
|
|
|
|
self.Destroy()
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class MyApp(wx.App):
|
2001-10-18 16:41:33 -04:00
|
|
|
def OnInit(self):
|
|
|
|
frame = MyFrame()
|
2003-03-25 01:35:27 -05:00
|
|
|
frame.Show(True)
|
2001-10-18 16:41:33 -04:00
|
|
|
self.SetTopWindow(frame)
|
2003-03-25 01:35:27 -05:00
|
|
|
return True
|
2001-10-18 16:41:33 -04:00
|
|
|
|
|
|
|
def runTest(pframe, nb, log):
|
|
|
|
panel = MyPanel(nb)
|
|
|
|
return panel
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
edlg._debug = 1
|
2001-10-18 16:41:33 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2003-12-08 20:23:28 -05:00
|
|
|
sys.stderr = edlg.wxPyNonWindowingErrorHandler()
|
2001-10-18 16:41:33 -04:00
|
|
|
app = MyApp(0)
|
|
|
|
app.MainLoop()
|
|
|
|
sys.exit()
|
|
|
|
else:
|
2003-12-08 20:23:28 -05:00
|
|
|
overview = edlg.__doc__
|