I’m trying to embed a matplotlib canvas with a notebook widget from wx.lib.agw.flatnotebook. My main file looks like this:
‘’’
Created on Feb 18, 2014
@author: Rob
‘’’
import wx
import wx.lib.agw.aquabutton as AB
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure
import wx.lib.agw.flatnotebook as fnb
from numpy import arange, sin, pi
from Console import ConsoleTab
Create notebook and add panels (tabs) to the Notebook
class Notebook(fnb.FlatNotebook):
def init(self, parent):
fnb.FlatNotebook.__init__(self, parent, id=wx.ID_ANY)
self.tabTwo = ConsoleTab(self)
self.AddPage(self.tabTwo, "Console")
class MainWindow(wx.Frame):
def init(self):
wx.Frame.init(self, None, wx.ID_ANY, “Notebook Tutorial”, size = (1000,800))
panel = wx.Panel(self)
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
self.axes.plot(t, s)
self.canvas = FigureCanvas(panel, -1, self.figure)
# Sizers
self.Mainsizer = wx.BoxSizer(wx.VERTICAL)
self.CanvasSizer = wx.BoxSizer(wx.VERTICAL)
self.NavigationToolbarSizer = wx.BoxSizer(wx.VERTICAL)
self.NotebookSizer = wx.BoxSizer(wx.VERTICAL)
# Add Sizers
self.CanvasSizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND)
# setup toolbar
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
# By adding toolbar in sizer, we are able to put it at the bottom
# of the frame - so appearance is closer to GTK version.
self.NavigationToolbarSizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
# update the axes menu on the toolbar
self.toolbar.update()
self.notebook = Notebook(panel)
self.NotebookSizer.Add(self.notebook, 1, wx.ALL | wx.EXPAND)
#self.Mainsizer.Add(self.CanvasSizer, 1, wx.LEFT | wx.TOP | wx.EXPAND)
self.Mainsizer.Add(self.NavigationToolbarSizer, 1, wx.ALL | wx.EXPAND)
self.Mainsizer.Add(self.NotebookSizer, 1, wx.ALL | wx.EXPAND)
# Set, Start
panel.SetSizer(self.Mainsizer)
panel.Layout()
#self.Layout()
self.Show()
if name == ‘main’:
app = wx.PySimpleApp()
frame = MainWindow()
app.MainLoop()
``
I’m trying to append a basic console text box with this file I’ve included. I figured as I continue to develop the application it would be handy and cleaner to have my tabs in different files.
class ConsoleTab(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
self.ConsoleTextBox = wx.TextCtrl(self, value= "", size=wx.Size(540, 195), style=(wx.TE_MULTILINE|wx.TE_DONTWRAP))
self.MainSizer = wx.BoxSizer(wx.VERTICAL)
self.MainSizer.Add(self.ConsoleTextBox, 0, wx.ALL, 5)
self.SetSizer(self.MainSizer)
self.Layout()
def PrintToConsole(self, data):
self.ConsoleTextBox.write( str(data) + '\n')
``
The window I actually get looks like this:
I’m assuming my panels are overlapping. I’m kind of unsure how to correctly implement this. I’ve tried passing the parent panel to all of my widgets, but that didn’t seem to work either. Does anyone see what I’m doing wrong or what the correct way to go about this would be? I’m just trying to get the canvas on top so I can plot data and have a notebook below it so I can have controls/widgets etc…on different tabs. I think my lack of background is tripping me up and I am missing something regarding panels.
Here is a screenshot showing the entire matplotlib canvas that I would expect to see. I want to put the canvas in one sizer and the notebook in another sizer and have them work like normal widgets would.
Thank you for any guidance!