Re: [Gtk-osx-users] Custom URL Handler

Hi Phil,

I've done something similar a while ago : let gPodder handle "Subscribe to RSS feed" from Firefox.
But I resorted to Carbon.AppleEvents to do it (deprecated I'm afraid).
In case you want to check it out, here it is :

Le 25/08/10 08:23, Phillip Heller a écrit :

  I'm wondering if anyone has implemented a Custom URL Handler within a pygtk project?  It doesn't look like gtk provides a method to do this directly, so I'm trying with pyobjc and the Foundation classes.

An example of how I'm trying to do it:

import Foundation
TRYTONSCHEME = u'tryton'
WINDOW = none

class TrytonURLProtocol(Foundation.NSURLProtocol):    
    def canInitWithRequest_(cls, request):
        if request.URL().scheme() == TRYTONSCHEME:
            return True
        return False

    def canonicalRequestForRequest_(cls, request):
        return request

    def startLoading(self):
        m ='tryton://([^/]+)/(\d+)', self.request())
        if m is not None:
            Window.create(False,, [int(], [], 'form', 
                    mode=['form'], window=WINDOW)
    def stopLoading(self):

class Main(object):

    def __init__(self):
        super(Main, self).__init__()

        self.window = gtk.Window()
        WINDOW = self.window

<snip snip snip>

<the following line called at a point where the application can satisfy a URL request>


I've added the following to the Application Bundle Info.plist:

                        <string>MyApp's URL</string>

Whenever I open a url like "tryton://sale.order/12345", the application gains focus, though nothing seemingly happens within the application itself.

Did you try with your application not open ?
From what I understand of your code, it's not possible, but my code doesn't work when the application is open (the event is not received).
The fact that your application gains focus is encouraging.
Maybe, when you'll be able to see debug output, it'll be easier to figure out (see next bullet).

I'm not sure how exactly to debug this either -- normally I do my development within Eclipse with pydev, though I'm not sure how to do that with a bundled application.  Any attempts to print to STDOUT within TrytonURLProtocol methods seem to fail.
Did you check in console.log (via /Applications/Utilities/Console) ?

Hope this helps,

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]