承接 toknot/gtk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

toknot/gtk

Composer 安装命令:

composer require toknot/gtk

包简介

PHP bindings to the GTK+3.

README 文档

README

PHP bindings to the gtk+3 C library.

The project only expose GTK API by FFI

Requirements

  • PHP >= 7.4
  • PHP FFI extension available
  • toknot/ffi-extend >=0.1

composer install

composer require toknot/gtk

Status

  • support C function call of GLib, GObject, Gio, Gtk, Atk, Gdk, Gdk-Pixbuf, Pango
  • support C macro value and call of GLib,GLib, and a small part of GTK

Defined Constants

DLL file name and header file name map list:

class PHPGtk {
    public static $gtkDllMap  = [
        self::GLIB_ID => ['name' => 'libglib', 'header' => ['glib'], 'require_version' => '2.56'],
        self::GIO_ID => ['name' => 'libgio', 'header' => ['gio']],
        self::GOBJECT_ID => ['name' => 'libgobject', 'header' => ['gtype', 'gobject']],
        self::GTK_ID => ['name' => 'libgtk', 'header' => ['gtkfunc']],
        self::GDK_ID => ['name' => 'libgdk', 'header' => ['gdk'], 'require_version' => '3.20'],
        self::PIXBUF_ID => ['name' => 'libgdk_pixbuf', 'header' => ['pixbuf'], 'require_version' => '2.36'],
        self::PANGO_ID => ['name' => 'libpango', 'header' => ['pango'], 'require_version' => '1.42'],
        self::PANGO_CAIRO_ID => ['name' => 'libpangocairo', 'header' => ['pango_cairo']],
        self::ATK_ID => ['name' => 'libatk', 'header' => ['atk'], 'require_version' => '2.28'],
    ];
......
}

Gtk\PHPGtk::$gtkDllMap determine load dynamic library name prefix and header file.

Load Dynamic Library

  • In Linux, default find:
    • when PHP_INT_SIZE equal 4, OS is 32bit, find /usr/lib
    • when PHP_INT_SIZE equal 8, OS is 64bit, find /usr/lib64
  • specify lib path by self through Gtk\PHPGtk::gtk($libpath),
    • if $libpath is string, value must be lib directory path
    • will find match $libpath/$name-*.so, and load the first dll
  • specify lib name through set name value of specify lib row of Gtk\APP::$gtkDllMap

Usage

  • basic example

    include dirname(__DIR__) . '/src/PHPGtk.php';
    $gtk = \GTK\PHPGtk::gtk();
    function activate()
    {
        global $gtk, $app;
        try {
        $window = $gtk->gtk_application_window_new($app);
        $gtk->gtk_window_set_title($gtk->GTK_WINDOW($window), "Window");
        $gtk->gtk_window_set_default_size($gtk->GTK_WINDOW($window), 200, 200);
        $gtk->gtk_widget_show_all($window);
        } catch(\Error $e) {
            echo $e;
        }
    }
    
    
    function main($argc, $argv) : int
    {
        global $gtk, $app;
    
        $app = $gtk->gtk_application_new("org.gtk.example", 0);
    
        $gtk->g_signal_connect($app, "activate", 'activate');
    
        $gapp = $gtk->G_APPLICATION($app);
    
        $status = $gtk->g_application_run($gapp, $argc, $argv);
    
        $gtk->g_object_unref($app);
        return $status;
    }
    return main($argc, $argv);
  • C Lib API call

    • PHPGtk class can be call Gtk,GLib,GObject,Gio,Gdk function
    • PHPGtk::atk() return Gtk\Atk, can be call GLib,GObject,ATK function
    • PHPGtk::gdk() return Gtk\Pixbuf, can be call GLib, GObject, GIO, GDK,gdk-pixbuf function
    • PHPGtk::pango() return Gtk\Pango, can be call GLib,GObject,Pango function
    • macro value get by same name constant of class
    • macro function call by same name method of class
    • lib version value defined by macro get by global same name constant
    • About gettext of glib:
      • Gtk\Glib::$GETTEXT_PACKAGE name of GETTEXT_PACKAGE when compile Glib, default is null
      • Gtk\Glib::$gettextDll path of gettext shared library, default is empty, if php eanble gettext, will use php gettext() function instead and the property invaild
    • Gtk\GtkWidget class provided simple OO method of call C function that related GtkWidget

Note:

  • Default, The number of callback function argument must less than 10, otherwise extra argument value always NULL, only when Gtk\GtkAbstract::$gCallbackArgNum be changed to other value
  • if C function for callback, use GObject::G_CALLBACK($callable) convert, the $callable is smailer [$gtk, $c_func_name, true], it php callable array has 3 entries, 3rd is bool value
  • if new C variable be used occur segfault, try new unmanaged variable
  • most class is sub of Gtk\GtkAbstract

For Windows

  1. get libgtk3 binary DLL file, see https://www.gtk.org/docs/installations/windows/
  2. copy libgtk3 all DLL file and dependency to your path, if use MSYS install, pass YOUP_PATH/mingw32/bin or YOUP_PATH/mingw64/bin to PHPGtk::gtk($libpath), if not installed other package,In the path DLL file is libgtk dependency package

toknot/gtk 适用场景与选型建议

toknot/gtk 是一款 基于 C 开发的 Composer 扩展包,目前已累计 82 次下载、GitHub Stars 达 12, 最近一次更新时间为 2020 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「ui」 「gtk」 「ffi」 「gtk3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 toknot/gtk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 toknot/gtk 我们能提供哪些服务?
定制开发 / 二次开发

基于 toknot/gtk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 82
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 1
  • Forks: 1
  • 开发语言: C

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-02-23