简体   繁体   中英

wxpython panel fullscreen?

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 panel go into fullscreen it self without forcing the whole frame to go into fullscreen using ShowFullscreen(true)

i hope you can help me

class top_panel(wx.Panel):

def __init__(self, parent):
    wx.Panel.__init__(self, parent=parent, size=(400,175))
    self.SetBackgroundColour('BLACK')
    self.ofullscreen = wx.Button(self, -1, "Fullscreen", (10,30))
    self.ofullscreen.Bind(wx.EVT_BUTTON, self.onfullscreen, self.ofullscreen)
    self.gbs = wx.GridBagSizer(2,2)
    self.Bind(wx.EVT_KEY_DOWN, self.onKey)
    wx.Frame.ShowFullScreen(True)
#----------------------------------------------------------------------
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()   

def onfullscreen(self):
    print "hola"
    #self.fullscreen?????

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM