I change my panels by destroying panel 1 and then show panel 2. I cannot use the method creating both and hide en show, because than I have other problems. But after redo my layout my panel is very small. How can I make it the same size as before?
This is my testcode
import wx
class Main(wx.Frame):
def __init__(self, parent=None, id=-1, notify_channel="chanMicroanalysis", **kwargs):
# general panel information
wx.Frame.__init__(self, parent, wx.ID_ANY)
self.SetTitle('Microanalysis')
self.backpanel = wx.Panel(self, wx.ID_ANY)
# first panel
self.Choicepanel = wx.Panel(self.backpanel, wx.ID_ANY)
self.lblChoose = wx.StaticText(self.Choicepanel, label="Choose:")
self.btnChooseFilterOnly = wx.Button(self.Choicepanel, wx.ID_ANY, "Filter only ")
self.btnChooseMA = wx.Button(self.Choicepanel, wx.ID_ANY, "Microanalyse")
self.btnChooseCellInfo = wx.Button(self.Choicepanel, wx.ID_ANY, " CellInfo ")
self.btnChooseReport = wx.Button(self.Choicepanel, wx.ID_ANY, "Report")
# second panel: cellinfo
self.test1 =wx.Panel(self.backpanel, wx.ID_ANY)
self.Cellinfopanel = self.test1
self.lblChooseingo = wx.StaticText(self.Cellinfopanel, label="Choose:")
self.btnChooseFilter = wx.Button(self.Cellinfopanel, wx.ID_ANY, "Filter only ")
self.btnChooseprr = wx.Button(self.Cellinfopanel, wx.ID_ANY, "Microanalyse")
self.btnChooseCell = wx.Button(self.Cellinfopanel, wx.ID_ANY, " CellInfo ")
self.btnChoose = wx.Button(self.Cellinfopanel, wx.ID_ANY, "Report")
self._do_layout()
self._do_bindings()
def _do_layout(self):
self.h_main_sizer = wx.BoxSizer()
self.h_centerbuttonsizer = wx.BoxSizer()
self.h_centerbutton1sizer = wx.BoxSizer()
self.v_firstsizer = wx.BoxSizer(wx.VERTICAL)
self.v_secondsizer = wx.BoxSizer(wx.VERTICAL)
self.v_thirdsizer = wx.BoxSizer(wx.VERTICAL)
self.v_fourthsizer = wx.BoxSizer(wx.VERTICAL)
self.v_buttonsizer = wx.BoxSizer(wx.VERTICAL)
self.v_button1sizer = wx.BoxSizer(wx.VERTICAL)
########################################"
self.v_firstsizer.Add(self.Choicepanel, 1, wx.EXPAND)
self.v_buttonsizer.Add(self.lblChoose, 0, wx.CENTER)
self.v_buttonsizer.Add(self.btnChooseFilterOnly, 0, wx.EXPAND)
self.v_buttonsizer.Add(self.btnChooseMA, 0, wx.EXPAND)
self.v_buttonsizer.Add(self.btnChooseCellInfo, 0, wx.EXPAND)
self.v_buttonsizer.Add(self.btnChooseReport, 0, wx.EXPAND)
self.h_centerbuttonsizer.AddStretchSpacer(1)
self.h_centerbuttonsizer.Add(self.v_buttonsizer, 0, wx.CENTER)
self.h_centerbuttonsizer.AddStretchSpacer(1)
self.Choicepanel.SetSizer(self.h_centerbuttonsizer)
self.h_centerbuttonsizer.Fit(self.Choicepanel)
########################################"
self.v_secondsizer.Add(self.Cellinfopanel, 5, wx.EXPAND)
self.v_button1sizer.Add(self.lblChooseingo, 0, wx.CENTER)
self.v_button1sizer.Add(self.btnChooseFilter, 0, wx.EXPAND)
self.v_button1sizer.Add(self.btnChooseprr, 0, wx.EXPAND)
self.v_button1sizer.Add(self.btnChooseCell, 0, wx.EXPAND)
self.v_button1sizer.Add(self.btnChoose, 0, wx.EXPAND)
self.h_centerbutton1sizer.AddStretchSpacer(1)
self.h_centerbutton1sizer.Add(self.v_button1sizer, 0, wx.CENTER)
self.h_centerbutton1sizer.AddStretchSpacer(1)
self.Cellinfopanel.SetSizer(self.h_centerbutton1sizer)
self.h_centerbutton1sizer.Fit(self.Choicepanel)
########################################"
self.h_main_sizer.Add(self.v_firstsizer, 20, wx.EXPAND)
self.h_main_sizer.Add(self.v_secondsizer, 20, wx.EXPAND)
self.backpanel.SetSizer(self.h_main_sizer)
self.h_main_sizer.Fit(self)
#
# self.Choicepanel.Show()
# self.Cellinfopanel.Hide()
# self.MApanel.Hide()
# self.Reportpanel.Hide()
self.Choicepanel.Show()
self.Cellinfopanel.Show()
self.statusMAPanelShown = False
def _do_bindings(self):
self.btnChooseprr.Bind(wx.EVT_BUTTON, self.on_chooseMA)
def on_chooseMA(self, event):
print "in choose MA"
self.showMAPanel()
self._do_layout()
#
# self.Layout()
def showMAPanel(self):
print "in showmapanel"
self.test1.Destroy()
self.test2 =wx.Panel(self.backpanel, wx.ID_ANY)
self.Cellinfopanel = self.test2
self.lblChooseingo = wx.StaticText(self.Cellinfopanel, label="test:")
self.btnChooseFilter = wx.Button(self.Cellinfopanel, wx.ID_ANY, "test1 ")
self.btnChooseprr = wx.Button(self.Cellinfopanel, wx.ID_ANY, "test2")
self.btnChooseCell = wx.Button(self.Cellinfopanel, wx.ID_ANY, " test3 ")
self.btnChoose = wx.Button(self.Cellinfopanel, wx.ID_ANY, "test4")
if __name__ == '__main__':
app = wx.PySimpleApp()
MAview = Main(None, wx.ID_ANY)
MAview.Maximize()
MAview.Show()
app.MainLoop()
EDIT: This is not the same question as is proposed. In the proposed question, I used the hide and show method, and there was also a resizing problem, but there the panel was to big. I actually solved the other question and I will add the answer.
This post helped me with my problem (http://forums.devshed.com/python-programming-11/wxpython-refreshing-panel-panel-392700.html)
With adding
self.Fit()
self.GetParent().SendSizeEvent()
my problem was solved.