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

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');
});

更多

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

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

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

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

原文标题:[clue/zenity-react]使用PHP创建一个GUI项目

原文地址:https://phpreturn.com/index/a63fc4b0c55929.html

原文平台:PHP武器库

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值