Introduction

This program explores the use of TopLevelWindow.ShowFullScreen() after some discussion on the mailing list.

What Objects are Involved

A Frame, but the code writes this into a panel so the panel can be used to test different types of frames.

Process Overview

Use a CheckListBox to list the available flags, then have a button to toggle between Full Screen mode and normal mode. Flags are only applied when going into full screen mode.

Special Concerns

Part of the mailing list discussion led to the conclusion that there is a bug in wxGTK, and toolbars, menus, and statusbars are not shown in full screen mode in wxPython 2.8.x.

Code Sample

   1 """FullScreen
   2 
   3 This file explores various ways to toggle into fullscreen mode
   4 """
   5 
   6 import wx
   7 
   8 from operator import or_
   9 
  10 TBFLAGS = ( wx.TB_HORIZONTAL
  11             | wx.NO_BORDER
  12             | wx.TB_FLAT
  13             #| wx.TB_TEXT
  14             #| wx.TB_HORZ_LAYOUT
  15             )
  16     
  17 class FullScreenTestPanel(wx.Panel):
  18     def __init__(self,parent):
  19         wx.Panel.__init__(self,parent,name="fullscreentestpanel")
  20         self.SetBackgroundColour('white')
  21 
  22         FlagList = ['FULLSCREEN_NOMENUBAR',
  23                     'FULLSCREEN_NOTOOLBAR',
  24                     'FULLSCREEN_NOSTATUSBAR',
  25                     'FULLSCREEN_NOBORDER',
  26                     'FULLSCREEN_NOCAPTION',
  27                     'FULLSCREEN_ALL']
  28         
  29         lb = wx.CheckListBox(self,choices=FlagList)
  30         self.lb = lb
  31         self.FullScreenBtn = wx.Button(self,label="Go to Full Screen")
  32         self.FullScreenBtn.Bind(wx.EVT_BUTTON,self.FullScreen)
  33         
  34         sizer = wx.StaticBoxSizer(wx.StaticBox(self,label="Full Screen"),
  35                                   wx.VERTICAL)
  36         sizer.Add(lb)
  37         sizer.Add(self.FullScreenBtn)
  38         self.SetSizer(sizer)
  39         self.Layout()
  40 
  41     def GetFlags(self):
  42         """Returns the flags selected in the box"""
  43         res = []
  44         for x in range(self.lb.GetCount()):
  45             if self.lb.IsChecked(x):
  46                 val = self.lb.GetString(x)
  47                 res.append(getattr(wx,val))
  48         return reduce(or_,res,0)
  49 
  50     def FullScreen(self,evt):
  51         top = self.GetTopLevelParent()
  52         top.OnFullScreen(evt)
  53         
  54 class TestFrame(wx.Frame):
  55     def __init__(self, parent):
  56         wx.Frame.__init__(self, parent, wx.ID_ANY, 'Test FullScreen', size=(600, 400))
  57         
  58         self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
  59 
  60         self.client = FullScreenTestPanel(self)
  61         
  62         ### Create the toolbar
  63         tb = self.CreateToolBar( TBFLAGS )
  64 
  65         ### Create the Menubar
  66         mbar = wx.MenuBar()
  67         the_menu = wx.Menu()
  68         fullscreenMI = the_menu.Append(wx.ID_ANY,"Full Screen\tF12","Toggles Full Screen Mode")
  69         mbar.Append(the_menu,"Stuff")
  70 
  71         self.SetMenuBar(mbar)
  72 
  73         ### Bind full menu stuff
  74         self.Bind(wx.EVT_MENU,self.OnFullScreen,id=fullscreenMI.GetId())
  75 
  76         self.CreateStatusBar()
  77 
  78         tsize = (24,24)
  79         new_bmp =  wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize)
  80         open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize)
  81         copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize)
  82         paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize)
  83 
  84         tb.SetToolBitmapSize(tsize)
  85         
  86         tb.AddLabelTool(10, "New", new_bmp, shortHelp="New", longHelp="Long help for 'New'")
  87         tb.AddLabelTool(20, "Open", open_bmp, shortHelp="Open", longHelp="Long help for 'Open'")
  88 
  89         tb.AddSeparator()
  90         tb.AddSimpleTool(30, copy_bmp, "Copy", "Long help for 'Copy'")
  91         tb.AddSimpleTool(40, paste_bmp, "Paste", "Long help for 'Paste'")
  92         tb.Realize()
  93 
  94     def OnCloseWindow(self, event):
  95         self.Destroy()
  96 
  97     def OnFullScreen(self,event):
  98         flags = self.client.GetFlags()
  99         self.ShowFullScreen(not self.IsFullScreen(),flags)
 100 
 101 class TestApp(wx.App):
 102     def OnInit(self):
 103 
 104         self.main = TestFrame(None)
 105         self.main.Show()
 106         self.SetTopWindow(self.main)
 107         return True
 108 
 109 def main():
 110     application = TestApp(redirect=False)
 111     application.MainLoop()
 112 
 113 if __name__=='__main__':
 114     main()

Discussion

On some platforms there may be no noticeable difference between some flags, such as FULLSCREEN_NOBORDER and FULLSCREEN_NOCAPTION.

Comments

Let me know what you think here, or at JoshEnglish

Using Frame.ShowFullScreen (last edited 2008-07-27 22:56:45 by 216-99-198-201)