0

我试图使用this stackoverflow question wxPython MacOS X Lion full screen mode的答案中的代码来获得对wxPython应用程序的全屏支持

我的错误

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'

我的代码(刚刚从上面的链接复制并粘贴到一个文件中)

# 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"
4

1 回答 1

1

虽然这已经很晚了,但最近看着它突然点击了。

如果您在错误中注意到它声明了一个类 NSHIObject(HI 我猜代表人机界面),这与 wxPython 使用的后端、古老的 Carbon(如本例中)或更新的 Cocoa 有关。在早期版本中,只有 Carbon 可用,但 2.9.5 (IIRC) Cocoa 可用(我相信使用 Cocoa 或 Carbon 转移到 3.0 是有意义的)。只需使用可可版本重新安装即可。

于 2014-01-19T16:29:36.753 回答