Zenity Help???

FreedomPay

Member
Joined
Aug 23, 2009
Messages
161
Reaction score
0
Hi Bro/Sis,

i dun know if it's the right forum to post this. Can anyone advise me ?

Regards
FreedomPay
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
Hi Bro/Sis,

i dun know if it's the right forum to post this. Can anyone advise me ?

Regards
FreedomPay

If it's a programming and development problem, I suppose EDMW is the best place.

Oh come on, is the title of the forum not obvious enough ? :)

Shoot !

So it seems Zenity is the X11 cousin of Dialog, so what would you like to know ?
 
Last edited:

FreedomPay

Member
Joined
Aug 23, 2009
Messages
161
Reaction score
0
If it's a programming and development problem, I suppose EDMW is the best place.

Oh come on, is the title of the forum not obvious enough ? :)

Shoot !

So it seems Zenity is the X11 cousin of Dialog, so what would you like to know ?


I am doing an assignment on Linux scripting using Bin/bash etc.However, the lecture mention that if we use Zenity to complete the assignment, we will get higher mark. ( fyip, I have not learn how to use Zenity ) . I tried google and i dun know how to link them together and called them out. I tried using like -> ./name.sh but cant work.


Regards
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
I am doing an assignment on Linux scripting using Bin/bash etc.However, the lecture mention that if we use Zenity to complete the assignment, we will get higher mark. ( fyip, I have not learn how to use Zenity ) . I tried google and i dun know how to link them together and called them out. I tried using like -> ./name.sh but cant work.


Regards

Zenity is very easy to use. Please refer to the manual found at
https://help.gnome.org/users/zenity/stable/

Depending on which dialog you invoke in your script, the interface to interact with it is different.

But based on https://help.gnome.org/users/zenity/stable/usage.html.en, you are expected to understand the exit code of the zenity program and react as accordingly.

After you have installed zenity into your system, you can easily invoke it by typing the program name on the command line like this

dvr76q.png


If you choose a date and click "OK", you get the following output like this
261m0m1.png


If you click "CANCEL", you get the last output shown in the console
2qwkcab.png


The actual command given is
Code:
zenity --calendar; echo $?

Hence the first line shown on the screen is the standard out of "zenity --calendar". The second line after the date(if any), is the exit code of the zenity program using "echo $?"

Standard output and exit code are part and parcel of all unix system interaction between processes in unix system.

You are using a shell(probably bash) and it is a program. When you type a unix command or program to execute, the shell spawn new process to run the program and attach the standard out of the program to be displayed onto the screen. After a program is executed, you can always use "$?" to retrieve the exit code of the last program just ran within the same shell.

However there are other ways of obtaining the exit code of any program too, using conditional blocks such as "if" as such

Code:
if zenity --calendar; then echo "SUCCESS"; fi

What the above command does is if the exit code of executing the command "zenity --calendar" equals ZERO(0) which is TRUE in shell script, then SUCCESS will be echo(displayed) on the display. Any non-zero exit code in unix processes is normally interpreted as an error (unless otherwise stated by the program.

However the program with the above program is you can't do much except display it only. What you really want is to capture the standard out of the zenity program and use it for processing. So watch below

Code:
davidktw@Locutus:~$ DATE=`zenity --calendar`; if [ $? -eq 0 ]; then echo SUCCESSFULLY RETRIEVE THE DATE $DATE; else echo NO DATE FOUND; fi
SUCCESSFULLY RETRIEVE THE DATE 25/07/2014
davidktw@Locutus:~$ DATE=`zenity --calendar`; if [ $? -eq 0 ]; then echo SUCCESSFULLY RETRIEVE THE DATE $DATE; else echo NO DATE FOUND; fi
NO DATE FOUND
davidktw@Locutus:~$

The first run, I click on OK and hence I capture the date into a variable called "DATE" and since $? return me the last exit code of command run, if it equals to zero, I will echo out a string combine with the $DATE variable content. If the exit code is non-zero, I deem it as an error and instead echo "NO DATE FOUND", as shown in the 2nd command
 

ykgoh

Master Member
Joined
Jan 1, 2000
Messages
2,782
Reaction score
0
fwah, jin high tech sia. I old uncle last time did bash scripting only got text output and command line nia.

Now bash shell got GUI. :eek:
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
fwah, jin high tech sia. I old uncle last time did bash scripting only got text output and command line nia.

Now bash shell got GUI. :eek:

Didn't you get to use "dialog" in the past ? :) This is just the GTK(X11) version of it with some more helpers. "dialog" is the ncurses text-mode ancestor version
 

ykgoh

Master Member
Joined
Jan 1, 2000
Messages
2,782
Reaction score
0
Didn't you get to use "dialog" in the past ? :) This is just the GTK(X11) version of it with some more helpers. "dialog" is the ncurses text-mode ancestor version

During my time, when the schools taught courses using Solaris or Redhat Linux, all boot into text mode. White text on black background like MSDOS. No X11. :(

Text editors? vi, emacs, nano or pico.
Email client? Pine or mail.
Web browser? Lynx.

Oh just to add after researching on dialog, it wasn't introduced by my lecturers so I wasn't aware such an application exists for ncurses in text mode. However, I believe some Linux installers (e.g. Archlinux and maybe earlier versions of RedHat/Fedora) are using it to build simple text UIs.
 
Last edited:
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top