gnome-shellgjs

Could not find Meta, Shell & St in Python's GTK bindings which gnome extension documentaion has


I have checked :

https://www.gtk.org/docs/language-bindings/python
https://gitlab.gnome.org/GNOME/pygobject/
https://pygobject.readthedocs.io/en/latest/
https://python-gtk-3-tutorial.readthedocs.io/en/latest/
http://lazka.github.io/pgi-docs/

What I could find is:

#!/usr/bin/python3

import gi

gi.require_version('Gtk', '3.0')
gi.require_version('Clutter', '1.0')
gi.require_version('ClutterX11', '1.0')
gi.require_version('WebKit2', '4.1')
gi.require_version('WebKit2WebExtension', '4.1')
gi.require_version('Polkit', '1.0')

from gi.repository import GLib, Gio, Gtk, GObject, Pango, GdkPixbuf, Clutter, ClutterX11, WebKit2, WebKit2WebExtension, Soup, Polkit

I mean I can include GLib, Gio, Gtk, GObject, Pango, GdkPixbuf ... in python.

But in https://gjs-docs.gnome.org/ , there are Shell, St, Meta... etc.

For example, to get the running apps I need apps = Shell.AppSystem.get_default().get_running(). For that I need to include Shell like:

from gi.repository import Meta, Shell, St

Which I can not do. I can not access these libraries from python. What am I missing? Have they not been ported to python? Which gnome libraries can I access from python? How to get access to these libraries from python?


Solution

  • As already mentioned in the comment section of the question, Meta, Shell & St are actually private. However, we can use them with the following method (this is a gjs example):

    #!/usr/bin/gjs
    
    const res = imports.gi.GIRepository.Repository
    
    // load library of Mutter project
    res.prepend_search_path('/usr/lib/x86_64-linux-gnu/mutter-11')
    res.prepend_library_path('/usr/lib/x86_64-linux-gnu/mutter-11')
    
    // load library of gnome-shell project
    res.prepend_search_path('/usr/lib/gnome-shell')
    res.prepend_library_path('/usr/lib/gnome-shell')
    
    const Shell = imports.gi.Shell;
    const appSys = Shell.AppSystem.get_default();
    print(appSys.get_installed().map(x => x.get_name()).join('\n'));
    

    Please check https://gist.github.com/buzztaiki/1492431 for more details. Please also look at https://discourse.gnome.org/t/get-running-app-from-gjs-script/16211

    P.S. Depending on your setup, the libraries can be on different location. Hopefully you will find them in /usr/lib/.