A complete zenity dialog examples 2
April 22nd, 2007 mysurface Posted in X11, lsof, tee, zenity | Hits: 39735 |
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

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.

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

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

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

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

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

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]
Live Chat!









April 22nd, 2007 at 5:48 pm
[...] Check out A complete zenity dialog examples 2. Related Posts A complete zenity dialog examples 2This is a continues post of A complete zenity dialog examples 1, in this post we will covers zenity dialog for progress,… using GUI dialog boxEvery GUI program has its command line, even dialog boxes too. zenity for gnome, kdialog for KDE, xmessage for other win… windows user access ssh through puttyPutty is a great ssh client for windows user, it is easy to use and lightweight too. Do you expect to see a tutorial or … [...]
April 24th, 2007 at 2:42 pm
Hello
This is a very useful information, I was searching the web 2days to get such information. Exellent
April 25th, 2007 at 8:04 pm
Anothr feed track -Linux by Examples…
One new subscriber from Anothr Alerts…
April 26th, 2007 at 11:28 pm
Nice tutorial guide for on zenity :)
It’s a nice tutorial..Zenity can also be used to transfer your bash script into gui front-end, for example i used zenity to run my campus local repo on top of https :)
Check out here http://y0nd13.blogspot.com/2007/04/what-heck.html
August 29th, 2007 at 1:15 am
The example for the progress dialog could be better. Rather than copping out with the –pulsate option, it would’ve been nice to see how you actually get it to track a job.
Good stuff, otherwise.
September 15th, 2007 at 4:23 am
To send progress you send percentage numbers. The following is an example (all on one line, of course).
(for ((i=0;i<100;i+=4)) ; do echo $i ; sleep 1; done) | zenity –progress –auto-close
In scripts I often create a function and generate the progress values from the function, redirecting the output. Another simple example.
function pro () {
read -p “Question 1″
echo “25″
read -p “Question 2″
echo “50″
read -p “Question 3″
echo “75″
read -p “Question 4″
echo “100″
}
pro | zenity –progress –auto-close
[edited by mysurface]
September 15th, 2007 at 4:25 am
Hmm… Trimmed my last comment because of the less-than. Let’s try this again!
(for ((i=0;i<100;i+=4)) ; do echo $i ; sleep 1; done) | zenity –progress –auto-close
September 15th, 2007 at 6:59 am
Thanks Stacy, very informative. I like the function pro(), make good use of zenity progressing dialog.
December 31st, 2007 at 11:48 am
[...] is here A complete zenity dialog examples 1Â & A complete zenity dialog examples 2. 2007-12-31 11:48 by admin, Filed under:Linux No Comments [...]