WindowStyle

Overview

This example will run a window style horizontal progress bar, that you can cancel if you click on the stop button.

This pseudo monitor follows the relative position pattern. You can also follow the absolute position pattern (remove option 'position' line 40, to set the default behaviour).

Screenshot

Will display something like that with absolute positionning (default behaviour):

sample screenshot

Be aware that this example use the relative position.

Demonstration

Give it a try

Dependencies

This example requires mandatory resources :

Explains step by step

When you use relative positionning scheme, option position on the class constructor (line 40), then top and left frame attributes are not applied; Even if you gave positive values (see line 41).

Source Code

  1. <!--
  2.   Demonstration of the windowstyle feature of Progress2_Lite
  3.   version of Progress2 without any dependencies
  4.  
  5.   @version    $Id: windowstyle2.php,v 1.3 2005/08/18 13:23:29 farell Exp $
  6.   @author     Laurent Laville <pear@laurent-laville.org>
  7.   @package    HTML_Progress2
  8.   @subpackage Examples
  9.   @access     public
  10. // -->
  11. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  12.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  13. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  14. <head>
  15. <title>Progress2 Lite - Window Style</title>
  16. </head>
  17. <body>
  18. <h1>Positioning schemes </h1>
  19. <p style="background-color:lightblue;width:320px;height:240px;text-align:center;">
  20. 320 x 240
  21. </p>
  22.  
  23. <?php
  24. require_once 'HTML/Progress2_Lite.php';
  25.  
  26. /**
  27. * NOTE: The function {@link http://www.php.net/manual/en/function.usleep.php}
  28. *       did not work on Windows systems until PHP 5.0.0
  29. */
  30. function _sleep($usecs)
  31. {
  32.     if ((substr(PHP_OS, 0, 3) == 'WIN') && (substr(PHP_VERSION,0,1) < '5') ){
  33.         for ($i=0; $i<$usecs; $i++) { }
  34.     } else {
  35.         usleep($usecs);
  36.     }
  37. }
  38.  
  39. // Creates new progress bar with defaults (300 pixels width and 25 pixels height)
  40. $pbl = new HTML_Progress2_Lite(array('padding' => 2, 'position' => 'relative'));
  41. $pbl->setFrameAttributes(array('left' => 50, 'top' => 180));
  42. $pbl->setBarAttributes(array('border-color' => '#404040 #dfdfdf #dfdfdf #404040'));
  43.  
  44. // Adds additional text as label 'txt1'
  45. $pbl->addLabel('text','txt1','Please wait ...');
  46.  
  47. // Adds percent info as label 'pct1'
  48. $pbl->addLabel('percent','pct1');
  49.  
  50. // Adds restart button as label 'btn1' with action 'restart=1'
  51. $pbl->addButton('btn1','Restart',$_SERVER['PHP_SELF'].'?restart=1');
  52.  
  53. // Adds stop button as label 'btn2' with action 'stop=1'
  54. $pbl->addButton('btn2','Stop',$_SERVER['PHP_SELF'].'?stop=1');
  55. // and make it right aligned with restart button (shift left 80 pixels)
  56. $pbl->setLabelAttributes('btn2', array('left' => 80));
  57.  
  58. // Show the progress bar frame
  59. $pbl->display();
  60.  
  61. if (isset($_GET['stop'])) {
  62.     $messageEnd = 'Canceled';
  63. } else {
  64.     // Processes
  65.     for($i=1; $i<=100; $i++) {
  66.         if ($i==15) {
  67.             $pbl->setLabelAttributes('txt1',
  68.                                      array('value' => 'Loading Demo')
  69.             );
  70.         }
  71.         if ($i==30) {
  72.             $pbl->setLabelAttributes('txt1',
  73.                                      array('value' => 'Scanning ...')
  74.             );
  75.         }
  76.         if ($i>50 && $i<80) {
  77.             $pbl->setLabelAttributes('txt1',
  78.                                      array('value' => 'Send Mail: '.$i.'/130')
  79.             );
  80.         }
  81.         if ($i==80) {
  82.             $pbl->setLabelAttributes('txt1',
  83.                                      array('value' => 'anything else ...')
  84.             );
  85.         }
  86.         $pbl->moveStep($i);
  87.         _sleep(100000);
  88.     }
  89.     $messageEnd = 'Completed';
  90. }
  91. // Finishs operation with final label 'txt1' text value
  92. $pbl->setLabelAttributes('txt1', array('value' => $messageEnd));
  93. ?>
  94. </body>
  95. </html>