LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   xdg-open, gnome-open or kde(4?)-open??? (http://www.linuxquestions.org/questions/programming-9/xdg-open-gnome-open-or-kde-4-open-823821/)

akamikeym 08-03-2010 08:54 AM

xdg-open, gnome-open or kde(4?)-open???
 
Hi there,

I've just been trying to get Muzik Brainz Picard to open my preferred browser (chromium) on my Arch system that's XFCE only. Bizarrely it was opening 'elinks'. I realised that it was doing something weird with gnome-open so I had a look through the code and found this:

Code:

if sys.version_info >= (2, 5):
    # KDE default browser
    if 'KDE_FULL_SESSION' in os.environ and os.environ['KDE_FULL_SESSION'] == 'true' and webbrowser._iscommand('kfmclient'):
        webbrowser.register('kfmclient', None, webbrowser.BackgroundBrowser(["kfmclient", "exec", "%s"]), update_tryorder=-1)
    # GNOME default browser
    if 'GNOME_DESKTOP_SESSION_ID' in os.environ and webbrowser._iscommand('gnome-open'):
        webbrowser.register('gnome-open', None, webbrowser.BackgroundBrowser(["gnome-open", "%s"]), update_tryorder=-1)


else:
    # KDE default browser
    if 'KDE_FULL_SESSION' in os.environ and os.environ['KDE_FULL_SESSION'] == 'true' and webbrowser._iscommand('kfmclient'):
        webbrowser.register('kfmclient', None, webbrowser.GenericBrowser("kfmclient exec '%s' &"))
        if 'BROWSER' in os.environ:
            webbrowser._tryorder.insert(len(os.environ['BROWSER'].split(os.pathsep)), 'kfmclient')
        else:
            webbrowser._tryorder.insert(0, 'kfmclient')
    # GNOME default browser
    if 'GNOME_DESKTOP_SESSION_ID' in os.environ and webbrowser._iscommand('gnome-open'):
        webbrowser.register('gnome-open', None, webbrowser.GenericBrowser("gnome-open '%s' &"))
        if 'BROWSER' in os.environ:
            webbrowser._tryorder.insert(len(os.environ['BROWSER'].split(os.pathsep)), 'gnome-open')
        else:
            webbrowser._tryorder.insert(0, 'gnome-open')


if 'windows-default' in webbrowser._tryorder:
    class WindowsDefault2(webbrowser.BaseBrowser):
        def open(self, url, new=0, autoraise=1):
            try:
                os.startfile(url)
            except WindowsError:
                # [Error 22] No application is associated with the specified
                # file for this operation: '<URL>'
                return False
            else:
                return True

    webbrowser._tryorder.remove('windows-default')
    webbrowser.register('windows-default-2', WindowsDefault2,
                        update_tryorder=-1)

    iexplore = webbrowser.BackgroundBrowser(
        os.path.join(os.environ.get('PROGRAMFILES', 'C:\\Program Files'),
                    'Internet Explorer\\IEXPLORE.EXE'))
    webbrowser.register('iexplore', None, iexplore)

So I tried changing it to:

Code:

webbrowser.register('xdg-open', None, webbrowser.BackgroundBrowser(["xdg-open", "%s"]), update_tryorder=-1)
Which works fine for me.

Would I be right in thinking that xdg-open would work - at least for the whole linux section? Or does it nead all that gnome and kde specific junk?


All times are GMT -5. The time now is 04:06 PM.