Examples TOCexamples

Half Indeterminate and Monitor

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

 Table of contents

Introduction

This example requires :


This example will run a basic ProgressBar in indeterminate mode (with monitor) then switch back to determinate mode when reached a limit-level (internal value > 240).

Actions to switch back to determinate mode are allowed by user callback myProgressHandler defined on lines 14 to 38.

This callback is attached on progress bar at line 66 and monitor renders are defined on lines 102 to 113 (following QF rendering rules).

[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     = 100
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.  * using the Progress_Monitor V2 solution (with QF renderer).
  5.  *
  6.  * @version    $Id: half_monitor.php,v 1.3 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/monitor.php';
  13.  
  14. function myProgressHandler($progressValue, &$bar)
  15. {
  16.     global $monitor;
  17.     static $c;
  18.  
  19.     if (!isset($c)) {
  20.         $c = 0;
  21.     }
  22.     $c += 16;
  23.     $monitor->setCaption("completed $c out of 400");
  24.  
  25.     $bar->sleep();
  26.     /* rules to determine when switch back from indeterminate to determinate mode */
  27.     if ($c >= 240 && $bar->isIndeterminate()) {
  28.         $bar->setIndeterminate(false);
  29.         $bar->setString(null);           // show percent-info
  30.         $bar->setValue(0);
  31.     }
  32.     if ($bar->getPercentComplete() == 1) {
  33.         if ($bar->isIndeterminate()) {
  34.             $bar->setValue(0);
  35.         } else {
  36.             $bar->setString('');            // hide percent-info
  37.         }
  38.     }
  39. }
  40.  
  41. $monitor = new HTML_Progress_Monitor('frmMonitor',
  42.     array( 'button' => array('style' => 'width:80px;'),
  43.            'title'  => 'Progress ...' )
  44. );
  45.  
  46. // Attach a progress bar custom model
  47. $progress = new HTML_Progress();
  48. $ui = & $progress->getUI();
  49. $ui->setProgressAttributes(array(
  50.     'background-color' => '#e0e0e0'
  51. ));
  52. $ui->setStringAttributes(array(
  53.     'color'  => '#996',
  54.     'background-color' => '#CCCC99'
  55. ));
  56. $ui->setCellAttributes(array(
  57.     'active-color' => '#996'
  58. ));
  59.  
  60. $progress->setAnimSpeed(100);
  61. $progress->setIncrement(10);
  62. $progress->setStringPainted(true);     // get space for the string
  63. $progress->setString("");              // but don't paint it
  64. $progress->setIndeterminate(true);     // Progress start in indeterminate mode
  65. // your custom user process goes here !
  66. $progress->setProgressHandler('myProgressHandler');
  67.  
  68. $monitor->setProgressElement($progress);
  69. ?>
  70. <html>
  71. <head>
  72. <title>Indeterminate Mode Progress example</title>
  73. <style type="text/css">
  74. <!--
  75. .progressStatus {
  76.     color:#000000;
  77.     font-size:10px;
  78. }
  79.  
  80. body {
  81.     background-color: #444444;
  82.     color: #EEEEEE;
  83.     font-family: Verdana, Arial;
  84. }
  85.  
  86. a:visited, a:active, a:link {
  87.     color: yellow;
  88. }
  89.  
  90. <?php echo $monitor->getStyle(); ?>
  91. // -->
  92. </style>
  93. <script type="text/javascript">
  94. <!--
  95. <?php echo $monitor->getScript(); ?>
  96. //-->
  97. </script>
  98. </head>
  99. <body>
  100.  
  101. <?php
  102. $renderer =& HTML_QuickForm::defaultRenderer();
  103. $renderer->setFormTemplate('
  104. <form{attributes}>
  105.  <table width="450" border="0" cellpadding="3" cellspacing="2" bgcolor="#CCCC99">
  106.  {content}
  107.  </table>
  108. </form>
  109. ');
  110. $renderer->setHeaderTemplate('
  111.  <tr>
  112.    <td style="white-space:nowrap;background:#996;color:#ffc;" align="left" colspan="2"><b>{header}</b></td>
  113.  </tr>
  114. ');
  115. $monitor->accept($renderer);
  116.  
  117. // Display progress monitor dialog box
  118. echo $renderer->toHtml();
  119. $monitor->run();
  120. ?>
  121.  
  122. </body>
  123. </html>

[Top]