「PyGObject」- PyGObject | GNOME Python API

认识

官网:https://pygobject.gnome.org/
文档:https://pygobject.gnome.org/guide/index.html
仓库:https://gitlab.gnome.org/GNOME/pygobject.git

根据 GNOME Developer Documentation / Programming Languages 文档,我们能够使用 PyGObject 来开发 GNOME 应用。—— https://developer.gnome.org/documentation/introduction/languages.html

PyGObject is a Python package which provides bindings for GObject based libraries such as GTK, GStreamer, WebKitGTK, GLib, GIO and many more. —— https://pygobject.gnome.org/

If you want to write a Python application for GNOME or a Python GUI application using GTK, then PyGObject is the way to go.

python3-gi 是 PyGObject 在 Ubuntu 上的包名。

组成

PyGObject uses glib, gobject, girepository, libffi and other libraries to access the C library (libgtk-4.so) in combination with the additional metadata from the accompanying typelib file (Gtk-4.0.typelib) and dynamically provides a Python interface based on that information.

性质

PyGObject supports Linux, Windows and macOS and works with Python 2.7+, Python 3.5+, PyPy and PyPy3.
PyGObject, including this documentation, is licensed under the LGPLv2.1+.

GTK

Gtk.TextView | https://docs.gtk.org/gtk4/class.TextView.html

A widget that displays the contents of a Gtk.TextBuffer.

Gtk.TextBuffer | https://docs.gtk.org/gtk4/class.TextBuffer.html

Stores text and attributes for display in a GtkTextView.

You may wish to begin by reading the text widget conceptual overview, which gives an overview of all the objects and data types related to the text widget and how they work together.

GtkTextBuffer can support undoing changes to the buffer content, see gtk_text_buffer_set_enable_undo().

Gtk.TextBuffer.set_modified | https://docs.gtk.org/gtk4/method.TextBuffer.set_modified.html

Used to keep track of whether the buffer has been modified since the last time it was saved.

Whenever the buffer is saved to disk, call gtk_text_buffer_set_modified (buffer, FALSE). When the buffer is modified, it will automatically toggle on the modified bit again. When the modified bit flips, the buffer emits the GtkTextBuffer::modified-changed signal.

HeaderBar

Python – HeaderBar in GTK+ 3 – GeeksforGeeks

构建

PyGObject 3.44.1

# pip show pygobject
WARNING: Ignoring invalid distribution -dot (/home/k4nz/.virtualenvs/zim-desktop-wiki@py3.9/lib/python3.10/site-packages)
Name: PyGObject
Version: 3.44.1
Summary: Python bindings for GObject Introspection
Home-page: https://pygobject.readthedocs.io
Author: James Henstridge
Author-email: james@daa.com.au
License: GNU LGPL
Location: /home/k4nz/.virtualenvs/zim-desktop-wiki@py3.9/lib/python3.10/site-packages
Requires: pycairo
Required-by: 

应用

Applications which use PyGObject include Music, Lollypop and Pitivi.

该笔记将记录:通过 Python 进行 GTK 图形化应用程序开发的笔记(涉及很多 GTK 的基本概念),以及相关问题的解决办法;

在图形化编程中,我们需要借助如下文档:

Who Is Using PyGObject? | https://pygobject.gnome.org/#who-is-using-pygobject

PyGObject | https://wiki.gnome.org/action/show/Projects/PyGObject
GTK and Python | https://www.gtk.org/docs/language-bindings/python
The Python GTK+ 3 Tutorial | https://python-gtk-3-tutorial.readthedocs.io/en/latest/index.html

Q:该部分笔记为通过 Python 进行 GTK 开发,应该属于 Python GUI 相关内容,为什么创建独立的笔记?
A:虽然该部分技术内容是通过 Python 进行 GTK 开发,但是实际内容依旧是以研究和理解 GTK 相关的概念为主,其仅借助 Python 语法,所以其以 GTK 为主,Python 为辅助(甚至很少提及和 Python 相关的内容)