无法在Python的GTK绑定中找到Meta、Shell和St,这与GNOME扩展文档有关。

huangapple go评论96阅读模式
英文:

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

问题

I have checked the content you provided, and it seems you are discussing Python bindings for various GNOME libraries. You have successfully imported some libraries like GLib, Gio, Gtk, and others in Python using GObject introspection.

However, you mentioned that you can't access certain libraries like Shell, St, Meta, etc., which are available in GJS (GNOME JavaScript). It's possible that these specific libraries haven't been fully ported to Python through GObject introspection, or they might not be directly accessible in Python.

To access GNOME libraries from Python, you typically rely on the GObject introspection bindings. If certain libraries are not available through GObject introspection, you may need to explore alternative solutions or consider using GJS (JavaScript) if those libraries are better supported in that environment.

If you have specific questions or need further assistance with using GNOME libraries in Python, please feel free to ask.

英文:

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?

答案1

得分: -1

如已在问题的评论部分提到的,Meta、Shell 和 St 实际上是私有的。但是,我们可以使用以下方法来使用它们(这是一个 gjs 的示例):

#!/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'));

请查看 https://gist.github.com/buzztaiki/1492431 以获取更多详细信息。还请参阅 https://discourse.gnome.org/t/get-running-app-from-gjs-script/16211

附注: 根据您的设置,库可以位于不同的位置。希望您能在 /usr/lib/ 中找到它们。

英文:

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

huangapple
  • 本文由 发表于 2023年7月13日 13:35:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676215.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定