]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ErrorDialogs.py
applied patch for calculating the tree items size with non default font (patch 520965)
[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 from wxPython.wx import *
7 from wxPython.lib.ErrorDialogs import *
8 _debug = 0
9 ID_TEXT = 10000
10 ID_BUTTON_wxPyNonFatalError = 10001
11 ID_BUTTON_wxPyFatalError = 10002
12 ID_BUTTON_wxPyFatalErrorDialog = 10003
13 ID_BUTTON_wxPyNonFatalErrorDialog = 10004
14 ID_BUTTON_wxPyFatalErrorDialogWithTraceback = 10005
15 ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback = 10006
16
17 def 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
73 class 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 EVT_CLOSE(self,self.OnClose)
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 OnClose(self,evt):
142 for d in self.dialogs:
143 d.Destroy ()
144 self.Destroy ()
145
146 class MyFrame(wxFrame):
147 def __init__(self,parent=None):
148 wxFrame.__init__(self,parent,-1,
149 "Please make a selection...",
150 )
151 self. panel = MyPanel(self)
152 EVT_CLOSE (self,self.OnCloseWindow)
153
154 def OnCloseWindow(self,event):
155 self.panel.Close()
156 self.Destroy()
157
158 class MyApp(wxApp):
159 def OnInit(self):
160 frame = MyFrame()
161 frame.Show(true)
162 self.SetTopWindow(frame)
163 return true
164
165 def runTest(pframe, nb, log):
166 panel = MyPanel(nb)
167 return panel
168
169 from wxPython.lib import ErrorDialogs
170 ErrorDialogs._debug = 1
171
172 if __name__ == "__main__":
173 sys.stderr = wxPyNonWindowingErrorHandler()
174 app = MyApp(0)
175 app.MainLoop()
176 sys.exit()
177 else:
178 overview = ErrorDialogs.__doc__