]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ErrorDialogs.py
Added equality operators
[wxWidgets.git] / wxPython / demo / ErrorDialogs.py
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.
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
17 import sys
18
19 import wx
20 import wx.lib.ErrorDialogs as edlg
21
22 _debug = 0
23
24 ID_TEXT = 10000
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
31
32 def ErrorDialogsDemoPanelFunc( parent, call_fit = True, set_sizer = True ):
33 item0 = wx.BoxSizer( wx.VERTICAL )
34
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 )
41
42 item2 = wx.FlexGridSizer( 0, 2, 0, 0 )
43
44 item3 = wx.Button( parent, ID_BUTTON_wxPyNonFatalError, "wxPyNonFatalError")
45 item2.AddWindow( item3, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
46
47 item4 = wx.Button( parent, ID_BUTTON_wxPyFatalError, "wxPyFatalError")
48 item2.AddWindow( item4, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
49
50 item0.AddSizer( item2, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
51
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 )
54
55 item6 = wx.FlexGridSizer( 0, 2, 0, 0 )
56
57 item7 = wx.Button( parent, ID_BUTTON_wxPyFatalErrorDialog, "wxPyFatalErrorDialog")
58 item6.AddWindow( item7, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
59
60 item8 = wx.Button( parent, ID_BUTTON_wxPyNonFatalErrorDialog, "wxPyNonFatalErrorDialog")
61 item6.AddWindow( item8, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
62
63 item9 = wx.Button(
64 parent, ID_BUTTON_wxPyFatalErrorDialogWithTraceback,
65 "wxPyFatalErrorDialogWithTraceback"
66 )
67 item6.AddWindow( item9, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
68
69 item10 = wx.Button(
70 parent, ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback,
71 "wxPyNonFatalErrorDialogWithTraceback"
72 )
73 item10.SetDefault()
74 item6.AddWindow( item10, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
75
76 item0.AddSizer( item6, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
77
78 item11 = wx.FlexGridSizer( 0, 2, 0, 0 )
79
80 item0.AddSizer( item11, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
81
82 if set_sizer == True:
83 parent.SetAutoLayout( True )
84 parent.SetSizer( item0 )
85 if call_fit == True:
86 item0.Fit( parent )
87 item0.SetSizeHints( parent )
88
89 return item0
90
91 # Menu bar functions
92
93 # Bitmap functions
94
95
96 # End of generated file
97
98 class MyPanel(wx.Panel):
99 def __init__(self,parent=None):
100 wx.Panel.__init__(self,parent,-1)
101
102 args = (None, -1)
103 kwargs = {
104 'programname': "sumthing",
105 'mailto': "me@sumwear",
106 'whendismissed': "from wxPython.wx import * ; wxBell()"
107 }
108
109 self.dialogs = map(apply,
110 [edlg.wxPyNonFatalErrorDialogWithTraceback,
111 edlg.wxPyNonFatalErrorDialog,#WithTraceback
112 edlg.wxPyFatalErrorDialogWithTraceback,
113 edlg.wxPyFatalErrorDialog #WithTraceback
114 ],
115 (args,) * 4,
116 (kwargs,) * 4
117 )
118
119 ErrorDialogsDemoPanelFunc(self)
120
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)
127
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):
136 id = event.GetId()
137
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
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>")
147 else:
148 print "%s.DoDialog(): testing explicit wxPyNonFatalError..."\
149 % self
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>")
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
159
160 def ShutdownDemo(self):
161 for d in self.dialogs:
162 d.Destroy()
163
164
165
166 class MyFrame(wx.Frame):
167 def __init__(self,parent=None):
168 wx.Frame.__init__(self,parent,-1,
169 "Please make a selection...",
170 )
171 self.panel = MyPanel(self)
172 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
173
174 def OnCloseWindow(self,event):
175 self.panel.Close()
176 self.Destroy()
177
178 class MyApp(wx.App):
179 def OnInit(self):
180 frame = MyFrame()
181 frame.Show(True)
182 self.SetTopWindow(frame)
183 return True
184
185 def runTest(pframe, nb, log):
186 panel = MyPanel(nb)
187 return panel
188
189 edlg._debug = 1
190
191 if __name__ == "__main__":
192 sys.stderr = edlg.wxPyNonWindowingErrorHandler()
193 app = MyApp(0)
194 app.MainLoop()
195 sys.exit()
196 else:
197 overview = edlg.__doc__