UserString

Overview

This example will run a horizontal progress bar with custom string.
It's a PEAR packages installation simulation. Use the HTML_Progress2 callback feature.

Screenshot

sample screenshot

Demonstration

Give it a try

Dependencies

This example requires mandatory resources :

And also but optional :

Explains step by step

The progress meter wait 200ms (line 34) between each step of 5% (line 35).

There are 10 cells with default values:

Property Value Default
active-color   #006600
inactive-color   #CCCCCC
width   15
height   20
spacing   2
See also :

The progress bar string is left aligned on right side (lines 36-38):

Property Value Default
class   progressTextLabel%s
width   0
height   0
font-size   11
font-family   Verdana, Tahoma, Arial
font-weight   normal
color   #000000
background-color    
align   left
valign right top
See also :

The PEAR packages simulation process (lines 18-31) is defined by the HTML_Progress2 callback (line 39): default is HTML_Progress2::sleep.

See also :

Source Code

  1. <?php
  2. /**
  3. * Horizontal progress bar with custom string
  4. * rather than percent text info.
  5. *
  6. * @version    $Id: userstring.php,v 1.4 2006/05/24 08:47:05 farell Exp $
  7. * @author     Laurent Laville <pear@laurent-laville.org>
  8. * @package    HTML_Progress2
  9. * @subpackage Examples
  10. * @access     public
  11. */
  12. require_once 'HTML/Progress2.php';
  13.  
  14. $pkg = array('PEAR', 'Archive_Tar', 'Config',
  15.     'HTML_QuickForm', 'HTML_CSS', 'HTML_Page', 'HTML_Template_Sigma',
  16.     'Log', 'MDB', 'PHPUnit');
  17.  
  18. function myFunctionHandler($pValue, &$pBar)
  19. {
  20.     global $pkg, $labelID1;
  21.  
  22.     $pBar->sleep();
  23.  
  24.     $i = floor($pValue / 10);
  25.     if ($pValue == 100) {
  26.         $msg = 'installation complete';
  27.     } else {
  28.         $msg = "installing package ($pValue %) ... : ".$pkg[$i];
  29.     }
  30.     $pBar->setLabelAttributes($labelID1, array('value' => $msg));
  31. }
  32.  
  33. $pb = new HTML_Progress2(null, HTML_PROGRESS2_BAR_HORIZONTAL, 0, 100, false);
  34. $pb->setAnimSpeed(200);
  35. $pb->setIncrement(5);
  36. $labelID1 = 'txt1';
  37. $pb->addLabel(HTML_PROGRESS2_LABEL_TEXT, $labelID1);
  38. $pb->setLabelAttributes($labelID1, 'valign=right');
  39. $pb->setProgressHandler('myFunctionHandler');
  40. ?>
  41. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  42.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  43. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  44. <head>
  45. <title>UserString Progress2 example</title>
  46. <style type="text/css">
  47. <!--
  48. <?php echo $pb->getStyle(); ?>
  49.  
  50. body {
  51.     background-color: #FFFFFF;
  52. }
  53.  -->
  54. </style>
  55. <?php echo $pb->getScript(false); ?>
  56. </head>
  57. <body>
  58.  
  59. <?php
  60. $pb->display();
  61. $pb->run();
  62. ?>
  63.  
  64. </body>
  65. </html>