美文网首页
自己写的php sciter gui扩展

自己写的php sciter gui扩展

作者: Spooking | 来源:发表于2019-09-23 10:26 被阅读0次

项目地址 https://gitee.com/eecoor/phpSciter

开发这个扩展,只是满足我作为phper对前端的小小梦想,演示性大于实用性,代码非常不严谨,有兴趣的可以看下。

因为能力有限,也不喜欢麻烦,仅做了php脚本与Sciter脚本间方法的相互调用,其他Sciter事件一律没做,请竟可能的依赖tis脚本。

使用说明 (php版本 7.2.12)

  1. 页面放置在UI目录下,入口文件为index.html
  2. 页面需要加载协助脚本 this://php/init.tis(具体看 example.php )
  3. 支持异步操作处理,后台最多可同时执行8线程php调用(多线程依赖 pthreads)。
  4. 前、后端仅支持UTF8,其他编码会出错。
  5. PHP与Sciter通信是通过json字符串(已由协助脚本处理),不能转换为json的变量类型不支持。
截图

例子

  1. ui
<html lang="zh" window-resizable="">
    <head>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
        <title>演示</title>
        <script type="text/tiscript">
            include "this://php/init.tis"
    function self.ready(){
      var (x,y,w,h) = view.screenBox(#workarea,#rectw);
      var l=(w-800)/2;
      var t=(h-480)/2/4*3;
        view.move(l,t,400,200); 
    }
    event click $(#bt1)
    {
      var fn=php("func1","a",[1,2,3]);
      view.msgbox(0,fn);
    }

    event click $(#bt2)
    {      
      var fn=php("func2","bbb",123,function(re){
        $(#tb).style["width"]=re+"%";
      });
    }

    event click $(#bt3)
    {
      var nv=view.dialog {
          url: self.url("index.html"),
          width : 400,
          height : 200
      };
    }
        </script>
    </head>
    <body>
        <button id="bt1">同步调用</button>
        <button id="bt2">异步调用</button>
        <button id="bt3">弹出窗口</button>
        <div#tb style="background: #999;width:1em;">
    </body>
</html>

  1. php
<?php
class MyApp
{
    public function CallBack($fname,$argstr,$cb){
        if(method_exists($this,$fname)){
            $args = json_decode($argstr, 1);
            if(is_callable($cb)){
                return $this->$fname($cb,...$args);
            }else{
                return $this->$fname(...$args);
            }
        }else{
            return null;
        }
    }
    public function func1($c1,$c2){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, 'http://www.baidu.com');
        curl_setopt($curl, CURLOPT_HEADER, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($curl);
        curl_close($curl);
        return "c1=".var_export($c1,true)."\nc2=".var_export($c2,true)."\n".$data;
    }

    public function func2($cb){
        $i=0;
        while($i++<100){
            $cb($i);
            echo "==$i==\n";
            usleep(100000);
        }
        return 100;
    }
}
\mlx\sciter::run(function ($fname, $jsonstr, $cb) {
    $app=new \MyApp();return $app->CallBack($fname,$jsonstr,$cb);
});

相关文章

网友评论

      本文标题:自己写的php sciter gui扩展

      本文链接:https://www.haomeiwen.com/subject/geypuctx.html