开发者

Cocoa exception: _createMenuRef called with existing principal MenuRef already associated with menu

开发者 https://www.devze.com 2023-04-04 08:01 出处:网络
This is the Python code: #!/usr/bin/python import os import sys from Foundation import * from AppKit import *

This is the Python code:

#!/usr/bin/python

import os
import sys

from Foundation import *
from AppKit import *
import objc

def setupWindowMenu(app):
    windowMenu = NSMenu.alloc().initWithTitle_('Window')
    windowMenu.retain()
    menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Minimize', 'performMiniaturize:', 'm')
    windowMenu.addItem_(menuItem)
    windowMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Window', None, '')
    windowMenuItem.setSubmenu_(windowMenu)
    app.mainMenu().addItem_(windowMenuItem)
    app.setWindowsMenu_(windowMenu)

app = NSApplication.sharedApplication()

mainMenu = NSMenu.alloc().init()
app.setMainMenu_(mainMenu)
setupWindowMenu(app)

app.finishLaunching()
app.updateWindows()
app.activateIgnoringOtherApps_(True)

app.run()

I am getting this output:

$ python pyobjcdemo.py
2011-09-11 23:22:40.470 Python[21409:1507] _createMenuRef called with existing principal MenuRef already associated with menu
2011-09-11 23:22:40.471 Python[21409:1507] (
    0   CoreFoundation                      0x00007fff93acb986 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00007fff8f3b4d5e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff93acb7ba +[NSException raise:format:arguments:] + 106
    3   CoreFoundation                      0x00007fff93acb744 +[NSException raise:format:] + 116
    4   AppKit                              开发者_C百科0x00007fff8a8841fb -[NSCarbonMenuImpl _createMenuRef] + 64
    5   AppKit                              0x00007fff8a883ae6 -[NSCarbonMenuImpl _instantiateCarbonMenu] + 148
    6   AppKit                              0x00007fff8a8588e9 -[NSApplication finishLaunching] + 878
    7   AppKit                              0x00007fff8a85827d -[NSApplication run] + 118
    8   libffi.dylib                        0x00007fff8cf29e7c ffi_call_unix64 + 76
    9   ???                                 0x00007fbd1b480d10 0x0 + 140450183253264
)

Why?

What does it mean?

Why does this simple PyObjC code has any Carbon dependencies?


The error is the call to finishLaunching. Just remove it, it should eliminate the error.

Concerning why you see Carbon types in Cocoa, it is just a matter of code layers. Carbon and Cocoa are not two totally separate systems, they are APIs into the same system. (Although the lower "Carbon" layers are often referred to as "core" technologies, like Core Graphics.)

0

精彩评论

暂无评论...
验证码 换一张
取 消