[PyQt] QDesktopServices.setUrlHandler not called on OS X
Marko Luther
marko.luther at gmx.net
Sun Jul 7 12:12:22 BST 2019
Now it seems to me that the
> QDesktopServices.setUrlHandler
is doing nothing, at least on Mac OS X and Windows.
Windows seems not to be able to send even the event to an already running instance of the app that got registered via the corresponding registry entries. Instead it starts a new instance of the app and hands the URL over via sys.args. Strange.
Is nobody using URL schemes?
Best,
Marko
> On 30. Jun 2019, at 16:34, Marko Luther <marko.luther at gmx.net> wrote:
>
> Dear all,
>
> I am struggling to get the expected call-back from a URL handler registered via QDesktopServices.setUrlHandler on opening the registered URL scheme (test://<path>).
>
> The scheme is registered via the following info.plist entry
>
> <key>CFBundleURLTypes</key>
> <array>
> <dict>
> <key>CFBundleURLName</key>
> <string>com.simple</string>
> <key>CFBundleURLSchemes</key>
> <array>
> <string>test</string>
> </array>
> </dict>
> </array>
>
> The handler is installed in the PyQt script via
>
> QDesktopServices.setUrlHandler('test', open_desktopservices_url)
>
> with
>
> def open_desktopservices_url(url):
> print("open",url)
>
> or
>
> handler = URLHandler()
> QDesktopServices.setUrlHandler("test", handler.handleURL)
>
> class URLHandler(QObject):
> def handleURL(self, url):
> open_desktopservices_url(url)
>
>
> To open the URL I put the URL "test://me" into Safari or use the terminal with
>
> # open test://me
>
> Opening the URL brings the app to the foreground, but the handler is never called.
>
> I found a way to catch this URL request by catching a FileOpen event and extracting the given URL from the event as follows
>
> class Simple(QApplication):
> def __init__(self, args):
> super(Simple, self).__init__(args)
>
> def event(self, event):
> if event.type() == QEvent.FileOpen:
> url = event.url()
> if url.isValid():
> print("url",event.url())
> return super(Simple, self).event(event)
>
>
> Is this the way it has to be done?
>
> I attached a minimal sample app sample.py together with a setup.py script to build the app with py2app that builds and runs as follows:
>
> # python3 setup.py py2app
> # dist/Simple.app/Contents/MacOS/Simple
>
> This is on OS X 10.13.6, Python 3.7.3, PyQt 5.12.13, py2app 0.19
>
> Thanks for any pointer in the right direction,
> Marko
>
> <setup.py><simple.py>_______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
More information about the PyQt
mailing list