prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  "ImportError: cannot import name WebKit" on Ubuntu 14.04
  Installed toga via global `sudo pip install toga`. Then, tried to import it:
  
  ```
  >>> import toga
  ERROR:root:Could not find any typelib for WebKit
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/local/lib/python2.7/dist-packages/toga/__init__.py", line 86, in <module>
      from .platform.gtk.app import *
    File "/usr/local/lib/python2.7/dist-packages/toga/platform/gtk/app.py", line 7, in <module>
      from .window import Window
    File "/usr/local/lib/python2.7/dist-packages/toga/platform/gtk/window.py", line 6, in <module>
      from .command import SEPARATOR, SPACER, EXPANDING_SPACER
    File "/usr/local/lib/python2.7/dist-packages/toga/platform/gtk/command.py", line 1, in <module>
      from .widgets import Icon
    File "/usr/local/lib/python2.7/dist-packages/toga/platform/gtk/widgets/__init__.py", line 17, in <module>
      from .webview import WebView
    File "/usr/local/lib/python2.7/dist-packages/toga/platform/gtk/widgets/webview.py", line 3, in <module>
      from gi.repository import Gtk, WebKit
  ImportError: cannot import name WebKit
  ```
  
  Did a `sudo apt-get install python-webkit`, but still getting the same import error. I'm running Ubuntu under Crouton on a Chromebook, which doesn't always contain the full set of packages.
  
  Since the application I aim to create (a GUI launcher for [KA Lite](https://github.com/learningequality/ka-lite/)) would rely on toga's awesome dedication to being pure Python and not needing any extra packages to be installed to work cross-platform, and since we wouldn't be needing the WebView, would it be possible to have it handle a lack of WebKit more gracefully, only erroring out if a WebView was actually used? Thanks!
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `toga/platform/gtk/widgets/webview.py`
  Content:
  ```
  1 from __future__ import print_function, absolute_import, division
  2 
  3 from gi.repository import Gtk, WebKit
  4 
  5 from .base import Widget
  6 
  7 
  8 class WebView(Widget):
  9     def __init__(self, url=None):
  10         super(WebView, self).__init__()
  11         self._url = url
  12 
  13         self._webview = None
  14 
  15     def _startup(self):
  16         self._impl = Gtk.ScrolledWindow()
  17         self._impl.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
  18 
  19         self._webview = WebKit.WebView()
  20 
  21         if self._url:
  22             self._webview.load_uri(self._url)
  23 
  24         self._impl.add(self._webview)
  25         self._impl.set_min_content_width(200)
  26         self._impl.set_min_content_height(200)
  27 
  28     @property
  29     def url(self):
  30         return self._url
  31 
  32     @url.setter
  33     def url(self, value):
  34         self._url = value
  35         if self._impl:
  36             self._webview.load_uri(self._url)
  37
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/toga/platform/gtk/widgets/webview.py b/toga/platform/gtk/widgets/webview.py
  --- a/toga/platform/gtk/widgets/webview.py
  +++ b/toga/platform/gtk/widgets/webview.py
  @@ -1,6 +1,13 @@
   from __future__ import print_function, absolute_import, division
   
  -from gi.repository import Gtk, WebKit
  +from gi.repository import Gtk
  +
  +# The following import sometimes fails; handle failure gracefully
  +# (see https://github.com/pybee/toga/issues/26)
  +try:
  +    from gi.repository import WebKit
  +except ImportError:
  +    WebKit = None
   
   from .base import Widget
   
  @@ -13,6 +20,12 @@
           self._webview = None
   
       def _startup(self):
  +
  +        if WebKit is None:
  +            raise RuntimeError(
  +                "Import 'from gi.repository import WebKit' failed;" +
  +                " may need to install gir1.2-webkit-3.0 or similar.")
  +
           self._impl = Gtk.ScrolledWindow()
           self._impl.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
  
verification_info: {"golden_diff": "diff --git a/toga/platform/gtk/widgets/webview.py b/toga/platform/gtk/widgets/webview.py\n--- a/toga/platform/gtk/widgets/webview.py\n+++ b/toga/platform/gtk/widgets/webview.py\n@@ -1,6 +1,13 @@\n from __future__ import print_function, absolute_import, division\n \n-from gi.repository import Gtk, WebKit\n+from gi.repository import Gtk\n+\n+# The following import sometimes fails; handle failure gracefully\n+# (see https://github.com/pybee/toga/issues/26)\n+try:\n+    from gi.repository import WebKit\n+except ImportError:\n+    WebKit = None\n \n from .base import Widget\n \n@@ -13,6 +20,12 @@\n         self._webview = None\n \n     def _startup(self):\n+\n+        if WebKit is None:\n+            raise RuntimeError(\n+                \"Import 'from gi.repository import WebKit' failed;\" +\n+                \" may need to install gir1.2-webkit-3.0 or similar.\")\n+\n         self._impl = Gtk.ScrolledWindow()\n         self._impl.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)\n", "issue": "\"ImportError: cannot import name WebKit\" on Ubuntu 14.04\nInstalled toga via global `sudo pip install toga`. Then, tried to import it:\n\n```\n>>> import toga\nERROR:root:Could not find any typelib for WebKit\nTraceback (most recent call last):\n  File \"<stdin>\", line 1, in <module>\n  File \"/usr/local/lib/python2.7/dist-packages/toga/__init__.py\", line 86, in <module>\n    from .platform.gtk.app import *\n  File \"/usr/local/lib/python2.7/dist-packages/toga/platform/gtk/app.py\", line 7, in <module>\n    from .window import Window\n  File \"/usr/local/lib/python2.7/dist-packages/toga/platform/gtk/window.py\", line 6, in <module>\n    from .command import SEPARATOR, SPACER, EXPANDING_SPACER\n  File \"/usr/local/lib/python2.7/dist-packages/toga/platform/gtk/command.py\", line 1, in <module>\n    from .widgets import Icon\n  File \"/usr/local/lib/python2.7/dist-packages/toga/platform/gtk/widgets/__init__.py\", line 17, in <module>\n    from .webview import WebView\n  File \"/usr/local/lib/python2.7/dist-packages/toga/platform/gtk/widgets/webview.py\", line 3, in <module>\n    from gi.repository import Gtk, WebKit\nImportError: cannot import name WebKit\n```\n\nDid a `sudo apt-get install python-webkit`, but still getting the same import error. I'm running Ubuntu under Crouton on a Chromebook, which doesn't always contain the full set of packages.\n\nSince the application I aim to create (a GUI launcher for [KA Lite](https://github.com/learningequality/ka-lite/)) would rely on toga's awesome dedication to being pure Python and not needing any extra packages to be installed to work cross-platform, and since we wouldn't be needing the WebView, would it be possible to have it handle a lack of WebKit more gracefully, only erroring out if a WebView was actually used? Thanks!\n\n", "before_files": [{"content": "from __future__ import print_function, absolute_import, division\n\nfrom gi.repository import Gtk, WebKit\n\nfrom .base import Widget\n\n\nclass WebView(Widget):\n    def __init__(self, url=None):\n        super(WebView, self).__init__()\n        self._url = url\n\n        self._webview = None\n\n    def _startup(self):\n        self._impl = Gtk.ScrolledWindow()\n        self._impl.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)\n\n        self._webview = WebKit.WebView()\n\n        if self._url:\n            self._webview.load_uri(self._url)\n\n        self._impl.add(self._webview)\n        self._impl.set_min_content_width(200)\n        self._impl.set_min_content_height(200)\n\n    @property\n    def url(self):\n        return self._url\n\n    @url.setter\n    def url(self, value):\n        self._url = value\n        if self._impl:\n            self._webview.load_uri(self._url)\n", "path": "toga/platform/gtk/widgets/webview.py"}], "after_files": [{"content": "from __future__ import print_function, absolute_import, division\n\nfrom gi.repository import Gtk\n\n# The following import sometimes fails; handle failure gracefully\n# (see https://github.com/pybee/toga/issues/26)\ntry:\n    from gi.repository import WebKit\nexcept ImportError:\n    WebKit = None\n\nfrom .base import Widget\n\n\nclass WebView(Widget):\n    def __init__(self, url=None):\n        super(WebView, self).__init__()\n        self._url = url\n\n        self._webview = None\n\n    def _startup(self):\n\n        if WebKit is None:\n            raise RuntimeError(\n                \"Import 'from gi.repository import WebKit' failed;\" +\n                \" may need to install gir1.2-webkit-3.0 or similar.\")\n\n        self._impl = Gtk.ScrolledWindow()\n        self._impl.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)\n\n        self._webview = WebKit.WebView()\n\n        if self._url:\n            self._webview.load_uri(self._url)\n\n        self._impl.add(self._webview)\n        self._impl.set_min_content_width(200)\n        self._impl.set_min_content_height(200)\n\n    @property\n    def url(self):\n        return self._url\n\n    @url.setter\n    def url(self, value):\n        self._url = value\n        if self._impl:\n            self._webview.load_uri(self._url)\n", "path": "toga/platform/gtk/widgets/webview.py"}]}