Re: Progress while waiting for Web Service response

From: Date: Thu, 01 Jan 1970 00:00:00 +0000
Subject: Re: Progress while waiting for Web Service response
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-7733@lists.php.net to get a copy of this message
Webmaster Phelios.org napisał(a):
Hello Łukasz Can you post a small portion of the code where you are monitoring the fread ? No problem
Just replace "My_File" with path to a file on your system which is minimum ~5MB (so You could see this example really working) This is version with fread() but I tested this with Web Services using fsockopen() and fgets() - it works too. <?php class FileReadProgressDemo {
    function __construct( $sFile )
    {
        $this->sFile = $sFile;
    }
    function BuildGui()
    {
$oWnd = new GtkWindow(); $oWnd->set_position( Gtk::WIN_POS_CENTER ); $oWnd->connect_simple( 'destroy', array( 'Gtk', 'main_quit' ) ); $oVbox = new GtkVBox( true, 10 ); $oButton = new GtkButton( 'click' ); $oButton->connect( 'clicked', array( $this, 'ReadFile' ) ); $oButtonBox = new GtkHButtonBox(); $oButtonBox->add( $oButton ); $oVbox->pack_start( $oButtonBox, true, true, 10 ); $oProgressBar = new GtkProgressBar(); $oProgressBar->set_size_request( 300, 20 ); $this->oProgressBar = $oProgressBar; $oVbox->pack_start( $oProgressBar, false, false, 10 ); $oWnd->add( $oVbox ); $oWnd->show_all();
    }
    function ReadFile()
    {
        $iFileSize = filesize( $this->sFile );
        $rFile = fopen( $this->sFile, 'r' );
        while( $junk = fread( $rFile, 1024 ) )
        {
            $iReadedBytes += 1024;
            $fFraction =  $iReadedBytes / $iFileSize;
            if( $fFraction > 1 )
            {
                $fFraction = 1;
            }
            $this->oProgressBar->set_fraction( $fFraction );
while (Gtk::events_pending()) { Gtk::main_iteration(); }
        }
        Gtk::main_quit();
    }
} $oWSTPD = new FileReadProgressDemo( 'My_File' ); $oWSTPD->BuildGui(); Gtk::main(); ?> -- greetings Łukasz Wojciechowski

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