I am trying to make my top_panel of my program go into fullscreen only, i hope to have a button which will do this, the issue i am faced with is i dont know how to make the pane
Using Mike Driscoll's example code, there is a way of faking full screen for a panel, when more than one panel is being used. It's a bit of a hack at the moment but it should give you the gist of it.
Use SetMinSize
and SendSizeEvent
.
Click on a coloured panel for focus and then press F1,F2 or F3 to swap the panels in and out of "full screen" or revert to equal sizes.
import wx
class MyPanel(wx.Panel):
""""""
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.Bind(wx.EVT_KEY_DOWN, self.onKey)
def onKey(self, event):
"""
Check for ESC key press and exit is ESC is pressed
F1 panel 1 is full screen
F2 panel 2 is full screen
F3 panels revert to equal sizes
"""
key_code = event.GetKeyCode()
parent = self.GetParent()
width, height = wx.GetDisplaySize()
if key_code == wx.WXK_ESCAPE:
self.GetParent().Close()
elif key_code == wx.WXK_F1:
parent.panel1.SetMinSize((1,1))
parent.panel2.SetMinSize((width,height))
parent.SendSizeEvent()
parent.Layout()
parent.Fit()
elif key_code == wx.WXK_F2:
parent.panel2.SetMinSize((1,1))
parent.panel1.SetMinSize((width,height))
parent.SendSizeEvent()
parent.Layout()
parent.Fit()
elif key_code == wx.WXK_F3:
parent.panel2.SetMinSize((120,70))
parent.panel1.SetMinSize((120,70))
parent.SendSizeEvent()
parent.Layout()
parent.Fit()
else:
event.Skip()
class MyFrame(wx.Frame):
""""""
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Test FullScreen")
self.panel1 = MyPanel(self)
self.panel2 = MyPanel(self)
self.panel1.SetBackgroundColour(wx.GREEN)
self.panel2.SetBackgroundColour(wx.BLUE)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(self.panel1)
vbox.Add(self.panel2)
self.SetSizer(vbox)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
app.MainLoop()
Note: for your case you will not want to really go to full screen, as you will probably need to still access some control buttons, so just deduct the amount you need from the full screen size.
I have written about this subject on my blog. Here's an example:
import wx
class MyPanel(wx.Panel):
""""""
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.Bind(wx.EVT_KEY_DOWN, self.onKey)
def onKey(self, event):
"""
Check for ESC key press and exit is ESC is pressed
"""
key_code = event.GetKeyCode()
if key_code == wx.WXK_ESCAPE:
self.GetParent().Close()
else:
event.Skip()
class MyFrame(wx.Frame):
""""""
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Test FullScreen")
panel = MyPanel(self)
self.ShowFullScreen(True)
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
app.MainLoop()
I have noticed that this code doesn't seem to work with Macs.
You can't show a child window, such as a panel, full screen. Only top level frames can be shown full screen but, of course, this shouldn't be a problem at all because absolutely nothing prevents you from creating a frame containing just the panel and then showing this frame full screen is completely equivalent to showing the panel full screen.