VMultiProgressMeter, HMultiProgressMeter — Progress bar with multiple segments (optional widget)
VMultiProgressMeter
( |
List<integer>
maxValues
) ; |
HMultiProgressMeter
( |
List<integer>
maxValues
) ; |
A vertical (VMultiProgressMeter) or horizontal (HMultiProgressMeter) progress display with multiple segments. The numbers passed on widget creation are the maximum numbers of each individual segment. Segments sizes will be displayed proportionally to these numbers.
This widget is intended for applications like showing the progress of installing from multiple CDs while giving the user a hint how much will be installed from each individual CD.
Set actual values later with UI::ChangeWidget(`id(...), `Values, [ 1, 2, ...] );
The widget may choose to reserve a minimum amount of space for each segment even if that means that some segments will be shown slightly out of proportion.
![]() | Note |
---|---|
This is a "special" widget, i.e. not all UIs necessarily support it. Check for availability with |
if ( HasSpecialWidget( `MultiProgressMeter ) {... `MultiProgressMeter( "Percentage", 1, 100, 50 )
// Simple example for MultiProgressMeter { if ( ! UI::HasSpecialWidget(`HMultiProgressMeter ) ) { UI::OpenDialog( `VBox( `Label("Error: This UI doesn't support the MultiProgressMeter widget!"), `PushButton(`opt(`default), "&OK") ) ); UI::UserInput(); UI::CloseDialog(); return; } UI::OpenDialog( `VBox( `VMultiProgressMeter(`id(`prog), [ 1000, 200, 500, 20, 100 ] ), `PushButton(`opt(`default), "&Ok" ) ) ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 100, 0, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 200, 0, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 300, 0, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 400, 0, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 500, 0, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 600, 0, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 700, 0, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 800, 0, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 900, 0, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 0, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 50, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 100, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 150, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 200, 0, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 200, 100, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 200, 200, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 200, 300, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 200, 400, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 200, 500, 0, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 200, 500, 10, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 200, 500, 20, 0 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 200, 500, 20, 20 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 200, 500, 20, 40 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 200, 500, 20, 80 ] ); UI::UserInput(); UI::ChangeWidget(`prog, `Values, [ 1000, 200, 500, 20, 100 ] ); UI::UserInput(); UI::UserInput(); UI::CloseDialog(); }
// // Advanced MultiProgressMeter example: // Change values interactively with sliders // and allow tests with huge numbers // { // // Global variables // list<integer> maxValueList = [ 950, 200, 500, 20, 100 ]; list<integer> valueList = [ 100, 30, 400, 0, 0 ]; integer unit = 0; // exponent: powers of 2 /** * Return a VBox term with Slider widgets for each list value. **/ term slidersVBox( list<integer> maxValuesList, list<integer> currentValuesList ) { term vbox = `VBox(); integer i=0; foreach ( integer maxVal, maxValuesList, { vbox = add( vbox, `Slider(`id(`slider(i) ), `opt(`notify), "", // label 0, // minVal maxVal, currentValuesList[i]:0 // currentVal ) ); i = i+1; }); return vbox; } /** * Apply unit to a list of values. Return the scaled list. **/ list<integer> scaleList( integer unit, list<integer> values ) { list<integer> scaledValues = []; foreach ( integer val, values, { scaledValues = add( scaledValues, val << unit ); }); // y2debug( "Values: %1 unit: %2 scaled: %3", values, unit, scaledValues ); return scaledValues; } /** * Get the current values from all sliders and return them as a list. **/ list<integer> getValues() { list<integer> values = []; integer i = 0; while ( true ) { term sliderID = `slider(i); // y2debug( "Looking for %1", sliderID ); if ( ! UI::WidgetExists(`id( sliderID) ) ) break; values = add( values, (integer) UI::QueryWidget(`id(sliderID), `Value ) ); i = i+1; } // y2debug( "Values: %1", values ); return values; } /** * Update progress meters with values from sliders. **/ void updateProgress() { list<integer> values = scaleList( unit, getValues() ); UI::ChangeWidget(`vProgress, `Values, values ); UI::ChangeWidget(`hProgress, `Values, values ); } // // Check if required special widgets are available // if ( ! UI::HasSpecialWidget(`HMultiProgressMeter ) || ! UI::HasSpecialWidget(`Slider ) ) { UI::OpenDialog( `VBox( `Label("Error: This UI doesn't support the required widgets!"), `PushButton(`opt(`default), "&OK") ) ); UI::UserInput(); UI::CloseDialog(); return; } // // Create dialog // term radioBox = `Frame( "Unit", `RadioButtonGroup(`id(`unit), `opt(`notify), `HBox( `HSpacing(0.5), `RadioButton(`id(`unit( 0)), `opt(`notify), "&Bytes"), `HSpacing(1.5), `RadioButton(`id(`unit(10)), `opt(`notify), "&kB"), `HSpacing(1.5), `RadioButton(`id(`unit(20)), `opt(`notify), "&MB"), `HSpacing(1.5), `RadioButton(`id(`unit(30)), `opt(`notify), "&GB"), `HSpacing(0.5) ) ) ); UI::OpenDialog( `VBox( `HBox( `VBox( `Heading( "MultiProgressMeter Example" ), `VSpacing( 1 ), slidersVBox( maxValueList, valueList ), radioBox, `VStretch() ), `HSpacing( 1 ), `ReplacePoint(`id(`rep_vProgress), `VMultiProgressMeter(`id(`vProgress), scaleList( unit, maxValueList ) ) ) ), `HBox( `ReplacePoint(`id(`rep_hProgress), `HMultiProgressMeter(`id(`hProgress), scaleList( unit, maxValueList ) ) ), `HSpacing( 0.5 ), `PushButton(`id(`cancel), "&Close" ) ) ) ); UI::ChangeWidget(`id(`unit), `Value, `unit( unit ) ); updateProgress(); // // Event loop // while ( true ) { map<string, any> event = UI::WaitForEvent(); // y2debug( "Event: %1", event ); any id = event["ID"]:nil; symbol widgetClass = (symbol) event["WidgetClass"]:nil; if ( widgetClass == `RadioButton ) { any currentUnitID = UI::QueryWidget(`unit, `CurrentButton ); if ( is( currentUnitID, term ) ) { unit = ( (term) currentUnitID )[0]:0; y2milestone( "New unit: 2^%1", unit ); UI::ReplaceWidget(`rep_vProgress, `VMultiProgressMeter(`id(`vProgress), scaleList( unit, maxValueList ) ) ); UI::ReplaceWidget(`rep_hProgress, `HMultiProgressMeter(`id(`hProgress), scaleList( unit, maxValueList ) ) ); updateProgress(); } } if ( widgetClass == `Slider ) { updateProgress(); list<integer> values = scaleList( unit, getValues() ); UI::ChangeWidget(`vProgress, `Values, values ); UI::ChangeWidget(`hProgress, `Values, values ); } if ( id == `cancel ) break; } // // Clean up // UI::CloseDialog(); }