views:

136

answers:

3

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 ?

A: 

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.

Warren P
yes current wx uses Carbon, but anyway it is more of API issue, wx hasn't provided ways to tweak messages as cocoa allows
Anurag Uniyal
A: 

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.

Mark
I was already doing that, but somehow we have decided to use native dialogs as much as we can instead of trying to replicate and maintain them
Anurag Uniyal
A: 

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

RyanWilcox
hmmm but what could go wrong? atleast for time being nothing seems to go wrong, I also added a NSProgressindicator to my app, it seems to be working fine, and if dialogs are modal, and are discarded after that, may be it won't be a problem?
Anurag Uniyal
@Anurag Uniyal: potentially. I've updated my answer after thinking about it again.
RyanWilcox