LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 09-24-2007, 03:07 AM   #1
Joydeep Bakshi
Member
 
Registered: May 2007
Distribution: debian
Posts: 62

Rep: Reputation: 15
Question how to design progress meter with dialog mox


Dear all,

I am writing a shell-script which will be a frontend of cdrecord and mkisofs. I am at the end of the script but I can't really solve one typical issue.

I like to make a progress indicator which will show the progress level during the burning process. I really can't under stand how to do it.
Could any kind soul please help me ?
thanks in advanced.
 
Old 09-24-2007, 03:12 AM   #2
Joydeep Bakshi
Member
 
Registered: May 2007
Distribution: debian
Posts: 62

Original Poster
Rep: Reputation: 15
Sorry for type mistake :-(
it would be "dialog box" not "dialog mox"
Sorry
 
Old 09-24-2007, 09:30 AM   #3
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,750

Rep: Reputation: 462Reputation: 462Reputation: 462Reputation: 462Reputation: 462
Have a look at this thread where we discussed this not long ago:
http://www.linuxquestions.org/questi...t=progress+bar

There are several similar solutions there.
 
Old 09-25-2007, 12:43 AM   #4
Joydeep Bakshi
Member
 
Registered: May 2007
Distribution: debian
Posts: 62

Original Poster
Rep: Reputation: 15
THANKS a lot for pointing out. Thanks once more for your kind response.
 
Old 09-25-2007, 02:47 AM   #5
Joydeep Bakshi
Member
 
Registered: May 2007
Distribution: debian
Posts: 62

Original Poster
Rep: Reputation: 15
I have visited the links. I must admit that programmers has done some good job by desiging progress bar with shell script. But I am looking a solution which allow me to use the gauge option of dialog box to design progress bar. could any one show me the way of doing that for say cdrecord ?
thanks for your time
 
Old 09-25-2007, 04:15 AM   #6
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,750

Rep: Reputation: 462Reputation: 462Reputation: 462Reputation: 462Reputation: 462
Which dialog box?
Search this forum for answers as this has also been discussed -using dialog, Xdialog , zenity and others. The trouble is that for most you will need a way to estimate how long a process is going to take so that you can feed the percentage already completed into the dialog progress bar. Notice that some of these tools have a similar function called a gauge which doesn't work the same way. Most methods for determining the time needed to do a job will consume more CPU cycles than the work itself, so a simple bar that just fills the space and then starts over, or goes back and forth from one side to the other is gonna be the simplest (like the one suggested by /bin/bash in the thread I linked to).
You should be able to use some of the code given in the thread to make the job easier -once you figure out which dialog-box tool you are going to use.
 
Old 09-25-2007, 04:45 AM   #7
Joydeep Bakshi
Member
 
Registered: May 2007
Distribution: debian
Posts: 62

Original Poster
Rep: Reputation: 15
Thanks for you clarification. I am talking about the dialog command available in linux. Generally you can find that shell scripts use "dialog" to make CLI frontend. I have designed a shell script which is based on cdrecord and msinfo to do a number of cd writing/erasing.. etc.
Now I like to make a simple progress bar with the gauge option already available in "dialog" box command in linux. But I really don't know how to implement it. where the linked mentioned by tou are really helpful. Specially the "bar" script is doing the job which I like to implement with the help of "dialog --gauge.." but "bar" script has the option to work with a command. For example I have tried

bar -c "cdrecord -dev=ATAPI:0,0,0 blank=all -speed=42 2>/dev/null 1>/dev/null"

and it is showing a clean pregress bar :-) I am trying to do the same with gauge option of "dialog" command but not succeeded yet :-( If you need any more clarification please ask me.
 
Old 09-25-2007, 10:30 AM   #8
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,750

Rep: Reputation: 462Reputation: 462Reputation: 462Reputation: 462Reputation: 462
If you are using dialog, the best examples are available from the Xdialog program which uses nearly exactly the same syntax. There are also good examples of using dialog from any of the Slackware utilities or installer.
Here's an example from the Xdialog program for using the gauge widget. You should be able to use it with dialog by just changing the Xdialog to dialog:

Code:
#!/bin/sh
DIALOG=Xdialog

(
echo "10" ; sleep 1
echo "XXX" ; echo "The new" ; echo "\\n" ; echo "message"; echo "XXX"
echo "20" ; sleep 1
echo "50" ; sleep 1
echo "75" ; sleep 1
echo "100" ; sleep 1
) |
$DIALOG --title "GAUGE" --gauge "Hi, this is a gauge widget" 8 30

if [ "$?" = 255 ] ; then
	echo ""
	echo "Box closed !"
fi
Hopefully, the exampleso of shell-only progress bars from the thread will help you to find a way to measure and pace the progress of the process. My example of using a while loop gives a chance to check the amount of work completed, or when you reach 100 percent in the above example just reset to 10 and let the gauge run that way until finished.
As I said, finding a way to estimate the time needed to do the job and scaling that to percentages is really the hard part -you must take into account differing screen or terminal widths and differing process speeds(what takes 30 seconds on your machine might take a minute on mine...)
Notice that first part of this example is where the percentage gets set and then it is piped into dialog itself.

Here's another example from Xdialog which uses the progress bar:

Code:
#!/bin/sh

# Formats a 1440Kb DOS floppy disk.

TITLE="HD floppy DOS format"

# Change the following variable to suit your system:
DEVICE="/dev/fd0u1440"
MAX_TRACK=79
# This changes depending on your language...
FDFORMAT_MSG_LENGTH=87

fdformat -n $DEVICE | \
Xdialog --title "$TITLE" --no-close \
	--progress "Please wait while low-level formatting...\n\n" 0 0 \
	$MAX_TRACK $FDFORMAT_MSG_LENGTH

( mkdosfs $DEVICE 2>/dev/null ; echo "XXXX" ) |
Xdialog --title "$TITLE" --no-close --no-buttons \
	--infobox "Making the DOS filesystem..." 0 0 0

Xdialog --title "$TITLE" --msgbox "All done !" 0 0
Note that for the progress bar to work, it needs input which prints a character at intervals -like programs which print out dots until finished, so you have to include some code which will generate these characters, if the program you are tracking does not do so.
 
Old 09-26-2007, 12:09 AM   #9
Joydeep Bakshi
Member
 
Registered: May 2007
Distribution: debian
Posts: 62

Original Poster
Rep: Reputation: 15
Thanks for the codes. As I can understand that the first code which is showing the progressbar after some intervals initiated by sleep command is for demo purpose. The second one for formatting a floppy is a real life example for showing the purpose of dialog --gauge.
But as you have also indicated that a program is required to show the dots or any other character to actually show the progress. I think "bar" command is the most efficient tool for progress bar. It also has the option to work with commands. Like I have successfully used

bar -c "cdrecord -dev=ATAPI:0,0,0 blank=all -speed=42 2>/dev/null 1>/dev/null"

Is there any way around to use bar with dialog command to design a progress bar ?
obviously in this case we don't need the -gauge option any more. But how to display the output of bar command through a nice looking dialog window ?

thanks so far for pointing out "bar" and the codes and your kind response.
 
Old 09-26-2007, 02:41 AM   #10
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,750

Rep: Reputation: 462Reputation: 462Reputation: 462Reputation: 462Reputation: 462
Have a look at the code for bar and figure out how to pipe the output of it's timing mechanism into dialog.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Linux for Graphic Design, web design, and publishing maelstrom209 Linux - Software 8 07-17-2011 11:35 AM
Download Meter CarnageBox Linux - Newbie 6 12-19-2004 10:59 AM
Dialog GAUGE - How to display progress of compile? broken pipe problem? laikos Programming 3 07-03-2004 07:08 PM
Battery Meter uveraser Linux - Laptop and Netbook 3 06-22-2004 07:09 AM
Battery Meter klfreese Red Hat 5 09-01-2003 06:59 PM


All times are GMT -5. The time now is 08:32 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration