Re: Help with Dialog/Popup

From: Date: Thu, 04 Aug 2005 09:44:36 +0000
Subject: Re: Help with Dialog/Popup
References: 1 2 3 4 5 6 7  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-6162@lists.php.net to get a copy of this message
Exactly. But when just the response from the server takes e.g. a minute this doesn't help me. It's pretty application specific anyway. It seems I've to find a way to split the executions on the server or something. cheers Simone Cosci wrote:
Hi, I think the only way to do what you want is with a RECURSIVE USE of gtk::timeout_add() and split the code in more than 1 part ... in this way the interface will process your event during the 10 msec of delay between the calls. Eg. $step = 0; $last_step = 5; $delay = 10; function call_start(){ // draw the win gtk::timeout_add(1, 'myfunct'); } function myfunct(){ global $step,$last_step,$delay; if($step<$last_step){
       // ... your code ...
       switch($step){
           case 0;
               dosomething();
           break;
           case 1;
               dosomethingelse();
           break;
           default:
               idontknow();
           break;
       }
       $step++;
       gtk::timeout_add($delay, 'myfunct');  // RECURSIVE
} } Hope this help Simone ----- Original Message ----- From: "Markus Fischer" <markus@fischer.name> To: <php-gtk-general@lists.php.net> Sent: Thursday, August 04, 2005 10:53 AM Subject: Re: [PHP-GTK] Help with Dialog/Popup
Hi, just wanted to throw in my 2c that I'm sturggling with the problem too. Sometimes queries to the server can take very long and I'm also searching for a few to have more control what happens during this time. For example, I don't just want to display a waiting message or progress bar, but also provide a 'cancel' button for too long queries. But this won't work if the call to the server is one long timeslice and I can't think of a way to split this calls to the server into smaller parts to still have at least some kind of UI reaction. Any ideas are welcome. - Markus Simone Cosci wrote:
Hi, again, I've used this code to show a window while my little app is autoupdating from the server web ... (sorry it's in italian) and it works as i want ...m i don't know if can be usefull but ... take a look ... Eplanation: call to a function "auto_update" ... the function display a window and create a call to another function after 10 msec. so the interface will be updated before this call ... Problems: During the execution of the second call, the interface, won't listen any event ... because phpgtk is NOT real multithread ... :-( function auto_update(){ global $windows; echo "Ricerca nuove versioni del software ...\n"; $winSrcNewVers = array(); $windows['winSrcNewVers']=&New GtkWindow(); $windows['winSrcNewVers']->connect('destroy', 'delete_event'); $windows['winSrcNewVers']->set_modal(true); $winSrcNewVers['label0'] = &new GtkLabel("Attendere prego"); $winSrcNewVers['label1'] = &new GtkLabel("Ricerca nuove versioni del software in corso ..."); $vbox = &new GtkVBox(); $vbox->pack_start($winSrcNewVers['label0'], true, false); $vbox->pack_start($winSrcNewVers['label1'], true, false); $windows['winSrcNewVers']->add($vbox); $windows['winSrcNewVers']->set_position(GTK_WIN_POS_CENTER); $windows['winSrcNewVers']->set_default_size(300,80); $windows['winSrcNewVers']->set_title(APP_NAME." AutoUpdate"); $windows["winSrcNewVers"]->show_all(); gtk::timeout_add(10, 'cerca_nuove_versioni'); } function cerca_nuove_versioni(){ global $windows, $myHttpreader, $SystemRoot; prepare_url(); $myHttpreader->query .= "&do=AGGIORNA"; $myHttpreader->ReadUrl(); if($myHttpreader->err!="") MsgBox($myHttpreader->err,"Attenzione",MB_ICONWARNING); else{ $serverErr = parsexml("ERR",$myHttpreader->httpresult); if(strstr($serverErr,"ERRORE:")) MsgBox($serverErr,"Attenzione",MB_ICONWARNING); else{ $updates = parsexml("UPDATE",$myHttpreader->httpresult); if($updates!=''){ $newfiles = stripfromtextarray($updates,"<FILE>","</FILE>"); if(count($newfiles)>0){
    $newbuild = stripfromtext($updates,"<BUILD>","</BUILD>");
    echo "\nBUILD $newbuild ...\nUPDATE di ".count($newfiles)." files ...\n";
    foreach ($newfiles as $file) {
     $name = stripfromtext($file,"<NAME>","</NAME>");
     $name = str_replace("%AppPath%",PWD,$name);
     $name = str_replace("%SystemRoot%",$SystemRoot,$name);
     $name = str_replace((OS=='WIN'?"/":"\\"),BAR,$name);
     echo "Installing: ".$name." ...";
     $content = stripfromtext($file,"<CONTENT>","</CONTENT>");
     FileWrite($name,base64_decode($content));
     echo "ok\n";
    }
    echo "Aggiornamento completato.\nRiavviare il software\n";
    MsgBox("Aggiornamento completato\nRiavviare il software",APP_NAME,MB_ICONEXCLAMATION);
} }else MsgBox("Nessun aggiornamento disponibile",APP_NAME,MB_ICONEXCLAMATION); } } $windows["winSrcNewVers"]->hide_all(); } I hope it will help ... bye Simone ----- Original Message ----- From: "Simone Cosci" <simone@interworld.it> To: <php-gtk-general@lists.php.net> Sent: Thursday, August 04, 2005 9:47 AM Subject: Re: [PHP-GTK] Help with Dialog/Popup
Hi, in my opinion the best way is this ... $popup = new GtkWindow(GTK_WINDOW_DIALOG); $label = new GtkLabel("Message goes here"); $label->show(); $popup->set_usize(300,150); $popup->set_position(GTK_WIN_POS_CENTER); $popup->add($label); $popup->show_all(); $delay = 5; // Secons of delay $callback_after_delay = "hide_popup"; function hide_popup(){ global $popup; $popup->destroy(); } gtk::timeout_add($delay,$callback_after_delay); gtk::main(); Bye S. ----- Original Message ----- From: "Neil Eisgruber" <neisgruber@sunblocksystems.com> To: "Christian Weiske" <cweiske@cweiske.de> Cc: <php-gtk-general@lists.php.net> Sent: Wednesday, August 03, 2005 8:16 PM Subject: Re: [PHP-GTK] Help with Dialog/Popup
Thanks Christian, that got me a bit further. Here is what is going on now. I have the following code: $popup = new GtkWindow(GTK_WINDOW_DIALOG); $label = new GtkLabel("Message goes here"); $label->show(); $popup->set_usize(300,150); $popup->set_position(GTK_WIN_POS_CENTER); $popup->add($label); $popup->show_all(); while(gtk::events_pending()) gtk::main_iteration(); sleep(5); //this will be replaced with the function that does the real work $popup->destroy(); Now the window appears for the 5 seconds, but the label is never drawn within it. I'm also not sure if this is the proper usage of gtk::events_pending() as the documentation confused me a bit... Thanks, Neil Quoting Christian Weiske <cweiske@cweiske.de>:
Hello Neil,
dialog box disappear when the function is done. Currently, not
matter > what I
do, the dialog box does not appear until after the action is
complete > and is
destroyed immediately. Is there any way I can accomplish this
kind of
functionallity with php-gtk?
You don't give the system enough time to display. Search for gtk::events_pending in the wiki or the docs. Regards/MfG, Christian Weiske -- XMMS is playing now:
-- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.gtk.general (#6162) next »