1

I have a long operations started with on-expose event or after user clicks the button. Also I have a progress bar, which works perfect when I try to update it state. But when I click the button, I see how my GUI is hanging up...

<?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);
}
?>

So, is there some way to avoid the freezing and to see the progress is rising?

Egor Richman
  • 559
  • 3
  • 13
  • Please [edit] your question to include your full source code you have as a [mcve], which can be compiled and tested by others. – Progman Nov 08 '19 at 21:03
  • My code is so much bigger. You could get it from [this link](https://github.com/egorchelovek/cairo_art/tree/master/fractals/complex). Just run the fractal_drawer.php, and try to change fractal type to any (for some fractals Math_Complex library is needed). Then push the Submit button. – Egor Richman Nov 09 '19 at 03:31
  • Does this answer your question? [GUI Freezes when clicking a button in PyGtk](https://stackoverflow.com/questions/15063932/gui-freezes-when-clicking-a-button-in-pygtk) (yes, I know it's python, but the reason is the same) – Progman Nov 09 '19 at 09:02
  • Unfortunately, It doesn't helps cause I can't find the way to run GTK functions in thread with php. Using of pthreads it's quite bit tricky for my OS (I'm using Ubuntu 18.04). The common way (using fork) doesn't work normally caused by error. I'm searching a variant for more elegant salvation. I finded that php-gtk has two functions: [threads_enter()](http://gtk.php.net/manual/en/html/gdk/gdk.method.threads_enter.html) and [threads_leave()](http://gtk.php.net/manual/en/html/gdk/gdk.method.threads_leave.html). But my php interpreter doesn't recognize it. It's f#king hard. – Egor Richman Nov 10 '19 at 14:33

0 Answers0