part2-progresshandler.pkg

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PKG 代码 · 共 117 行

PKG
117
字号

<refentry id="{@id}">

 <refnamediv>
  <refname>Progress Handler </refname>
  <refpurpose>how to control your progress meter </refpurpose>
 </refnamediv>

 <para>
  You have a long task to execute, and you want to display a progress meter that show the
  progress of the task. How can you do it ? 
 </para>
 <para>
  There are two main way: 
  <orderedlist>
   <listitem>your task is master and the progress meter is slave (never use a progress callback) </listitem>
   <listitem>your task is slave and the progress meter is master (use a progress callback) </listitem>
  </orderedlist>
 </para>

 {@toc}

 <refsect1 id="{@id without-progress-callback}">
  <title>Without Progress callback</title>
  <para>
   Goal of this example is to simulate packages download (user task). Here is a screenshot
   of what we will produces :
   <para><graphic fileref="../media/screenshots/scratch22.png"/></para>
   <para>
   On left frame we find a form used to select what package the user want to download.
   On right frame we show an horizontal progress bar with results of download process. 
   </para>
   <example><title>Code listing 2.2: a package select-download demonstration</title>
    {@example listing-2.2.html}
   </example>
   <para>
    Here is the main page: a frameset which contains the two frames : 
    Left (see code listing 2.2.1) and 
    Right (see code listing 2.2.2).
   </para>
   <example><title>Code listing 2.2.1: a package selection</title>
    {@example listing-2.2.1.php}
   </example>
   <para>
    The form that allows to select what package to download, was built with help 
    of {@link http://pear.php.net/package/HTML_QuickForm PEAR::HTML_QuickForm} package. 
    If you don't know it, i suggest you to read the
    {@link http://pear.php.net/manual/en/package.html.html-quickform.php QuickForm Manual} 
    on PEAR website.
   </para>
   <para>
    Let's consider now the important lines in this script:
    <para>
     <emphasis>Line 4</emphasis>, the form target is the right frame 
     (meter: see line 17 of code listing 2.2). 
     That will allows results of lines 23 thru 47 to be display in the good place.
    </para>
    <para>
     <emphasis>Line 21</emphasis>, the form is validate. 
     Next (<emphasis>line 25</emphasis>) we extract data to know your package-selection. 
    </para>
    <para>
     On <emphasis>lines 29 to 41</emphasis>, we find the master process: download simulation. 
     If we have a real download operation, it should replace the sleep function at line 34.
     <emphasis>Lines 31 and 32</emphasis> prepare the result of operation which is given at line 36.
    </para>
    <para>
     <emphasis>Line 38</emphasis> we compute the next value of the progress bar. 
     We make changes at <emphasis>line 39</emphasis> 
     and refresh the progress bar at <emphasis>line 40</emphasis>.
    </para>
   </para>
   <example><title>Code listing 2.2.2: slave-progress pattern</title>
    {@example listing-2.2.2.php}
   </example>
   <para>
    There are not so many changes on this script since {@tutorial part2-firstprogressmeter.pkg}.
    You may notice at least four important differences.
    <itemizedlist>
     <listitem>No need to slow progress bar animation with {@tutorial progress.setanimspeed.pkg} </listitem>
     <listitem>The progress bar has 20 cells long rather than 10 (line 7) </listitem>
     <listitem>We use W3C doctype lines 16 to 20 to avoid IE box model break rules, 
      because we have choosen to display a progress bar with a border (line 8).</listitem>
     <listitem>The cells got a new layout (lines 9 to 14) </listitem>
    </itemizedlist>
   </para>
  </para>
 </refsect1>

 <refsect1 id="{@id wit-progress-callback}">
  <title>Use a Progress callback</title>
  <para>
   Sometimes you can't immediately determine the length of a long-running task.
   Goal of this example is to display a progress meter in indeterminate mode 
   (while you determines the length of the task), and then switch back in determinate mode 
   to finish the works.
  </para>
  <example><title>Code listing 2.3: master-progress pattern</title>
   {@example listing-2.3.php}
  </example>
  <para>
   The user callback 'myProgressHandler' defined on <emphasis>lines 4 thru 30</emphasis>,
   present the user-task. We informs HTML_Progress at <emphasis>line 50</emphasis> to use
   this user callback.
  </para>
  <para>
   The progress meter will run in indeterminate mode for 3 full loops (equivalent to 300%).
   This rule is given at <emphasis>line 24</emphasis>.
  </para>
  <para>
   Process go back in determinate mode at <emphasis>line 25</emphasis>.
   Next (<emphasis>lines 26 and 27</emphasis>) we finish the works with a standard behavior.
  </para>
 </refsect1>

</refentry>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?