In the following example the scrollbar disappears after using the calculating button, although the layout function was called. If you manually resize the frame it reappears. This behavior occurs only under windows, in linux the scrollbar functions as it should.
To fix it I tried the functions refresh() and update() (in layout funtion of class GUI_Diagrams_GHL) - but it didn't help.
I tried to reduce my application to this minmal working example:
# -*- coding: utf-8 -*-
import wx
from wx.lib.pubsub import pub
import wx.lib.scrolledpanel as scrolled
import matplotlib
matplotlib.use('WXAgg')
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
class MainWindow(wx.Frame):
'''Frame that contains pretty much everything'''
def __init__(self,*args,**kwargs):
'''Constructor'''
super(MainWindow,self).__init__(*args,**kwargs)
self.panel = wx.Panel(self)
notebook = Notebook(self.panel)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(notebook,1, wx.ALL|wx.EXPAND,4)
self.panel.SetSizerAndFit(sizer)
self.panel.Layout()
class Notebook(wx.Notebook):
def __init__(self, parent):
wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style = wx.BK_DEFAULT)
tabTwo = GUI_Input_GHL(self)
self.AddPage(tabTwo, 'Input')
tabThree = GUI_Diagrams_GHL(self)
self.AddPage(tabThree, 'Diagrams')
class GUI_Input_GHL(scrolled.ScrolledPanel):
"""This panel contains the input fields for basic data."""
def __init__(self, parent):
scrolled.ScrolledPanel.__init__(self, parent=parent, id=wx.ID_ANY)
self.label_1 = wx.StaticText(self,-1,label=u'Label 1')
self.button2 = wx.Button(self,-1,label=u'Start')
self.Bind(wx.EVT_BUTTON, self.StartCalc, self.button2)
self.layout()
def layout(self):
sizer = wx.GridBagSizer()
sizer.Add(self.button2, (8,0),(2,3), flag =wx.EXPAND)
sizer.Add(self.label_1, (0,0),flag=wx.ALIGN_CENTER_VERTICAL)
self.SetAutoLayout(1)
self.SetupScrolling()
self.SetSizerAndFit(sizer)
def StartCalc(self,event):
pub.sendMessage('GUI_Diagrams_Listener', message = 'test')
class GUI_Diagrams_GHL(scrolled.ScrolledPanel):
"""This panel contains diagrams"""
def __init__(self, parent):
scrolled.ScrolledPanel.__init__(self, parent=parent, id=wx.ID_ANY)
self.parent = parent
self.fig1 = Figure()
self.fig6 = Figure()
self.canvas1 = FigCanvas(self,-1,self.fig1)
self.axes1 = self.fig1.add_subplot(111)
self.canvas6 = FigCanvas(self,-1,self.fig6)
self.axes6 = self.fig6.add_subplot(111)
self.dia_R_hat_SetValues('test')
self.dia_theta_SetValues('test')
self.layout()
pub.subscribe(self.diagrams_SetValues, "GUI_Diagrams_Listener")
def layout(self):
sizer = wx.GridBagSizer()
sizer.Add(self.canvas1, (1,0), (12,12), wx.EXPAND)
sizer.Add(self.canvas6, (53,0), (12,12), wx.EXPAND)
## I guess here is the problem somewhere:
self.SetSizerAndFit(sizer)
self.SetAutoLayout(1)
self.SetupScrolling()
#self.Fit()
#self.Layout()
#self.FitInside()
#self.AlwaysShowScrollbars(True,True)
#self.Refresh()
#self.Update()
#self.parent.SetSize(self.parent.GetSize())
def diagrams_SetValues(self, message):
self.Output = message
self.dia_R_hat_SetValues(message)
self.dia_theta_SetValues(message)
self.layout()
def dia_R_hat_SetValues(self, Output):
self.axes1.clear()
self.axes1.plot(range(15),range(15), 'r-', linewidth = 2)
self.canvas1.draw()
def dia_theta_SetValues(self, Output):
self.axes6.clear()
self.axes6.plot(range(5),'k')
self.axes6.set_title(r"Absolute Temperature")
self.canvas6.draw()
if __name__ == '__main__':
app = wx.App()
frame = MainWindow(None, -1, 'MyApp')
frame.Show()
app.MainLoop()
I've figured it out myself :)
If you call the layout function of the main panel ('MainWindow.panel.Layout()') after updating the diagrams/in the layout of the diagram class, the whole panel refreshes and
the Scrollbars reappear. So a 'parent.parent.Layout()' worked for me in this case.
Any other suggestions/solutions?
Related
I have a simple matplotlib plot integrated with wxPython, and for some reason the x/y co-ordinates are not showing up under the status bar (the co-ordinates that show when you move the mouse), they used to appear but cannot get it to happen anymore. Any ideas why this may be possible? (I've also tried setting the format_coord attribute manually but that doesn't seem to work).
I think it's wx doing something funny, since if I just create a matplotlib plot in a new Python shell it works fine. Example code is below:
#Subclassing WX Panel Class to be able to integrate matplotlib into it
class p1(wx.Panel):
def __init__(self, parent, frame):
#Initialize WX Panel
wx.Panel.__init__(self, parent, -1, size=(50,50))
#Set up Figure/Canvas
self.frame = frame
self.figure = Figure()
self.canvas = FigureCanvas(self, -1, self.figure)
#Set up Matplotlib Toolbar
self.chart_toolbar = NavigationToolbar2Wx(self.canvas)
tw,th = self.chart_toolbar.GetSizeTuple()
fw,fh = self.canvas.GetSizeTuple()
self.chart_toolbar.SetSize(wx.Size(fw, th))
self.chart_toolbar.Realize()
graphs_sizer = wx.BoxSizer(wx.VERTICAL)
graphs_sizer.Add(self.canvas, 20, flag=wx.EXPAND, border=5)
graphs_sizer.Add(self.chart_toolbar, 1, flag=wx.ALIGN_CENTER, border=5)
self.SetSizer(graphs_sizer)
def plot(self):
self.axs1 = self.figure.add_subplot(1,1,1)
self.axs1.plot([1,2,3,4,5],color='blue')
class TestFrame(wx.Frame):
def __init__(self, parent, title):
#Initialize WX Frame
wx.Frame.__init__(self, parent, title=title, size=(1000,800))
#Create Splitter Window and Add Left/Right Panels
self.splitterWindow = wx.SplitterWindow(self)
self.panel1 = p1(self.splitterWindow, self)
self.panel2 = wx.Panel(self.splitterWindow)
self.splitterWindow.SplitVertically(self.panel1, self.panel2, 700)
#Create Status Bar
self.statusbar = self.CreateStatusBar()
#Plot
self.panel1.plot()
app = wx.App(redirect=False)
frame = TestFrame(None, "Test")
frame.Show(True)
app.MainLoop()
whereas something as simple as this works fine:
plt.plot([1,2,3,4,5])
plt.show()
It is easier for people to help if you make the code complete, i.e. with the imports in your case.
Note that you don't need the "SetSize" stuff for the toolbar, IIRC that was only needed with some wxPython versions on MAC.
To get the mouse coordinates you need to connect an event, that might be done out of the box with plt.plot.
Doc for the events is here: http://matplotlib.org/users/event_handling.html
import wx
import matplotlib
matplotlib.use('WXAgg')
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure
#Subclassing WX Panel Class to be able to integrate matplotlib into it
class p1(wx.Panel):
def __init__(self, parent, frame):
#Initialize WX Panel
wx.Panel.__init__(self, parent, -1, size=(50,50))
#Set up Figure/Canvas
self.frame = frame
self.figure = Figure()
self.canvas = FigureCanvas(self, -1, self.figure)
#Set up Matplotlib Toolbar
self.chart_toolbar = NavigationToolbar2Wx(self.canvas)
self.chart_toolbar.Realize()
graphs_sizer = wx.BoxSizer(wx.VERTICAL)
graphs_sizer.Add(self.canvas, 20, flag=wx.EXPAND, border=5)
graphs_sizer.Add(self.chart_toolbar, 1, flag=wx.ALIGN_CENTER, border=5)
self.SetSizer(graphs_sizer)
def plot(self):
self.axs1 = self.figure.add_subplot(1,1,1)
self.axs1.plot([1,2,3,4,5],color='blue')
class TestFrame(wx.Frame):
def __init__(self, parent, title):
#Initialize WX Frame
wx.Frame.__init__(self, parent, title=title, size=(1000,800))
#Create Splitter Window and Add Left/Right Panels
self.splitterWindow = wx.SplitterWindow(self)
self.panel1 = p1(self.splitterWindow, self)
self.panel2 = wx.Panel(self.splitterWindow)
self.splitterWindow.SplitVertically(self.panel1, self.panel2, 700)
#Create Status Bar
self.statusbar = self.CreateStatusBar()
#Plot
self.panel1.plot()
mouseMoveID = self.panel1.canvas.mpl_connect('motion_notify_event',
self.onMotion)
def onMotion(self, evt):
x = evt.x
y = evt.y
inaxes = evt.inaxes
xdata = evt.xdata
ydata = evt.ydata
self.statusbar.SetStatusText("%s, %s, %s, %s, %s" % (
x, y, inaxes, xdata, ydata))
app = wx.App(redirect=False)
frame = TestFrame(None, "Test")
frame.Show(True)
app.MainLoop()
I am running a wxpython application. Within the application i have a panel that contains a notebook with some number of notebook pages/tabs. On a button press (wx.button), i would like to be able to clear one of the notebook pages and replace it with new information provided in my GUI.
I have not seen any kind of Clear() function for wx.Notebook, so I had the thought of deleting the page and creating a new one. However, I cannot seem to get this to work. Here is my code...help??
def UpdatePanel(self):
self.Notebook3.DeletePage(0)
self.newpage = scrolled.ScrolledPanel(self.Notebook3, -1)
self.newpage.SetupScrolling()
self.Notebook3.AddPage(self.newpage,"Page Inserted Here")
# self.Notebook3.InsertPage(0,"Page Inserted Here")
Checkout this code and see how you can adapt it to yours:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import wx
class Page(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
t = wx.StaticText(self, -1, "THIS IS A PAGE OBJECT", (20,20))
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Notebook Remove Pages Example")
pannel = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
self.buttonRemove = wx.Button(pannel, id=wx.ID_ANY, label="DELETE", size=(80, 25))
self.buttonRemove.Bind(wx.EVT_BUTTON, self.onButtonRemove)
hbox.Add(self.buttonRemove)
self.buttonInsert = wx.Button(pannel, id=wx.ID_ANY, label="CREATE", size=(80, 25))
self.buttonInsert.Bind(wx.EVT_BUTTON, self.onButtonInsert)
hbox.Add(self.buttonInsert)
vbox.Add(hbox)
self.Notebook3 = wx.Notebook(pannel)
vbox.Add(self.Notebook3, 2, flag=wx.EXPAND)
pannel.SetSizer(vbox)
self.pageCounter = 0
self.addPage()
def addPage(self):
self.pageCounter += 1
page = Page(self.Notebook3)
pageTitle = "Page: {0}".format(str(self.pageCounter))
self.Notebook3.AddPage(page, pageTitle)
def onButtonRemove(self, event):
self.Notebook3.DeletePage(0)
def onButtonInsert(self, event):
self.addPage()
if __name__ == "__main__":
app = wx.App()
MainFrame().Show()
app.MainLoop()
I want to make a game in wxPython (no other modules) and I want to make it so that you can enter some values in popup screens before the game starts, and then the game will be drawn on a canvas which in turn is drawn on a panel, which is bound to the main game.
I made the gamescreen with all fancy stuff (works solo)
I made the input screens
But I cannot link them.
How do I start the game so it will open a dialog box, then on the closure of it open another one, and then open the game ?
I tried the following, but it will not open my canvas:
# makes a game by showing 2 dialogs
# after dialogs have been answered, starts the game by drawing the canvas.
# imports
import wx
import Speelveld3
# globals
SCRWIDTH = 950
SCRHEIGHT = 700
# dialogbox class
class MyDialog1(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent)
self.username = wx.TextCtrl(self)
self.okButton = wx.Button(self, wx.ID_OK, "OK")
class MyDialog2(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent)
self.canvasWidth = wx.TextCtrl(self)
self.okButton = wx.Button(self, wx.ID_OK, "OK")
# main class
class Game(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, title='My game', size=(SCRWIDTH, SCRHEIGHT))
self.username = ""
self.canvasWidth = 10
# hide the frame for now
self.Hide()
def OnInit(self):
#Make your dialogs
dlg1 = MyDialog1(self)
#if the user pressed "OK" (i.e. NOT "Cancel" or any other button you might add)
if dlg1.ShowModal() == wx.ID_OK:
#get the username from the dialog
self.username = dlg1.username.GetValue()
#clean up the dialog (AFTER you get the username)
dlg1.Destroy()
dlg2 = MyDialog2(self)
#if the user pressed "OK" (i.e. NOT "Cancel" or any other button you might add)
if dlg2.ShowModal() == wx.ID_OK:
#get the username from the dialog
self.canvasWidth = dlg2.canvasWidth.GetValue()
#clean up the dialog (AFTER you get the username)
dlg2.Destroy()
# Now that you have your settings, Make the gameboard
# THIS PART IS STILL BROKEN!
# I can paste the whole board class (structure of it is taken from the tetris tutorial)
# but that seems a bit much tbh...
self.gameBoard = Board.Board(self)
self.gameBoard = SetFocus()
self.gameBoard.start()
self.Centre()
self.Show(True) #show the frame
if __name__ == '__main__':
# how can I start the game here?
app = wx.App()
frame = Game()
board = Speelveld3.Speelveld(frame)
board.start()
frame.Show()
app.MainLoop()
You've double posted, and the lack of any wx.Dialog in your sample code suggests to me that you haven't even looked at a tutorial yet, but I will give you the benefit of the doubt.
First, if you want to return information from a dialog, the easiest way is to define a custom dialog. Define a new class that inherits from wx.Dialog and then set it up just like you would a normal panel or a frame. It seems to me that you will need two of these. They'll look something like this:
class MyDialog1(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent)
self.username = wx.TextCtrl(self) #this is where users will enter their username
self.okButton = wx.Button(self, wx.ID_OK, "OK") #Note that I'm using wx.ID_OK. This is important
Now, for the logic you want. Pretty much every object in wxPython that you actually see has the functions Show() and Hide() (API here). You don't want to show your frame until AFTER the dialogs are finished, so in your __init__(), call Hide(). I'm also initializing a variable, username, which is where I will store the data from my dialog.
class Game(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(SCRWIDTH, SCRHEIGHT))
self.username = ""
self.Hide() #don't show the frame just yet
#self.Hide() is the exact same as self.Show(False)
Now, for your dialogs. Like Mike Driscoll suggested, you call your dialogs BEFORE making your canvas. wx.Dialogs are launched using ShowModal(). By setting the ID of self.okButton to the constant wx.ID_OK, wxPython recognizes that the dialog should be closed after the button in clicked. You should also be aware of wx.ID_CANCEL.
def OnInit(self):
#Make your dialogs
dlg1 = MyDialog1(self)
if dlg1.ShowModal() == wx.ID_OK:
#if the user pressed "OK" (i.e. NOT "Cancel" or any other button you might add)
self.username = dlg1.username.GetValue() #get the username from the dialog
dlg1.Destroy() #clean up the dialog (AFTER you get the username)
#do this again for your second dialog
#Now that you have your settings, Make the gameboard
self.gameBoard = Board.Board(self)
self.gameBoard = SetFocus()
self.gameBoard.start()
self.Centre()
self.Show(True) #show the frame
In your OnInit you just need to call your dialogs and show them modally BEFORE you create your Board instance. Then it should work correctly.
EDIT (6-28-12): Here's some code:
import wx
########################################################################
class MyDlg(wx.Dialog):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Dialog.__init__(self, None, title="I'm a dialog!")
lbl = wx.StaticText(self, label="Hi from the panel's init!")
btn = wx.Button(self, id=wx.ID_OK, label="Close me")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(lbl, 0, wx.ALL, 5)
sizer.Add(btn, 0, wx.ALL, 5)
self.SetSizer(sizer)
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
# show a custom dialog
dlg = MyDlg()
dlg.ShowModal()
dlg.Destroy()
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, evt):
pdc = wx.PaintDC(self)
try:
dc = wx.GCDC(pdc)
except:
dc = pdc
rect = wx.Rect(0,0, 100, 100)
for RGB, pos in [((178, 34, 34), ( 50, 90)),
(( 35, 142, 35), (110, 150)),
(( 0, 0, 139), (170, 90))
]:
r, g, b = RGB
penclr = wx.Colour(r, g, b, wx.ALPHA_OPAQUE)
brushclr = wx.Colour(r, g, b, 128) # half transparent
dc.SetPen(wx.Pen(penclr))
dc.SetBrush(wx.Brush(brushclr))
rect.SetPosition(pos)
dc.DrawRoundedRectangleRect(rect, 8)
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Example frame")
# show a MessageDialog
style = wx.OK|wx.ICON_INFORMATION
dlg = wx.MessageDialog(parent=None,
message="Hello from the frame's init",
caption="Information", style=style)
dlg.ShowModal()
dlg.Destroy()
# create panel
panel = MyPanel(self)
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
frame.Show()
app.MainLoop()
I currently have a toolbar in wxpython with an start icon. I want it so when this icon is clicked the icon and method that it uses changes to stop.
This is the code that I have so far:
#!/usr/bin/env python
# encoding: utf-8
"""
logClient2.py
Created by Allister on 2010-11-30.
"""
import wx
import sqlite3
WINDOW_SIZE = (900,400)
class logClient(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=WINDOW_SIZE)
self.toolbar = self.CreateToolBar()
self.toolbar.AddLabelTool(1, 'Refresh', wx.Bitmap('icons/refresh_icon.png'))
self.toolbar.Realize()
self.Bind(wx.EVT_TOOL, self.startLiveUpdate, id=1)
self.Show(True)
def startLiveUpdate(self, event):
pass
if __name__ == '__main__':
app = wx.App(False)
logClient(None, -1, "Log Event Viewer")
app.MainLoop()
Not really sure what to put in the startLiveUpdate method ?
Thanks for any help!
Here's a quickly hacked together one. Tested on Ubuntu 9.10, Python 2.6, wx 2.8.10.1
#!/usr/bin/env python
# encoding: utf-8
"""
logClient2.py
Created by Allister on 2010-11-30.
"""
import wx
import sqlite3
WINDOW_SIZE = (900,400)
class logClient(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=WINDOW_SIZE)
self.toolbar = self.CreateToolBar()
self.startLiveUpdate(None)
self.Show(True)
def startLiveUpdate(self, event):
self.createToolbarItem("Refresh", "refresh.jpg", self.stopLiveUpdate)
def stopLiveUpdate(self, event):
self.createToolbarItem("Stop", "refresh2.jpg", self.startLiveUpdate)
def createToolbarItem(self, label, imageName, method):
self.toolbar.RemoveTool(1)
self.toolbar.AddLabelTool(1, label, wx.Bitmap(imageName))
self.toolbar.Realize()
self.Bind(wx.EVT_TOOL, method, id=1)
if __name__ == '__main__':
app = wx.App(False)
logClient(None, -1, "Log Event Viewer")
app.MainLoop()
Here is a less hacked version than the accepted answer for wxpython 4.x
self.tool = self.toolbar.AddTool(-1, "A tool", "image.png")
...
def change_tool_label(self):
self.tool.SetLabel("A new label")
# need to call Realize() to re-draw the toolbar
self.toolbar.Realize()
I can't understand how to refresh FigureCanvasWxAgg instance. Here is the example:
import wx
import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.NewId(), "Main")
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.figure = Figure(figsize=(1,2))
self.axe = self.figure.add_subplot(111)
self.figurecanvas = FigureCanvas(self, -1, self.figure)
self.buttonPlot = wx.Button(self, wx.NewId(), "Plot")
self.buttonClear = wx.Button(self, wx.NewId(), "Clear")
self.sizer.Add(self.figurecanvas, proportion=1, border=5, flag=wx.ALL | wx.EXPAND)
self.sizer.Add(self.buttonPlot, proportion=0, border=2, flag=wx.ALL)
self.sizer.Add(self.buttonClear, proportion=0, border=2, flag=wx.ALL)
self.SetSizer(self.sizer)
self.figurecanvas.Bind(wx.EVT_LEFT_DCLICK, self.on_dclick)
self.buttonPlot.Bind(wx.EVT_BUTTON, self.on_button_plot)
self.buttonClear.Bind(wx.EVT_BUTTON, self.on_button_clear)
self.subframe_opened = False
def on_dclick(self, evt):
self.subframe = SubFrame(self, self.figure)
self.subframe.Show(True)
self.subframe_opened = True
def on_button_plot(self, evt):
self.axe.plot(range(10), color='green')
self.figurecanvas.draw()
def on_button_clear(self, evt):
if self.subframe_opened:
self.subframe.Close()
self.figure.set_canvas(self.figurecanvas)
self.axe.clear()
self.figurecanvas.draw()
class SubFrame(wx.Frame):
def __init__(self, parent, figure):
wx.Frame.__init__(self, parent, wx.NewId(), "Sub")
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.figurecanvas = FigureCanvas(self, -1, figure)
self.sizer.Add(self.figurecanvas, proportion=1, border=5, flag=wx.ALL | wx.EXPAND)
self.SetSizer(self.sizer)
self.Bind(wx.EVT_CLOSE, self.on_close)
def on_close(self, evt):
self.GetParent().subframe_opened = False
evt.Skip()
class MyApp(wx.App):
def OnInit(self):
frame = MainFrame()
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(0)
app.MainLoop()
I'm interested in the following sequence of operations:
run a script
resize the main frame
press Plot button
double click on plot
press Clear button
Now I get a mess on main frame plot. If I resize the frame it redraws properly. My question is what should I add to my code to do that without resizing?
By a "mess" I mean something like this:
http://img227.imageshack.us/img227/5407/mess.png
Thanks in advance.
As I said in the comments, I don't think that the figure canvas refresh is your problem, in fact I think it's doing exactly what it's supposed to (redrawing itself based on it's last state [ie as it was in your subplot]). I think your problem is more that the wxFrame is not refreshing.
The easiest way to fix that would be to make it resize itself on your "Clear" event. Something like:
def on_button_clear(self, evt):
if self.subframe_opened:
self.subframe.Close()
self.figure.set_canvas(self.figurecanvas)
self.axe.clear()
self.figurecanvas.draw()
self.SetSize((self.Size[0],self.figurecanvas.Size[1]))
The set size would cause the frame and all the controls it contains to be redrawn.
That said, I think sharing your figure between the two figurecanvas is dangerous. I was able to produce some serious errors by clicking/resizing things in different combinations. On occasion your figure would be garbage collected when the subframe was closed, making it unavailable to your main frame.