[Pythonmac-SIG] [SOLVED] open program via a protocol (eg. myapp:command)

Brendan Simon (eTRIX) Brendan.Simon at eTRIX.com.au
Sat Jul 11 12:30:18 CEST 2009


Brendan Simon (eTRIX) wrote:
> 
> Cody Precord wrote:
>> Hello,
>>
>> On Jul 10, 2009, at 10:35 PM, Brendan Simon (eTRIX) wrote:
>>
>>> Brendan Simon (eTRIX) wrote:
>>> I registered the __geturl() event handler but it never gets called.

I forget to add self to the 'method' that's why it failed.  It does in
fact get called when the method is defined properly :)


I modified argv_emulation.py from the py2app package.
Added an event handler for the GetURL to extract the url and append to
sys.argv.  The code was based on the existing handler for OpenDocuments
event and the snippet that 'has' posted (changed typeUTF8Text to
typeWildCard as typeUTF8Text didn't exist on my system).

Here is the diff.

k9m:bootstrap $ diff argv_emulation.py.orig argv_emulation.py
10c10,11
<         kAEOpenDocuments, keyDirectObject, typeAEList, typeAlias
---
>         kAEOpenDocuments, keyDirectObject, typeAEList, typeAlias, \
>         kAEInternetSuite, kAEISGetURL, typeWildCard
25a27,29
>             #AE.AEInstallEventHandler(kAEInternetSuite, kAEISGetURL,
>             AE.AEInstallEventHandler('GURL', 'GURL',
>                 self.__geturl)
29a34,35
>             #AE.AERemoveEventHandler(kAEInternetSuite, kAEISGetURL)
>             AE.AERemoveEventHandler('GURL', 'GURL')
93a100,111
>         def __geturl(self, requestevent, replyevent): # event handler
>             try:
>                 listdesc =
requestevent.AEGetParamDesc(keyDirectObject, typeAEList)
>                 for i in range(listdesc.AECountItems()):
>                     desc = listdesc.AEGetNthDesc(i+1, typeWildCard)[1]
>                     url = desc.data.decode('utf8')
>                     sys.argv.append(url)
>             except Exception, e:
>                 print "argvemulator.py warning: can't unpack an GetURL
event"
>
>             self._quit()
>

Should I submit this as a patch somewhere ???

Thanks, Brendan.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Brendan_Simon.vcf
Type: text/x-vcard
Size: 267 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20090711/1782ec5d/attachment.vcf>


More information about the Pythonmac-SIG mailing list