wxPython Mac OS X Fullscreen work around error

冷暖自知 提交于 2019-12-13 22:12:45

问题


I was trying to get fullscreen support for a wxPython app using the code in the answer from this stackoverflow question wxPython MacOS X Lion full screen mode

My Error

Traceback (most recent call last):
  File "test_mac_fullscreen.py", line 36, in <module>
    frame = Frame()
  File "test_mac_fullscreen.py", line 29, in __init__
    SetFullScreenCapable(self)
  File "test_mac_fullscreen.py", line 16, in SetFullScreenCapable
    window = frameobj.window()
AttributeError: 'NSHIObject' object has no attribute 'window'

My Code (just copied and pasted into one file from the above link)

# from https://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)

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):
        print "Closing"
        exit()
if __name__ == "__main__":
    app = wx.App(False)
    frame = Frame()
    frame.Show()
    app.MainLoop()
    print "running app loop"

回答1:


While this is rather late, recently looking at this it suddenly clicked.

If you notice in the error it states a class NSHIObject (HI I am guessing stands for Human Interface) this has to do with the backend that wxPython uses, the archaic Carbon (as in this case) or the updated Cocoa. In earlier versions only Carbon was available but with 2.9.5 (IIRC) Cocoa is available (and I believe it has sense moved to 3.0 with Cocoa or Carbon ). Simply reinstall with a cocoa version and it works.



来源:https://stackoverflow.com/questions/14068923/wxpython-mac-os-x-fullscreen-work-around-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!