Skip to content
27 changes: 19 additions & 8 deletions examples/user_interfaces/embedding_in_wx2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# Used to guarantee to use at least Wx2.8
import wxversion
wxversion.ensureMinimal('2.8')
#wxversion.select('2.8')
#wxversion.select('2.9.5') # 2.9.x classic
#wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix

from numpy import arange, sin, pi

Expand All @@ -25,14 +28,18 @@
from matplotlib.figure import Figure

import wx
print wx.VERSION_STRING

class CanvasFrame(wx.Frame):

def __init__(self):
wx.Frame.__init__(self,None,-1,
'CanvasFrame',size=(550,350))

self.SetBackgroundColour(wx.NamedColour("WHITE"))
if 'phoenix' in wx.PlatformInfo:
self.SetBackgroundColour(wx.Colour("WHITE"))
else:
self.SetBackgroundColour(wx.NamedColour("WHITE"))

self.figure = Figure()
self.axes = self.figure.add_subplot(111)
Expand All @@ -48,7 +55,11 @@ def __init__(self):
self.Fit()

self.add_toolbar() # comment this out for no toolbar

self.Bind(wx.EVT_PAINT, self.OnPaint)

def OnPaint(self, event):
self.canvas.draw()
event.Skip()

def add_toolbar(self):
self.toolbar = NavigationToolbar2Wx(self.canvas)
Expand All @@ -61,8 +72,12 @@ def add_toolbar(self):
else:
# On Windows platform, default window size is incorrect, so set
# toolbar width to figure width.
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
if 'phoenix' in wx.PlatformInfo:
tw, th = self.toolbar.GetSize()
fw, fh = self.canvas.GetSize()
else:
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
# By adding toolbar in sizer, we are able to put it at the bottom
# of the frame - so appearance is closer to GTK version.
# As noted above, doesn't work for Mac.
Expand All @@ -71,10 +86,6 @@ def add_toolbar(self):
# update the axes menu on the toolbar
self.toolbar.update()


def OnPaint(self, event):
self.canvas.draw()

class App(wx.App):

def OnInit(self):
Expand Down
29 changes: 24 additions & 5 deletions examples/user_interfaces/embedding_in_wx3.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
# Used to guarantee to use at least Wx2.8
import wxversion
wxversion.ensureMinimal('2.8')
#wxversion.select('2.8')
#wxversion.select('2.9.5') # 2.9.x classic
#wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix

import sys, time, os, gc
import matplotlib
Expand All @@ -35,6 +38,9 @@
import numpy as np

import wx

print(wx.VERSION_STRING)

import wx.xrc as xrc

ERR_TOL = 1e-5 # floating point slop for peak-detection
Expand All @@ -61,7 +67,12 @@ def __init__(self, parent):
sizer.Add(self.toolbar, 0, wx.GROW)
self.SetSizer(sizer)
self.Fit()

self.Bind(wx.EVT_PAINT, self.OnPaint)

def OnPaint(self, event):
self.canvas.draw()
event.Skip()

def init_plot_data(self):
a = self.fig.add_subplot(111)

Expand Down Expand Up @@ -132,14 +143,22 @@ def OnInit(self):
# whiz button ------------------

whiz_button = xrc.XRCCTRL(self.frame,"whiz_button")
wx.EVT_BUTTON(whiz_button, whiz_button.GetId(),
self.plotpanel.OnWhiz)

if 'phoenix' in wx.PlatformInfo:
whiz_button.Bind(wx.EVT_BUTTON, self.plotpanel.OnWhiz)
else:
wx.EVT_BUTTON(whiz_button, whiz_button.GetId(),
self.plotpanel.OnWhiz)

# bang button ------------------

bang_button = xrc.XRCCTRL(self.frame,"bang_button")
wx.EVT_BUTTON(bang_button, bang_button.GetId(),
self.OnBang)
if 'phoenix' in wx.PlatformInfo:
bang_button.Bind(wx.EVT_BUTTON, self.OnBang)

else:
wx.EVT_BUTTON(bang_button, bang_button.GetId(),
self.OnBang)

# final setup ------------------

