]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ErrorDialogs.py
Demo updates for new wx namespace, from Jeff Grimmett
[wxWidgets.git] / wxPython / demo / ErrorDialogs.py
CommitLineData
79f1bf32
RD
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
4# mailing list.
8fa876ca
RD
5#
6# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
7#
8# o Updated for wx namespace
9#
10# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
11#
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.
15#
16
17import sys
18
19import wx
20import wx.lib.ErrorDialogs as edlg
79f1bf32 21
79f1bf32 22_debug = 0
8fa876ca 23
5e217089
RD
24ID_TEXT = 10000
25ID_BUTTON_wxPyNonFatalError = 10001
26ID_BUTTON_wxPyFatalError = 10002
27ID_BUTTON_wxPyFatalErrorDialog = 10003
28ID_BUTTON_wxPyNonFatalErrorDialog = 10004
29ID_BUTTON_wxPyFatalErrorDialogWithTraceback = 10005
30ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback = 10006
79f1bf32 31
1e4a197e 32def ErrorDialogsDemoPanelFunc( parent, call_fit = True, set_sizer = True ):
8fa876ca 33 item0 = wx.BoxSizer( wx.VERTICAL )
1e4a197e 34
8fa876ca
RD
35 item1 = wx.StaticText(
36 parent, ID_TEXT,
37 "Please select one of the buttons below for an example using explicit errors..."
38 )
39
40 item0.AddWindow( item1, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
79f1bf32 41
8fa876ca 42 item2 = wx.FlexGridSizer( 0, 2, 0, 0 )
1e4a197e 43
8fa876ca
RD
44 item3 = wx.Button( parent, ID_BUTTON_wxPyNonFatalError, "wxPyNonFatalError")
45 item2.AddWindow( item3, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
79f1bf32 46
8fa876ca
RD
47 item4 = wx.Button( parent, ID_BUTTON_wxPyFatalError, "wxPyFatalError")
48 item2.AddWindow( item4, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
79f1bf32 49
8fa876ca 50 item0.AddSizer( item2, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
79f1bf32 51
8fa876ca
RD
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 )
5e217089 54
8fa876ca 55 item6 = wx.FlexGridSizer( 0, 2, 0, 0 )
1e4a197e 56
8fa876ca
RD
57 item7 = wx.Button( parent, ID_BUTTON_wxPyFatalErrorDialog, "wxPyFatalErrorDialog")
58 item6.AddWindow( item7, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
5e217089 59
8fa876ca
RD
60 item8 = wx.Button( parent, ID_BUTTON_wxPyNonFatalErrorDialog, "wxPyNonFatalErrorDialog")
61 item6.AddWindow( item8, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
5e217089 62
8fa876ca
RD
63 item9 = wx.Button(
64 parent, ID_BUTTON_wxPyFatalErrorDialogWithTraceback,
65 "wxPyFatalErrorDialogWithTraceback"
66 )
67 item6.AddWindow( item9, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
5e217089 68
8fa876ca
RD
69 item10 = wx.Button(
70 parent, ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback,
71 "wxPyNonFatalErrorDialogWithTraceback"
72 )
5e217089 73 item10.SetDefault()
8fa876ca 74 item6.AddWindow( item10, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
5e217089 75
8fa876ca 76 item0.AddSizer( item6, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
5e217089 77
8fa876ca 78 item11 = wx.FlexGridSizer( 0, 2, 0, 0 )
1e4a197e 79
8fa876ca 80 item0.AddSizer( item11, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
5e217089 81
1e4a197e
RD
82 if set_sizer == True:
83 parent.SetAutoLayout( True )
79f1bf32 84 parent.SetSizer( item0 )
1e4a197e 85 if call_fit == True:
79f1bf32
RD
86 item0.Fit( parent )
87 item0.SetSizeHints( parent )
1e4a197e 88
79f1bf32
RD
89 return item0
90
5e217089
RD
91# Menu bar functions
92
93# Bitmap functions
94
95
96# End of generated file
79f1bf32 97
8fa876ca 98class MyPanel(wx.Panel):
79f1bf32 99 def __init__(self,parent=None):
8fa876ca
RD
100 wx.Panel.__init__(self,parent,-1)
101
79f1bf32
RD
102 args = (None, -1)
103 kwargs = {
104 'programname': "sumthing",
105 'mailto': "me@sumwear",
8fa876ca
RD
106 'whendismissed': "from wxPython.wx import * ; wxBell()"
107 }
108
79f1bf32 109 self.dialogs = map(apply,
8fa876ca
RD
110 [edlg.wxPyNonFatalErrorDialogWithTraceback,
111 edlg.wxPyNonFatalErrorDialog,#WithTraceback
112 edlg.wxPyFatalErrorDialogWithTraceback,
113 edlg.wxPyFatalErrorDialog #WithTraceback
114 ],
79f1bf32 115 (args,) * 4,
8fa876ca
RD
116 (kwargs,) * 4
117 )
79f1bf32 118
8fa876ca 119 ErrorDialogsDemoPanelFunc(self)
1e4a197e 120
8fa876ca
RD
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)
1e4a197e 127
79f1bf32
RD
128 IndexFromID = {
129 ID_BUTTON_wxPyFatalErrorDialog: 3,
130 ID_BUTTON_wxPyFatalErrorDialogWithTraceback: 2,
131 ID_BUTTON_wxPyNonFatalErrorDialog: 1,
132 ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback: 0
133 }
134
135 def DoDialog(self,event):
5e217089 136 id = event.GetId()
8fa876ca 137
5e217089
RD
138 if id in [ID_BUTTON_wxPyFatalError,ID_BUTTON_wxPyNonFatalError]:
139 if id == ID_BUTTON_wxPyFatalError:
140 print "%s.DoDialog(): testing explicit wxPyFatalError..."\
141 % self
8fa876ca 142 edlg.wxPyFatalError(self,"Test Non-fatal error.<p>"
5e217089
RD
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>")
147 else:
148 print "%s.DoDialog(): testing explicit wxPyNonFatalError..."\
149 % self
8fa876ca 150 edlg.wxPyNonFatalError(self,"Test Non-fatal error.<p>"
5e217089
RD
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>")
155 else:
156 sys.stderr = self.dialogs[self.IndexFromID[id]]
157 print "%s.DoDialog(): testing %s..." % (self,sys.stderr)
158 this_will_generate_a_NameError_exception
79f1bf32 159
1e4a197e 160 def ShutdownDemo(self):
79f1bf32 161 for d in self.dialogs:
1e4a197e
RD
162 d.Destroy()
163
164
79f1bf32 165
8fa876ca 166class MyFrame(wx.Frame):
79f1bf32 167 def __init__(self,parent=None):
8fa876ca 168 wx.Frame.__init__(self,parent,-1,
79f1bf32
RD
169 "Please make a selection...",
170 )
8fa876ca
RD
171 self.panel = MyPanel(self)
172 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
79f1bf32
RD
173
174 def OnCloseWindow(self,event):
175 self.panel.Close()
176 self.Destroy()
177
8fa876ca 178class MyApp(wx.App):
79f1bf32
RD
179 def OnInit(self):
180 frame = MyFrame()
1e4a197e 181 frame.Show(True)
79f1bf32 182 self.SetTopWindow(frame)
1e4a197e 183 return True
79f1bf32
RD
184
185def runTest(pframe, nb, log):
186 panel = MyPanel(nb)
187 return panel
188
8fa876ca 189edlg._debug = 1
79f1bf32
RD
190
191if __name__ == "__main__":
8fa876ca 192 sys.stderr = edlg.wxPyNonWindowingErrorHandler()
79f1bf32
RD
193 app = MyApp(0)
194 app.MainLoop()
195 sys.exit()
196else:
8fa876ca 197 overview = edlg.__doc__