「GTK」- 图形工具包

认识

官网:https://www.gtk.org/
文档:https://www.gtk.org/docs/
仓库:https://gitlab.gnome.org/GNOME/gtk/

GTK was originally designed and used in the GNU Image Manipulation Program (GIMP) as a replacement of the Motif toolkit; at some point Peter Mattis became disenchanted with Motif and began to write his own GUI toolkit named the GIMP toolkit and had successfully replaced Motif by the 0.60 release of GIMP. Finally GTK was re-written to be object-oriented and was renamed GTK+. This was first used in the 0.99 release of GIMP. GTK was subsequently adopted for maintenance by the GNOME Foundation, which uses it in the GNOME desktop environment. 简而言之,GTK 是个图形化工具包,能够用来创建图形化程序。

针对其历史,参考站点:https://www.gtk.org/about/

  • The ‘+’ was dropped returning to simply ‘GTK’ in February 2019 during a Hackathon.

组成

GLib

GTK and its Libraries

随着时间的推移,GTK 已经建立在各种库的基础上,这些库也是由 GTK 团队开发的。

GObject | The base type system and object class

  • 在 GTK+ 2.0 发布前,类似于 GObject 的代码是 GTK 代码库的一部分。所以,尚未使用“GObject”名称,而是作为通用基类(被称为 GtkObject)存在;
  • 在 GTK+ 2.0 发布时,由于 GObject 的通用性,整个对象系统被提取到一个单独的库中。并且,针对 GtkObject Class 的大多数非特定于 GUI 的部分,其都被移至新的公共基类 GObject 中。现在被许多非 GUI 程序(例如命令行和服务器应用程序)使用;

官网:
文档:https://docs.gtk.org/gobject/
仓库:https://gitlab.gnome.org/GNOME/glib/-/tree/main/gobject?ref_type=heads

根据 Wikipedia/GObject/History 部分:

注意,实际情况是复杂的,所以该结构图并不准确,其仅是为表达相关组件的层次关系。

GObject Introspection

GObject introspection is a middleware layer between C libraries (using GObject) and language bindings. The C library can be scanned at compile time and generate metadata files, in addition to the actual native C library. Then language bindings can read this metadata and automatically provide bindings to call into the C library.

… With the introspection project, you can write for example a ClutterActor or GtkWidget subclass in C, and then without any additional work use that class inside the high level language of your choice … 其思路是,通过高性能的、复杂的语言来实现底层核心功能,然后通过高级语言对其进行调用并实现上层逻辑功能。

其存在的目的也是减少 Language Binding 的维护工作。所以,通过 Python GTK 使用 from gi.repository import GtkSource 来创建 Source View 对象。

文档:https://gi.readthedocs.io/en/latest/#

GModule

Portable API for dynamically loading modules

GIO

GObject Interfaces and Objects, Networking, IPC, and I/O

PyGTK

Wikipedia/PyGTK

PyGTK 是旧版本 GTK 图形用户界面库的一组 Python 包装器。随着向 GTK 版本 3 的过渡,PyGTK 将而逐步淘汰,并被 PyGObject 取代。PyGObject 使用 GObject Introspection 动态生成 Python 和其他语言的绑定。

性质

图形控件工具箱,这是 GTK 最核心的功能。它提供了一整套丰富、可主题化的小部件,包括:

  • 基本控件:按钮、标签、输入框、复选框、单选按钮。
  • 容器:窗口、对话框、布局框、网格、面板,用于组织和其他控件的排列。
  • 复杂控件:树形视图、列表视图、工具栏、状态栏、进度条、滚动条。
  • 现代控件:头栏、弹出框、动态列表等。

跨平台支持

  • 虽然 GTK 最初是为 GIMP 开发的,但它现在是一个真正的跨平台工具包。这意味着用 GTK 编写的应用程序可以在 Linux、Windows、macOS 甚至 BSD 系统上运行,只需重新编译即可。

主题和外观

  • GTK 定义了一套完整的主题引擎。这允许用户和设计师通过更换 CSS 和配置文件,来彻底改变所有基于 GTK 应用程序的外观,包括颜色、字体、控件形状、阴影等。这是 Linux 桌面高度可定制性的关键所在。

国际化与可访问性

  • 国际化:GTK 内置了对多语言的支持,可以轻松地创建支持不同语言和书写方向(如从右到左)的应用程序。
  • 可访问性:它通过 ATK 接口提供了对屏幕阅读器等辅助技术的支持,确保残障人士也能使用这些应用程序。

与桌面环境的深度集成

  • GTK 是 GNOME 桌面环境的官方工具包。因此,它与 GNOME 的底层服务(如设置、通知、文件选择器、全局菜单等)有着最紧密的集成。使用 GTK 开发的应用程序在 GNOME 上能提供最原生、最一致的体验。

构建

# https://www.gtk.org/docs/installations/linux/ 

apt-get install libgtk-3-0 libgtk-3-dev gtk-3-examples # Debian/Ubuntu

参考

The GTK Project – A free and open-source cross-platform widget toolkit