57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace VfxApply\Dialog;
|
|
|
|
use VfxApply\Dialog;
|
|
|
|
class ProgressDialog extends Dialog
|
|
{
|
|
protected $ps;
|
|
|
|
protected $pipe;
|
|
|
|
protected $out;
|
|
|
|
protected function onCreate()
|
|
{
|
|
$this->out = fopen("php://temp", "wb");
|
|
$cmdl = sprintf("zenity --progress --title=%s --auto-close --text='Running' --width=400 --progress=0 2>/dev/null", escapeshellarg($this->title));
|
|
$ds = [
|
|
0 => [ "pipe", "r" ],
|
|
1 => [ "pipe", "w" ],
|
|
2 => [ "pipe", "w" ]
|
|
];
|
|
$this->ps = proc_open($cmdl, $ds, $pipes);
|
|
$this->pipe = $pipes[0];
|
|
}
|
|
|
|
protected function onDestroy()
|
|
{
|
|
/*
|
|
$status = proc_get_status($this->ps);
|
|
$pid = $status['pid'];
|
|
posix_kill($pid,15);
|
|
pcntl_waitpid($pid,$status);
|
|
print_r($status);
|
|
*/
|
|
proc_terminate($this->ps);
|
|
proc_close($this->ps);
|
|
}
|
|
|
|
public function setProgress($pc)
|
|
{
|
|
fprintf($this->pipe, "%d\n", $pc);
|
|
}
|
|
|
|
public function setText($text)
|
|
{
|
|
fprintf($this->pipe, "# %s\r\n", addslashes($text));
|
|
}
|
|
|
|
public function isCancelled()
|
|
{
|
|
$status = proc_get_status($this->ps);
|
|
return ($status['running']==false);
|
|
}
|
|
|
|
} |