]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/ErrorDialogs.py
Updated to current API.
[wxWidgets.git] / wxPython / demo / ErrorDialogs.py
... / ...
CommitLineData
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
6from wxPython.wx import *
7from wxPython.lib.ErrorDialogs import *
8_debug = 0
9ID_TEXT = 10000
10ID_BUTTON_wxPyNonFatalError = 10001
11ID_BUTTON_wxPyFatalError = 10002
12ID_BUTTON_wxPyFatalErrorDialog = 10003
13ID_BUTTON_wxPyNonFatalErrorDialog = 10004
14ID_BUTTON_wxPyFatalErrorDialogWithTraceback = 10005
15ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback = 10006
16
17def ErrorDialogsDemoPanelFunc( parent, call_fit = True, set_sizer = True ):
18 item0 = wxBoxSizer( wxVERTICAL )
19
20 item1 = wxStaticText( parent, ID_TEXT, "Please select one of the buttons below for an example using explicit errors...", wxDefaultPosition, wxDefaultSize, 0 )
21 item0.AddWindow( item1, 0, wxALIGN_CENTRE|wxALL, 5 )
22
23 item2 = wxFlexGridSizer( 0, 2, 0, 0 )
24
25 item3 = wxButton( parent, ID_BUTTON_wxPyNonFatalError, "wxPyNonFatalError", wxDefaultPosition, wxDefaultSize, 0 )
26 item2.AddWindow( item3, 0, wxALIGN_CENTRE|wxALL, 5 )
27
28 item4 = wxButton( parent, ID_BUTTON_wxPyFatalError, "wxPyFatalError", wxDefaultPosition, wxDefaultSize, 0 )
29 item2.AddWindow( item4, 0, wxALIGN_CENTRE|wxALL, 5 )
30
31 item0.AddSizer( item2, 0, wxALIGN_CENTRE|wxALL, 5 )
32
33 item5 = wxStaticText( parent, ID_TEXT, "Please select one of the buttons below for interpreter errors...", wxDefaultPosition, wxDefaultSize, 0 )
34 item0.AddWindow( item5, 0, wxALIGN_CENTRE|wxALL, 5 )
35
36 item6 = wxFlexGridSizer( 0, 2, 0, 0 )
37
38 item7 = wxButton( parent, ID_BUTTON_wxPyFatalErrorDialog, "wxPyFatalErrorDialog", wxDefaultPosition, wxDefaultSize, 0 )
39 item6.AddWindow( item7, 0, wxALIGN_CENTRE|wxALL, 5 )
40
41 item8 = wxButton( parent, ID_BUTTON_wxPyNonFatalErrorDialog, "wxPyNonFatalErrorDialog", wxDefaultPosition, wxDefaultSize, 0 )
42 item6.AddWindow( item8, 0, wxALIGN_CENTRE|wxALL, 5 )
43
44 item9 = wxButton( parent, ID_BUTTON_wxPyFatalErrorDialogWithTraceback, "wxPyFatalErrorDialogWithTraceback", wxDefaultPosition, wxDefaultSize, 0 )
45 item6.AddWindow( item9, 0, wxALIGN_CENTRE|wxALL, 5 )
46
47 item10 = wxButton( parent, ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback, "wxPyNonFatalErrorDialogWithTraceback", wxDefaultPosition, wxDefaultSize, 0 )
48 item10.SetDefault()
49 item6.AddWindow( item10, 0, wxALIGN_CENTRE|wxALL, 5 )
50
51 item0.AddSizer( item6, 0, wxALIGN_CENTRE|wxALL, 5 )
52
53 item11 = wxFlexGridSizer( 0, 2, 0, 0 )
54
55 item0.AddSizer( item11, 0, wxALIGN_CENTRE|wxALL, 5 )
56
57 if set_sizer == True:
58 parent.SetAutoLayout( True )
59 parent.SetSizer( item0 )
60 if call_fit == True:
61 item0.Fit( parent )
62 item0.SetSizeHints( parent )
63
64 return item0
65
66# Menu bar functions
67
68# Bitmap functions
69
70
71# End of generated file
72
73class MyPanel(wxPanel):
74 def __init__(self,parent=None):
75 wxPanel.__init__(self,parent,-1)
76 args = (None, -1)
77 kwargs = {
78 'programname': "sumthing",
79 'mailto': "me@sumwear",
80 'whendismissed': "from wxPython.wx import * ; wxBell()"}
81 self.dialogs = map(apply,
82 [wxPyNonFatalErrorDialogWithTraceback,
83 wxPyNonFatalErrorDialog,#WithTraceback
84 wxPyFatalErrorDialogWithTraceback,
85 wxPyFatalErrorDialog],#WithTraceback
86 (args,) * 4,
87 (kwargs,) * 4)
88 ErrorDialogsDemoPanelFunc(self)
89
90 EVT_BUTTON(self,
91 ID_BUTTON_wxPyFatalErrorDialog,
92 self.DoDialog)
93 EVT_BUTTON(self,
94 ID_BUTTON_wxPyNonFatalError,
95 self.DoDialog)
96 EVT_BUTTON(self,
97 ID_BUTTON_wxPyFatalError,
98 self.DoDialog)
99 EVT_BUTTON(self,
100 ID_BUTTON_wxPyFatalErrorDialogWithTraceback,
101 self.DoDialog)
102 EVT_BUTTON(self,
103 ID_BUTTON_wxPyNonFatalErrorDialog,
104 self.DoDialog)
105 EVT_BUTTON(self,
106 ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback,
107 self.DoDialog)
108
109
110 IndexFromID = {
111 ID_BUTTON_wxPyFatalErrorDialog: 3,
112 ID_BUTTON_wxPyFatalErrorDialogWithTraceback: 2,
113 ID_BUTTON_wxPyNonFatalErrorDialog: 1,
114 ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback: 0
115 }
116
117 def DoDialog(self,event):
118 id = event.GetId()
119 if id in [ID_BUTTON_wxPyFatalError,ID_BUTTON_wxPyNonFatalError]:
120 if id == ID_BUTTON_wxPyFatalError:
121 print "%s.DoDialog(): testing explicit wxPyFatalError..."\
122 % self
123 wxPyFatalError(self,"Test Non-fatal error.<p>"
124 "Nearly arbitrary HTML (i.e., that which is"
125 " understood by <B><I>wxHtmlWindow</i></b>)."
126 "<p><table border=\"2\"><tr><td>This</td><td>is</td></tr>"
127 "<tr><td>a</td><td>table</td></tr></table></p>")
128 else:
129 print "%s.DoDialog(): testing explicit wxPyNonFatalError..."\
130 % self
131 wxPyNonFatalError(self,"Test Non-fatal error.<p>"
132 "Nearly arbitrary HTML (i.e., that which is"
133 " understood by <B><I>wxHtmlWindow</i></b>)."
134 "<p><table border=\"2\"><tr><td>This</td><td>is</td></tr>"
135 "<tr><td>a</td><td>table</td></tr></table></p>")
136 else:
137 sys.stderr = self.dialogs[self.IndexFromID[id]]
138 print "%s.DoDialog(): testing %s..." % (self,sys.stderr)
139 this_will_generate_a_NameError_exception
140
141 def ShutdownDemo(self):
142 for d in self.dialogs:
143 d.Destroy()
144
145
146
147class MyFrame(wxFrame):
148 def __init__(self,parent=None):
149 wxFrame.__init__(self,parent,-1,
150 "Please make a selection...",
151 )
152 self. panel = MyPanel(self)
153 EVT_CLOSE (self,self.OnCloseWindow)
154
155 def OnCloseWindow(self,event):
156 self.panel.Close()
157 self.Destroy()
158
159class MyApp(wxApp):
160 def OnInit(self):
161 frame = MyFrame()
162 frame.Show(True)
163 self.SetTopWindow(frame)
164 return True
165
166def runTest(pframe, nb, log):
167 panel = MyPanel(nb)
168 return panel
169
170from wxPython.lib import ErrorDialogs
171ErrorDialogs._debug = 1
172
173if __name__ == "__main__":
174 sys.stderr = wxPyNonWindowingErrorHandler()
175 app = MyApp(0)
176 app.MainLoop()
177 sys.exit()
178else:
179 overview = ErrorDialogs.__doc__