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

1

0

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?

Feldspar answered 13/7, 2023 at 5:35 Comment(6)
What is the error?Biddick
Does this answer your question? ImportError: cannot import name GstRtspServer, introspection typelib not foundBiddick
From your post I can not access these libraries from python. What am I missing? the answer could be in the suggested link based on your posted error.Biddick
I got the answer from discourse.gnome.org/t/…Feldspar
Great, you can answer your own post for others' future reference.Biddick
https://mcmap.net/q/1711499/-how-to-import-st-library-in-gjs/1772898Feldspar
F
-1

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/.

Feldspar answered 15/7, 2023 at 5:21 Comment(2)
Please don't do this. It will break every time you upgrade your system. You cannot use these libraries effectively except from inside the GNOME Shell process, in an extension.Garnetgarnett
@Garnetgarnett it is mentioned in the discourse link provided in the answer. This is not a reliable way of doing it. i do not use it. It is just out there for others to know. I use gnome extension (for exposing data and making method calls) to use these libraries.Feldspar

© 2022 - 2024 — McMap. All rights reserved.