diff --git a/docs/cn/php/core.md b/docs/cn/php/core.md index 066fa53..b8ac1c2 100644 --- a/docs/cn/php/core.md +++ b/docs/cn/php/core.md @@ -87,3 +87,22 @@ foreach($_ENV as $k => $v) { $os->environ->__setitem__($k, $v); } ``` + +## undefined symbol:ffi_type_uint32, version LIBFFI_BASE_7.0 +动态连接库路径存在冲突问题,可以尝试使用下面的方法解决。 +若依然有问题,建议使用系统自带的 `Python` 环境代替 `conda` 创建的环境。 + +```shell +export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libffi.so.7 +``` + +## Import 失败 +大部分情况下,`from a import b` 是等价于 `PyCore::import('a')->b` , +但有些特殊的库无法通过以上方法正确加载,可替换为以下方法: + +```php +# 无法加载 +$b = PyCore::import('a')->b; +# 替换为以下代码 +$b = PyCore::import('a.b'); +``` diff --git a/examples/gtk/build.php b/examples/gtk/build.php new file mode 100644 index 0000000..bb1528e --- /dev/null +++ b/examples/gtk/build.php @@ -0,0 +1,20 @@ +require_version("Gtk", "3.0"); +$Gtk = PyCore::import('gi.repository.Gtk'); +$builder = $Gtk->Builder(); +$builder->add_from_file(__DIR__ . '/test.glade'); +$window = $builder->get_object('window1'); +$window->set_title("hello world"); +$window->show_all(); +$handlers = new PyDict([ + "onDestroy" => $Gtk->main_quit, + "onButtonPressed" => function () { + echo "hello\n"; + } +]); +$builder->connect_signals($handlers); +$Gtk->main(); diff --git a/examples/gtk/gtk.php b/examples/gtk/gtk.php new file mode 100644 index 0000000..0bd721e --- /dev/null +++ b/examples/gtk/gtk.php @@ -0,0 +1,10 @@ +require_version("Gtk", "3.0"); +$Gtk = PyCore::import('gi.repository.Gtk'); +$win = $Gtk->Window(title: "Hello World"); +$win->connect("destroy", $Gtk->main_quit); +$win->show_all(); +$Gtk->main(); diff --git a/examples/gtk/test.glade b/examples/gtk/test.glade new file mode 100644 index 0000000..f70fb36 --- /dev/null +++ b/examples/gtk/test.glade @@ -0,0 +1,19 @@ + + + + + False + + + + button + False + True + True + True + False + + + + +