1

我从 on-expose 事件或用户单击按钮后开始了长时间的操作。此外,我还有一个进度条,当我尝试更新它的状态时效果很好。但是当我单击按钮时,我看到我的 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);
}
?>

那么,有什么方法可以避免冻结并看到进展正在上升?

4

0 回答 0