[Gtk-osx-users] Custom URL Handler



Greetings,

  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 = re.search('tryton://([^/]+)/(\d+)', self.request())
        if m is not None:
            Window.create(False, m.group(1), [int(m.group(2))], [], 'form', 
                    mode=['form'], window=WINDOW)
        
    def stopLoading(self):
        pass


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>

                Foundation.NSURLProtocol.registerClass_(TrytonURLProtocol)

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

<key>CFBundleURLTypes</key>
        <array>
                <dict>
                        <key>CFBundleURLName</key>
                        <string>MyApp's URL</string>
                        <key>CFBundleURLSchemes</key>
                        <array>
                                <string>tryton</string>
                        </array>
                </dict>
        </array>

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

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.

Any suggestions?  

Regards,

  Phil


Attachment: smime.p7s
Description: S/MIME cryptographic signature







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