[meld] Fall back to Python's webbrowser module when show_uri fails us
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] Fall back to Python's webbrowser module when show_uri fails us
- Date: Tue, 19 Oct 2010 21:17:05 +0000 (UTC)
commit 76b04300dffb89fbccb8363b22ed7cf2f4cbddce
Author: Kai Willadsen <kai willadsen gmail com>
Date: Wed Oct 20 05:45:46 2010 +1000
Fall back to Python's webbrowser module when show_uri fails us
On non-Linux systems, gtk.show_uri fails for a variety of situations.
This commit deals with the open-a-web-page use case by falling back to
the Pythonn webbrowser module in that case.
This commit also introduces a dependency on pygobject 2.16 for its
gio bindings.
bin/meld | 7 +++++++
meld/misc.py | 17 ++++++++++++++---
2 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/bin/meld b/bin/meld
index e9eeb63..e2c02b9 100755
--- a/bin/meld
+++ b/bin/meld
@@ -89,6 +89,7 @@ except locale.Error:
# Check requirements: Python 2.5, pygtk 2.14
pyver = (2, 5)
pygtkver = (2, 14, 0)
+pygobjectver = (2, 16, 0)
def missing_reqs(mod, ver, exception=None):
if isinstance(exception, ImportError):
@@ -114,6 +115,12 @@ try:
except (ImportError, AssertionError), e:
missing_reqs("pygtk", pygtkver, e)
+try:
+ import gobject
+ assert gobject.pygobject_version >= pygobjectver
+except (ImportError, AssertionError), e:
+ missing_reqs("pygobject", pygobjectver, e)
+
gtk.icon_theme_get_default().append_search_path(meld.paths.icon_dir())
diff --git a/meld/misc.py b/meld/misc.py
index be51d3c..d272df8 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -23,12 +23,15 @@ import os
from gettext import gettext as _
import select
import errno
-import gobject
-import gtk
import shutil
import re
import subprocess
+import gio
+import gobject
+import gtk
+
+
whitespace_re = re.compile(r"\s")
NULL = open(os.devnull, "w+b")
@@ -78,7 +81,15 @@ def run_dialog( text, parent=None, messagetype=gtk.MESSAGE_WARNING, buttonstype=
return ret
def open_uri(uri, timestamp=0):
- gtk.show_uri(gtk.gdk.screen_get_default(), uri, timestamp)
+ try:
+ gtk.show_uri(gtk.gdk.screen_get_default(), uri, timestamp)
+ except gio.Error:
+ if uri.startswith("http://"):
+ import webbrowser
+ webbrowser.open_new_tab(uri)
+ else:
+ # Unhandled URI
+ pass
# Taken from epiphany
def position_menu_under_widget(menu, widget):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]