提问人:Egor Richman 提问时间:11/9/2019 更新时间:11/9/2019 访问量:55
如何避免长时间操作后 GUI 冻结
How to avoid GUI freezing after run of long ops
问:
我有一个很长的操作,从曝光事件或用户单击按钮后开始。我还有一个进度条,当我尝试更新它的状态时,它可以完美地工作。但是当我单击按钮时,我看到我的 GUI 是如何挂起的......
<?php
abstract class FractalDrawingWindow extends GtkWindow {
public function FractalDrawingWindow() {
parent::__construct();
$this->set_title($this->getName());
$this->connect_simple('destroy', array('gtk', 'main_quit'));
$drawingArea = new GtkDrawingArea();
$drawingArea->connect('expose_event',array($this,'onExpose'));
$drawingArea->set_size_request(640,480);
$updateButton = new GtkButton('Update');
$updateButton->connect('clicked', array($this,'update'), $drawingArea);
$progress = new GtkProgressBar();
$vbox = new GtkVBox(false,0);
$vbox->pack_start($drawingArea,false,false,0);
$vbox->pack_start($progress, false, false, 0);
$vbox->pack_start($updateButton,false,false,0);
$this->add($vbox);
$this->set_position(GTK::WIN_POS_CENTER);
Gtk::timeout_add(200,array($this,'updateProgress'), $progress);
$this->show_all();
}
function onExpose($drawingArea, $event){
$context = $drawingArea->window->cairo_create();
$this->onDraw($context); // here I have a long ops wasting time...
}
function update($widget, $drawingArea){
$this->set_title($this->getName());
$drawingArea->queue_draw(); // after that onExpose event created
}
// simple update the progress
function updateProgress($progress){
$progress->set_fraction($this->getState());
return true;
}
abstract public function getName();
abstract public function getState();
abstract protected function onDraw($context);
}
?>
那么,有没有办法避免冻结并看到进展正在上升?
答: 暂无答案
评论