1
"""A Simple wx example to test IPython's event loop integration.
9
Ref: Modified from wxPython source code wxPython/samples/simple/simple.py
11
This example can only be run once in a given IPython session because when
12
the frame is closed, wx goes through its shutdown sequence, killing further
13
attempts. I am sure someone who knows wx can fix this issue.
15
Furthermore, once this example is run, the Wx event loop is mostly dead, so
16
even other new uses of Wx may not work correctly. If you know how to better
17
handle this, please contact the ipython developers and let us know.
19
Note however that we will work with the Matplotlib and Enthought developers so
20
that the main interactive uses of Wx we are aware of, namely these tools, will
21
continue to work well with IPython interactively.
27
class MyFrame(wx.Frame):
29
This is MyFrame. It just shows a few controls on a wxPanel,
30
and has a simple menu.
32
def __init__(self, parent, title):
33
wx.Frame.__init__(self, parent, -1, title,
34
pos=(150, 150), size=(350, 200))
37
menuBar = wx.MenuBar()
42
# add an item to the menu, using \tKeyName automatically
43
# creates an accelerator, the third param is some help text
44
# that will show up in the statusbar
45
menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample")
47
# bind the menu event to an event handler
48
self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT)
50
# and put the menu on the menubar
51
menuBar.Append(menu, "&File")
52
self.SetMenuBar(menuBar)
54
self.CreateStatusBar()
56
# Now create the Panel to put the other controls on.
57
panel = wx.Panel(self)
60
text = wx.StaticText(panel, -1, "Hello World!")
61
text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
62
text.SetSize(text.GetBestSize())
63
btn = wx.Button(panel, -1, "Close")
64
funbtn = wx.Button(panel, -1, "Just for fun...")
66
# bind the button events to handlers
67
self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, btn)
68
self.Bind(wx.EVT_BUTTON, self.OnFunButton, funbtn)
70
# Use a sizer to layout the controls, stacked vertically and with
71
# a 10 pixel border around each
72
sizer = wx.BoxSizer(wx.VERTICAL)
73
sizer.Add(text, 0, wx.ALL, 10)
74
sizer.Add(btn, 0, wx.ALL, 10)
75
sizer.Add(funbtn, 0, wx.ALL, 10)
80
def OnTimeToClose(self, evt):
81
"""Event handler for the button click."""
85
def OnFunButton(self, evt):
86
"""Event handler for the button click."""
87
print "Having fun yet?"
92
frame = MyFrame(None, "Simple wxPython App")
93
self.SetTopWindow(frame)
95
print "Print statements go to this stdout window by default."
102
app = MyApp(redirect=False, clearSigInt=False)
105
from IPython.lib.inputhook import appstart_wx