wxPython Mac OS X全屏解决错误 [英] wxPython Mac OS X Fullscreen work around error

查看:137
本文介绍了wxPython Mac OS X全屏解决错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用此stackoverflow问题

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

我的错误

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"

推荐答案

虽然这已经很晚了,但最近看到它时却突然点击了它.

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

如果您在错误中注意到它指出了一个NSHIObject类(我想代表人机接口),这与wxPython使用的后端,过时的Carbon(在这种情况下)或更新的Cocoa有关.在早期版本中,只有Carbon可用,但带有2.9.5(IIRC)的Cocoa可用(我相信使用Cocoa或Carbon可以将其提高到3.0).只需重新安装可可版本即可.

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.

这篇关于wxPython Mac OS X全屏解决错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