开发者

Should I mix wxpython and pyobjc?

开发者 https://www.devze.com 2022-12-25 15:03 出处:网络
I have a wxPython based app which I am porting to Mac OS X, in that I 开发者_如何学Pythonneed to show some alerts which should look like native mac alerts, so I am using pyobjc for that e.g.

I have a wxPython based app which I am porting to Mac OS X, in that I 开发者_如何学Pythonneed to show some alerts which should look like native mac alerts, so I am using pyobjc for that e.g.

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 ?


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...))


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.

0

精彩评论

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