Closed ncoghlan closed 8 years ago
Looking at http://lazka.github.io/pgi-docs/#WebKit2-4.0 suggests only 4.0 may be available, and sure enough, if I try that at the Python 3 prompt it works:
Python 3.5.1 (default, Sep 14 2016, 11:27:59)
[GCC 6.1.1 20160621 (Red Hat 6.1.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> gi.require_version('WebKit2', '3.0')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.5/site-packages/gi/__init__.py", line 106, in require_version
(namespace, version))
ValueError: Namespace WebKit2 not available for version 3.0
>>> gi.require_version('WebKit2', '4.0')
>>>
Ditto for Python 2:
Python 2.7.12 (default, Sep 2 2016, 14:46:00)
[GCC 6.1.1 20160621 (Red Hat 6.1.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> gi.require_version('WebKit2', '3.0')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/gi/__init__.py", line 106, in require_version
(namespace, version))
ValueError: Namespace WebKit2 not available for version 3.0
>>> gi.require_version('WebKit2', '4.0')
>>>
Thanks for the report, @ncoghlan. It looks like Ubuntu 16.04 has Webkit2-4.0 bindings available. I'll need to take a closer look to see if there's a better way to specify this version string that won't be as problematic across platforms (suggestions welcome!).
The error handling also needs some work, apparently, because webkit should be optional - it isn't used by the demo, so the fact it isn't installed shouldn't be an issue.
I had a quick look for examples, but didn't see anything other than folks just writing "require_version" with a specific version number (as in https://developer.fedoraproject.org/tech/languages/python/pygobject.html ).
Following some of the links from there and searching a bit more, it looks like there is a C level API to list the versions of available namespaces, but that isn't visible to Python: https://developer.gnome.org/gi/stable/GIRepository.html#g-irepository-enumerate-versions
The one introspection API that does seem to be available is gi.get_required_version
which at least lets you detect if a namespace is already loaded, and what version that was:
>>> gi.get_required_version("WebKit2")
>>> gi.require_version("WebKit2", "4.0")
>>> gi.get_required_version("WebKit2")
'4.0'
I guess one thing you could try if toga can handle multiple versions of the WebKit2
namespace is something like:
acceptable_versions = [" 4.0", "3.0"]
for namespace_version in acceptable_versions:
try:
gi.require_version("WebKit2", namespace_version)
except ValueError:
continue
break
else:
# Whatever you need to do to indicate internally that WebKit2 is unavailable
(I don't know how different the 3.0 and 4.0 WebKit2 bindings actually are, though)
Thanks for the Gtk support! Unfortunately, the demo is failing to find the WebKit bindings on Fedora, and the number of different projects and version numbers interacting, as well as the major naming differences between Debian and Fedora in this area, makes it hard to figure out what it's actually looking for:
gir1.2-webkit2-3.0
seems to be the relevant Debian package (which is mentioned on toga's Gtk support page), and looking at https://packages.debian.org/sid/gir1.2-webkit2-4.0 shows that's the Gobject introspection bindings for WebKit2 3.0However, I can't find anything similar for Fedora, which suggests this may work quite differently on non-Debian derived Linux systems.