PDA

View Full Version : zenity --progress



Firewing1
27th September 2005, 02:47 AM
Hey,
I'm using Zenity, and i'm wondering how do I use progress -- Can only some thing use it? EG of i type
yum update | zenity --progress
will it show progress or do only certain apps support Zenity?
Firewing1

Jman
29th September 2005, 12:29 AM
If you want a pretty graphical yum update use yumex.

Firewing1
29th September 2005, 02:01 AM
no that was just an example -- which apps support zenity?
Firewing1

raoul
29th September 2005, 03:20 AM
yum update | zenity --progress
will it show progress or do only certain apps support Zenity?
What would be the purpose of its existence if it was app-dependent?
There is a good example of "zenity --progress" in yelp->Desktop.

raoul
29th September 2005, 03:53 AM
Firewing1:
Just had a look at your php script for virus scanning on the other thread. I think you want to implement the progress bar to this script. Take a look at a similar script (http://www.raoul.shacknet.nu/files/scan_for_viruses.sh) of mine how I managed to do it. It's a bash script. Nothing exceptional, just a simple example that works well.

Firewing1
29th September 2005, 01:21 PM
Thanks! I just wanna know tho, when / how is it that I can make --progress work?
Firewing1

Firewing1
30th September 2005, 11:54 PM
FYI, raoul, the progress for ur script never increases. I'm trying to get it to work, but the progress bar sits at 0 until the scan's fully completed, then it jumps to 100%.
Firewing1

raoul
1st October 2005, 03:27 AM
Hmm, now I get it... The progress bar in my script increases when you scan multiple files. Actually, it's the number of files that creates the steps in which the percentage increases. Scanning 1 file takes one step to fill the bar.
I'm afraid I cannot help with what you are asking. You want the bar to increase as clamscan scans one file. This seems difficult but not impossible.
Files can be scanned like this

cat file1.zip | clamscan -
The ((amount of piped data*100)/filesize) can be used to increase the bar. But this is theory. I do not know how this can be implemented. Maybe a console expert can help...

Firewing1
1st October 2005, 04:25 AM
ok... thanks!.. but im still wondering, what makes that bar increase? a variable? in between what numbers must this variable be? plz i need to know...
Firewing1

raoul
1st October 2005, 06:25 AM
It is explained via an example in Gnome help and I use the same thing in my script. I repost it here from gnome help:

(
echo "10" ; sleep 1
echo "# Updating mail logs" ; sleep 1
echo "20" ; sleep 1
echo "# Resetting cron jobs" ; sleep 1
echo "50" ; sleep 1
echo "This line will just be ignored" ; sleep 1
echo "75" ; sleep 1
echo "# Rebooting system" ; sleep 1
echo "100" ; sleep 1
) |
zenity --progress \
--title="Update System Logs" \
--text="Scanning mail logs..." \
--percentage=0
The entire loop is piped to zenity. Zenity has an initial percentage of 0. When you "echo" a number between 1-100 from within the loop, the zenity bar is increased to this value. This value usually is a result of an arithmetic operation, so that it represents a percentage (%) of completeness of the script's operation.

I am unable to explain it any further. Below is the whole example script. Save and execute it. Try to change the 10, 20, 50, 75 values to see how it works. This script does absolutely nothing, but exhibits how the percentage is set in zenity--progress.

#!/bin/sh
(
echo "10" ; sleep 1
echo "# Updating mail logs" ; sleep 1
echo "20" ; sleep 1
echo "# Resetting cron jobs" ; sleep 1
echo "50" ; sleep 1
echo "This line will just be ignored" ; sleep 1
echo "75" ; sleep 1
echo "# Rebooting system" ; sleep 1
echo "100" ; sleep 1
) |
zenity --progress \
--title="Update System Logs" \
--text="Scanning mail logs..." \
--percentage=0

if [ "$?" = -1 ] ; then
zenity --error \
--text="Update canceled."
fi

raoul
1st October 2005, 06:31 AM
The entire loop is piped to zenity.

There is no loop actually in this example. With "loop" I meant the script's main function.

Firewing1
1st October 2005, 06:04 PM
Thanks!
Firewing1