Expand Down
31 changes: 24 additions & 7 deletions examples/user_interfaces/embedding_in_wx4.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# Used to guarantee to use at least Wx2.8
import wxversion
wxversion.ensureMinimal('2.8')
#wxversion.select('2.8')
#wxversion.select('2.9.5') # 2.9.x classic
#wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix


from numpy import arange, sin, pi

Expand All @@ -32,9 +36,15 @@ def __init__(self, canvas, cankill):

# for simplicity I'm going to reuse a bitmap from wx, you'll
# probably want to add your own.
self.AddSimpleTool(self.ON_CUSTOM, _load_bitmap('stock_left.xpm'),
'Click me', 'Activate custom contol')
wx.EVT_TOOL(self, self.ON_CUSTOM, self._on_custom)
if 'phoenix' in wx.PlatformInfo:
self.AddTool(self.ON_CUSTOM, 'Click me',
_load_bitmap('stock_left.xpm'),
'Activate custom contol')
self.Bind(wx.EVT_TOOL, self._on_custom, id=self.ON_CUSTOM)
else:
self.AddSimpleTool(self.ON_CUSTOM, _load_bitmap('stock_left.xpm'),
'Click me', 'Activate custom contol')
wx.EVT_TOOL(self, self.ON_CUSTOM, self._on_custom)

def _on_custom(self, evt):
# add some text to the axes in a random location in axes (0,1)
Expand All @@ -61,7 +71,10 @@ def __init__(self):
wx.Frame.__init__(self,None,-1,
'CanvasFrame',size=(550,350))

self.SetBackgroundColour(wx.NamedColour("WHITE"))
if 'phoenix' in wx.PlatformInfo:
self.SetBackgroundColour(wx.Colour("WHITE"))
else:
self.SetBackgroundColour(wx.NamedColour("WHITE"))

self.figure = Figure(figsize=(5,4), dpi=100)
self.axes = self.figure.add_subplot(111)
Expand All @@ -75,7 +88,7 @@ def __init__(self):
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.TOP | wx.LEFT | wx.EXPAND)
# Capture the paint message
wx.EVT_PAINT(self, self.OnPaint)
self.Bind(wx.EVT_PAINT, self.OnPaint)

self.toolbar = MyNavigationToolbar(self.canvas, True)
self.toolbar.Realize()
Expand All @@ -87,8 +100,12 @@ def __init__(self):
else:
# On Windows platform, default window size is incorrect, so set
# toolbar width to figure width.
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
if 'phoenix' in wx.PlatformInfo:
tw, th = self.toolbar.GetSize()
fw, fh = self.canvas.GetSize()
else:
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
# By adding toolbar in sizer, we are able to put it at the bottom
# of the frame - so appearance is closer to GTK version.
# As noted above, doesn't work for Mac.
Expand Down
29 changes: 23 additions & 6 deletions examples/user_interfaces/embedding_in_wx5.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Used to guarantee to use at least Wx2.8
import wxversion
wxversion.ensureMinimal('2.8')
#wxversion.select('2.8')
#wxversion.select('2.9.5') # 2.9.x classic
#wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix


import wx
import wx.aui
print wx.VERSION_STRING

if 'phoenix' in wx.PlatformInfo:
import wx.lib.agw.aui as aui
else:
import wx.aui as aui

import matplotlib as mpl
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as Toolbar
Expand All @@ -20,23 +30,30 @@ def __init__(self, parent, id = -1, dpi = None, **kwargs):
sizer.Add(self.canvas,1,wx.EXPAND)
sizer.Add(self.toolbar, 0 , wx.LEFT | wx.EXPAND)
self.SetSizer(sizer)
self.Bind(wx.EVT_PAINT, self.OnPaint)

def OnPaint(self, event):
self.canvas.draw()
event.Skip()


class PlotNotebook(wx.Panel):
def __init__(self, parent, id = -1):
wx.Panel.__init__(self, parent, id=id)
self.nb = wx.aui.AuiNotebook(self)
self.nb = aui.AuiNotebook(self)
sizer = wx.BoxSizer()
sizer.Add(self.nb, 1, wx.EXPAND)
self.SetSizer(sizer)

