问题
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:
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()
来源:https://stackoverflow.com/questions/12327641/wxpython-macos-x-lion-full-screen-mode