Skip to content

Commit

Permalink
Add gtk examples, Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Jan 11, 2024
1 parent 05fab29 commit 3e80730
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/cn/php/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
```
20 changes: 20 additions & 0 deletions examples/gtk/build.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

$operator = PyCore::import("operator");
$builtins = PyCore::import("builtins");
$gi = PyCore::import('gi');
$gi->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();
10 changes: 10 additions & 0 deletions examples/gtk/gtk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
$operator = PyCore::import("operator");
$builtins = PyCore::import("builtins");
$gi = PyCore::import('gi');
$gi->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();
19 changes: 19 additions & 0 deletions examples/gtk/test.glade
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can-focus">False</property>
<signal name="destroy" handler="onDestroy" swapped="no"/>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="use-action-appearance">False</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-action-appearance">False</property>
<signal name="pressed" handler="onButtonPressed" swapped="no"/>
</object>
</child>
</object>
</interface>

0 comments on commit 3e80730

Please sign in to comment.