[Level 2] Shell Interactive With Zenity Episode 4 -- file-selection

Does zenity provide the file/directory GUI? Yes, you can use the option "--file-selection". The command synopsis as following:

SYNOPSIS      zenity --file-selection [--title=title] [--window-icon=path]  --width=width]  [--height=height] [--timeout=seconds]  [--filename=path]  [--multiple]  [--directory] [--save] [--separator=character] [--confirm-overwrite]

When you use the option "--file-selection", you will see a pop out screen at the directory that you run this command, like below.
# cd /etc

# zenity --file-selection


Just like "--calendar", if you press "ESC" key or click button "Cancel", the return code will be "1". If you select one file and click "OK", zenity will response the filename 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.

If you want to show a default directory when you run zenity, you can use the option "--filename". When you use "--filename=/etc/security", the start directory will be /etc; "--filename==/etc/security/", the start directory will be "/etc/security". And at this moment, the GUI can only select file, if you click directory, the zneity will enter the directory.

# zenity --file-selection --filename=/etc/security


# zenity --file-selection --filename=/etc/security/

If you want to let user to select only directory (not file), you can use the option "--directory". When you used this option, the color of filename will be grey. That means "disabled".
# zenity --file-selection --directory

if you want to let use can select more than one file, you can use the option "--multiple". After you click the button "OK", all the filenames will be responsed and be separated by the "separator" that you assigned. Ex. If you select two files "/etc/passwd" and "/etc/shadow", the response will be like below:
# zenity --file-selection --multipole -- separator=:
/etc/passwd:/etc/shadow
#


If you want to provide a file saving interface, you can use the option "--save" and "--confirm-overwrite". With option "--save", the screen will have a column for user to key the filename directly. With option "--confirm-overwrite", if user select(key in) the filename that has be already exist, zenity will pop out the confirmation screen to let user to double check again.
# zenity --save --confirm-overwrite
 
 

Wish this helps.

regards,
Stanley Huang

Comments

Popular posts from this blog

[Level 1] Rar tool for Solaris.

[Level 2] iif in Python