Quantcast
Channel: Linux by Examples » lsof
Viewing all articles
Browse latest Browse all 2

A complete zenity dialog examples 2

$
0
0

This is a continues post of A complete zenity dialog examples 1, in this post we will covers zenity dialog for progress, question, warning, scale, text info and list.

How to create zenity progress dialog?
Progress dialog is to track a progression of a routine, it can be anything, let say I want store the results list of open files (lsof) into a file call lsof.txt, and uses zenity progress to track the progression, I do this:

gksudo lsof | tee >(zenity --progress --pulsate) >lsof.txt

zenity progress dialog

I need to use tee, because without using tee, zenity will strip off my result output. Check out tee examples for more information.

How to create zenity question dialog?

zenity --question --text "Are you sure you want to shutdown?"; echo $?

As echo $? returns result 0 means user press yes, 1 means cancel.
zenity question dialog

How to create zenity warning dialog?

zenity --warning --text "This will kill, are you sure?";echo $?

zenity warning dialog

How to create zenity scale dialog?
Scale dialog allows you to set a range of number, so that user are force to pick a number within the range.

ans=$(zenity --scale --text "pick a number" --min-value=2 --max-value=100 --value=2 --step 2);echo $ans

zenity scale dialog

How to create zenity text info dialog?
Text Info can be very useful to display text out to a GUI. I use back the lsof examples, but this time I feed the results to text info box.

gksudo lsof | zenity --text-info --width 530

zenity text info dialog

As you can see, you can specified the width and height of a zenity dialog. Too bad, text info dialog do not have option to disable text wrap and specified what font to use.

How to create zenity list dialog?
List dialog is the most flexible dialog and I have spend quite sometimes to utilize the usage. As it can generate multiple columns, multiple selection, checklist, radiolist etc. checkout –help-list for more information.

This is for radiolist:

ans=$(zenity  --list  --text "Is linux.byexamples.com helpful?" --radiolist  --column "Pick" --column "Opinion" TRUE Amazing FALSE Average FALSE "Difficult to follow" FALSE "Not helpful"); echo $ans

zenity list dialog
First you need to define a columns, then feed all the list options one by one.

This is for checklist:

ans=$(zenity  --list  --text "How linux.byexamples can be improved?" --checklist  --column "Pick" --column "options" TRUE "More pictures" TRUE "More complete post" FALSE "Includes Installation guidelines" FALSE "Create a forum for question queries" --separator=":"); echo $ans

zenity list dialog

The result this time will be long and probably more than one, so you can spefify a separator to differentiate them.

[tags]GUI dialog, GTK+, GUI programming[/tags]


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images