Sunday, September 13, 2009

[Level 2] Shell Interactive With Zenity Episode 8 -- scale

If you want to let user to set the scale, you can use the option ""--scale" to show a scale diagram. The synopsis as below:

SYNOPSIS
     zenity  --scale  [--title=title]  [--window-icon=path]   [--width=width]   [--height=height]   [--timeout=seconds]   [--text=text]  [--value=number]  [--min-value=number]   [--max-value=number]   [--step=number]  [--print-partial]  [--hide-value]

Just like "--calendar", if you press "ESC" key or click button "Cancel", the return code will be "1". If you select one option and click "OK", zenity will response the option and return the code will be "0". And also the same effect about the options "--title", "--timeout"...etc, for saving your time, please refer to the previous post "[Level 2] Shell Interactive With Zenity Episode 1 -- calendar", too.
The fist command that you can try is "zenity --scale", When user poll the bar and click button "OK" , then the terminal will return the value that user choose.
# zenity --scale
64
#

If you want the scale diagram has a default value, you can use the option "--value". Ex.
# zenity --scale --value=60
If you want to set the scale diagram max value and min value, you can use the option "--max-value" and "--min-value". Ex.
# zenity --scale --max-value=60 --min-value=30
Value out of range.
#
But maybe you will see the error return like above. Why? That's because the scale default value is "0", and the value "0" is out of your range. So you have to assign the default value between 30 and 60. Ex.
# zenity --scale --max-value=60 --min-value=30 --value=45

 If you want to control the steps when user uses the "left arrow" or "right arrow" key, you can use the option "--step". Ex.
# zenity --scale --step=5
If you want the terminal show every step that user change the value, you can use the option "--print-partial". Ex.
# zenity --scale --print-partial
30

60
60

#
The second "60" shows up, because the user click the button "OK".

If you  don't want to show the "value", while user poll the bar, you can use the option "--hide-value". Ex.
# zenity --scale --hide-value

Wish this helps.

regards,
Stanley Huang