Examples TOCexamples

Half Indeterminate

$Date: 2005/07/25 11:33:24 $

 Table of contents

Introduction

This example requires :


This example will run a basic ProgressBar in indeterminate mode (without monitor) until it reached a limit-level (elapse time > 12 seconds).

Actions to wait are allowed by user callback myProgressHandler defined on lines 20 to 41.

This callback is attached on progress bar at line 61. If you forget to do that, default will be to wait, done by HTML_Progress::sleep() method.

[Top]

 Render options

Here are options to build this progress bar :
background-color = #e0e0e0
HTML_Progress_UI::setProgressAttributes()
Here are options to build this progress bar string (percent text info):
color            = #996
background-color = #CCCC99
HTML_Progress_UI::setStringAttributes()
Here are options to build the progress bar cells :
active-color   = #996
HTML_Progress_UI::setCellAttributes()
Here are options to run the progress bar :
speed     = 200
increment = 10
HTML_Progress::setAnimSpeed()
HTML_Progress::setIncrement()

[Top]

 Output

Screenshot

[Top]

 PHP source syntax highlight

  1. <?php
  2. /**
  3.  * Horizontal ProgressBar in indeterminate mode
  4.  * without using the Progress_Monitor V2 solution.
  5.  *
  6.  * @version    $Id: half_basic.php,v 1.2 2005/07/25 11:33:24 farell Exp $
  7.  * @author     Laurent Laville <pear@laurent-laville.org>
  8.  * @package    HTML_Progress
  9.  * @subpackage Examples
  10.  */
  11.  
  12. require_once 'HTML/Progress.php';
  13.  
  14. /**
  15.  *  This user callback process simulate a reply given after 12 seconds
  16.  *  Parameters
  17.  *  1. current value of the progress bar
  18.  *  2. the progress bar (object) itself
  19.  */
  20. function myProgressHandler($progressValue, &$bar)
  21. {
  22.     static $c;
  23.  
  24.     if (!isset($c)) {
  25.         $c = time();
  26.     }
  27.  
  28.     // wait a bit ...
  29.     $bar->sleep();
  30.  
  31.     /* rules to determine when switch back from indeterminate to determinate mode */
  32.     $elapse = time() - $c;
  33.  
  34.     echo "myProgressHandler -> elapse time = $elapse s.<br/>\n";
  35.     if ($elapse >= 12) {
  36.         if ($bar->isIndeterminate()) {
  37.             $bar->setIndeterminate(false);
  38.             $bar->setValue(100);
  39.         }
  40.     }
  41. }
  42.  
  43. $progress = new HTML_Progress();
  44. $ui = & $progress->getUI();
  45. $ui->setProgressAttributes(array(
  46.     'background-color' => '#e0e0e0'
  47. ));
  48. $ui->setStringAttributes(array(
  49.     'color'  => '#996',
  50.     'background-color' => '#CCCC99'
  51. ));
  52. $ui->setCellAttributes(array(
  53.     'active-color' => '#996'
  54. ));
  55.  
  56. $progress->setAnimSpeed(200);
  57. $progress->setIncrement(10);
  58. $progress->setStringPainted(true);     // get space for the string
  59. $progress->setString("");              // but don't paint it
  60. $progress->setIndeterminate(true);     // Progress start in indeterminate mode
  61. $progress->setProgressHandler('myProgressHandler');
  62. ?>
  63. <html>
  64. <head>
  65. <title>Basic Indeterminate Mode Progress example</title>
  66. <style type="text/css">
  67. <!--
  68. body {
  69.     background-color: #CCCC99;
  70.     color: #996;
  71.     font-family: Verdana, Arial;
  72. }
  73.  
  74. a:visited, a:active, a:link {
  75.     color: yellow;
  76. }
  77.  
  78. <?php echo $progress->getStyle(); ?>
  79. // -->
  80. </style>
  81. <script type="text/javascript">
  82. <!--
  83. <?php echo $progress->getScript(); ?>
  84. //-->
  85. </script>
  86. </head>
  87. <body>
  88.  
  89. <?php
  90. echo $progress->toHtml();
  91. $progress->run();
  92. ?>
  93.  
  94. </body>
  95. </html>

[Top]