Search code examples
pythonobjective-cwxpythonwxwidgetspyobjc

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 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 ?


Solution

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