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 the top right corner?
1
votes
What have you tried? A quick Google search for "wxpython full screen" has revealed several different options.
- acattle
He specifically wants to use Lion's new full-screen API. wxWidgets doesn't have this functionality yet.
- nneonneo
@nneonneo That's as may be but the question as written doesn't show any independent research effort, which is against community guidelines.
- acattle
I wouldn't have known how to do it either...this is a new feature of OS X, and not a lot of GUI frameworks aside from Apple's own support it yet.
- nneonneo
1 Answers
2
votes
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 wxWidgets
import wx
class Frame(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)
def OnClose(self, event):
exit()
app = wx.App()
frame = Frame()
frame.Show()
app.MainLoop()