Hi, I'm trying to add some navigation tools to my mpl embedded in a wx app.
I noticed the default navigation tools here:
http://matplotlib.sourceforge.net/users/navigation_toolbar.html?highlight=matplotlib%20widgets
http://matplotlib.sourceforge.net/users/navigation_toolbar.html?highlight=matplotlib%20widgets
and am able to implement them using this example:
http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_wx2.html
http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_wx2.html
.
However, I don't want to add the toolbar to the bottom of my canvas or to
any part of my canvas. I want to add the toolbar, or actually more
specifically, add the pan, zoom, and save buttons to a different panel and
sizer.
So far I tried adding the navigation toolbar to a different sizer, which is
on a different panel, but toolbar always shows up on the canvas.
Can someone suggest some methods on how to:
1. force and add the navigation toolbar to a different sizer or panel?
2. Add select buttons from the navigation toolbar to a different sizer or
panel than where the canvas is located?
Here is my example code:
#Boa:Frame:Frame1
import wx
import numpy as np
import matplotlib as mpl
mpl.use('WXAgg')
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1PANEL1, wxID_FRAME1PANEL2,
] = [wx.NewId() for _init_ctrls in range(3)]
class Frame1(wx.Frame):
def _init_coll_bshPanels_Items(self, parent):
# generated method, don't edit
parent.AddWindow(self.panel1, 4, border=0, flag=wx.EXPAND)
parent.AddWindow(self.panel2, 1, border=0, flag=wx.EXPAND)
def _init_sizers(self):
# generated method, don't edit
self.bshPanels = wx.BoxSizer(orient=wx.HORIZONTAL)
self.bsvPanel1 = wx.BoxSizer(orient=wx.VERTICAL)
self.bsvPanel2 = wx.BoxSizer(orient=wx.VERTICAL)
self._init_coll_bshPanels_Items(self.bshPanels)
self.SetSizer(self.bshPanels)
self.panel1.SetSizer(self.bsvPanel1)
self.panel2.SetSizer(self.bsvPanel2)
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(-870, 286), size=wx.Size(718, 547),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(710, 520))
self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1',
parent=self,
pos=wx.Point(0, 0), size=wx.Size(568, 520),
style=wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
self.panel2 = wx.Panel(id=wxID_FRAME1PANEL2, name='panel2',
parent=self,
pos=wx.Point(568, 0), size=wx.Size(142, 520),
style=wx.TAB_TRAVERSAL)
self._init_sizers()
def __init__(self, parent):
self._init_ctrls(parent)
self.InitCanvas()
self.AddToolBar()
self.AddToolBarBtns()
self.t = np.arange(0, np.pi*2, 0.01)
self.x = np.sin(2*np.pi*self.t)
self.myplot = self.ax.plot(self.t, self.x, 'b')
self.canvas.draw()
def InitCanvas(self):
self.fig = Figure(None)
self.canvas = FigureCanvasWxAgg(self.panel1, -1, self.fig)
self.bsvPanel1.Add(self.canvas, -1, wx.EXPAND)
## self.panel1.Fit()
self.ax = self.fig.add_subplot(111)
self.ax.grid('On')
return True
def AddToolBar(self):
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
self.toolbar.SetSize(wx.Size(fw, th))
#Trying to add to different sizer than to whom the canvas belongs
self.bsvPanel2.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
#but this doesn't work. The toolbar is still on the canvas,
#but disapears as soon as I resize or do a redraw.
#Need correct code here, please.
self.toolbar.update()
return True
def AddToolBarBtns(self):
'''add specific tool buttons from the navigatio toolbar to panel2'''
#need code here, if possible
pass
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = create(None)
frame.Show()
app.MainLoop()
···
-----
Krishna Adrianto Pribadi
Test Engineer
Harley-Davidson Motor Co.
Talladega Test Facility
Vehicle Test Stands
–
View this message in context: http://old.nabble.com/navigationtoolbar%3A-1.-force-location--2.-add-select-button(s)-only-tp28268828p28268828.html
Sent from the matplotlib - users mailing list archive at Nabble.com.