LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-14-2011, 03:32 AM   #1
mard0
LQ Newbie
 
Registered: Mar 2011
Distribution: Debian Squeeze
Posts: 11

Rep: Reputation: 0
Zenity progress bar


Hi i am busy writing this script to get a pixel count of a large batch of images in a directory for a research project. To do this i'm using a loop to get all the images in the directory. To make the whole procedure more user friendly for some colleagues i decided to use zenity, something i haven't yet really worked with.

As not to make sure that the users dont have to watch to this blank screen during the actual processing of the images i'm trying to get the zenity progress bar working. So far the progress bar comes up but instead of changing over time it stays "empty" till all the images are processed and then becomes 100% when all images are done. What servers my needs for now, but since im trying to learn more about zenity i was wondering how i could change the script to get the progress bar propery working? Below is the piece of script im talking about.

Code:
cd $input #goto path of image directory
(for a in *jpg *JPG *jpeg *JPEG; do 
  if [ -f "$a" ]; then #was it a image file
    b="$a" #set b to $a
    convert -resize 1000x1000\! ${b} -depth 1 -format %c histogram:info:$b.txt #get pixelcount and write to .txt file
  fi
done) | zenity --progress
Thanks, Mardo
 
Old 04-14-2011, 08:22 AM   #2
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Where are you piping the percentage into Zenity?

How do you think it will know when the loop loops and how many times it will loop?

Here's an example:

Code:
i=0
(while [ $((i <= 100)) '=' 1 ]
do
    echo $i
    sleep 1
    i=$((i + 5))
done) | zenity --progress --auto-close
Basically, whenever you want to change the value of the slider, pipe the percentage value plus a newline into Zenity's stdin.

EDIT: unrelated note: You should use "*.jpg" instead of "*jpg". What if you have a file with no extension that happens to end in "jpg"?

Last edited by MTK358; 04-14-2011 at 09:15 AM.
 
1 members found this post helpful.
Old 04-14-2011, 04:25 PM   #3
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 386

Rep: Reputation: 43
You should be able to get the percentage to increment just by setting the initial percentage value to 0. Below is a sample from a bulk file renaming script I use on a daily basis. You can also leave out the --percentage attribute and use --pulsate if you just want an ongoing indicator to pulse back and forth until the entire process is complete.

Code:
(for file in *.$mask
do
    # Code that processes files
    ...
done)|
        zenity --progress --auto-close --title="Renaming Files"  \
               --text="Processing files ..."  --percentage=0
 
Old 09-22-2012, 02:19 PM   #4
jayboe
LQ Newbie
 
Registered: Nov 2011
Posts: 6

Rep: Reputation: Disabled
Quote:
Originally Posted by MTK358 View Post
Where are you piping the percentage into Zenity?

How do you think it will know when the loop loops and how many times it will loop?

Here's an example:

Code:
i=0
(while [ $((i <= 100)) '=' 1 ]
do
    echo $i
    sleep 1
    i=$((i + 5))
done) | zenity --progress --auto-close
Basically, whenever you want to change the value of the slider, pipe the percentage value plus a newline into Zenity's stdin.

EDIT: unrelated note: You should use "*.jpg" instead of "*jpg". What if you have a file with no extension that happens to end in "jpg"?

I was using the shred command on some larger files and the progress prompt was long gone before it finished. Maybe need to implement a file size solution. Thanks anyway, it gives a noob like me something to play with.

Last edited by jayboe; 09-22-2012 at 03:09 PM. Reason: update
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mv with progress bar gbowden Linux - General 28 08-14-2013 04:42 AM
converting a for loop to an array so zenity can give progress wonderfullyrich Programming 2 03-01-2012 08:58 AM
cp progress bar edwardsiow Linux - General 26 09-04-2011 08:53 AM
Problem with combining bash with zenity --progress chii-chan Programming 2 05-06-2005 03:12 AM
Progress Bar zael Programming 3 10-01-2003 12:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration