简体   繁体   中英

Should I mix wxpython and pyobjc?

I have a wxPython based app which I am porting to Mac OS X, in that I need to show some alerts which should look like native mac alerts, so I am using pyobjc for that eg

import Cocoa

import wx

app = wx.PySimpleApp()
frame = wx.Frame(None, title="mac alert test")
app.SetTopWindow(frame)
frame.Show()

def onclick(event):
    Cocoa.CFUserNotificationDisplayAlert(0, 3, 0, 0, 0, "Should i mix wxpython and objc", "hmmm...", 
                                         "Cool", "Not Cool", "Whatever")

frame.Bind(wx.EVT_LEFT_DOWN, onclick)
app.MainLoop()

Is there any thing wrong in such mixing of wx and objc code, any failure points ?

One possible question to ask; I believe you must be using wx version for Mac that rests atop Carbon, because I think the Cocoa version hasn't been released yet. Once the cocoa version is released (for wx) then I would think there would have to be "fewer" issues. A mix of carbon and cocoa sounds problematic to me, but I can't point out specific gotchas.

Any reason you don't just write a custom WX dialog, that inherits from wx.Dialog? The WX demo has a very nice example of that . A little more work, but a cleaner approach.

I don't think that will work too well, mixing the event loops...

[EDIT: I thought this initially, because the dialog is model and the window behind it is not, and there might be two event loops fighting for control. (Because each window has its own, which is why you can have Carbon and Cocoa windows in (an application of mostly the other type).

On the other hand, the front window - your dialog box - controls the entire event loop if it's model, so it could work actually.]

I'd really suggest you read the Carbon/Cocoa Integration guide . Now, this is more difficult because you're in Python and not C, but it may explain some concepts.

I think on a previous project we implemented our own dialog like this, including customizable texts. (Since we were using wxWidgets/C++ we just implemented this using Carbon APIs with a wxWidgets layer and we looked pretty good. (... and we had a pretty heavily modified version of wx...))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM