]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ErrorDialogs.py
wxGLCanvas updates
[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.
5
6from wxPython.wx import *
7from wxPython.lib.ErrorDialogs import *
8_debug = 0
9ID_BUTTON_wxPyFatalErrorDialog = 10001
10ID_BUTTON_wxPyNonFatalErrorDialog = 10002
11ID_BUTTON_wxPyFatalErrorDialogWithTraceback = 10003
12ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback = 10004
13
14def ErrorDialogsDemoPanelFunc( parent, call_fit = true, set_sizer = true ):
15 item0 = wxBoxSizer( wxVERTICAL )
16
17 item1 = wxStaticText( parent, -1, "Please select one of the buttons below...", wxDefaultPosition, wxDefaultSize, 0 )
18 item0.AddWindow( item1, 0, wxALIGN_CENTRE|wxALL, 5 )
19
20 item2 = wxFlexGridSizer( 0, 2, 0, 0 )
21
22 item6 = wxButton( parent, ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback, "wxPyNonFatalErrorDialogWithTraceback", wxDefaultPosition, wxDefaultSize, 0 )
23 item6.SetDefault()
24 item2.AddWindow( item6, 0, wxALIGN_CENTRE|wxALL, 5 )
25
26 item3 = wxButton( parent, ID_BUTTON_wxPyFatalErrorDialog, "wxPyFatalErrorDialog", wxDefaultPosition, wxDefaultSize, 0 )
27 item2.AddWindow( item3, 0, wxALIGN_CENTRE|wxALL, 5 )
28
29 item4 = wxButton( parent, ID_BUTTON_wxPyNonFatalErrorDialog, "wxPyNonFatalErrorDialog", wxDefaultPosition, wxDefaultSize, 0 )
30 item2.AddWindow( item4, 0, wxALIGN_CENTRE|wxALL, 5 )
31
32 item5 = wxButton( parent, ID_BUTTON_wxPyFatalErrorDialogWithTraceback, "wxPyFatalErrorDialogWithTraceback", wxDefaultPosition, wxDefaultSize, 0 )
33 item2.AddWindow( item5, 0, wxALIGN_CENTRE|wxALL, 5 )
34
35 item0.AddSizer( item2, 0, wxALIGN_CENTRE|wxALL, 5 )
36
37 if set_sizer == true:
38 parent.SetAutoLayout( true )
39 parent.SetSizer( item0 )
40 if call_fit == true:
41 item0.Fit( parent )
42 item0.SetSizeHints( parent )
43
44 return item0
45
46# End of generated bit
47
48class MyPanel(wxPanel):
49 def __init__(self,parent=None):
50 wxPanel.__init__(self,parent,-1)
51 args = (None, -1)
52 kwargs = {
53 'programname': "sumthing",
54 'mailto': "me@sumwear",
55 'whendismissed': "from wxPython.wx import * ; wxBell()"}
56 self.dialogs = map(apply,
57 [wxPyNonFatalErrorDialogWithTraceback,
58 wxPyNonFatalErrorDialog,#WithTraceback
59 wxPyFatalErrorDialogWithTraceback,
60 wxPyFatalErrorDialog],#WithTraceback
61 (args,) * 4,
62 (kwargs,) * 4)
63 ErrorDialogsDemoPanelFunc(self)
64
65 EVT_BUTTON(self,
66 ID_BUTTON_wxPyFatalErrorDialog,
67 self.DoDialog)
68 EVT_BUTTON(self,
69 ID_BUTTON_wxPyFatalErrorDialogWithTraceback,
70 self.DoDialog)
71 EVT_BUTTON(self,
72 ID_BUTTON_wxPyNonFatalErrorDialog,
73 self.DoDialog)
74 EVT_BUTTON(self,
75 ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback,
76 self.DoDialog)
77 EVT_CLOSE(self,self.OnClose)
78
79 IndexFromID = {
80 ID_BUTTON_wxPyFatalErrorDialog: 3,
81 ID_BUTTON_wxPyFatalErrorDialogWithTraceback: 2,
82 ID_BUTTON_wxPyNonFatalErrorDialog: 1,
83 ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback: 0
84 }
85
86 def DoDialog(self,event):
87 sys.stderr = self.dialogs[self.IndexFromID[event.GetId()]]
88 print "%s.DoDialog(): testing %s..." % (self,sys.stderr)
89 this_will_generate_a_NameError_exception
90
91 def OnClose(self,evt):
92 for d in self.dialogs:
93 d.Destroy ()
94 self.Destroy ()
95
96class MyFrame(wxFrame):
97 def __init__(self,parent=None):
98 wxFrame.__init__(self,parent,-1,
99 "Please make a selection...",
100 )
101 self. panel = MyPanel(self)
102 EVT_CLOSE (self,self.OnCloseWindow)
103
104 def OnCloseWindow(self,event):
105 self.panel.Close()
106 self.Destroy()
107
108class MyApp(wxApp):
109 def OnInit(self):
110 frame = MyFrame()
111 frame.Show(true)
112 self.SetTopWindow(frame)
113 return true
114
115def runTest(pframe, nb, log):
116 panel = MyPanel(nb)
117 return panel
118
119from wxPython.lib import ErrorDialogs
120ErrorDialogs._debug = 1
121
122if __name__ == "__main__":
123 sys.stderr = wxPyNonWindowingErrorHandler()
124 app = MyApp(0)
125 app.MainLoop()
126 sys.exit()
127else:
128 overview = ErrorDialogs.__doc__