def add(self,name="plot"):
page = Plot(self.nb)
self.nb.AddPage(page,name)
return page.figure
page = Plot(self.nb)
self.nb.AddPage(page,name)
return page.figure


def demo():
app = wx.PySimpleApp()
import wx.lib.mixins.inspection as wit
app = wit.InspectableApp()
frame = wx.Frame(None,-1,'Plotter')
plotter = PlotNotebook(frame)
axes1 = plotter.add('figure 1').gca()
Expand Down
20 changes: 18 additions & 2 deletions examples/user_interfaces/fourier_demo_wx.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import numpy as np
import wx

# Used to guarantee to use at least Wx2.8
import wxversion
wxversion.ensureMinimal('2.8')
#wxversion.select('2.8')
#wxversion.select('2.9.5') # 2.9.x classic
#wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix


import wx
print wx.VERSION_STRING
import matplotlib
matplotlib.interactive(False)
matplotlib.use('WXAgg')
Expand Down Expand Up @@ -64,7 +73,8 @@ def __init__(self, parent, label, param):
self.sliderLabel = wx.StaticText(parent, label=label)
self.sliderText = wx.TextCtrl(parent, -1, style=wx.TE_PROCESS_ENTER)
self.slider = wx.Slider(parent, -1)
self.slider.SetMax(param.maximum*1000)
#self.slider.SetMax(param.maximum*1000)
self.slider.SetRange(0, param.maximum*1000)
self.setKnob(param.value)

sizer = wx.BoxSizer(wx.HORIZONTAL)
Expand Down Expand Up @@ -133,6 +143,12 @@ def __init__(self, *args, **kwargs):
self.f0.attach(self)
self.A.attach(self)
self.Bind(wx.EVT_SIZE, self.sizeHandler)

self.Bind(wx.EVT_PAINT, self.OnPaint)

def OnPaint(self, event):
self.canvas.draw()
event.Skip()

def sizeHandler(self, *args, **kwargs):
self.canvas.SetSize(self.GetSize())
Expand Down
26 changes: 22 additions & 4 deletions examples/user_interfaces/wxcursor_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
"""
Example to draw a cursor and report the data coords in wx
"""
# Used to guarantee to use at least Wx2.8
import wxversion
wxversion.ensureMinimal('2.8')
#wxversion.select('2.8')
#wxversion.select('2.9.5') # 2.9.x classic
#wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix

import matplotlib
matplotlib.use('WXAgg')
Expand All @@ -11,14 +17,17 @@
from numpy import arange, sin, pi

import wx
print wx.VERSION_STRING

class CanvasFrame(wx.Frame):

def __init__(self, ):
wx.Frame.__init__(self,None,-1,
'CanvasFrame',size=(550,350))

self.SetBackgroundColour(wx.NamedColour("WHITE"))
if 'phoenix' in wx.PlatformInfo:
self.SetBackgroundColour(wx.Colour("WHITE"))
else:
self.SetBackgroundColour(wx.NamedColour("WHITE"))

self.figure = Figure()
self.axes = self.figure.add_subplot(111)
Expand All @@ -41,14 +50,23 @@ def __init__(self, ):

self.statusBar = wx.StatusBar(self, -1)
self.statusBar.SetFieldsCount(1)
self.statusBar.SetStatusWidths([-1])
self.SetStatusBar(self.statusBar)

self.toolbar = NavigationToolbar2Wx(self.figure_canvas)
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
self.toolbar.Show()

self.Bind(wx.EVT_PAINT, self.OnPaint)

def OnPaint(self, event):
self.figure_canvas.draw()
event.Skip()

def ChangeCursor(self, event):
self.figure_canvas.SetCursor(wx.StockCursor(wx.CURSOR_BULLSEYE))
if 'phoenix' in wx.PlatformInfo:
self.figure_canvas.SetCursor(wx.Cursor(wx.CURSOR_BULLSEYE))
else:
self.figure_canvas.SetCursor(wx.StockCursor(wx.CURSOR_BULLSEYE))

def UpdateStatusBar(self, event):
if event.inaxes:
Expand Down
Loading