numpy
as
np
from
matplotlib.backends.backend_wxagg
import
FigureCanvasWxAgg
as
FigureCanvas
from
matplotlib.backends.backend_wxagg
import
NavigationToolbar2WxAgg
as
NavigationToolbar
import
matplotlib.cbook
as
cbook
from
matplotlib.figure
import
ERR_TOL
=
1e-5
class
PlotPanel
(
):
def
__init__
(
self
,
parent
):
super
()
.
__init__
(
parent
,
-
1
)
self
.
fig
=
((
5
,
4
),
75
)
self
.
canvas
=
FigureCanvas
(
self
,
-
1
,
self
.
fig
)
self
.
toolbar
=
NavigationToolbar
(
self
.
canvas
)
self
.
toolbar
.
Realize
()
sizer
=
(
wx
.
VERTICAL
)
sizer
.
Add
(
self
.
canvas
,
1
,
wx
.
LEFT
|
wx
.
TOP
|
wx
.
GROW
)
sizer
.
Add
(
self
.
toolbar
,
0
,
wx
.
GROW
)
self
.
SetSizer
(
sizer
)
self
.
Fit
()
def
init_plot_data
(
self
):
ax
=
self
.
fig
.
add_subplot
()
x
=
(
120.0
)
*
2
*
/
60.0
y
=
(
100.0
)
*
2
*
/
50.0
self
.
x
,
self
.
y
=
(
x
,
y
)
z
=
(
self
.
x
)
+
(
self
.
y
)
self
.
im
=
ax
.
imshow
(
z
,
cmap
=
"RdBu"
,
origin
=
'lower'
)
zmax
=
(
z
)
-
ERR_TOL
ymax_i
,
xmax_i
=
(
z
>=
zmax
)
if
self
.
im
.
origin
==
'upper'
:
ymax_i
=
z
.
shape
[
0
]
-
ymax_i
self
.
lines
=
ax
.
plot
(
xmax_i
,
ymax_i
,
'ko'
)
self
.
toolbar
.
update
()
def
GetToolBar
(
self
):
return
self
.
toolbar
def
OnWhiz
(
self
,
event
):
self
.
x
+=
/
15
self
.
y
+=
/
20
z
=
(
self
.
x
)
+
(
self
.
y
)
self
.
im
.
set_array
(
z
)
zmax
=
(
z
)
-
ERR_TOL
ymax_i
,
xmax_i
=
(
z
>=
zmax
)
if
self
.
im
.
origin
==
'upper'
:
ymax_i
=
z
.
shape
[
0
]
-
ymax_i
self
.
lines
[
0
]
.
set_data
(
xmax_i
,
ymax_i
)
self
.
canvas
.
draw
()
class
MyApp
(
):
def
OnInit
(
self
):
xrcfile
=
(
'embedding_in_wx3.xrc'
,
asfileobj
=
False
)
print
(
'loading'
,
xrcfile
)
self
.
res
=
(
xrcfile
)
self
.
frame
=
self
.
res
.
LoadFrame
(
None
,
"MainFrame"
)
self
.
panel
=
(
self
.
frame
,
"MainPanel"
)
plot_container
=
(
self
.
frame
,
"plot_container_panel"
)
sizer
=
(
wx
.
VERTICAL
)
self
.
plotpanel
=
PlotPanel
(
plot_container
)
self
.
plotpanel
.
init_plot_data
()
sizer
.
Add
(
self
.
plotpanel
,
1
,
wx
.
EXPAND
)
plot_container
.
SetSizer
(
sizer
)
whiz_button
=
(
self
.
frame
,
"whiz_button"
)
whiz_button
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
plotpanel
.
OnWhiz
)
bang_button
=
(
self
.
frame
,
"bang_button"
)
bang_button
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
OnBang
)
self
.
frame
.
Show
()
self
.
SetTopWindow
(
self
.
frame
)
return
True
def
OnBang
(
self
,
event
):
bang_count
=
(
self
.
frame
,
"bang_count"
)
bangs
=
bang_count
.
GetValue
()
bangs
=
int
(
bangs
)
+
1
bang_count
.
SetValue
(
str
(
bangs
))
if
__name__
==
'__main__'
:
app
=
MyApp
()
app
.
MainLoop
()