[clue/zenity-react]使用PHP创建一个GUI项目

2023-02-27 奥古斯宏

zenity是一个很小的小程序,能够在命令行创建GTK的对话框。本库则是对他调用的封装。clue/zenity-react基于ReachPHP,目前还不能在Windows下运行。

使用clue/zenity-react可以用很简单易读的代码实现各种对话框的调用。

输入对话框

$launcher = new Clue\React\Zenity\Launcher();

$entry = new EntryDialog();
$entry->setText('你是谁?');
$entry->setEntryText('PHP武器库'); // 默认填写

$launcher->launch($entry)->then(function ($name) use ($launcher) {
    $launcher->launch(new InfoDialog('那挺6的!'));
});

以上几行代码的效果就是开头的截图那样。

系统通知

$launcher = new Launcher();
$builder = new Builder();

$notification = $builder->notifier();
$zen = $launcher->launchZen($notification);

$zen->setMessage('你收到一条来自PHP武器库的问候:今晚等我');

进度条


$launcher = new Launcher();
$builder = new Builder();

$progress = $launcher->launchZen($builder->pulsate('执行下班流程...'));

$texts = array(
    '回家',
    '开门',
    '拖鞋',
    '洗头',
    '洗脸',
    '洗脚',
    '上床',
    '睡觉'
);

$timer = Loop::addPeriodicTimer(2.0, function ($timer) use ($progress, $texts) {
    static $i = 0;

    if (isset($texts[$i])) {
        $text = $texts[$i++];
        $text = '[' . $i . '/' . count($texts) . '] ' . $text . '...';

        $progress->setText($text);
    } else {
        $progress->complete();
    }
});

$progress->promise()->then(function () use ($timer, $builder, $launcher) {
    $timer->cancel();

    $launcher->launch($builder->info('Done'));
});

$progress->promise()->then(null, function() use ($timer, $builder, $launcher) {
    $timer->cancel();

    $launcher->launch($builder->error('Canceled'));
});

提交表单

$launcher = new Launcher();

$form = new FormsDialog();
$form->setWindowIcon('info');
$form->setText('请提交你的隐私信息');

$form->addEntry('姓名');
$form->addPassword('银行卡密码');
$form->addCalendar('生日');
//$form->addList('Group', array('Admin', 'User', 'Random'));
$form->addEntry('小名');
$form->addList('性别', array('男', 10, '女', 0), array('名称', '值'));

$launcher->launch($form)->then(function($result) {
    var_dump('result', $result);
}, function() {
    var_dump('form canceled');
});

版权声明:本文由phpreturn.com(PHP武器库官网)原创和首发,所有权利归phpreturn(PHP武器库)所有,本站允许任何形式的转载/引用文章,但必须同时注明出处。

更多

还可以通过他实现更多的效果,比如:

  • 日历
  • 文件选择
  • 表格
  • 列表
  • 通知图标
  • 消息 错误 信息 问题 警告
  • 密码输入
  • 进度
  • 文本输入
  • 文本信息
  • 范围
  • 颜色选择

如果说有什么遗憾,那就是还不能在windows上运行,因为在windows上,PHP无法正确开启文件句柄,也无法正确获取子进程的退出状态,这在以后或许会被修复,但主要靠PHP本身的兼容性更新了。

总的来说,这是一个很有趣的项目,在安装了桌面环境的GTK中,几乎无需安装更多依赖,只要安装了PHP7.0以上的版本即可。

最近浏览
IP用户:39.173.*.*
13 小时前 Generic Bot
IP用户:112.13.*.*
1 天前 Generic Bot
IP用户:223.72.*.*
3 天前 Chrome Webview Android 7.1
IP用户:42.202.*.*
3 天前 Go-http-client
IP用户:66.249.*.*
3 天前 Googlebot
IP用户:34.64.*.*
6 天前 Googlebot
IP用户:34.64.*.*
7 天前 Googlebot
IP用户:34.64.*.*
7 天前 Googlebot
IP用户:74.125.*.*
7 天前 Googlebot
IP用户:34.64.*.*
10 天前 Googlebot
IP用户:34.64.*.*
10 天前 Googlebot
IP用户:66.249.*.*
11 天前 Googlebot
累计浏览次数:765
评论
点击登录
phpreturn,PHP武器库,专注PHP领域的项目和资讯,收录和介绍PHP相关项目。
最近浏览 点击登录
IP用户:39.155.*.*
IP用户:185.191.*.*
IP用户:39.163.*.*
累计浏览次数:103829
一周浏览次数:2831
今日浏览次数:224

本站所有权利归 phpreturn.com 所有

举报/反馈/投稿邮箱:phpreturn@ulthon.com

鲁ICP备19027671号-2