Skip to content Skip to sidebar Skip to footer

Wxpython Macos X Lion Full Screen Mode

I am making a wxPython application that needs to work in full screen. I want to use the new full screen mode that came in OS X Lion. How can I make the full screen icon appear on t

Solution 1:

Until bug #14357 is fixed, there's no direct way to do this using only wxPython functions that I know of.

However, you can bypass wxWidgets and access the Cocoa APIs directly to do what you need. Note that you must be using the wxMac/Cocoa bindings (wxPython 2.9 or above).

This is the code necessary to make a frame full-screen capable:

# from http://stackoverflow.com/questions/12328143/getting-pyobjc-object-from-integer-id
import ctypes, objc
_objc = ctypes.PyDLL(objc._objc.__file__)

# PyObject *PyObjCObject_New(id objc_object, int flags, int retain)
_objc.PyObjCObject_New.restype = ctypes.py_object
_objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]

def objc_object(id):
    return _objc.PyObjCObject_New(id, 0, 1)

def SetFullScreenCapable(frame):
    frameobj = objc_object(frame.GetHandle())

    NSWindowCollectionBehaviorFullScreenPrimary = 1<<7
    window = frameobj.window()
    newBehavior = window.collectionBehavior() | NSWindowCollectionBehaviorFullScreenPrimary
    window.setCollectionBehavior_(newBehavior)

And here's a short test app that demonstrates it:

import wxversion
wxversion.select('2-osx_cocoa') # require Cocoa version of wxWidgetsimport wx

classFrame(wx.Frame):
    def__init__(self):
        wx.Frame.__init__(self, None)
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        wx.Button(self, label="Hello!") # test button to demonstrate full-screen resizing
        SetFullScreenCapable(self)

    defOnClose(self, event):
        exit()

app = wx.App()
frame = Frame()
frame.Show()
app.MainLoop()

Post a Comment for "Wxpython Macos X Lion Full Screen Mode"