Friday, June 14, 2013

GTK+ dialogs in Shell Scripting


I had written a blog previously what shell scripting programming is all about and I had also written about my project(i.e. Package Installer) created in shell scripting as back-end and zenity as front-end for GUI.

Now, in this blog I am going to focus on zenity only, as I consider that you all had read my both blogs, so no need to talk on those two topics.

What is Zenity?

Zenity was written by Glynn Foster <glynn.foster@sun.com>. Zenity is a program that will help you to create GTK+ dialogs in shell scripting, for example if you type following command on your Linux Terminal then it will open a calendar with GUI.

zenity --calender [ 1 ]

Fig : 01
As you can see you can select date as you wish and after click on OK button it will return date as (for example)“Friday 14 June 2013” on terminal or you can save this date into the variable and you can use it in your program as per your program requirement.

Zenity provides many options as you can see one above. For example when you use zenity --question command then you can see following dialog, this dialog provides you two buttons that is YES and NO. When you press any one, it will return 0, 1 or 5. It will return 0 for NO, 1 for YES or 5 if timeout has been reached. Now question is how to check the returns codes, it's actually a quite easy task, you have to use '$?' command immediately after 'zenity –-question'.
Fig : 02
 
In fact zenity provides many ways to create your own GTK+ dialogs as you want to create. Just you have to follow rules of options provided by zenity program. To read more information about zenity program you can type 'man zenity' on your Linux terminal. Zenity programs also provide sub options for particular dialogs, like you can change the text, colour, height, width etc.

Type following commands on your Linux terminal as it is, you can see this commands also by using 'man zenity'.

zenity --title="Select a file to remove" –file-selection [2]


zenity --title "Select Host" --entry --text "Select the host
you would like to flood-ping" [3]

zenity --question --title "Alert" --text "Microsoft Windows
has been found! Would you like to remove it?" [4]

zenity --list --checklist --column "Buy" --column "Item" TRUE [5]

No comments:

Post a Comment