| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2007-06-06 11:49 UTC] ar018 at yahoo dot com
 Description:
------------
System: Kubuntu Feisty, libnewt0.52_0.52.2-8ubuntu2, 
libnewt-dev_0.52.2-8ubuntu2, php-cli 5.2.1, pecl/newt-1.1
newt_scale_set shows the scale at 100% regardless of the 
input given. Cross checked with whiptail, which uses the 
same libnewt (might be compiled statically against another 
libnewt version though - I don't know), and seen that 
whiptail's "--gauge" works as expected.
Reproduce code:
---------------
#!/usr/bin/php
<?php
newt_init(); newt_cls();
newt_centered_window(60, 9, "Please wait...");
$waitlbl = newt_label(30, 3, "");
$waitscl = newt_scale(5, 6, 50, 100);
$waitform = newt_form();
newt_form_add_components($waitform, array($waitlbl, $waitscl));
newt_form_set_timer($waitform, 1);
newt_run_form($waitform);
for ($i = 1; $i <= 100; $i++) {
    sleep(1);
    newt_label_set_text($waitlbl, $i);
    newt_scale_set($waitscl, $percent);
    newt_refresh();
}
newt_form_destroy($waitform);
newt_pop_window ();
newt_finished ();
?>
Expected result:
----------------
A window with a label and scale widget, both counting from 
0 up to 100 in sync.
Actual result:
--------------
Label widget counts up. Scale widget shows 0% at initial 
creation, but then gets stuck at 100% at the first (and 
subsequent) newt_scale_set() updates.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 03:00:01 2025 UTC | 
3rd line in the for() body needs to be corrected as: newt_scale_set($waitscl, $i); The result is the same. This err of mine revealed that it's the same for newt_scale_set() if it's been given a valid amount or null. It doesn't get/see/process the amount value passed.$ file /usr/bin/whiptail /usr/bin/whiptail: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), stripped So whiptail is using the same libnewt, then this is not a libnewt bug. The script I used to test with whiptail follows: #!/bin/bash { for ((i = 0 ; i <= 100 ; i++)); do sleep 1 echo $i done } | whiptail --gauge "Please wait" 5 50 77 As a workaround, I've written 2 functions (mewt_scale and mewt_scale_set) to mimic the originals: function mewt_scale($mewt_left, $mewt_top, $mewt_width, $mewt_full_value) { global $mewt_scale_instances; $mewt_barlen = $mewt_width - 6; $mewt_scale_this = newt_label($mewt_left, $mewt_top, "[" . str_repeat("_", $mewt_barlen) . "]% --"); $mewt_scale_instances[$mewt_scale_this] = array($mewt_left, $mewt_top, $mewt_barlen, $mewt_full_value); return $mewt_scale_this; } function mewt_scale_set($mewt_scale_this, $mewt_amount) { global $mewt_scale_instances; list($mewt_left, $mewt_top, $mewt_barlen, $mewt_full_value) = $mewt_scale_instances[$mewt_scale_this]; $mewt_amount = min(max(0, $mewt_amount), $mewt_full_value); $mewt_percent = (int) ($mewt_amount * 100.0 / $mewt_full_value + 0.5); $mewt_barfull = (int) ($mewt_barlen * $mewt_percent / 100 + 0.5); $mewt_barempty = $mewt_barlen - $mewt_barfull; $mewt_barcontent = substr("[" . str_repeat("*", $mewt_barfull) . str_repeat(" ", $mewt_barempty) . "]%" . sprintf("%3d ", $mewt_percent), 0, $mewt_barlen + 6); newt_label_set_text($mewt_scale_this, $mewt_barcontent); }Thank you for taking the time to write to us, but this is not a bug. Can't re-create. This script works pretty well: <?php newt_init(); newt_cls(); newt_centered_window(60, 9, "Please wait..."); $waitlbl = newt_label(30, 3, ""); $waitscl = newt_scale(5, 6, 50, 100); $waitform = newt_form(); newt_form_add_components($waitform, array($waitlbl, $waitscl)); newt_form_set_timer($waitform, 1); newt_run_form($waitform); for ($i = 1; $i <= 100; $i++) { usleep(100); newt_label_set_text($waitlbl, $i); newt_scale_set($waitscl, $i); newt_refresh(); } newt_form_destroy($waitform); newt_pop_window (); newt_finished (); ?>