From 01ec2582b14607fa58234ceba2ef074990dd014c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Thu, 15 Mar 2007 09:59:29 +0100 Subject: [PATCH] Better detecting of the default Windows browser, with fallback to Internet Explorer. (#2502) --- NEWS.txt | 2 ++ picard/util/webbrowser2.py | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/NEWS.txt b/NEWS.txt index 8aaf0f0b6..2275d7b09 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -5,6 +5,8 @@ Version 0.9.0alpha5 - 2007-03-XX * Fixed fileId generator (caused problems with drag&drop if files with multiple formats are used). * Original Metadata not greyed out when no tracks are attached. (#2461) + * Better detecting of the default Windows browser, with fallback to + Internet Explorer. (#2502) Version 0.9.0alpha4 - 2007-03-09 * Bug Fixes: diff --git a/picard/util/webbrowser2.py b/picard/util/webbrowser2.py index f576467e9..59572bc55 100644 --- a/picard/util/webbrowser2.py +++ b/picard/util/webbrowser2.py @@ -27,6 +27,7 @@ enough, in my opinion. See also: http://sourceforge.net/tracker/index.php?func=detail&aid=1681228&group_id=5470&atid=105470 """ + # 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' &")) @@ -35,6 +36,7 @@ if 'KDE_FULL_SESSION' in os.environ and os.environ['KDE_FULL_SESSION'] == 'true' 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' &")) @@ -43,8 +45,27 @@ if 'GNOME_DESKTOP_SESSION_ID' in os.environ and webbrowser._iscommand('gnome-ope 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: '' + return False + else: + return True + webbrowser._tryorder.remove('windows-default') - webbrowser._tryorder.insert(0, '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) + open = webbrowser.open