public function __construct($file) { $this->loadGlade($file); $this->mainWindow = new \Explorer\GUI\MainWindow($this); $status = $this->glade->get_widget('loadingprogress'); $r = new \ReflectionObject($this); $methods = iterator_to_array(new InitFuncFilterIterator(new \ArrayIterator($r->getMethods()))); $count = count($methods); $i = 0; foreach ($methods as $method) { $this->{$method}(); $status->set_pulse_step(++$i / $count); while (\Gtk::events_pending()) { \Gtk::main_iteration(); } } $this->glade->get_widget('loadingwindow')->set_visible(false); $this->mainWindow->show(); }
function process_task() { global $start_time, $G; /* if ($G["js"]) { $G["stav"]->set_label('spojene'); } else { $G["stav"]->set_label('ODPOJENE'); } */ $read = array($G["js"]); $write = $except = NULL; if (false === ($num_changed_streams = @stream_select($read, $write, $except, 0, 10000))) { #echo "CHYBA\n"; $num_changed_streams = 1; if ($G["bezim"]) { $acas = getmicrotime(); $jcas = $cas; $cas = $acas - $G["startcas"]; #echo $G["rezim"]." CAS: ".sprintf("%1.2f",$cas)." \r"; $sekundy = floor($cas); $stotiny = floor(($cas - $sekundy) * 10); $stotiny = str_pad($stotiny, 1, STR_PAD_LEFT, '0'); // note 2 $sekundy = str_pad($sekundy, 3, STR_PAD_LEFT, '0'); // note 2 if ($G["z"] == 5) { zobraz_cas($sekundy . "." . $stotiny . "0", true); #echo $sekundy.".".$stotiny."X\r"; $G["z"] = 0; } $G["z"]++; #global $progress; #$progress->set_text($sekundy.":".$stotiny); } } elseif ($num_changed_streams > 0) { #echo "m\n"; for ($i2 = 0; $i2 < $num_changed_streams; $i2++) { if ($read[$i2] == $G["js"]) { #echo "mam js\n"; $buf = fread($G["js"], 8); for ($i = 0; $i < strlen($buf); $i++) { $bd[$i] = ord($buf[$i]); } for ($i = 0; $i < 8; $i++) { echo sprintf("%3d", $bd[$i]) . "|"; } echo "\n"; $cas = $bd[3] * 256 * 256 * 256 + $bd[2] * 256 * 256 + $bd[1] * 256 + $bd[0]; $senzorid = $bd[6] . ":" . $bd[7]; #echo " cas: ".$cas."\n"; #echo "\n"; $acas = getmicrotime(); $cas1 = $acas - $G["startcas"]; if ($senzorid == $G["senzory"]["AB"][0]) { $G["sensorstatus1"]->set_text($bd[4] == 1 ? "[*]" : "[ ]"); } elseif ($senzorid == $G["senzory"]["AB"][1]) { $G["sensorstatus2"]->set_text($bd[4] == 1 ? "[*]" : "[ ]"); } if ($senzorid == $G["senzor1"] && $bd[4] == 1 && $G["bezim"] == false && $cas1 > $G["limit"]) { #start casomiery $G["startcas"] = getmicrotime(); $G["startcas2"] = $cas; $G["bezim"] = true; fputs($G["log"], date("Y-m-d-H-i-s") . "\tstart\n"); global $posledny; for ($i = 0; $i < count($G["historia"]); $i++) { if ($i == count($G["historia"]) - 1) { $G["historia"][$i] = $G["progress"]->get_text(); } else { $G["historia"][$i] = $G["historia"][$i + 1]; } } $posledny->set_text(join(" ; ", $G["historia"])); global $button2; $button2->set_label("STOP"); pipni(); grab_webcam($G["startcas"]); } elseif ($senzorid == $G["senzor2"] && $bd[4] == 1 && $G["bezim"] == true && $cas1 > $G["limit"]) { $cielcas = getmicrotime(); $cielcas2 = $cas; $cas = $cielcas - $G["startcas"]; #echo "CAS: ".sprintf("%1.2f",$cas)."\n"; $cas2 = ($cielcas2 - $G["startcas2"]) / 1000; #echo "CAS2: ".sprintf("%1.2f",$cas)."\n"; fputs($G["log"], date("Y-m-d-H-i-s") . "\t" . $cas2 . "\n"); global $button2; $button2->set_label("START"); $G["bezim"] = false; $G["startcas"] = $cielcas; zobraz_cas($cas2); pipni(); hovor($cas2); grab_webcam($cielcas); } elseif (($senzorid == $G["senzor1"] || $senzorid == $G["senzor2"]) && $bd[4] == 1 && $cas1 > $G["limit"]) { #ak mam signal, zaznamenam kameru // pipni(); grab_webcam(getmicrotime()); } } } } else { #echo "x"; if ($G["bezim"]) { $acas = getmicrotime(); $jcas = $cas; $cas = $acas - $G["startcas"]; #echo $G["rezim"]." CAS: ".sprintf("%1.2f",$cas)." \r"; $sekundy = floor($cas); $stotiny = floor(($cas - $sekundy) * 10); $stotiny = str_pad($stotiny, 1, STR_PAD_LEFT, '0'); // note 2 $sekundy = str_pad($sekundy, 3, STR_PAD_LEFT, '0'); // note 2 if ($G["z"] == 5) { zobraz_cas($sekundy . "." . $stotiny . "0", true); #echo $sekundy.".".$stotiny."X\r"; $G["z"] = 0; } $G["z"]++; #global $progress; #$progress->set_text($sekundy.":".$stotiny); } } while (Gtk::events_pending()) { Gtk::main_iteration(); } return true; }
/** * Método que libera o loop principal do Gtk * * @name DoEvents() */ public function DoEvents() { // Espera enquanto existe evento pendente while (Gtk::events_pending()) { // Libera o loop Gtk::main_iteration(); } }
function grava_dados() { if (!$this->check_dados()) { return; } $db = new Database($this, false); if (!$db->link) { return; } $nome = $this->nome->get_text(); $descricao = $this->descricao->get_text(); if ($this->operacao == 'i') { $sql = 'call SP_Perfil_Inc'; } else { $sql = 'call SP_Perfil_Alt'; } $data = $sql . '(' . String($this->CodPerfil) . ',' . String($nome) . ',' . String($descricao) . ',' . $GLOBALS['CodUsuario'] . ');'; if (!$db->multi_query($data)) { return; } // Mensagem $line = $db->line(); $mensagem = $line['Mensagem']; if ($this->operacao == 'i') { $line = $db->line(); $CodPerfil = $line['CodPerfil']; } // limpa BUFFER while ($db->line()) { } // pega CodPerfil if (!$CodPerfil) { $CodPerfil = $this->CodPerfil; } // Permissoes $db->query(' DELETE FROM Tb_Permissoes WHERE Cod_S_Perfil = ' . $CodPerfil); foreach ($this->itens as $key => $value) { if ($value->get_active()) { if (!$db->query(' INSERT INTO Tb_Permissoes (Cod_S_Perfil, Cod_S_Item) ' . ' VALUES (' . String($CodPerfil) . ',' . String($key) . ');')) { return; } else { $this->progresso->pulse(); while (Gtk::events_pending()) { Gtk::main_iteration(); } } } } new Message($this, $mensagem); return true; }
<?php /** * The exception is not visible in the Gtk::main() loop * But visible when doing the main_iteration - that's * because of the while that is a php method. * * Change the "if (true)" into "if (false)" to see that * the exception is thrown in the while loop */ function cb() { echo "Exception will be thrown next line\r\n"; throw new Exception('Will not get displayed anywhere'); } Gtk::timeout_add(10, 'cb'); if (true) { Gtk::main(); } else { sleep(1); while (Gtk::events_pending()) { Gtk::main_iteration(); } } echo "done throwing exception\r\n";
public function click_section(GtkTreeView $view, GtkTreeIter $iter, array $path) { // Set the path to make sure the selection is selected $view->set_cursor($path); /** @var GtkTreeModel */ $model = $view->get_model(); $value = $model->get_value($iter, 0); // Do multi processing here! ~_~ // TODO: Detect Windows verse Unix $proc = new Gorilla3d\Process(); // Unix $proc->setCommand("php threads.php &"); // Windows //$proc->setCommand("start php threads.php"); $proc->open(); $proc->write($value); // Keep checking if the process is done foreach (range(1, 6) as $i) { // Needed to not block UI while (Gtk::events_pending()) { Gtk::main_iteration(); } // Sleep 0.5 seconds before checking again (locks UI for 1/2 a second usleep(500000); echo "SLEEP!" . PHP_EOL; } $proc->close(); /* $sections = Fourchan\Sections::getSections(); $url = false; if(isset($sections[$value])) { $url = $sections[$value]; } else { echo "fart!\n"; } if($url) { $parser = new Fourchan\Parser($url); $parser->getPages(); $parser->getThreads(); // lots of threads >.< var_dump($parser->threads); } */ /** @var GtkTreeSelection */ /* For multiple selections $selection = $view->get_selection(); list($model, $arPaths) = $selection->get_selected_rows(); echo "Selection is now:\r\n"; foreach ($arPaths as $path) { $iter = $model->get_iter($path); echo ' ' . $model->get_value($iter, 0) . "\r\n"; } */ /* */ echo "clicked Thread!" . PHP_EOL; }
/** * Process events * * @see http://gtk.php.net/manual/en/gtk.method.events_pending.php */ public function processEvents() { while (Gtk::events_pending()) { Gtk::main_iteration(); } }