1 # demo for ErrorDialogs.py 
   2 # usual wxWindows license stuff here. 
   3 # by Chris Fama, with thanks to Robin Dunn, and others on the wxPython-users 
   6 # 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net) 
   8 # o Updated for wx namespace 
  10 # 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net) 
  12 # o Looks like we have issues until the library is updated. 
  13 #   - Had to rename back to wx* naming conventions 
  14 #   - Getting unusual failures in the library itself when that is done. 
  20 import  wx
.lib
.ErrorDialogs 
as  edlg
 
  25 ID_BUTTON_wxPyNonFatalError 
= 10001 
  26 ID_BUTTON_wxPyFatalError 
= 10002 
  27 ID_BUTTON_wxPyFatalErrorDialog 
= 10003 
  28 ID_BUTTON_wxPyNonFatalErrorDialog 
= 10004 
  29 ID_BUTTON_wxPyFatalErrorDialogWithTraceback 
= 10005 
  30 ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback 
= 10006 
  32 def ErrorDialogsDemoPanelFunc( parent
, call_fit 
= True, set_sizer 
= True ): 
  33     item0 
= wx
.BoxSizer( wx
.VERTICAL 
) 
  35     item1 
= wx
.StaticText( 
  37         "Please select one of the buttons below for an example using explicit errors..." 
  40     item0
.AddWindow( item1
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 ) 
  42     item2 
= wx
.FlexGridSizer( 0, 2, 0, 0 ) 
  44     item3 
= wx
.Button( parent
, ID_BUTTON_wxPyNonFatalError
, "wxPyNonFatalError") 
  45     item2
.AddWindow( item3
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 ) 
  47     item4 
= wx
.Button( parent
, ID_BUTTON_wxPyFatalError
, "wxPyFatalError") 
  48     item2
.AddWindow( item4
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 ) 
  50     item0
.AddSizer( item2
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 ) 
  52     item5 
= wx
.StaticText( parent
, ID_TEXT
, "Please select one of the buttons below for interpreter errors...") 
  53     item0
.AddWindow( item5
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 ) 
  55     item6 
= wx
.FlexGridSizer( 0, 2, 0, 0 ) 
  57     item7 
= wx
.Button( parent
, ID_BUTTON_wxPyFatalErrorDialog
, "wxPyFatalErrorDialog") 
  58     item6
.AddWindow( item7
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 ) 
  60     item8 
= wx
.Button( parent
, ID_BUTTON_wxPyNonFatalErrorDialog
, "wxPyNonFatalErrorDialog") 
  61     item6
.AddWindow( item8
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 ) 
  64         parent
, ID_BUTTON_wxPyFatalErrorDialogWithTraceback
,  
  65         "wxPyFatalErrorDialogWithTraceback" 
  67     item6
.AddWindow( item9
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 ) 
  70         parent
, ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback
,  
  71         "wxPyNonFatalErrorDialogWithTraceback" 
  74     item6
.AddWindow( item10
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 ) 
  76     item0
.AddSizer( item6
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 ) 
  78     item11 
= wx
.FlexGridSizer( 0, 2, 0, 0 ) 
  80     item0
.AddSizer( item11
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 ) 
  83         parent
.SetAutoLayout( True ) 
  84         parent
.SetSizer( item0 
) 
  87             item0
.SetSizeHints( parent 
) 
  96 # End of generated file 
  98 class MyPanel(wx
.Panel
): 
  99     def __init__(self
,parent
=None): 
 100         wx
.Panel
.__init
__(self
,parent
,-1) 
 104             'programname': "sumthing", 
 105             'mailto': "me@sumwear", 
 106             'whendismissed': "from wxPython.wx import * ; wxBell()" 
 109         self
.dialogs 
= map(apply, 
 110                            [edlg
.wxPyNonFatalErrorDialogWithTraceback
, 
 111                             edlg
.wxPyNonFatalErrorDialog
,#WithTraceback 
 112                             edlg
.wxPyFatalErrorDialogWithTraceback
, 
 113                             edlg
.wxPyFatalErrorDialog 
#WithTraceback 
 119         ErrorDialogsDemoPanelFunc(self
) 
 121         self
.Bind(wx
.EVT_BUTTON
, self
.DoDialog
, id=ID_BUTTON_wxPyFatalErrorDialog
) 
 122         self
.Bind(wx
.EVT_BUTTON
, self
.DoDialog
, id=ID_BUTTON_wxPyNonFatalError
) 
 123         self
.Bind(wx
.EVT_BUTTON
, self
.DoDialog
, id=ID_BUTTON_wxPyFatalError
) 
 124         self
.Bind(wx
.EVT_BUTTON
, self
.DoDialog
, id=ID_BUTTON_wxPyFatalErrorDialogWithTraceback
) 
 125         self
.Bind(wx
.EVT_BUTTON
, self
.DoDialog
, id=ID_BUTTON_wxPyNonFatalErrorDialog
) 
 126         self
.Bind(wx
.EVT_BUTTON
, self
.DoDialog
, id=ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback
) 
 129         ID_BUTTON_wxPyFatalErrorDialog
: 3, 
 130         ID_BUTTON_wxPyFatalErrorDialogWithTraceback
: 2, 
 131         ID_BUTTON_wxPyNonFatalErrorDialog
: 1, 
 132         ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback
: 0 
 135     def DoDialog(self
,event
): 
 138         if id in [ID_BUTTON_wxPyFatalError
,ID_BUTTON_wxPyNonFatalError
]: 
 139             if id == ID_BUTTON_wxPyFatalError
: 
 140                 print "%s.DoDialog(): testing explicit wxPyFatalError..."\
 
 142                 edlg
.wxPyFatalError(self
,"Test Non-fatal error.<p>" 
 143                                "Nearly arbitrary HTML (i.e., that which is" 
 144                                " understood by <B><I>wxHtmlWindow</i></b>)." 
 145                                "<p><table border=\"2\"><tr><td>This</td><td>is</td></tr>" 
 146                                "<tr><td>a</td><td>table</td></tr></table></p>") 
 148                 print "%s.DoDialog(): testing explicit wxPyNonFatalError..."\
 
 150                 edlg
.wxPyNonFatalError(self
,"Test Non-fatal error.<p>" 
 151                                   "Nearly arbitrary HTML (i.e., that which is" 
 152                                   " understood by <B><I>wxHtmlWindow</i></b>)." 
 153                                   "<p><table border=\"2\"><tr><td>This</td><td>is</td></tr>" 
 154                                   "<tr><td>a</td><td>table</td></tr></table></p>") 
 156             sys
.stderr 
= self
.dialogs
[self
.IndexFromID
[id]] 
 157             print "%s.DoDialog(): testing %s..." % (self
,sys
.stderr
) 
 158             this_will_generate_a_NameError_exception
 
 160     def ShutdownDemo(self
): 
 161         for d 
in self
.dialogs
: 
 166 class MyFrame(wx
.Frame
): 
 167     def __init__(self
,parent
=None): 
 168         wx
.Frame
.__init
__(self
,parent
,-1, 
 169                          "Please make a selection...", 
 171         self
.panel 
= MyPanel(self
) 
 172         self
.Bind(wx
.EVT_CLOSE
, self
.OnCloseWindow
) 
 174     def OnCloseWindow(self
,event
): 
 182         self
.SetTopWindow(frame
) 
 185 def runTest(pframe
, nb
, log
): 
 191 if __name__ 
== "__main__": 
 192     sys
.stderr 
= edlg
.wxPyNonWindowingErrorHandler() 
 197     overview 
= edlg
.__doc
__